let podcasts, episodes link to their publisher pages
authorStefan Kögl <stefan@skoegl.net>
Sun, 16 Jun 2013 14:38:08 +0000 (16 16:38 +0200)
committerStefan Kögl <stefan@skoegl.net>
Sun, 16 Jun 2013 14:38:08 +0000 (16 16:38 +0200)
mygpo/publisher/utils.py
mygpo/web/templates/episode.html
mygpo/web/templates/episodes.html
mygpo/web/templates/podcast.html
mygpo/web/views/episode.py
mygpo/web/views/podcast.py

index 3e35476..374d854 100644 (file)
@@ -132,6 +132,11 @@ def subscriber_data(podcasts):
 
 
 def check_publisher_permission(user, podcast):
+    """ Checks if the user has publisher permissions for the given podcast """
+
+    if not user.is_authenticated():
+        return False
+
     if user.is_staff:
         return True
 
index d9c03f6..f8cc0e2 100644 (file)
 
 {% block sidebar %}
 
+  {% if is_publisher %}
+   <div class="well">
+    <h4>{% trans "Publisher Pages" %}</h4>
+
+    <a class="btn" href="{% episode_link_target episode podcast "episode-publisher-detail" %}"><i class="icon-wrench"></i> {% trans "Go" %}</a>
+   </div>
+  {% endif %}
+
+
  <div class="well">
 
   <h4>Share</h4>
index e3af91b..c804598 100755 (executable)
 {% endblock %}
 
 
+{% block sidebar %}
+
+  {% if is_publisher %}
+   <div class="well">
+    <h4>{% trans "Publisher Pages" %}</h4>
+
+    <a class="btn" href="{% podcast_link_target podcast "podcast-publisher-episodes" %}"><i class="icon-wrench"></i> {% trans "Go" %}</a>
+   </div>
+  {% endif %}
+
+
+{% endblock %}
+
 {% block ads %}
  {% comment %}disable ads on podcast pages{% endcomment %}
 {% endblock %}
index aee5a50..7a15507 100755 (executable)
       <td>{{ episode.action|episode_status_icon }}</td>
       <td class="short">
           <div class="title">{% episode_link episode podcast %}</div>
-          <div class="description short">{{ episode.description|default:""|truncatewords:"20"|markdown|striptags }}</div>
+          <div class="description short">{{ episode.subtitle|default:episode.description|default:""|truncatewords:"20"|markdown|striptags }}</div>
       </td>
       <td>{{ episode.released|default:""|date:"Y-m-d" }}</td>
       <td>
 
 {% block sidebar %}
 
+  {% if is_publisher %}
+   <div class="well">
+    <h4>{% trans "Publisher Pages" %}</h4>
+
+    <a class="btn" href="{% podcast_link_target podcast "podcast-publisher-detail" %}"><i class="icon-wrench"></i> {% trans "Go" %}</a>
+   </div>
+  {% endif %}
+
   <div class="well">
    <h4>{% trans "Subscriptions" %}</h4>
    {% if not user.is_authenticated %}
index 254cc0d..27a1bc6 100644 (file)
@@ -37,6 +37,7 @@ from mygpo.users.models import Chapter, HistoryEntry, EpisodeAction
 from mygpo.utils import parse_time, get_timestamp
 from mygpo.users.settings import FLATTR_TOKEN
 from mygpo.web.heatmap import EpisodeHeatmap
+from mygpo.publisher.utils import check_publisher_permission
 from mygpo.web.utils import get_episode_link_target, fetch_episode_data
 from mygpo.db.couchdb.episode import episode_for_slug_id, episode_for_oldid, \
          favorite_episodes_for_user, chapters_for_episode
@@ -53,13 +54,14 @@ from mygpo.userfeeds.feeds import FavoriteFeed
 def episode(request, episode):
 
     podcast = podcast_by_id(episode.podcast)
+    user = request.user
 
     if not podcast:
         raise Http404
 
