From: Jan Szejko Date: Thu, 28 Jul 2016 12:19:28 +0000 (+0200) Subject: newsletter checkboxes in suggestions and registration X-Git-Url: https://git.mdrn.pl/wolnelektury.git/commitdiff_plain/e7d557155e2cd195f975e4559c353be5f28d7d66 newsletter checkboxes in suggestions and registration --- diff --git a/src/ajaxable/templates/ajaxable/form.html b/src/ajaxable/templates/ajaxable/form.html index af98d5158..3363bc8a4 100755 --- a/src/ajaxable/templates/ajaxable/form.html +++ b/src/ajaxable/templates/ajaxable/form.html @@ -3,7 +3,7 @@

{{ title }}

-
{% ssi_csrf_token %} {% if honeypot %} @@ -12,7 +12,9 @@ {% endif %}
    - {{ form.as_ul }} + {% block form_fields %} + {{ form.as_ul }} + {% endblock %}
diff --git a/src/ajaxable/templatetags/ajaxable_tags.py b/src/ajaxable/templatetags/ajaxable_tags.py index 351e9f13d..c262a92c3 100644 --- a/src/ajaxable/templatetags/ajaxable_tags.py +++ b/src/ajaxable/templatetags/ajaxable_tags.py @@ -3,6 +3,8 @@ # 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() @@ -15,3 +17,23 @@ def placeholdize(form): @register.filter def placeholdized_ul(form): return placeholdized(form).as_ul() + + +@register.filter +def pretty_field(field, template=None): + if template is None: + template = ''' +
  • + %(errors)s + +
  • ''' + return mark_safe(template % {'errors': field.errors, 'input': field, 'label': field.label}) + + +@register.filter +def pretty_checkbox(field): + return pretty_field(field, template=''' +
  • + %(errors)s + +
  • ''') diff --git a/src/ajaxable/utils.py b/src/ajaxable/utils.py index c2c368840..9fd009108 100755 --- a/src/ajaxable/utils.py +++ b/src/ajaxable/utils.py @@ -63,6 +63,7 @@ class AjaxableFormView(object): # override to customize form look template = "ajaxable/form.html" submit = _('Send') + action = '' title = '' success_message = '' @@ -140,6 +141,7 @@ class AjaxableFormView(object): "honeypot": self.honeypot, "placeholdize": self.placeholdize, "submit": self.submit, + "action": self.action, "response_data": response_data, "ajax_template": self.template, "view_args": args, diff --git a/src/catalogue/forms.py b/src/catalogue/forms.py index c547279ad..c1348a1e4 100644 --- a/src/catalogue/forms.py +++ b/src/catalogue/forms.py @@ -47,7 +47,7 @@ CUSTOMIZATION_FLAGS = ( ('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"), ( diff --git a/src/catalogue/tasks.py b/src/catalogue/tasks.py index aff0e6bca..30bc55fe2 100644 --- a/src/catalogue/tasks.py +++ b/src/catalogue/tasks.py @@ -48,9 +48,9 @@ def build_custom_pdf(book_id, customizations, file_name, waiter_id=None): 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, diff --git a/src/catalogue/templates/catalogue/custom_pdf_form.html b/src/catalogue/templates/catalogue/custom_pdf_form.html new file mode 100644 index 000000000..3abc22d28 --- /dev/null +++ b/src/catalogue/templates/catalogue/custom_pdf_form.html @@ -0,0 +1,21 @@ +{% load i18n %} +{% load honeypot %} +{% load ssi_csrf_token from ssify %} +{% load ajaxable_tags %} + +

    {% trans "Download custom PDF" %}

    + +
    + {% ssi_csrf_token %} + {% render_honeypot_field %} +
      + {{ form.nofootnotes|pretty_checkbox }} + {{ form.nothemes|pretty_checkbox }} + {{ form.nowlfont|pretty_checkbox }} + {{ form.nocover|pretty_checkbox }} + {{ form.leading|pretty_field }} + {{ form.fontsize|pretty_field }} + +
    1. +
    +
    diff --git a/src/catalogue/templatetags/catalogue_tags.py b/src/catalogue/templatetags/catalogue_tags.py index c02a5d74f..afb2e7ef5 100644 --- a/src/catalogue/templatetags/catalogue_tags.py +++ b/src/catalogue/templatetags/catalogue_tags.py @@ -10,7 +10,6 @@ from django.conf import settings 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 _ @@ -24,22 +23,6 @@ from picture.models import Picture register = template.Library() -class RegistrationForm(UserCreationForm): - def as_ul(self): - """Returns this form rendered as HTML
  • s -- excluding the .""" - return self._html_output( - u'
  • %(errors)s%(label)s %(field)s%(help_text)s
  • ', u'
  • %s
  • ', - '', u' %s', False) - - -class LoginForm(AuthenticationForm): - def as_ul(self): - """Returns this form rendered as HTML
  • s -- excluding the .""" - return self._html_output( - u'
  • %(errors)s%(label)s %(field)s%(help_text)s
  • ', u'
  • %s
  • ', - '', u' %s', False) - - def iterable(obj): try: iter(obj) @@ -228,16 +211,6 @@ def all_editors(extra_info): 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() diff --git a/src/catalogue/views.py b/src/catalogue/views.py index 44a17b412..99e3c8244 100644 --- a/src/catalogue/views.py +++ b/src/catalogue/views.py @@ -628,6 +628,7 @@ class CustomPDFFormView(AjaxableFormView): 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): diff --git a/src/newsletter/forms.py b/src/newsletter/forms.py index f8927e5b8..d9f931b3d 100644 --- a/src/newsletter/forms.py +++ b/src/newsletter/forms.py @@ -1,5 +1,6 @@ # -*- 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 _ @@ -8,7 +9,8 @@ from newsletter.models import Subscription 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: @@ -16,9 +18,16 @@ class NewsletterForm(Form): 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? diff --git a/src/suggest/forms.py b/src/suggest/forms.py index 57e5eeef8..452180559 100644 --- a/src/suggest/forms.py +++ b/src/suggest/forms.py @@ -10,14 +10,18 @@ from django.core.urlresolvers import reverse 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'] @@ -54,7 +58,8 @@ The suggestion has been referred to the project coordinator.""") + '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) @@ -68,6 +73,7 @@ class PublishingSuggestForm(forms.Form): 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') diff --git a/src/suggest/templates/publishing_suggest.html b/src/suggest/templates/publishing_suggest.html index 16c70a49b..66792c7ab 100755 --- a/src/suggest/templates/publishing_suggest.html +++ b/src/suggest/templates/publishing_suggest.html @@ -1,33 +1,16 @@ +{% extends "ajaxable/form.html" %} {% load i18n %} -{% load honeypot %} -{% load ssi_csrf_token from ssify %} +{% load ajaxable_tags %} -

    {% trans "Didn't find a book? Make a suggestion." %}

    +{% block form_fields %} +{{ form.contact|pretty_field }} +
  • {% trans "I'd like to find in WolneLektury.pl these…" %}
  • + {{ form.books|pretty_field }} + {{ form.ebook|pretty_checkbox }} + {{ form.audiobook|pretty_checkbox }} + {{ form.agree_newsletter|pretty_checkbox }} +{% endblock %} -
    - {% ssi_csrf_token %} - {% render_honeypot_field %} -
      -
    1. - {{ form.contact.errors }} - - {{ form.contact }} -
    2. - -
    3. {% trans "I'd like to find in WolneLektury.pl these…" %}
    4. - -
    5. {{ form.books }}
    6. - -
    7. - {{ form.ebook.errors }} - - {{ form.ebook }} -
    8. -
    9. - {{ form.audiobook.errors }} - - {{ form.audiobook }} -
    10. {% trans "Remember that we can only publish books in public domain, ie. 70 years after the death of the author!" %}
    11. diff --git a/src/suggest/templates/suggest.html b/src/suggest/templates/suggest.html new file mode 100644 index 000000000..11667069e --- /dev/null +++ b/src/suggest/templates/suggest.html @@ -0,0 +1,8 @@ +{% 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 diff --git a/src/suggest/views.py b/src/suggest/views.py index 035074d0a..706c549ab 100644 --- a/src/suggest/views.py +++ b/src/suggest/views.py @@ -2,6 +2,7 @@ # 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 @@ -10,15 +11,19 @@ from suggest import forms 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') diff --git a/src/wolnelektury/forms.py b/src/wolnelektury/forms.py new file mode 100644 index 000000000..0973e7d93 --- /dev/null +++ b/src/wolnelektury/forms.py @@ -0,0 +1,16 @@ +# -*- 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) diff --git a/src/wolnelektury/static/scss/main/dialogs.scss b/src/wolnelektury/static/scss/main/dialogs.scss index 5825979e1..6e5c90ae3 100755 --- a/src/wolnelektury/static/scss/main/dialogs.scss +++ b/src/wolnelektury/static/scss/main/dialogs.scss @@ -97,11 +97,20 @@ .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; } } } @@ -111,10 +120,19 @@ -.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 { diff --git a/src/wolnelektury/templates/auth/register.html b/src/wolnelektury/templates/auth/register.html index 3252caeb8..fef1f19de 100644 --- a/src/wolnelektury/templates/auth/register.html +++ b/src/wolnelektury/templates/auth/register.html @@ -1,9 +1,20 @@ {% 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 %}

      {% trans "Sign in using:" %}

        @@ -11,5 +22,6 @@
      {% include "socialaccount/snippets/login_extra.html" %} +{% endcomment %} {% endblock %} diff --git a/src/wolnelektury/views.py b/src/wolnelektury/views.py index 265f76694..7d6ed2be9 100644 --- a/src/wolnelektury/views.py +++ b/src/wolnelektury/views.py @@ -22,6 +22,7 @@ from catalogue.models import Book, Collection, Tag, Fragment from ssify import ssi_included from social.utils import get_or_choose_cite +from wolnelektury.forms import RegistrationForm def main_page(request): @@ -83,7 +84,7 @@ class LoginFormView(AjaxableFormView): class RegisterFormView(AjaxableFormView): - form_class = UserCreationForm + form_class = RegistrationForm template = "auth/register.html" placeholdize = True title = _('Register')