diff --git a/forms.py b/forms.py index 6e91d84..ac0e2d0 100644 --- a/forms.py +++ b/forms.py @@ -405,6 +405,9 @@ ) moderator_password = forms.CharField( label = _('Moderator password'), + widget = forms.PasswordInput, + error_messages = {'required': _('Please enter your password.'), + 'invalid': _('Please enter a valid password.')}, ) msg_footer = forms.CharField( label = _('Message footer'), @@ -637,3 +640,143 @@ included in each. """ layout = [["Mass subscription", "emails"],] + +class MembershipSettings(FieldsetForm): + """Form handling the membership settings. + """ + choices = ((True, 'Yes'), (False, 'No'),) + acknowledge_posts = forms.BooleanField( + widget = forms.RadioSelect(choices = choices), + required = False, + label = _('Acknowledge posts'), + ) + hide_address = forms.BooleanField( + widget = forms.RadioSelect(choices = choices), + required = False, + label = _('Hide address'), + ) + receive_list_copy = forms.BooleanField( + widget = forms.RadioSelect(choices = choices), + required = False, + label = _('Receive list copy'), + ) + receive_own_postings = forms.BooleanField( + widget = forms.RadioSelect(choices = choices), + 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..."), # this must later be + # changed to what modes are available + ), + label = _('Delivery mode'), + ) + delivery_status = forms.ChoiceField( + widget = forms.Select(), + error_messages = { + 'required': _("Please choose a status."), + }, + required = False, + choices = ( + ("", _("Please choose")), + ("delivery_status", "some status..."), # this must later be + # changed to what statuses are available + ), + label = _('Delivery status'), + ) + name = forms.CharField( + label = "", + widget = forms.HiddenInput(), + initial = "membership", + ) + + class Meta: + """ + Class to define the name of the fieldsets and what should be + included in each. + """ + layout = [["Membership Settings", "acknowledge_posts", "hide_address", + "receive_list_copy", "receive_own_postings", + "delivery_mode", "delivery_status", "name"],] + +class UserSettings(FieldsetForm): + """Form handling the user settings. + """ + id = forms.IntegerField( # this should probably not be + # changeable... + label = _('ID'), + initial = 9, + widget = forms.HiddenInput(), + required = False, + error_messages = { + 'invalid': _('Please provide an integer ID.') + } + ) + mailing_list = forms.CharField( # not sure this needs to be here + label = _('Mailing list'), + widget = forms.HiddenInput(), + required = False, + ) + address = forms.ChoiceField( + widget = forms.Select(), + error_messages = { + 'required': _("Please choose an address."), + }, + required = True, + choices = ( + ("", _("Please choose")), + ("address", "address@example.com"), # this must later be + # changed to what addresses are available + ), + label = _('Default email address'), + ) + real_name =forms.CharField( + label = _('Real name'), + required = False, + ) + preferred_language = forms.ChoiceField( + label = _('Default/Preferred language'), + widget = forms.Select(), + error_messages = { + 'required': _("Please choose a language."), + }, + required = False, + choices = ( + ("", _("Please choose")), + ("English (USA)", "English (USA)"), # this must later be + # changed to what languages the list offers + ) + ) + password = forms.CharField( + label = _('Change password'), + widget = forms.PasswordInput, + required = False, + error_messages = {'required': _('Please enter your password.'), + 'invalid': _('Please enter a valid password.')}, + ) + conf_password = forms.CharField( + label = _('Confirm password'), + widget = forms.PasswordInput, + required = False, + error_messages = {'required': _('Please enter your password.'), + 'invalid': _('Please enter a valid password.')}, + ) + name = forms.CharField( + label = "", + widget = forms.HiddenInput(), + initial = "user", + ) + class Meta: + """ + Class to define the name of the fieldsets and what should be + included in each. + """ + layout = [["User settings", "real_name", "password", + "conf_password", "preferred_language", "address", "name"],] diff --git a/templates/mailman-django/lists/user_settings.html b/templates/mailman-django/lists/user_settings.html new file mode 100644 index 0000000..79f18ac --- /dev/null +++ b/templates/mailman-django/lists/user_settings.html @@ -0,0 +1,47 @@ +{% extends "mailman-django/base.html" %} +{% load i18n %} + + +{% block content %} + +

{{ settings_type }}{% trans "Settings" %}

+ +
+ + + +

Logout

+ +

This page visualizes the user/membership settings. Currently the page is not connected to the rest server so the settings will not be saved when changing them. However, this gives an idea of what the settings page could look like.

+ + +{% if message %} +

{{ message }}

+{% endif %} + +
+
+{{ user_form.as_div }} +
+ +
+
+
+ +
+{% for form in membership_forms %} +
+{{ form.as_div }} +
+ +
+
+{% endfor %} +
+ +
+ +{% endblock %} \ No newline at end of file diff --git a/urls.py b/urls.py index eab4e3f..e10a1f5 100644 --- a/urls.py +++ b/urls.py @@ -9,6 +9,7 @@ url(r'^lists/logout/$', 'logout', name = 'logout'), url(r'^lists/(?P.+)/$', 'list_info', name = 'list_info'), url(r'^delete_list/(?P[^/]+)/$', 'list_delete', name = 'list_delete'), + url(r'^user_settings/(?P[^/]+)/$', 'user_settings', name = 'user_settings'), url(r'^settings/(?P[^/]+)/$', 'list_settings', name = 'list_settings'), url(r'^settings/(?P[^/]+)/mass_subscribe/$', 'mass_subscribe', name = 'mass_subscribe'), # to override the default templates specifiy your own: diff --git a/views.py b/views.py index abd5dcf..b008c03 100644 --- a/views.py +++ b/views.py @@ -273,6 +273,56 @@ return render_to_response(template, {'form': form, 'message': message, 'fqdn_listname': the_list.info['fqdn_listname']}) +@login_required +def user_settings(request, member = None, + template = 'mailman-django/lists/user_settings.html'): + """ + Change the user or the membership settings. + The user must be logged in to be allowed to change any settings. + TODO: * deal with the actual member and updating the list + * add CSS to display tabs + * create a function returning all membership lists for a user + """ + message = "" + settings_type = "User " + membership_forms = [] + # TODO: call function to append all membership lists for a user + if request.method == 'POST': + # The form enables both user and member settings. As a result + # we must find out which was the case. + tab_type = request.POST.get('name', '') + if tab_type == "membership": + membership_forms.append(MembershipSettings(request.POST)) + user_form = UserSettings() + settings_type = "Membership " + # TODO: make sure the correct form is evaluated, this is + # just a temporary solution with one membership list + if membership_forms[0].is_valid(): + # TODO: add a call to an update function of the member + # settings HERE, once the member class is created + message = "The membership settings have been updated." + else: + user_form = UserSettings(request.POST) + membership_forms.append(MembershipSettings()) + if user_form.is_valid(): + # TODO: add a call to an update function of the user + # settings HERE, once the member class is created + message = "The user settings have been updated." + + else: + tab_type = "user" + user_form = UserSettings() + # TODO: add a call to a function adding all membership forms, + # this is just a temporary solution until we know what lists + # the user is subscribed to + membership_forms.append(MembershipSettings()) + + return render_to_response(template, {'user_form': user_form, + 'membership_forms': membership_forms, + 'settings_type': settings_type, + 'tab_type': tab_type, + 'message': message, + 'member': member}) def logout(request): """