mirror of
https://github.com/zulip/zulip.git
synced 2025-11-04 22:13:26 +00:00
Add a navigation link for managing subscriptions (for starters, just unsubbing).
(imported from commit 23274a8790bf1f017e9c33db52bf746e291f23ba)
This commit is contained in:
@@ -16,6 +16,8 @@ urlpatterns = patterns('',
|
|||||||
url(r'^accounts/login/', 'django.contrib.auth.views.login', {'template_name': 'zephyr/login.html'}),
|
url(r'^accounts/login/', 'django.contrib.auth.views.login', {'template_name': 'zephyr/login.html'}),
|
||||||
url(r'^accounts/logout/', 'django.contrib.auth.views.logout', {'template_name': 'zephyr/index.html'}),
|
url(r'^accounts/logout/', 'django.contrib.auth.views.logout', {'template_name': 'zephyr/index.html'}),
|
||||||
url(r'^accounts/register/', 'zephyr.views.register', name='register'),
|
url(r'^accounts/register/', 'zephyr.views.register', name='register'),
|
||||||
|
url(r'^subscriptions/$', 'zephyr.views.subscriptions', name='subscriptions'),
|
||||||
|
url(r'^subscriptions/manage/$', 'zephyr.views.manage_subscriptions', name='manage_subscriptions'),
|
||||||
url(r'^static/(?P<path>.*)$', 'django.views.static.serve',
|
url(r'^static/(?P<path>.*)$', 'django.views.static.serve',
|
||||||
{'document_root': os.path.join(settings.SITE_ROOT, '..', 'zephyr', 'static/')})
|
{'document_root': os.path.join(settings.SITE_ROOT, '..', 'zephyr', 'static/')})
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
{% extends "zephyr/base.html" %}
|
{% extends "zephyr/base.html" %}
|
||||||
|
|
||||||
{% block nav %}
|
{% block nav %}
|
||||||
<li><a href="/accounts/logout/?next=/">Log out</a></li>
|
<li><a href="/accounts/logout?next=/">Log out</a></li>
|
||||||
|
<li><a href="/subscriptions/">Manage subscriptions</a></li>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
|
|||||||
37
templates/zephyr/subscriptions.html
Normal file
37
templates/zephyr/subscriptions.html
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
{% extends "zephyr/base.html" %}
|
||||||
|
|
||||||
|
{% block nav %}
|
||||||
|
<li><a href="/accounts/logout?next=/">Log out</a></li>
|
||||||
|
<li><a href="/subscriptions/">Manage subscriptions</a></li>
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
|
||||||
|
<script type="text/javascript" src="/static/js/zephyr.js"></script>
|
||||||
|
|
||||||
|
<h1>Current subscriptions</h1>
|
||||||
|
<div class="row-fluid">
|
||||||
|
<div id="current_subscriptions" class="span12">
|
||||||
|
<form action="/subscriptions/manage/" method="post" class="subscriptions">{% csrf_token %}
|
||||||
|
<table id="current_subscriptions_table">
|
||||||
|
<tr>
|
||||||
|
<th>Unsubscribe?</th>
|
||||||
|
<th>Class</th>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
{% for subscription in subscriptions %}
|
||||||
|
<td class="checkbox">
|
||||||
|
<input type="checkbox" name="subscription" value="{{ subscription }}" /></input>
|
||||||
|
</td>
|
||||||
|
<td class="subscription">
|
||||||
|
{{ subscription }}
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
{% endfor %}
|
||||||
|
</table>
|
||||||
|
<input type="submit" name="change_subscriptions" value="Change subscriptions" class="btn" />
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{% endblock %}
|
||||||
@@ -91,7 +91,7 @@ def send_zephyr(**kwargs):
|
|||||||
assert(len(recipients) == 1)
|
assert(len(recipients) == 1)
|
||||||
elif zephyr.recipient.type == "class":
|
elif zephyr.recipient.type == "class":
|
||||||
recipients = [UserProfile.objects.get(user=s.userprofile_id) for
|
recipients = [UserProfile.objects.get(user=s.userprofile_id) for
|
||||||
s in Subscription.objects.filter(recipient_id=zephyr.recipient)]
|
s in Subscription.objects.filter(recipient_id=zephyr.recipient, active=True)]
|
||||||
else:
|
else:
|
||||||
raise
|
raise
|
||||||
for recipient in recipients:
|
for recipient in recipients:
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ from django.utils.timezone import utc
|
|||||||
|
|
||||||
from django.contrib.auth.models import User
|
from django.contrib.auth.models import User
|
||||||
from zephyr.models import Zephyr, UserProfile, ZephyrClass, Subscription, \
|
from zephyr.models import Zephyr, UserProfile, ZephyrClass, Subscription, \
|
||||||
Recipient, filter_by_subscriptions
|
Recipient, filter_by_subscriptions, get_display_recipient
|
||||||
from zephyr.forms import RegistrationForm
|
from zephyr.forms import RegistrationForm
|
||||||
|
|
||||||
import tornado.web
|
import tornado.web
|
||||||
@@ -140,3 +140,31 @@ def zephyr(request):
|
|||||||
new_zephyr.save()
|
new_zephyr.save()
|
||||||
|
|
||||||
return HttpResponse('')
|
return HttpResponse('')
|
||||||
|
|
||||||
|
@login_required
|
||||||
|
def subscriptions(request):
|
||||||
|
userprofile = UserProfile.objects.get(user=request.user)
|
||||||
|
subscriptions = Subscription.objects.filter(userprofile_id=userprofile, active=True)
|
||||||
|
# For now, don't display the subscription for your ability to receive personals.
|
||||||
|
sub_names = [get_display_recipient(sub.recipient_id) for sub in subscriptions if sub.recipient_id.type != "personal"]
|
||||||
|
|
||||||
|
return render_to_response('zephyr/subscriptions.html',
|
||||||
|
{'subscriptions': sub_names, 'user_profile': userprofile},
|
||||||
|
context_instance=RequestContext(request))
|
||||||
|
|
||||||
|
@login_required
|
||||||
|
def manage_subscriptions(request):
|
||||||
|
if not request.POST:
|
||||||
|
# Do something reasonable.
|
||||||
|
return
|
||||||
|
user_profile = UserProfile.objects.get(user=request.user)
|
||||||
|
|
||||||
|
unsubs = request.POST.getlist('subscription')
|
||||||
|
for sub_name in unsubs:
|
||||||
|
zephyr_class = ZephyrClass.objects.get(name=sub_name)
|
||||||
|
subscription = Subscription.objects.get(
|
||||||
|
userprofile_id=user_profile.id, recipient_id=zephyr_class.id)
|
||||||
|
subscription.active = False
|
||||||
|
subscription.save()
|
||||||
|
|
||||||
|
return HttpResponseRedirect(reverse('zephyr.views.subscriptions'))
|
||||||
|
|||||||
Reference in New Issue
Block a user