Mercurial > public > sg101
changeset 803:b3eeaefc39a8
Private message refactoring: add options page.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Sun, 31 Aug 2014 12:46:21 -0500 |
parents | dbc389a409f5 |
children | 95b3d59913ad |
files | messages/urls.py messages/views.py sg101/templates/messages/messages_base.html sg101/templates/messages/options.html sg101/templates/messages/options_tab.html |
diffstat | 5 files changed, 41 insertions(+), 46 deletions(-) [+] |
line wrap: on
line diff
--- 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'),
--- 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.
--- 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 @@ <li>{% if tab != 'outbox' %}<a href="{% url 'messages-outbox' %}">{% endif %}Outbox{% if tab != 'outbox' %}</a>{% endif %} {% if outbox_pct %}({{ outbox_pct }}% used){% endif %}</li> <li>{% if tab != 'trash' %}<a href="{% url 'messages-trash' %}">{% endif %}Trash{% if tab != 'trash' %}</a>{% endif %}</li> -{% comment %} <li>{% if tab != 'options' %}<a href="{% url 'messages-options' %}">{% endif %}Options{% if tab != 'options' %}</a>{% endif %}</li> -{% endcomment %} </ul> {% block messages_content %}{% endblock %}
--- /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 %} +<h3>Private Message Options</h3> +<p>Set your private message preferences here.</p> +<form action="." method="post">{% csrf_token %} +<table> +{{ form.as_table }} +<tr> + <td> </td> + <td> + <input type="submit" name="submit_button" value="Save" /> + </td> +</tr> +</table> +</form> +{% endblock %}
--- 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 %} -<ul id="message-opts-messages" class="user-messages"> - {% for msg in messages %} - <li{% if msg.tags %} class="{{ msg.tags }}"{% endif %}>{{ msg }}</li> - {% endfor %} -</ul> -{% endif %} -<form action="." method="post" onsubmit="return submitOptions(this);">{% csrf_token %} -<table> -{{ form.as_table }} -<tr> - <td> </td> - <td> - <input type="submit" name="submit_button" value="Save" /> - </td> -</tr> -</table> -</form>