From 213b44b3dadbba3c944a72739f4c1ee27d2b3e36 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Stefan=20K=C3=B6gl?= Date: Fri, 27 Sep 2013 17:01:39 +0200 Subject: [PATCH] use private-toggle component for podcast privacy settings --- mygpo/core/podcasts.py | 4 +++ mygpo/web/templates/privacy.html | 73 +++++++++++++++++++++++++++++----------- mygpo/web/views/settings.py | 13 +++---- 3 files changed, 63 insertions(+), 27 deletions(-) diff --git a/mygpo/core/podcasts.py b/mygpo/core/podcasts.py index 63448d26..413e7a4a 100644 --- a/mygpo/core/podcasts.py +++ b/mygpo/core/podcasts.py @@ -6,6 +6,10 @@ from mygpo.db.couchdb.episode import episodes_for_podcast from mygpo.utils import sorted_chain +# the default sort order for podcasts +PODCAST_SORT=lambda p: p.display_title + + class PodcastSet(set): """ Represents a set of podcasts """ diff --git a/mygpo/web/templates/privacy.html b/mygpo/web/templates/privacy.html index 9a90f416..9a64a3e5 100644 --- a/mygpo/web/templates/privacy.html +++ b/mygpo/web/templates/privacy.html @@ -22,25 +22,47 @@

-

- {% if public_subscriptions %} - {% trans "New subscriptions will be public by default." %} -

- {% csrf_token %} - -
- {% else %} - {% trans "New subscriptions will be private by default." %} -
- {% csrf_token %} - -
- {% endif %} -

+

{% trans "Subscriptions" %}

+ + + + + + + + {% for podcast, private in subscriptions %} + + + + + + {% endfor %} +
{% trans "Default for new subscriptions" %} +
+ {% csrf_token %} +
+
+ {% csrf_token %} +
+ {% include "share/components/private-toggle.html" with private=private_subscriptions public_action="default_public" private_action="default_private" %} +
{% podcast_group_link podcast %} +
+ {% csrf_token %} +
+
+ {% csrf_token %} +
+ {% include "share/components/private-toggle.html" with private=private public_action="podcast_public_" private_action="podcast_private_" param=podcast.get_id %} +
+ {% if included_subscriptions %}

{% trans "Public Subscriptions" %}

@@ -86,3 +108,16 @@ {% endblock %} + + +{% block javascript %} + +{% endblock %} diff --git a/mygpo/web/views/settings.py b/mygpo/web/views/settings.py index 43bad26e..3a4eccb0 100644 --- a/mygpo/web/views/settings.py +++ b/mygpo/web/views/settings.py @@ -33,6 +33,7 @@ from django.utils.html import strip_tags from django_couchdb_utils.auth.models import UsernameException, \ PasswordException +from mygpo.core.podcasts import PODCAST_SORT from mygpo.decorators import allowed_methods, repeat_on_conflict from mygpo.web.forms import UserAccountForm, ProfileForm, FlattrForm from mygpo.web.utils import normalize_twitter @@ -224,7 +225,6 @@ class DefaultPrivacySettings(View): @method_decorator(never_cache) def post(self, request): self.set_privacy_settings(user=request.user) - messages.success(request, 'Success') return HttpResponseRedirect(reverse('privacy')) @repeat_on_conflict(['user']) @@ -243,8 +243,6 @@ class PodcastPrivacySettings(View): podcast = podcast_by_id(podcast_id) state = podcast_state_for_user_podcast(request.user, podcast) set_podcast_privacy_settings(state, self.public) - self.set_privacy_settings(state=state) - messages.success(request, 'Success') return HttpResponseRedirect(reverse('privacy')) @@ -256,13 +254,12 @@ def privacy(request): subscriptions = subscriptions_by_user(request.user) podcasts = podcasts_to_dict([x[1] for x in subscriptions]) - included_subscriptions = set(filter(None, [podcasts.get(x[1], None) for x in subscriptions if x[0] == True])) - excluded_subscriptions = set(filter(None, [podcasts.get(x[1], None) for x in subscriptions if x[0] == False])) + subs = set((podcasts.get(x[1], None), not x[0]) for x in subscriptions) + subs = sorted(subs, key=lambda (p, _): PODCAST_SORT(p)) return render(request, 'privacy.html', { - 'public_subscriptions': request.user.get_wksetting(PUBLIC_SUB_USER), - 'included_subscriptions': included_subscriptions, - 'excluded_subscriptions': excluded_subscriptions, + 'private_subscriptions': not request.user.get_wksetting(PUBLIC_SUB_USER), + 'subscriptions': subs, 'domain': site.domain, }) -- 2.11.4.GIT