From: Radek Czajka Date: Thu, 11 Oct 2012 11:06:30 +0000 (+0200) Subject: Simplify forms X-Git-Url: https://git.mdrn.pl/prawokultury.git/commitdiff_plain/02164b121436ba228e7393a15aa9a5ad99f5d8f3 Simplify forms --- diff --git a/chunks/templatetags/chunks.py b/chunks/templatetags/chunks.py index ac762ad..fd24b02 100644 --- a/chunks/templatetags/chunks.py +++ b/chunks/templatetags/chunks.py @@ -7,45 +7,23 @@ from ..models import Chunk, Attachment register = template.Library() -def do_get_chunk(parser, token): - # split_contents() knows not to split quoted strings. - tokens = token.split_contents() - if len(tokens) < 2 or len(tokens) > 3: - raise template.TemplateSyntaxError, "%r tag should have either 2 or 3 arguments" % (tokens[0],) - if len(tokens) == 2: - tag_name, key = tokens - cache_time = 0 - if len(tokens) == 3: - tag_name, key, cache_time = tokens - # Check to see if the key is properly double/single quoted - if not (key[0] == key[-1] and key[0] in ('"', "'")): - raise template.TemplateSyntaxError, "%r tag's argument should be in quotes" % tag_name - # Send key without quotes and caching time - return ChunkNode(key[1:-1], cache_time) - - -class ChunkNode(template.Node): - def __init__(self, key, cache_time=0): - self.key = key - self.cache_time = cache_time - - def render(self, context): - try: - cache_key = 'chunk_' + self.key - c = cache.get(cache_key) - if c is None: - c = Chunk.objects.get(key=self.key) - cache.set(cache_key, c, int(self.cache_time)) - content = c.content - except Chunk.DoesNotExist: - n = Chunk(key=self.key) - n.save() - return '' - return content - -register.tag('chunk', do_get_chunk) +@register.simple_tag +def chunk(key, cache_time=0): + try: + cache_key = 'chunk_' + key + c = cache.get(cache_key) + if c is None: + c = Chunk.objects.get(key=key) + cache.set(cache_key, c, int(cache_time)) + content = c.content + except Chunk.DoesNotExist: + n = Chunk(key=key) + n.save() + return '' + return content +@register.simple_tag def attachment(key, cache_time=0): try: cache_key = 'attachment_' + key @@ -57,5 +35,4 @@ def attachment(key, cache_time=0): except Attachment.DoesNotExist: return '' -register.simple_tag(attachment) diff --git a/contact/forms.py b/contact/forms.py index 70a415b..4f5cf65 100644 --- a/contact/forms.py +++ b/contact/forms.py @@ -5,6 +5,7 @@ from django.core.validators import email_re from django import forms from django.template.loader import render_to_string from django.template import RequestContext +from django.utils.translation import ugettext_lazy as _ from .models import Attachment, Contact @@ -20,9 +21,13 @@ class ContactFormMeta(forms.Form.__metaclass__): class ContactForm(forms.Form): """Subclass and define some fields.""" __metaclass__ = ContactFormMeta + + form_tag = None + title = _('Contact form') + submit_label = _('Submit') + required_css_class = 'required' contact = forms.CharField(max_length=128) - form_tag = None def save(self, request): body = {} diff --git a/contact/templates/contact/form.html b/contact/templates/contact/form.html index 8c1a256..15ad117 100644 --- a/contact/templates/contact/form.html +++ b/contact/templates/contact/form.html @@ -1,11 +1,12 @@ {% extends "base.html" %} -{% load i18n %} +{% load i18n chunks %} {% block "body" %} -

{% block contact_form_title %}{% trans "Contact form" %}{% endblock %}

+

{% block contact_form_title %}{{ form.title }}{% endblock %}

