Skip to content

Commit

Permalink
moving item_type help_text function out of instance function, adding …
Browse files Browse the repository at this point in the history
…to item type views like new, list
  • Loading branch information
mikhuang committed Jul 10, 2013
1 parent 23e2f89 commit bbc42c1
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 21 deletions.
39 changes: 23 additions & 16 deletions deme_django/cms/models.py
Expand Up @@ -34,6 +34,7 @@
'Site', 'Subscription', 'TextComment', 'TextDocument',
'TextDocumentExcerpt', 'Transclusion', 'ViewerRequest',
'WebsiteContactMethod', 'all_item_types', 'get_item_type_with_name',
'get_item_type_help_text',
'ActionNotice', 'RelationActionNotice', 'DeactivateActionNotice',
'ReactivateActionNotice', 'DestroyActionNotice', 'CreateActionNotice',
'EditActionNotice', 'FixedBooleanField', 'FixedForeignKey',
Expand Down Expand Up @@ -271,22 +272,7 @@ def display_name(self, can_view_name_field=True):
return u'%s %s' % (capfirst(self.actual_item_type()._meta.verbose_name), self.pk)

def display_help_text(self):
help_text = None
breadcrumb_iter = self.actual_item_type()
while breadcrumb_iter != models.base.Model and help_text == None:
# look for help text as html doc
try:
name = breadcrumb_iter.__name__.lower()
template = loader.get_template('help_text/%s.html' % name)
help_text = template.render(Context({}))
except:
pass
breadcrumb_iter = breadcrumb_iter.__base__

if help_text == None:
if self.help_text:
return self.help_text
return help_text
return get_item_type_help_text(self.item_type_string)

def actual_item_type(self):
"""
Expand Down Expand Up @@ -2855,3 +2841,24 @@ def get_item_type_with_name(name, case_sensitive=True):
except StopIteration:
return None

def get_item_type_help_text(name):
help_text = None
item_type = get_item_type_with_name(name, False)
item_type_iter = item_type
while item_type_iter != models.base.Model and help_text == None:
# look for help text as html doc
try:
name = item_type_iter.__name__.lower()
template = loader.get_template('help_text/%s.html' % name)
help_text = template.render(Context({}))
except:
pass
try:
item_type_iter = item_type_iter.__base__
except:
break

if help_text == None:
if item_type and item_type.help_text:
return item_type.help_text
return help_text
1 change: 1 addition & 0 deletions deme_django/cms/templates/help_text/htmldocument.html
@@ -0,0 +1 @@
HTML document!! default item help text
15 changes: 10 additions & 5 deletions deme_django/cms/templates/includes/metabar_swap.html
Expand Up @@ -114,8 +114,6 @@ <h3>Help</h3>
</div>
</div>
</div>


{% else %}
<ul class="title nav navbar-nav">
<li>
Expand All @@ -129,10 +127,17 @@ <h3>Help</h3>
</li>
</ul>
<div class="content">
{% if metabar_contents %}
<h3>Help</h3>
{% if metabar_contents %}
<div class="metabar_contents">
{{ metabar_contents }}
{% endif %}
</div>
{% endif %}
{% if item_type_lower %}
<div class="help_text">
{% display_item_type_help_text item_type_lower %}
</div>
{% endif %}

</div>
{% endif %}

Expand Down
4 changes: 4 additions & 0 deletions deme_django/cms/templatetags/item_tags.py
Expand Up @@ -689,6 +689,10 @@ def metadata_item_details(parser, token):
raise template.TemplateSyntaxError, "%r takes zero arguments" % bits[0]
return ItemDetails()

@register.simple_tag
def display_item_type_help_text(item_type):
return get_item_type_help_text(item_type)


@register.simple_tag
def display_body_with_inline_transclusions(item, is_html):
Expand Down
5 changes: 5 additions & 0 deletions deme_django/cms/views.py
Expand Up @@ -385,6 +385,7 @@ def item_pubdate(self, item):
def type_newother_html(self):
self.context['action_title'] = u'New'
self.context['metabar_contents'] = u'Create a new item'
self.context['item_type_lower'] = self.accepted_item_type.__name__.lower()
sorted_item_types = sorted(all_item_types(), key=lambda x: x._meta.verbose_name_plural.lower())
all_item_types_can_create = [{'item_type': x, 'url': reverse('item_type_url', kwargs={'viewer': x.__name__.lower(), 'action': 'new'})} for x in sorted_item_types if self.cur_agent_can_global('create %s' % x.__name__)]
self.context['all_item_types_can_create'] = all_item_types_can_create
Expand All @@ -394,6 +395,7 @@ def type_newother_html(self):
def type_new_html(self, form=None):
self.context['action_title'] = u'New %s' % self.accepted_item_type._meta.verbose_name
self.context['metabar_contents'] = u'Create a new %s' % self.accepted_item_type._meta.verbose_name
self.context['item_type_lower'] = self.accepted_item_type.__name__.lower()
if not self.cur_agent_can_global('create %s' % self.accepted_item_type.__name__):
form = None
else:
Expand Down Expand Up @@ -436,6 +438,7 @@ def type_new_html(self, form=None):
def type_create_html(self):
self.require_global_ability('create %s' % self.accepted_item_type.__name__)
self.context['metabar_contents'] = u'Create a new %s' % self.accepted_item_type._meta.verbose_name
self.context['item_type_lower'] = self.accepted_item_type.__name__.lower()
form_class = self.get_form_class_for_item_type(self.accepted_item_type, True)
form = form_class(self.request.POST, self.request.FILES)
if form.is_valid():
Expand Down Expand Up @@ -562,6 +565,7 @@ def item_pubdate(self, item):

def item_copy_html(self):
self.context['action_title'] = 'Copy'
self.context['item_type_lower'] = self.accepted_item_type.__name__.lower()
self.require_global_ability('create %s' % self.accepted_item_type.__name__)
form_class = self.get_form_class_for_item_type(self.accepted_item_type, True)
fields_to_copy = []
Expand Down Expand Up @@ -598,6 +602,7 @@ def item_edit_html(self, form=None):
if edit_lock_response:
return edit_lock_response
self.context['action_title'] = 'Edit'
self.context['item_type_lower'] = self.accepted_item_type.__name__.lower()
abilities_for_item = self.permission_cache.item_abilities(self.item)
self.require_ability('edit ', self.item, wildcard_suffix=True)
if form is None:
Expand Down

0 comments on commit bbc42c1

Please sign in to comment.