diff --git a/src/postorius/forms.py b/src/postorius/forms.py index e093870..da68656 100644 --- a/src/postorius/forms.py +++ b/src/postorius/forms.py @@ -587,10 +587,13 @@ layout = [["Mass subscription", "emails"]] -class MembershipSettings(FieldsetForm): - """Form handling the membership settings. +class UserPreferences(FieldsetForm): + """Form handling the user's global preferences. """ choices = ((True, _('Yes')), (False, _('No'))) + + delivery_mode_choices = (("regular", _('Regular')), ("plaintext_digests",_('Plain Text Digests')),("mime_digests",_('Mime Digests')),("summary_digests", _('Summary Digests'))) + delivery_status_choices = (("enabled", _('Enabled')),("by_user",_('Disabled'))) acknowledge_posts = forms.BooleanField( widget=forms.RadioSelect(choices=choices), required=False, @@ -608,22 +611,14 @@ required=False, label=_('Receive own postings')) delivery_mode = forms.ChoiceField( - widget=forms.Select(), - error_messages={ - 'required': _("Please choose a mode.")}, - required=False, - choices=( - ("", _("Please choose")), - ("delivery_mode", "some mode...")), - label=_('Delivery mode')) + widget = forms.Select(), + choices = delivery_mode_choices, + required = False, + label = _('Delivery mode')) delivery_status = forms.ChoiceField( - widget=forms.Select(), - error_messages={ - 'required': _("Please choose a status.")}, + widget = forms.Select(), required=False, - choices=( - ("", _("Please choose")), - ("delivery_status", "some status...")), + choices= delivery_status_choices, label=_('Delivery status')) class Meta: @@ -635,7 +630,6 @@ "receive_list_copy", "receive_own_postings", "delivery_mode", "delivery_status"]] - class UserNew(FieldsetForm): """ Form field to add a new user diff --git a/src/postorius/templates/postorius/user_mailmansettings.html b/src/postorius/templates/postorius/user_mailmansettings.html index 273292b..accd7d0 100644 --- a/src/postorius/templates/postorius/user_mailmansettings.html +++ b/src/postorius/templates/postorius/user_mailmansettings.html @@ -12,90 +12,56 @@ {% else %}
-

{% trans "Subscription Settings" %} - {{ user }}

+

{% trans "Subscription Settings" %} - {{ user }}

-

Mailman display name: {{ mm_user.display_name}}

-

Django email: {{ user.email }}

-

Mailman primary email: {{ mm_user.email }}

-

Valid email addresses for this account:

- + -

WARNING: This page is currently a mockup and -anything below this line may not work

+

Global Preferences Overview

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
{% trans 'Receive List Copy' %}{{ mm_user.preferences.receive_list_copy }}
{% trans 'Hide Address' %}{{ mm_user.preferences.hide_address }}
{% trans 'Preferred Language' %}{{ mm_user.preferences.preferred_language }}
{% trans 'Acknowledge Posts' %}{{ mm_user.preferences.acknowledge_posts }}
{% trans 'Delivery Mode' %}{{ mm_user.preferences.delivery_mode }}
{% trans 'Receive Own Postings' %}{{ mm_user.preferences.receive_own_postings }}
{% trans 'Delivery Status' %}{{ mm_user.preferences.delivery_status }}
-

Preferences:

-

preferences: {{ mm_user.preferences }} -

user: {{ mm_user }} -

tko -

memberships: {{ membership_lists }} - {% for pref in mm_user.preferences %} -

  • {{ pref }}
  • - {% endfor %} - -

    Sample output: not real

    - -

    Prefs form

    +

    Global Preferences Form

    +
    {% csrf_token %} {{ settingsform.as_p }}
    -

    List Preferences Overview

    -

    Sample output: not real

    - -
    {% csrf_token %} - - - - - - - - - - - - - - - - - - {% for preference in mm_user.preferences %} - {% endfor %} - - - - - - - - - - - -
    {% trans "Setting" %}{% trans "Description" %}{% trans "Set all" %}list1@example.comkumquat@example.comstarfruit@example.com
    {% trans "Mail delivery" %} ({{ preference }})Set this option to Enabled to receive -messages posted - to this mailing list. Set it to Disabled if you want - to stay subscribed, but don't want mail delivered to you for a - while (e.g. you're going on vacation). If you disable mail - delivery, don't forget to re-enable it when you come back; it - will not be automatically re-enabled."
    {% trans "Per-Email subscriptions" %}
    anna@example.com
    -
    + {% endif %} {% endblock main %} -~ +~ diff --git a/src/postorius/views/user.py b/src/postorius/views/user.py index a5acb5c..b6d2d5e 100644 --- a/src/postorius/views/user.py +++ b/src/postorius/views/user.py @@ -53,7 +53,23 @@ @method_decorator(login_required) def post(self, request): - raise NotImplementedError + try: + mm_user = MailmanUser.objects.get(address=request.user.email) + userprefs_form = UserPreferences(request.POST) + if userprefs_form.is_valid(): + user_preferences = mm_user.preferences + for key in userprefs_form.fields.keys(): + user_preferences[key] = userprefs_form.cleaned_data[key] + user_preferences.save() + messages.success(request, 'Your preferences have been updated.') + else: + messages.error(request, 'Something went wrong.') + except MailmanApiError: + return utils.render_api_error(request) + except HTTPError, e: + messages.error(request, e.msg) + return redirect("user_mailmansettings") + @method_decorator(login_required) def get(self, request): @@ -69,13 +85,12 @@ 'postorius/user_mailmansettings.html', {'nolists': 'true'}, context_instance=RequestContext(request)) - settingsform = MembershipSettings() + settingsform = UserPreferences(initial = mm_user.preferences) return render_to_response('postorius/user_mailmansettings.html', {'mm_user': mm_user, 'settingsform': settingsform}, context_instance=RequestContext(request)) - class UserSummaryView(MailmanUserView): """Shows a summary of a user. """