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
.requests
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
.podcasts
.models
import Podcast
, Episode
, Tag
34 from mygpo
.users
.models
import HistoryEntry
, Client
35 from mygpo
.subscriptions
import get_subscribed_podcasts
36 from mygpo
.web
.utils
import process_lang_params
37 from mygpo
.utils
import parse_range
38 from mygpo
.podcastlists
.models
import PodcastList
39 from mygpo
.favorites
.models
import FavoriteEpisode
40 #from mygpo.web.views.podcast import slug_id_decorator
41 from mygpo
.users
.settings
import FLATTR_AUTO
, FLATTR_TOKEN
42 from mygpo
.publisher
.models
import PublishedPodcast
46 @cache_control(private
=True)
48 if request
.user
.is_authenticated():
49 return dashboard(request
)
51 return welcome(request
)
55 @cache_control(private
=True)
57 current_site
= RequestSite(request
)
59 lang
= process_lang_params(request
)
61 toplist
= Podcast
.objects
.all().toplist(lang
)
63 return render(request
, 'home.html', {
70 @cache_control(private
=True)
72 def dashboard(request
, episode_count
=10):
74 subscribed_podcasts
= get_subscribed_podcasts(request
.user
)
75 subscribed_podcasts
= [sp
.podcast
for sp
in subscribed_podcasts
]
77 podcast_ad
= Podcast
.objects
.get_advertised_podcast()
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 FavoriteEpisode
.objects
.filter(user
=request
.user
).exists():
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 Tag
.objects
.filter(user
=request
.user
).exists():
102 checklist
.append('tags')
104 if PodcastList
.objects
.filter(user
=request
.user
).exists():
105 checklist
.append('lists')
107 if PublishedPodcast
.objects
.filter(publisher
=request
.user
).exists():
108 checklist
.append('publish')
110 if request
.user
.profile
.settings
.get_wksetting(FLATTR_TOKEN
):
111 checklist
.append('flattr')
113 if request
.user
.profile
.settings
.get_wksetting(FLATTR_AUTO
):
114 checklist
.append('auto-flattr')
116 tomorrow
= datetime
.today() + timedelta(days
=1)
118 newest_episodes
= Episode
.objects
.filter(podcast__in
=subscribed_podcasts
,
119 released__lt
=tomorrow
).\
120 select_related('podcast').\
121 prefetch_related('slugs',
123 order_by('-released')[:episode_count
]
126 # we only show the "install reader" link in firefox, because we don't know
127 # yet how/if this works in other browsers.
128 # hints appreciated at https://bugs.gpodder.org/show_bug.cgi?id=58
129 show_install_reader
= \
130 'firefox' in request
.META
.get('HTTP_USER_AGENT', '').lower()
132 random_podcast
= Podcast
.objects
.all().random().prefetch_related('slugs').first()
134 return render(request
, 'dashboard.html', {
135 'user': request
.user
,
136 'subscribed_podcasts': subscribed_podcasts
,
137 'newest_episodes': list(newest_episodes
),
138 'random_podcast': random_podcast
,
139 'checklist': checklist
,
141 'show_install_reader': show_install_reader
,
142 'podcast_ad': podcast_ad
,
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()),
164 def csrf_failure(request
, reason
=""):
165 site
= RequestSite(request
)
166 return render(request
, 'csrf.html', {
168 'method': request
.method
,
169 'referer': request
.META
.get('HTTP_REFERER', _('another site')),
170 'path': request
.path
,
172 'post': request
.POST
,