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
.podcastlists
.models
import PodcastList
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
43 from mygpo
.db
.couchdb
.episode_state
import favorite_episode_ids_for_user
47 @cache_control(private
=True)
49 if request
.user
.is_authenticated():
50 return dashboard(request
)
52 return welcome(request
)
56 @cache_control(private
=True)
58 current_site
= RequestSite(request
)
60 lang
= process_lang_params(request
)
62 toplist
= Podcast
.objects
.all().toplist(lang
)
64 return render(request
, 'home.html', {
71 @cache_control(private
=True)
73 def dashboard(request
, episode_count
=10):
75 subscribed_podcasts
= get_subscribed_podcasts(request
.user
)
76 subscribed_podcasts
= [sp
.podcast
for sp
in subscribed_podcasts
]
78 site
= RequestSite(request
)
82 if request
.user
.client_set
.count():
83 checklist
.append('devices')
85 if subscribed_podcasts
:
86 checklist
.append('subscriptions')
88 if favorite_episode_ids_for_user(request
.user
):
89 checklist
.append('favorites')
91 if not request
.user
.profile
.get_token('subscriptions_token'):
92 checklist
.append('share')
94 if not request
.user
.profile
.get_token('favorite_feeds_token'):
95 checklist
.append('share-favorites')
97 if not request
.user
.profile
.get_token('userpage_token'):
98 checklist
.append('userpage')
100 if Tag
.objects
.filter(user
=request
.user
).exists():
101 checklist
.append('tags')
103 if PodcastList
.objects
.filter(user
=requset
.user
).exists():
104 checklist
.append('lists')
106 if PublishedPodcast
.objects
.filter(publisher
=request
.user
).exists():
107 checklist
.append('publish')
109 if request
.user
.profile
.get_wksetting(FLATTR_TOKEN
):
110 checklist
.append('flattr')
112 if request
.user
.profile
.get_wksetting(FLATTR_AUTO
):
113 checklist
.append('auto-flattr')
115 tomorrow
= datetime
.today() + timedelta(days
=1)
117 newest_episodes
= Episode
.objects
.filter(podcast__in
=subscribed_podcasts
,
118 released__lt
=tomorrow
).\
119 select_related('podcast').\
120 prefetch_related('slugs',
122 order_by('-released')[:episode_count
]
125 # we only show the "install reader" link in firefox, because we don't know
126 # yet how/if this works in other browsers.
127 # hints appreciated at https://bugs.gpodder.org/show_bug.cgi?id=58
128 show_install_reader
= \
129 'firefox' in request
.META
.get('HTTP_USER_AGENT', '').lower()
131 random_podcast
= Podcast
.objects
.all().random().prefetch_related('slugs').first()
133 return render(request
, 'dashboard.html', {
134 'user': request
.user
,
135 'subscribed_podcasts': subscribed_podcasts
,
136 'newest_episodes': list(newest_episodes
),
137 'random_podcast': random_podcast
,
138 'checklist': checklist
,
140 'show_install_reader': show_install_reader
,
145 @cache_control(private
=True)
148 tags_tag
= defaultdict(list)
152 tags
= Tag
.objects
.filter(source
=Tag
.USER
, user
=user
).order_by('tag')
154 tags_tag
[tag
.tag
].append(tag
.content_object
)
156 return render(request
, 'mytags.html', {
157 'tags_tag': dict(tags_tag
.items()),