Skip to content

Commit

Permalink
Merge branch 'master' of github.com:rapidsms/rapidsms-core-dev
Browse files Browse the repository at this point in the history
  • Loading branch information
adammck committed Aug 27, 2010
2 parents c74e743 + b60d1d8 commit 7b7d4aa
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 46 deletions.
3 changes: 1 addition & 2 deletions lib/rapidsms/skeleton/project/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,7 @@
# this rapidsms-specific setting defines which views are linked by the
# tabbed navigation. when adding an app to INSTALLED_APPS, you may wish
# to add it here, also, to expose it in the rapidsms ui.
TABS = [
("rapidsms.views.dashboard", "Dashboard"),
RAPIDSMS_TABS = [
("rapidsms.contrib.messagelog.views.message_log", "Message Log"),
("rapidsms.contrib.registration.views.registration", "Registration"),
("rapidsms.contrib.messaging.views.messaging", "Messaging"),
Expand Down
4 changes: 2 additions & 2 deletions lib/rapidsms/templates/layout.html
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ <h1>

{% block auth %}
<div id="auth">{% if user.is_authenticated %}
<a href="/accounts/logout/">{% trans "Log out" %} {{ user.username }}</a>{% else %}
<a href="/accounts/login/">{% trans "Log in" %}</a>{% endif %}
<a href="{% url rapidsms.views.logout %}">{% trans "Log out" %} {{ user.username }}</a>{% else %}
<a href="{% url rapidsms.views.login %}">{% trans "Log in" %}</a>{% endif %}
</div>
{% endblock %}

Expand Down
2 changes: 1 addition & 1 deletion lib/rapidsms/templates/rapidsms/loggedout.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ <h1>Thanks for visiting RapidSMS!</h1>

<p>Please come again.</p>

<a href="/accounts/login">Log in again</a>
<a href="{% url rapidsms.views.login %}">Log in again</a>

{% endblock %}
50 changes: 9 additions & 41 deletions lib/rapidsms/templatetags/tabs_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,45 +15,13 @@


class Tab(object):
def __init__(self, callback, caption=None):
if isinstance(callback, basestring):
module = '.'.join(callback.split('.')[:-1])
view = callback.split('.')[-1]
self.callback = getattr(import_module(module), view)
else:
self.callback = callback
def __init__(self, view, caption=None):
self._caption = caption
self._view = None

@staticmethod
def _looks_like(a, b):
return (a.__module__ == b.__module__) and\
(a.__name__ == b.__name__)
self._view = view

def _auto_caption(self):
func_name = self.callback.__name__ # my_view
return func_name.replace("_", " ").title() # My View

@property
def view(self):
"""
Return the view of this tab.
This is a little more complex than just returning the 'callback'
attribute, since that is often wrapped (by decorators and the
such). This iterates the project's urlpatterns, to find the
real view function by name.
"""

if not self._view:
resolver = get_resolver(None)
for pattern in resolver.url_patterns:
if type(pattern) is RegexURLPattern:
if self._looks_like(self.callback, pattern.callback):
self._view = pattern.callback
break

return self._view
func_name = self._view.split('.')[-1] # my_view
return func_name.replace("_", " ").title() # My View

@property
def url(self):
Expand All @@ -64,8 +32,7 @@ def url(self):
will silently ignore the exception, and return the value of the
TEMPLATE_STRING_IF_INVALID setting.
"""

return reverse(self.view)
return reverse(self._view)

@property
def caption(self):
Expand All @@ -78,7 +45,7 @@ class TabsNode(template.Node):
def __init__(self, tabs, varname):
self.tabs = tabs
self.varname = varname

def render(self, context):
request = Variable("request").resolve(context)
for tab in self.tabs:
Expand Down Expand Up @@ -109,7 +76,8 @@ def get_tabs(parser, token):

if args[0] != "as":
raise template.TemplateSyntaxError(
'The second argument to the {%% %s %%} tag must be "as"' % (tag_name))
'The second argument to the {%% %s %%} tag must be "as"' %
(tag_name))

tabs = [Tab(callback, caption) for callback, caption in settings.TABS]
tabs = [Tab(view, caption) for view, caption in settings.RAPIDSMS_TABS]
return TabsNode(tabs, str(args[1]))

0 comments on commit 7b7d4aa

Please sign in to comment.