-    if request.user.is_authenticated():
+    if user.is_authenticated():
 
-        episode_state = episode_state_for_user_episode(request.user, episode)
+        episode_state = episode_state_for_user_episode(user, episode)
         is_fav = episode_state.is_favorite()
 
 
@@ -68,14 +70,14 @@ def episode(request, episode):
         episodes_dict = {episode._id: episode}
 
         history = list(episode_state.get_history_entries())
-        HistoryEntry.fetch_data(request.user, history,
+        HistoryEntry.fetch_data(user, history,
                 podcasts=podcasts_dict, episodes=episodes_dict)
 
         played_parts = EpisodeHeatmap(podcast.get_id(),
-                episode._id, request.user._id, duration=episode.duration)
+                episode._id, user._id, duration=episode.duration)
 
-        devices = dict( (d.id, d.name) for d in request.user.devices )
-        can_flattr = request.user.get_wksetting(FLATTR_TOKEN) and episode.flattr_url
+        devices = dict( (d.id, d.name) for d in user.devices )
+        can_flattr = user.get_wksetting(FLATTR_TOKEN) and episode.flattr_url
 
     else:
         history = []
@@ -84,11 +86,12 @@ def episode(request, episode):
         devices = {}
         can_flattr = False
 
+    is_publisher = check_publisher_permission(user, podcast)
 
     chapters = []
-    for user, chapter in chapters_for_episode(episode._id):
-        chapter.is_own = request.user.is_authenticated() and \
-                         user == request.user._id
+    for user_id, chapter in chapters_for_episode(episode._id):
+        chapter.is_own = user.is_authenticated() and \
+                         user_id == user._id
         chapters.append(chapter)
 
 
@@ -107,6 +110,7 @@ def episode(request, episode):
         'actions': EPISODE_ACTION_TYPES,
         'devices': devices,
         'can_flattr': can_flattr,
+        'is_publisher': is_publisher,
     })
 
 
index 037f98c..6f34e0e 100644 (file)
@@ -15,6 +15,7 @@ from mygpo.core.proxy import proxy_object
 from mygpo.core.tasks import flattr_thing
 from mygpo.utils import normalize_feed_url
 from mygpo.users.settings import PUBLIC_SUB_PODCAST, FLATTR_TOKEN
+from mygpo.publisher.utils import check_publisher_permission
 from mygpo.users.models import HistoryEntry, DeviceDoesNotExist, SubscriptionAction
 from mygpo.web.forms import SyncForm
 from mygpo.decorators import allowed_methods, repeat_on_conflict
@@ -98,6 +99,8 @@ def show(request, podcast):
         subscribe_targets = []
         can_flattr = False
 
+    is_publisher = check_publisher_permission(user, podcast)
+
     def _set_objects(h):
         dev = user.get_device(h.device)
         return proxy_object(h, device=dev)
@@ -117,6 +120,7 @@ def show(request, podcast):
         'episodes': episodes,
         'max_listeners': max_listeners,
         'can_flattr': can_flattr,
+        'is_publisher': is_publisher,
     })
 
 
@@ -181,7 +185,9 @@ def all_episodes(request, podcast, page_size=20):
     except ValueError:
         page = 1
 
-    episodes = episode_list(podcast, request.user, (page-1) * page_size,
+    user = request.user
+
+    episodes = episode_list(podcast, user, (page-1) * page_size,
             page_size)
     episodes_total = podcast.episode_count or 0
     num_pages = episodes_total / page_size
@@ -189,12 +195,15 @@ def all_episodes(request, podcast, page_size=20):
 
     max_listeners = max([e.listeners for e in episodes] + [0])
 
+    is_publisher = check_publisher_permission(user, podcast)
+
     return render(request, 'episodes.html', {
         'podcast': podcast,
         'episodes': episodes,
         'max_listeners': max_listeners,
         'page_list': page_list,
         'current_page': page,
+        'is_publisher': is_publisher,
     })