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
This commit is contained in:
Jan Dittberner 2015-01-25 12:10:17 +01:00
parent 6cb61ea105
commit 449af174ec
8 changed files with 231 additions and 5 deletions

View file

@ -12,14 +12,35 @@
:py:mod:`apps <managemails.apps>` :py:mod:`apps <managemails.apps>`
----------------------------------- ---------------------------------
.. automodule:: managemails.apps .. automodule:: managemails.apps
:members: :members:
:py:mod:`forms <managemails.forms>`
-----------------------------------
.. automodule:: managemails.forms
:members:
:py:mod:`models <managemails.models>` :py:mod:`models <managemails.models>`
------------------------------------- -------------------------------------
.. automodule:: managemails.models .. automodule:: managemails.models
:members: :members:
:py:mod:`urls <managemails.urls>`
---------------------------------
.. automodule:: managemails.urls
:members:
:py:mod:`views <managemails.views>`
-----------------------------------
.. automodule:: managemails.views
:members:

View file

@ -7,8 +7,8 @@ msgid ""
msgstr "" msgstr ""
"Project-Id-Version: gnuviechadmin\n" "Project-Id-Version: gnuviechadmin\n"
"Report-Msgid-Bugs-To: \n" "Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2015-01-25 00:46+0100\n" "POT-Creation-Date: 2015-01-25 12:04+0100\n"
"PO-Revision-Date: 2015-01-25 00:55+0100\n" "PO-Revision-Date: 2015-01-25 12:06+0100\n"
"Last-Translator: Jan Dittberner <jan@dittberner.info>\n" "Last-Translator: Jan Dittberner <jan@dittberner.info>\n"
"Language-Team: Jan Dittberner <jan@dittberner.info>\n" "Language-Team: Jan Dittberner <jan@dittberner.info>\n"
"Language: de\n" "Language: de\n"
@ -793,6 +793,27 @@ msgstr "Diesem Hostingpaket sind noch keine Datenbanken zugeordnet."
msgid "Add database" msgid "Add database"
msgstr "Datenbank hinzufügen" 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:5
#: templates/osusers/user_setpassword.html:13 #: templates/osusers/user_setpassword.html:13
#, python-format #, python-format
@ -897,5 +918,10 @@ msgstr ""
"%(site_name)s zu nutzen. Als letzten Schritt füllen Sie bitte folgendes " "%(site_name)s zu nutzen. Als letzten Schritt füllen Sie bitte folgendes "
"Formular aus:" "Formular aus:"
#, fuzzy
#~| msgid "Password Reset"
#~ msgid "Password (again)"
#~ msgstr "Passwort zurücksetzen"
#~ msgid "My Profile" #~ msgid "My Profile"
#~ msgstr "Mein Profil" #~ msgstr "Mein Profil"

View file

@ -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)

View file

@ -7,8 +7,8 @@ msgid ""
msgstr "" msgstr ""
"Project-Id-Version: managemails\n" "Project-Id-Version: managemails\n"
"Report-Msgid-Bugs-To: \n" "Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2015-01-25 00:46+0100\n" "POT-Creation-Date: 2015-01-25 12:04+0100\n"
"PO-Revision-Date: 2015-01-25 00:48+0100\n" "PO-Revision-Date: 2015-01-25 12:07+0100\n"
"Last-Translator: Jan Dittberner <jan@dittberner.info>\n" "Last-Translator: Jan Dittberner <jan@dittberner.info>\n"
"Language-Team: Jan Dittberner <jan@dittberner.info>\n" "Language-Team: Jan Dittberner <jan@dittberner.info>\n"
"Language: de\n" "Language: de\n"
@ -47,6 +47,10 @@ msgstr "Deaktivieren"
msgid "Mailboxes and Mail Addresses" msgid "Mailboxes and Mail Addresses"
msgstr "Postfächer und E-Mailadressen" msgstr "Postfächer und E-Mailadressen"
#: managemails/forms.py:33
msgid "Create mailbox"
msgstr "Postfach anlegen"
#: managemails/models.py:79 #: managemails/models.py:79
msgid "Mailbox" msgid "Mailbox"
msgstr "Postfach" msgstr "Postfach"
@ -70,3 +74,12 @@ msgstr "E-Mailadresse"
#: managemails/models.py:142 #: managemails/models.py:142
msgid "mailbox" msgid "mailbox"
msgstr "Postfach" 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."

View file

@ -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<package>\d+)/mailbox/create$',
CreateMailbox.as_view(), name='create_mailbox'),
)

View file

@ -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())

View file

@ -0,0 +1 @@
{% extends "base.html" %}

View file

@ -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 %}
<p>{% if customer == user %}{% trans "Please specify the password for your new mailbox." %}{% else %}{% trans "Please specify the password for the new mailbox." %}{% endif %}</p>
{% crispy form %}
{% endblock content %}
{% block extra_js %}
<script type="text/javascript">
$(document).ready(function() {
$('input[type=password]').val('');
$('input[type=password]').first().focus();
});
</script>
{% endblock extra_js %}