From 449af174ecea7e23ad7f4c6b2f0da62bd808f0dc Mon Sep 17 00:00:00 2001 From: Jan Dittberner Date: Sun, 25 Jan 2015 12:10:17 +0100 Subject: [PATCH] implement create_mailbox functionality - implement managemails.forms.CreateMailboxForm - implement managemails.views.CreateMailbox - add url pattern 'create_mailbox' to managemails.urls - add templates managemails/base.html and managemails/mailbox_create.html - add german translation - add generated code documentation --- docs/code/managemails.rst | 23 ++++++- gnuviechadmin/locale/de/LC_MESSAGES/django.po | 30 ++++++++- gnuviechadmin/managemails/forms.py | 48 ++++++++++++++ .../locale/de/LC_MESSAGES/django.po | 17 ++++- gnuviechadmin/managemails/urls.py | 18 +++++ gnuviechadmin/managemails/views.py | 65 +++++++++++++++++++ gnuviechadmin/templates/managemails/base.html | 1 + .../templates/managemails/mailbox_create.html | 34 ++++++++++ 8 files changed, 231 insertions(+), 5 deletions(-) create mode 100644 gnuviechadmin/managemails/forms.py create mode 100644 gnuviechadmin/managemails/urls.py create mode 100644 gnuviechadmin/managemails/views.py create mode 100644 gnuviechadmin/templates/managemails/base.html create mode 100644 gnuviechadmin/templates/managemails/mailbox_create.html diff --git a/docs/code/managemails.rst b/docs/code/managemails.rst index 17c1763..42f060d 100644 --- a/docs/code/managemails.rst +++ b/docs/code/managemails.rst @@ -12,14 +12,35 @@ :py:mod:`apps ` ------------------------------------ +--------------------------------- .. automodule:: managemails.apps :members: +:py:mod:`forms ` +----------------------------------- + +.. automodule:: managemails.forms + :members: + + :py:mod:`models ` ------------------------------------- .. automodule:: managemails.models :members: + + +:py:mod:`urls ` +--------------------------------- + +.. automodule:: managemails.urls + :members: + + +:py:mod:`views ` +----------------------------------- + +.. automodule:: managemails.views + :members: diff --git a/gnuviechadmin/locale/de/LC_MESSAGES/django.po b/gnuviechadmin/locale/de/LC_MESSAGES/django.po index b70640b..8056f97 100644 --- a/gnuviechadmin/locale/de/LC_MESSAGES/django.po +++ b/gnuviechadmin/locale/de/LC_MESSAGES/django.po @@ -7,8 +7,8 @@ msgid "" msgstr "" "Project-Id-Version: gnuviechadmin\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2015-01-25 00:46+0100\n" -"PO-Revision-Date: 2015-01-25 00:55+0100\n" +"POT-Creation-Date: 2015-01-25 12:04+0100\n" +"PO-Revision-Date: 2015-01-25 12:06+0100\n" "Last-Translator: Jan Dittberner \n" "Language-Team: Jan Dittberner \n" "Language: de\n" @@ -793,6 +793,27 @@ msgstr "Diesem Hostingpaket sind noch keine Datenbanken zugeordnet." msgid "Add database" msgstr "Datenbank hinzufügen" +#: templates/managemails/mailbox_create.html:6 +#: templates/managemails/mailbox_create.html:15 +#, python-format +msgid "Add Mailbox to Hosting Package %(package)s" +msgstr "Postfach zum Hostingpaket %(package)s hinzufügen" + +#: templates/managemails/mailbox_create.html:8 +#: templates/managemails/mailbox_create.html:17 +#, python-format +msgid "Add Mailbox to Hosting Package %(package)s of Customer %(full_name)s" +msgstr "" +"Postfach zum Hostingpaket %(package)s des Kunden %(full_name)s hinzufügen" + +#: templates/managemails/mailbox_create.html:23 +msgid "Please specify the password for your new mailbox." +msgstr "Bitte geben Sie das Passwort für Ihr neues Postfach ein." + +#: templates/managemails/mailbox_create.html:23 +msgid "Please specify the password for the new mailbox." +msgstr "Bitte geben Sie das Passwort für das neue Postfach ein." + #: templates/osusers/user_setpassword.html:5 #: templates/osusers/user_setpassword.html:13 #, python-format @@ -897,5 +918,10 @@ msgstr "" "%(site_name)s zu nutzen. Als letzten Schritt füllen Sie bitte folgendes " "Formular aus:" +#, fuzzy +#~| msgid "Password Reset" +#~ msgid "Password (again)" +#~ msgstr "Passwort zurücksetzen" + #~ msgid "My Profile" #~ msgstr "Mein Profil" diff --git a/gnuviechadmin/managemails/forms.py b/gnuviechadmin/managemails/forms.py new file mode 100644 index 0000000..00c309f --- /dev/null +++ b/gnuviechadmin/managemails/forms.py @@ -0,0 +1,48 @@ +""" +This module defines form classes for mailbox and mail address editing. + +""" +from __future__ import absolute_import, unicode_literals + +from django import forms +from django.core.urlresolvers import reverse +from django.utils.translation import ugettext as _ + +from crispy_forms.helper import FormHelper +from crispy_forms.layout import Submit + +from .models import Mailbox +from gvawebcore.forms import PasswordModelFormMixin + + +class CreateMailboxForm(PasswordModelFormMixin, forms.ModelForm): + """ + This form is used to create new Mailbox instances. + + """ + class Meta: + model = Mailbox + fields = [] + + def __init__(self, *args, **kwargs): + self.hosting_package = kwargs.pop('hostingpackage') + super(CreateMailboxForm, self).__init__(*args, **kwargs) + self.helper = FormHelper() + self.helper.form_action = reverse( + 'create_mailbox', kwargs={'package': self.hosting_package.id}) + self.helper.add_input(Submit('submit', _('Create mailbox'))) + + def save(self, commit=True): + """ + Set the new mailbox's password and osuser. + + :param boolean commit: whether to save the created mailbox + :return: mailbox instance + :rtype: :py:class:`managemails.models.Mailbox` + + """ + osuser = self.hosting_package.osuser + self.instance.osuser = osuser + self.instance.username = Mailbox.objects.get_next_mailbox_name(osuser) + self.instance.set_password(self.cleaned_data['password1']) + return super(CreateMailboxForm, self).save(commit=commit) diff --git a/gnuviechadmin/managemails/locale/de/LC_MESSAGES/django.po b/gnuviechadmin/managemails/locale/de/LC_MESSAGES/django.po index 52f2d8f..818ecd3 100644 --- a/gnuviechadmin/managemails/locale/de/LC_MESSAGES/django.po +++ b/gnuviechadmin/managemails/locale/de/LC_MESSAGES/django.po @@ -7,8 +7,8 @@ msgid "" msgstr "" "Project-Id-Version: managemails\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2015-01-25 00:46+0100\n" -"PO-Revision-Date: 2015-01-25 00:48+0100\n" +"POT-Creation-Date: 2015-01-25 12:04+0100\n" +"PO-Revision-Date: 2015-01-25 12:07+0100\n" "Last-Translator: Jan Dittberner \n" "Language-Team: Jan Dittberner \n" "Language: de\n" @@ -47,6 +47,10 @@ msgstr "Deaktivieren" msgid "Mailboxes and Mail Addresses" msgstr "Postfächer und E-Mailadressen" +#: managemails/forms.py:33 +msgid "Create mailbox" +msgstr "Postfach anlegen" + #: managemails/models.py:79 msgid "Mailbox" msgstr "Postfach" @@ -70,3 +74,12 @@ msgstr "E-Mailadresse" #: managemails/models.py:142 msgid "mailbox" msgstr "Postfach" + +#: managemails/views.py:35 +msgid "You are not allowed to add more mailboxes to this hosting package" +msgstr "Sie können keine weiteren Postfächer zu diesem Hostingpaket hinzufügen" + +#: managemails/views.py:61 +#, python-brace-format +msgid "Mailbox {mailbox} created successfully." +msgstr "Postfach {mailbox} erfolgreich angelegt." diff --git a/gnuviechadmin/managemails/urls.py b/gnuviechadmin/managemails/urls.py new file mode 100644 index 0000000..6695cd2 --- /dev/null +++ b/gnuviechadmin/managemails/urls.py @@ -0,0 +1,18 @@ +""" +This module defines the URL patterns for mailbox and mail address related +views. + +""" +from __future__ import absolute_import, unicode_literals + +from django.conf.urls import patterns, url + +from .views import ( + CreateMailbox, +) + +urlpatterns = patterns( + '', + url(r'^(?P\d+)/mailbox/create$', + CreateMailbox.as_view(), name='create_mailbox'), +) diff --git a/gnuviechadmin/managemails/views.py b/gnuviechadmin/managemails/views.py new file mode 100644 index 0000000..c53cca8 --- /dev/null +++ b/gnuviechadmin/managemails/views.py @@ -0,0 +1,65 @@ +""" +This module defines views for mailbox and mail address handling. + +""" +from __future__ import absolute_import, unicode_literals + +from django.http import HttpResponseForbidden +from django.shortcuts import get_object_or_404, redirect +from django.utils.translation import ugettext as _ +from django.views.generic.edit import CreateView +from django.contrib import messages + +from gvacommon.viewmixins import StaffOrSelfLoginRequiredMixin + +from hostingpackages.models import CustomerHostingPackage + +from .forms import CreateMailboxForm +from .models import Mailbox + + +class CreateMailbox(StaffOrSelfLoginRequiredMixin, CreateView): + """ + This view is used to setup new mailboxes for a customer hosting package. + + """ + model = Mailbox + context_object_name = 'mailbox' + template_name_suffix = '_create' + form_class = CreateMailboxForm + + def dispatch(self, request, *args, **kwargs): + resp = super(CreateMailbox, self).dispatch(request, *args, **kwargs) + if not self._get_hosting_package().may_add_mailbox(): + resp = HttpResponseForbidden( + _('You are not allowed to add more mailboxes to this' + ' hosting package')) + return resp + + def _get_hosting_package(self): + return get_object_or_404( + CustomerHostingPackage, pk=int(self.kwargs['package'])) + + def get_customer_object(self): + return self._get_hosting_package().customer + + def get_context_data(self, **kwargs): + context = super(CreateMailbox, self).get_context_data(**kwargs) + context['hostingpackage'] = self._get_hosting_package() + context['customer'] = self.get_customer_object() + return context + + def get_form_kwargs(self): + kwargs = super(CreateMailbox, self).get_form_kwargs() + kwargs['hostingpackage'] = self._get_hosting_package() + return kwargs + + def form_valid(self, form): + mailbox = form.save() + messages.success( + self.request, + _('Mailbox {mailbox} created successfully.').format( + mailbox=mailbox.username + ) + ) + return redirect(self._get_hosting_package().get_absolute_url()) diff --git a/gnuviechadmin/templates/managemails/base.html b/gnuviechadmin/templates/managemails/base.html new file mode 100644 index 0000000..94d9808 --- /dev/null +++ b/gnuviechadmin/templates/managemails/base.html @@ -0,0 +1 @@ +{% extends "base.html" %} diff --git a/gnuviechadmin/templates/managemails/mailbox_create.html b/gnuviechadmin/templates/managemails/mailbox_create.html new file mode 100644 index 0000000..7446d6c --- /dev/null +++ b/gnuviechadmin/templates/managemails/mailbox_create.html @@ -0,0 +1,34 @@ +{% extends "managemails/base.html" %} +{% load i18n crispy_forms_tags %} +{% block title %}{{ block.user }} - {% spaceless %} +{% with full_name=customer.get_full_name package=hostingpackage.name %} +{% if customer == user %} +{% blocktrans %}Add Mailbox to Hosting Package {{ package }}{% endblocktrans %} +{% else %} +{% blocktrans %}Add Mailbox to Hosting Package {{ package }} of Customer {{ full_name }}{% endblocktrans %} +{% endif %} +{% endwith %} +{% endspaceless %}{% endblock title %} +{% block page_title %}{% spaceless %} +{% with full_name=customer.get_full_name package=hostingpackage.name %} +{% if customer == user %} +{% blocktrans %}Add Mailbox to Hosting Package {{ package }}{% endblocktrans %} +{% else %} +{% blocktrans %}Add Mailbox to Hosting Package {{ package }} of Customer {{ full_name }}{% endblocktrans %} +{% endif %} +{% endwith %} +{% endspaceless %}{% endblock page_title %} + +{% block content %} +

{% if customer == user %}{% trans "Please specify the password for your new mailbox." %}{% else %}{% trans "Please specify the password for the new mailbox." %}{% endif %}

+{% crispy form %} +{% endblock content %} + +{% block extra_js %} + +{% endblock extra_js %}