| 1 | |
|---|
| 2 | """ |
|---|
| 3 | setup some "static" variables |
|---|
| 4 | """ |
|---|
| 5 | |
|---|
| 6 | from django.utils.translation import ugettext as _ |
|---|
| 7 | from django.utils.safestring import mark_safe |
|---|
| 8 | |
|---|
| 9 | from PyLucid import PYLUCID_VERSION_STRING |
|---|
| 10 | from PyLucid.tools.shortcuts import makeUnique |
|---|
| 11 | |
|---|
| 12 | from django.conf import settings |
|---|
| 13 | |
|---|
| 14 | def static(request): |
|---|
| 15 | """ |
|---|
| 16 | A django TEMPLATE_CONTEXT_PROCESSORS |
|---|
| 17 | http://www.djangoproject.com/documentation/templates_python/#writing-your-own-context-processors |
|---|
| 18 | """ |
|---|
| 19 | return { |
|---|
| 20 | "powered_by": mark_safe( |
|---|
| 21 | '<a href="http://www.pylucid.org">PyLucid v%s</a>' \ |
|---|
| 22 | % PYLUCID_VERSION_STRING |
|---|
| 23 | ), |
|---|
| 24 | # This value would be changed in index._render_cms_page(), if the |
|---|
| 25 | # plugin manager or any plugin set request.anonymous_view = False |
|---|
| 26 | "robots": "index,follow", # TODO: remove in v0.9, see: ticket:161 |
|---|
| 27 | } |
|---|
| 28 | |
|---|
| 29 | |
|---|
| 30 | def add_dynamic_context(request, context): |
|---|
| 31 | """ |
|---|
| 32 | Add some dynamic stuff into the context. |
|---|
| 33 | """ |
|---|
| 34 | URLs = context["URLs"] |
|---|
| 35 | |
|---|
| 36 | #___________________________________________________________________________ |
|---|
| 37 | |
|---|
| 38 | if hasattr(request, "user") and request.user.username != "": |
|---|
| 39 | # User is logged in |
|---|
| 40 | url = URLs.commandLink("auth", "logout") |
|---|
| 41 | txt = "%s [%s]" % (_("Log out"), request.user.username) |
|---|
| 42 | else: |
|---|
| 43 | # url = URLs.commandLink("auth", "login/?next=%s" % request.path) |
|---|
| 44 | url = URLs.commandLink("auth", "login") |
|---|
| 45 | txt = _("Log in") |
|---|
| 46 | |
|---|
| 47 | context["login_link"] = mark_safe('<a href="%s">%s</a>' % (url, txt)) |
|---|
| 48 | |
|---|
| 49 | # Put the language information into the context, if it exists. |
|---|
| 50 | # see: http://www.djangoproject.com/documentation/i18n/ |
|---|
| 51 | if hasattr(request, 'session') and 'django_language' in request.session: |
|---|
| 52 | context['django_language']=request.session['django_language'] |
|---|
| 53 | else: |
|---|
| 54 | context['django_language']='' |
|---|
| 55 | |
|---|
| 56 | |
|---|
| 57 | def add_css_tag(context, content, plugin_name, method_name): |
|---|
| 58 | """ |
|---|
| 59 | Add a unique CSS-ID and a class name defined in the settings.py |
|---|
| 60 | """ |
|---|
| 61 | id = plugin_name + u"_" + method_name |
|---|
| 62 | id = makeUnique(id, context["CSS_ID_list"]) |
|---|
| 63 | context["CSS_ID_list"].append(id) |
|---|
| 64 | class_name = getattr(settings, "CSS_PLUGIN_CLASS_NAME", "PyLucidPlugins") |
|---|
| 65 | |
|---|
| 66 | try: |
|---|
| 67 | return ( |
|---|
| 68 | u'<div class="%(c)s %(p)s" id="%(id)s">\n' |
|---|
| 69 | '%(content)s\n' |
|---|
| 70 | '</div>\n' |
|---|
| 71 | ) % { |
|---|
| 72 | "c": class_name, "p": plugin_name, "m": method_name, |
|---|
| 73 | "id": id, "content": content, |
|---|
| 74 | } |
|---|
| 75 | except UnicodeDecodeError: |
|---|
| 76 | # FIXME: In some case (with mysql_old) we have trouble here. |
|---|
| 77 | # I get this traceback on www.jensdiemer.de like this: |
|---|
| 78 | # |
|---|
| 79 | #Traceback (most recent call last): |
|---|
| 80 | #File ".../django/template/__init__.py" in render_node |
|---|
| 81 | # 750. result = node.render(context) |
|---|
| 82 | #File ".../PyLucid/defaulttags/lucidTag.py" in render |
|---|
| 83 | # 102. content = self._add_unique_div(context, content) |
|---|
| 84 | #File ".../PyLucid/defaulttags/lucidTag.py" in _add_unique_div |
|---|
| 85 | # 73. return u'<div class="%s" id="%s">\n%s\n</div>\n' % ( |
|---|
| 86 | # |
|---|
| 87 | #UnicodeDecodeError at /FH-D-sseldorf/ |
|---|
| 88 | #'ascii' codec can't decode byte 0xc3 in position 55: ordinal not in range(128) |
|---|
| 89 | # |
|---|
| 90 | #content += "UnicodeDecodeError hack active!" |
|---|
| 91 | return ( |
|---|
| 92 | '<div class="%(c)s %(p)s" id="%(id)s">\n' |
|---|
| 93 | '%(content)s\n' |
|---|
| 94 | '</div>\n' |
|---|
| 95 | ) % { |
|---|
| 96 | "c": class_name, "p": str(plugin_name), "m": str(method_name), |
|---|
| 97 | "id": str(id), "content": content, |
|---|
| 98 | } |
|---|