{% block contact_form_description %} + {% chunk "contact_form "|add:form.form_tag %} {% endblock %}
@@ -13,7 +14,7 @@ {% csrf_token %} {{ form.as_table }} - +
diff --git a/prawokultury/contact_forms.py b/prawokultury/contact_forms.py index 90fc529..7689269 100644 --- a/prawokultury/contact_forms.py +++ b/prawokultury/contact_forms.py @@ -5,10 +5,14 @@ from django.utils.translation import ugettext_lazy as _ class RegistrationForm(ContactForm): form_tag = 'register' + title = _('Registration form') + name = forms.CharField(label=_('Name'), max_length=128) contact = forms.EmailField(label=_('E-mail'), max_length=128) organization = forms.CharField(label=_('Organization'), max_length=256, required=False) + title = forms.CharField(label=_('Title of presentation'), + max_length=256, required=False) presentation = forms.FileField(label=_('Presentation'), required=False) summary = forms.CharField(label=_('Summary'), diff --git a/prawokultury/locale/pl/LC_MESSAGES/django.mo b/prawokultury/locale/pl/LC_MESSAGES/django.mo index 6a54584..13c910c 100644 Binary files a/prawokultury/locale/pl/LC_MESSAGES/django.mo and b/prawokultury/locale/pl/LC_MESSAGES/django.mo differ diff --git a/prawokultury/locale/pl/LC_MESSAGES/django.po b/prawokultury/locale/pl/LC_MESSAGES/django.po index 193eb47..e86f7b0 100644 --- a/prawokultury/locale/pl/LC_MESSAGES/django.po +++ b/prawokultury/locale/pl/LC_MESSAGES/django.po @@ -7,8 +7,8 @@ msgid "" msgstr "" "Project-Id-Version: prawokultury\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2012-10-10 12:41+0200\n" -"PO-Revision-Date: 2012-10-10 12:42+0100\n" +"POT-Creation-Date: 2012-10-11 12:45+0200\n" +"PO-Revision-Date: 2012-10-11 13:03+0100\n" "Last-Translator: Radek Czajka \n" "Language-Team: FNP \n" "Language: \n" @@ -18,21 +18,33 @@ msgstr "" "Plural-Forms: nplurals=3; plural=(n==1 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2)\n" #: contact_forms.py:8 +msgid "Registration form" +msgstr "Formularz rejestracyjny" + +#: contact_forms.py:10 msgid "Name" msgstr "Imię i nazwisko" -#: contact_forms.py:9 +#: contact_forms.py:11 +msgid "E-mail" +msgstr "E-mail" + +#: contact_forms.py:12 msgid "Organization" msgstr "Organizacja" -#: contact_forms.py:10 -msgid "Summary" -msgstr "Podsumowanie prezentacji" +#: contact_forms.py:14 +msgid "Title of presentation" +msgstr "Tytuł prezentacji" -#: contact_forms.py:11 +#: contact_forms.py:16 msgid "Presentation" msgstr "Prezentacja" +#: contact_forms.py:18 +msgid "Summary" +msgstr "Podsumowanie prezentacji" + #: menu_items.py:22 msgid "Form" msgstr "Formularz" @@ -50,18 +62,14 @@ msgstr "Strona, której szukasz, nie istnieje." msgid "CopyCamp" msgstr "CopyCamp" -#: templates/base.html:41 +#: templates/base.html:42 msgid "Search" msgstr "Szukaj" -#: templates/base.html:84 +#: templates/base.html:85 msgid "If not explicitly stated otherwise, all texts are licensed under the Creative Commons Attribution-Share Alike free license." msgstr "Jeśli nie oznaczono inaczej, wszystkie teksty są objęte wolną licencją Creative Commons Uznanie autorstwa – Na tych samych warunkach." -#: templates/contact/register/form.html:4 -msgid "Registration form" -msgstr "Formularz rejestracyjny" - #~ msgid "events" #~ msgstr "wydarzenia" diff --git a/prawokultury/templates/contact/register/form.html b/prawokultury/templates/contact/register/form.html deleted file mode 100755 index 8e6a807..0000000 --- a/prawokultury/templates/contact/register/form.html +++ /dev/null @@ -1,9 +0,0 @@ -{% extends "contact/form.html" %} -{% load i18n %} -{% load chunks %} - -{% block contact_form_title %}{% trans "Registration form" %}{% endblock %} - -{% block contact_form_description %} - {% chunk "formularz rejestracyjny" %} -{% endblock %}