2 # This file is part of my.gpodder.org.
4 # my.gpodder.org is free software: you can redistribute it and/or modify it
5 # under the terms of the GNU Affero General Public License as published by
6 # the Free Software Foundation, either version 3 of the License, or (at your
7 # option) any later version.
9 # my.gpodder.org is distributed in the hope that it will be useful, but
10 # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
11 # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public
12 # License for more details.
14 # You should have received a copy of the GNU Affero General Public License
15 # along with my.gpodder.org. If not, see <http://www.gnu.org/licenses/>.
19 from collections
import defaultdict
20 from datetime
import datetime
, timedelta
22 from django
.core
.urlresolvers
import reverse
23 from django
.http
import HttpResponseRedirect
24 from django
.contrib
import messages
25 from django
.utils
.translation
import ugettext
as _
26 from django
.contrib
.auth
.decorators
import login_required
27 from django
.shortcuts
import render
28 from django
.contrib
.sites
.models
import RequestSite
29 from django
.views
.generic
.base
import View
30 from django
.views
.decorators
.vary
import vary_on_cookie
31 from django
.views
.decorators
.cache
import never_cache
, cache_control
33 from mygpo
.decorators
import repeat_on_conflict
34 from mygpo
.podcasts
.models
import Podcast
, Episode
, Tag
35 from mygpo
.users
.models
import HistoryEntry
, Client
36 from mygpo
.subscriptions
import get_subscribed_podcasts
37 from mygpo
.web
.utils
import process_lang_params
38 from mygpo
.utils
import parse_range
39 #from mygpo.web.views.podcast import slug_id_decorator
40 from mygpo
.users
.settings
import FLATTR_AUTO
, FLATTR_TOKEN
41 from mygpo
.publisher
.models
import PublishedPodcast
42 from mygpo
.db
.couchdb
.episode_state
import favorite_episode_ids_for_user
43 from mygpo
.db
.couchdb
.directory
import tags_for_user
44 from mygpo
.db
.couchdb
.podcastlist
import podcastlists_for_user
48 @cache_control(private
=True)
50 if request
.user
.is_authenticated():
51 return dashboard(request
)
53 return welcome(request
)
57 @cache_control(private
=True)
59 current_site
= RequestSite(request
)
61 lang
= process_lang_params(request
)
63 toplist
= Podcast
.objects
.all().toplist(lang
)
65 return render(request
, 'home.html', {
72 @cache_control(private
=True)
74 def dashboard(request
, episode_count
=10):
76 subscribed_podcasts
= get_subscribed_podcasts(request
.user
)
77 subscribed_podcasts
= [sp
.podcast
for sp
in subscribed_podcasts
]
79 site
= RequestSite(request
)
83 if request
.user
.client_set
.count():
84 checklist
.append('devices')
86 if subscribed_podcasts
:
87 checklist
.append('subscriptions')
89 if favorite_episode_ids_for_user(request
.user
):
90 checklist
.append('favorites')
92 if not request
.user
.profile
.get_token('subscriptions_token'):
93 checklist
.append('share')
95 if not request
.user
.profile
.get_token('favorite_feeds_token'):
96 checklist
.append('share-favorites')
98 if not request
.user
.profile
.get_token('userpage_token'):
99 checklist
.append('userpage')
101 if tags_for_user(request
.user
):
102 checklist
.append('tags')
104 # TODO add podcastlist_count_for_user
105 if podcastlists_for_user(request
.user
.profile
.uuid
.hex):
106 checklist
.append('lists')
108 if PublishedPodcast
.objects
.filter(publisher
=request
.user
).exists():
109 checklist
.append('publish')
111 if request
.user
.profile
.get_wksetting(FLATTR_TOKEN
):
112 checklist
.append('flattr')
114 if request
.user
.profile
.get_wksetting(FLATTR_AUTO
):
115 checklist
.append('auto-flattr')
117 tomorrow
= datetime
.today() + timedelta(days
=1)
119 newest_episodes
= Episode
.objects
.filter(podcast__in
=subscribed_podcasts
,
120 released__lt
=tomorrow
).\
121 select_related('podcast').\
122 prefetch_related('slugs',
124 order_by('-released')[:episode_count
]
127 # we only show the "install reader" link in firefox, because we don't know
128 # yet how/if this works in other browsers.
129 # hints appreciated at https://bugs.gpodder.org/show_bug.cgi?id=58
130 show_install_reader
= \
131 'firefox' in request
.META
.get('HTTP_USER_AGENT', '').lower()
133 random_podcast
= Podcast
.objects
.all().random().prefetch_related('slugs').first()
135 return render(request
, 'dashboard.html', {
136 'user': request
.user
,
137 'subscribed_podcasts': subscribed_podcasts
,
138 'newest_episodes': list(newest_episodes
),
139 'random_podcast': random_podcast
,
140 'checklist': checklist
,
142 'show_install_reader': show_install_reader
,
147 @cache_control(private
=True)
150 tags_tag
= defaultdict(list)
154 tags
= Tag
.objects
.filter(source
=Tag
.USER
, user
=user
).order_by('tag')
156 tags_tag
[tag
.tag
].append(tag
.content_object
)
158 return render(request
, 'mytags.html', {
159 'tags_tag': dict(tags_tag
.items()),