# HG changeset patch # User Brian Neal # Date 1409507181 18000 # Node ID b3eeaefc39a8d5efe882563cf9a728a70a2211a7 # Parent dbc389a409f5879a0ba4092321fe15d77d801f28 Private message refactoring: add options page. diff -r dbc389a409f5 -r b3eeaefc39a8 messages/urls.py --- a/messages/urls.py Sat Aug 30 19:11:32 2014 -0500 +++ b/messages/urls.py Sun Aug 31 12:46:21 2014 -0500 @@ -18,9 +18,9 @@ url(r'^trash/$', 'messages.views.trash', name='messages-trash'), -# url(r'^options/$', -# 'messages.views.options', -# name='messages-options'), + url(r'^options/$', + 'messages.views.options', + name='messages-options'), # url(r'^delete/$', # 'messages.views.delete', # name='messages-delete'), diff -r dbc389a409f5 -r b3eeaefc39a8 messages/views.py --- a/messages/views.py Sat Aug 30 19:11:32 2014 -0500 +++ b/messages/views.py Sun Aug 31 12:46:21 2014 -0500 @@ -112,6 +112,28 @@ @login_required +def options(request): + """ + This view handles the displaying and changing of private message options. + + """ + if request.method == 'POST': + options = Options.objects.for_user(request.user) + form = OptionsForm(request.POST, instance=options, prefix='opts') + if form.is_valid(): + form.save() + django_messages.success(request, 'Options saved.') + else: + options = Options.objects.for_user(request.user) + form = OptionsForm(instance=options, prefix='opts') + + return render(request, 'messages/options.html', { + 'tab': 'options', + 'form': form, + }) + + +@login_required def compose_to(request, receiver): """ This function displays the base tabbed private messages view, @@ -158,29 +180,6 @@ return HttpResponse(result, content_type='application/json') -def options(request): - """ - This view handles the displaying and changing of private message options. - - """ - if not request.user.is_authenticated(): - return HttpResponseForbidden() - - if request.method == "POST": - options = Options.objects.for_user(request.user) - form = OptionsForm(request.POST, instance=options, prefix='opts') - if form.is_valid(): - form.save() - django_messages.success(request, 'Options saved.') - else: - options = Options.objects.for_user(request.user) - form = OptionsForm(instance=options, prefix='opts') - - return render(request, 'messages/options_tab.html', { - 'form': form, - }) - - def compose(request, receiver=None): """ Process or prepare the compose form to create a new private message. diff -r dbc389a409f5 -r b3eeaefc39a8 sg101/templates/messages/messages_base.html --- a/sg101/templates/messages/messages_base.html Sat Aug 30 19:11:32 2014 -0500 +++ b/sg101/templates/messages/messages_base.html Sun Aug 31 12:46:21 2014 -0500 @@ -24,9 +24,7 @@
  • {% if tab != 'outbox' %}{% endif %}Outbox{% if tab != 'outbox' %}{% endif %} {% if outbox_pct %}({{ outbox_pct }}% used){% endif %}
  • {% if tab != 'trash' %}{% endif %}Trash{% if tab != 'trash' %}{% endif %}
  • -{% comment %}
  • {% if tab != 'options' %}{% endif %}Options{% if tab != 'options' %}{% endif %}
  • -{% endcomment %} {% block messages_content %}{% endblock %} diff -r dbc389a409f5 -r b3eeaefc39a8 sg101/templates/messages/options.html --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/sg101/templates/messages/options.html Sun Aug 31 12:46:21 2014 -0500 @@ -0,0 +1,16 @@ +{% extends 'messages/messages_base.html' %} +{% block messages_content %} +

    Private Message Options

    +

    Set your private message preferences here.

    +
    {% csrf_token %} + +{{ form.as_table }} + + + + +
      + +
    +
    +{% endblock %} diff -r dbc389a409f5 -r b3eeaefc39a8 sg101/templates/messages/options_tab.html --- a/sg101/templates/messages/options_tab.html Sat Aug 30 19:11:32 2014 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,18 +0,0 @@ -{% if messages %} - -{% endif %} -
    {% csrf_token %} - -{{ form.as_table }} - - - - -
      - -
    -