<h1>{{ title }}</h1>
-<form action="{{ request.get_full_path }}" method="post" accept-charset="utf-8"
+<form action="{{ action }}" method="post" accept-charset="utf-8"
class="cuteform{% if placeholdize %} hidelabels{% endif %}">
{% ssi_csrf_token %}
{% if honeypot %}
{% endif %}
<ol>
<div id="id_{% if form_prefix %}{{ form_prefix }}-{% endif %}__all__"></div>
- {{ form.as_ul }}
+ {% block form_fields %}
+ {{ form.as_ul }}
+ {% endblock %}
<li><input type="submit" value="{{ submit }}"/></li>
</ol>
</form>
# Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
#
from django import template
+from django.utils.safestring import mark_safe
+
from ajaxable.utils import placeholdized
register = template.Library()
@register.filter
def placeholdized_ul(form):
return placeholdized(form).as_ul()
+
+
+@register.filter
+def pretty_field(field, template=None):
+ if template is None:
+ template = '''
+ <li>
+ <span class="error">%(errors)s</span>
+ <label class="nohide"><span class="label">%(label)s: </span>%(input)s</label>
+ </li>'''
+ return mark_safe(template % {'errors': field.errors, 'input': field, 'label': field.label})
+
+
+@register.filter
+def pretty_checkbox(field):
+ return pretty_field(field, template='''
+ <li class="checkbox">
+ <span class="error">%(errors)s</span>
+ <label class="nohide">%(input)s<span class="label"> %(label)s</span></label>
+ </li>''')
# override to customize form look
template = "ajaxable/form.html"
submit = _('Send')
+ action = ''
title = ''
success_message = ''
"honeypot": self.honeypot,
"placeholdize": self.placeholdize,
"submit": self.submit,
+ "action": self.action,
"response_data": response_data,
"ajax_template": self.template,
"view_args": args,
('nofootnotes', _("Don't show footnotes")),
('nothemes', _("Don't disply themes")),
('nowlfont', _("Don't use our custom font")),
- ('no-cover', _("Without cover")),
+ ('nocover', _("Without cover")),
)
CUSTOMIZATION_OPTIONS = (
('leading', _("Leading"), (
kwargs = {
'cover': True,
}
- if 'no-cover' in customizations:
+ if 'nocover' in customizations:
kwargs['cover'] = False
- customizations.remove('no-cover')
+ customizations.remove('nocover')
wldoc = Book.objects.get(pk=book_id).wldocument()
pdf = wldoc.as_pdf(
customizations=customizations,
--- /dev/null
+{% load i18n %}
+{% load honeypot %}
+{% load ssi_csrf_token from ssify %}
+{% load ajaxable_tags %}
+
+<h1>{% trans "Download custom PDF" %}</h1>
+
+<form id='custom-pdf-form' action="" method="post" accept-charset="utf-8" class="cuteform">
+ {% ssi_csrf_token %}
+ {% render_honeypot_field %}
+ <ol>
+ {{ form.nofootnotes|pretty_checkbox }}
+ {{ form.nothemes|pretty_checkbox }}
+ {{ form.nowlfont|pretty_checkbox }}
+ {{ form.nocover|pretty_checkbox }}
+ {{ form.leading|pretty_field }}
+ {{ form.fontsize|pretty_field }}
+
+ <li><input type="submit" value="{% trans "Download" %}"/></li>
+ </ol>
+</form>
from django import template
from django.template import Node, Variable, Template, Context
from django.core.urlresolvers import reverse
-from django.contrib.auth.forms import UserCreationForm, AuthenticationForm
from django.utils.cache import add_never_cache_headers
from django.utils.translation import ugettext as _
register = template.Library()
-class RegistrationForm(UserCreationForm):
- def as_ul(self):
- """Returns this form rendered as HTML <li>s -- excluding the <ul></ul>."""
- return self._html_output(
- u'<li>%(errors)s%(label)s %(field)s<span class="help-text">%(help_text)s</span></li>', u'<li>%s</li>',
- '</li>', u' %s', False)
-
-
-class LoginForm(AuthenticationForm):
- def as_ul(self):
- """Returns this form rendered as HTML <li>s -- excluding the <ul></ul>."""
- return self._html_output(
- u'<li>%(errors)s%(label)s %(field)s<span class="help-text">%(help_text)s</span></li>', u'<li>%s</li>',
- '</li>', u' %s', False)
-
-
def iterable(obj):
try:
iter(obj)
for person in sorted(set(editors)))
-@register.simple_tag
-def user_creation_form():
- return RegistrationForm(prefix='registration').as_ul()
-
-
-@register.simple_tag
-def authentication_form():
- return LoginForm(prefix='login').as_ul()
-
-
@register.tag
def catalogue_url(parser, token):
bits = token.split_contents()
form_class = forms.CustomPDFForm
title = ugettext_lazy('Download custom PDF')
submit = ugettext_lazy('Download')
+ template = 'catalogue/custom_pdf_form.html'
honeypot = True
def __call__(self, *args, **kwargs):
# -*- coding: utf-8 -*-
-
+from django.core.exceptions import ValidationError
+from django.core.validators import validate_email
from django.forms import Form, BooleanField
from django.utils.translation import ugettext_lazy as _
class NewsletterForm(Form):
email_field = 'email'
- agree_newsletter = BooleanField(required=False, label=_(u'I want to receive Wolne Lektury\'s newsletter.'))
+ agree_newsletter = BooleanField(
+ required=False, initial=True, label=_(u'I want to receive Wolne Lektury\'s newsletter.'))
def save(self):
try:
super(NewsletterForm, self).save()
except AttributeError:
pass
+ if not self.cleaned_data.get('agree_newsletter'):
+ return
email = self.cleaned_data[self.email_field]
- subscription, created = Subscription.objects.get_or_create(email=email)
- if not created and not subscription.active:
- subscription.active = True
- subscription.save()
- # Send some test email?
+ try:
+ validate_email(email)
+ except ValidationError:
+ pass
+ else:
+ subscription, created = Subscription.objects.get_or_create(email=email)
+ if not created and not subscription.active:
+ subscription.active = True
+ subscription.save()
+ # Send some test email?
from django.core.validators import validate_email
from django.utils.translation import ugettext_lazy as _
from django.utils.translation import ugettext
+
+from newsletter.forms import NewsletterForm
from suggest.models import PublishingSuggestion, Suggestion
-class SuggestForm(forms.Form):
+class SuggestForm(NewsletterForm):
+ email_field = 'contact'
contact = forms.CharField(label=_('Contact'), max_length=120, required=False)
description = forms.CharField(label=_('Description'), widget=forms.Textarea, required=True)
def save(self, request):
+ super(SuggestForm, self).save()
contact = self.cleaned_data['contact']
description = self.cleaned_data['description']
'no-reply@wolnelektury.pl', [contact], fail_silently=True)
-class PublishingSuggestForm(forms.Form):
+class PublishingSuggestForm(NewsletterForm):
+ email_field = 'contact'
contact = forms.CharField(label=_('Contact'), max_length=120, required=False)
books = forms.CharField(label=_('books'), widget=forms.Textarea, required=True)
ebook = forms.BooleanField(label=_('ebook'), required=False, initial=True)
return super(PublishingSuggestForm, self).clean()
def save(self, request):
+ super(PublishingSuggestForm, self).save()
contact = self.cleaned_data['contact']
suggestion_text = self.cleaned_data['books'].strip(', \n\r')
+{% extends "ajaxable/form.html" %}
{% load i18n %}
-{% load honeypot %}
-{% load ssi_csrf_token from ssify %}
+{% load ajaxable_tags %}
-<h1>{% trans "Didn't find a book? Make a suggestion." %}</h1>
+{% block form_fields %}
+{{ form.contact|pretty_field }}
+ <li>{% trans "I'd like to find in WolneLektury.pl these…" %}</li>
+ {{ form.books|pretty_field }}
+ {{ form.ebook|pretty_checkbox }}
+ {{ form.audiobook|pretty_checkbox }}
+ {{ form.agree_newsletter|pretty_checkbox }}
+{% endblock %}
-<form id='suggest-publishing-form' action="{% url 'suggest_publishing' %}" method="post" accept-charset="utf-8" class="cuteform">
- {% ssi_csrf_token %}
- {% render_honeypot_field %}
- <ol>
- <li>
- <span class="error">{{ form.contact.errors }}</span>
- <label for="id_contact">{{ form.contact.label }}</label>
- {{ form.contact }}
- </li>
-
- <li>{% trans "I'd like to find in WolneLektury.pl these…" %}</li>
-
- <li><label for="id_books">{{ form.books.label }}:</label> {{ form.books }}</li>
-
- <li class="checkbox">
- <span class="error">{{ form.ebook.errors }}</span>
- <label for="id_ebook">{{ form.ebook.label }}:</label>
- {{ form.ebook }}
- </li>
- <li class="checkbox">
- <span class="error">{{ form.audiobook.errors }}</span>
- <label for="id_audiobook">{{ form.audiobook.label }}:</label>
- {{ form.audiobook }}
- </li>
<li><input type="submit" value="{% trans "Send report" %}"/></li>
<li>{% trans "Remember that we can only publish books in public domain, ie. 70 years after the death of the author!" %}</li>
--- /dev/null
+{% extends "ajaxable/form.html" %}
+{% load ajaxable_tags %}
+
+{% block form_fields %}
+ {{ form.contact|pretty_field }}
+ {{ form.description|pretty_field }}
+ {{ form.agree_newsletter|pretty_checkbox }}
+{% endblock %}
\ No newline at end of file
# This file is part of Wolnelektury, licensed under GNU Affero GPLv3 or later.
# Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
#
+from django.core.urlresolvers import reverse_lazy
from django.utils.translation import ugettext_lazy as _
from ajaxable.utils import AjaxableFormView
class PublishingSuggestionFormView(AjaxableFormView):
form_class = forms.PublishingSuggestForm
- title = _('Report a bug or suggestion')
+ title = _("Didn't find a book? Make a suggestion.")
template = "publishing_suggest.html"
+ submit = _('Send report')
success_message = _('Report was sent successfully.')
honeypot = True
+ action = reverse_lazy('suggest_publishing')
class SuggestionFormView(AjaxableFormView):
form_class = forms.SuggestForm
title = _('Report a bug or suggestion')
+ template = "suggest.html"
submit = _('Send report')
success_message = _('Report was sent successfully.')
honeypot = True
+ action = reverse_lazy('suggest')
--- /dev/null
+# -*- coding: utf-8 -*-
+from django.contrib.auth.forms import UserCreationForm
+from django.contrib.auth.models import User
+
+from newsletter.forms import NewsletterForm
+
+
+# has to be this order, because otherwise the form is lacking fields
+class RegistrationForm(UserCreationForm, NewsletterForm):
+ class Meta:
+ model = User
+ fields = ('username', 'email')
+
+ def save(self, commit=True):
+ super(RegistrationForm, self).save(commit=commit)
+ NewsletterForm.save(self)
.checkbox {
label {
- display: inline;
+ display: block;
+ padding-left: 15px;
+ text-indent: -15px;
}
input {
- width: auto;
+ width: 13px;
+ height: 13px;
+ padding: 0;
+ margin:0;
+ vertical-align: bottom;
+ position: relative;
+ top: -1px;
+ *overflow: hidden;
}
}
}
-.hidelabels label {
+.hidelabels label, .hidelabels .label {
@include hidden-label;
}
+.hidelabels label.nohide {
+ width: auto;
+ height: auto;
+}
+
+.hidelabels .checkbox .label {
+ display: inline;
+}
+
@media screen and (min-width: 30em) {
#login-window {
{% extends "ajaxable/form.html" %}
{% load i18n %}
+{% load ajaxable_tags %}
+
+
+{% block form_fields %}
+ {{ form.username|pretty_field }}
+ {{ form.email|pretty_field }}
+ {{ form.password1|pretty_field }}
+ {{ form.password2|pretty_field }}
+ {{ form.agree_newsletter|pretty_checkbox }}
+{% endblock %}
{% block extra %}
+{% comment %}
<h1>{% trans "Sign in using:" %}</h1>
<ul class="socialaccount_providers">
</ul>
{% include "socialaccount/snippets/login_extra.html" %}
+{% endcomment %}
{% endblock %}
from ssify import ssi_included
from social.utils import get_or_choose_cite
+from wolnelektury.forms import RegistrationForm
def main_page(request):
class RegisterFormView(AjaxableFormView):
- form_class = UserCreationForm
+ form_class = RegistrationForm
template = "auth/register.html"
placeholdize = True
title = _('Register')