I've got the following function that I include in my views to set context 
variables.  Occasionally my templates start caching these variables, no 
matter what model my views are based on.

def set_context_vars(context, model, request=None):
    """
    Set Extra Context Variables
    """
    print 'Conext Model: %s' % model._meta.verbose_name.title()
    context['modelTitle'] = model._meta.verbose_name.title()
    context['modelTitlePlural'] = model._meta.verbose_name_plural.title()
    context['modelNamePlural'] = model._meta.verbose_name_plural.lower()
    context['modelName'] = model._meta.verbose_name.lower()
    context['modelSlug'] = slugify(model._meta.verbose_name.lower())
    context['modelSlugPlural'] = 
slugify(model._meta.verbose_name_plural.lower())
    context['modelViewCreate'] = '%s-create' % 
slugify(model._meta.verbose_name.lower())
    context['modelViewUpdate'] = '%s-update' % 
slugify(model._meta.verbose_name.lower())
    context['modelViewList'] = '%s' % 
slugify(model._meta.verbose_name_plural.lower())
    context['modelViewDelete'] = '%s-delete' % 
slugify(model._meta.verbose_name.lower())
    context['modelViewDetail'] = '%s' % 
slugify(model._meta.verbose_name.lower())
 
    # Set Permissions
    emPerms = {}
    permsModelName = model._meta.verbose_name.replace(' ', '')
    app_label = model._meta.app_label
    if request and request.user:
        if request.user.has_perm('%s.add_%s' % (app_label, permsModelName)):
            emPerms['add'] = True
        if request.user.has_perm('%s.change_%s' % (app_label, permsModelName)):
            emPerms['change'] = True
        if request.user.has_perm('%s.delete_%s' % (app_label, permsModelName)):
            emPerms['delete'] = True
    context['emPerms'] = emPerms
 
    return context

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/0rTwTj-P178J.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to