Commit 94417368 authored by fred's avatar fred

update for focus changes

parent bfef443b
......@@ -48,10 +48,10 @@ def has_focus(object):
else:
return False
try:
Focus.objects.get(**{object_type: object})
focus = Focus.objects.get(**{object_type: object})
except Focus.DoesNotExist:
return False
return True
return (focus.current == True)
@register.filter
......
......@@ -93,26 +93,42 @@ class FocusSetView(RedirectView):
raise PermissionDenied()
if object_type == 'emission':
emission = Emission.objects.get(id=object_id)
f = Focus()
try:
f = Focus.objects.get(emission=emission)
except Focus.DoesNotExist:
f = Focus()
f.current = True
f.emission = emission
f.save()
return reverse('emission-view', kwargs={'slug': emission.slug})
if object_type == 'episode':
episode = Episode.objects.get(id=object_id)
f = Focus()
try:
f = Focus.objects.get(episode=episode)
except Focus.DoesNotExist:
f = Focus()
f.current = True
f.episode = episode
f.save()
return reverse('episode-view', kwargs={
'emission_slug': episode.emission.slug, 'slug': episode.slug})
if object_type == 'newsitem':
newsitem = NewsItem.objects.get(id=object_id)
f = Focus()
try:
f = Focus.objects.get(newsitem=newsitem)
except Focus.DoesNotExist:
f = Focus()
f.current = True
f.newsitem = newsitem
f.save()
return reverse('newsitem-view', kwargs={'slug': newsitem.slug})
if object_type == 'soundfile':
soundfile = SoundFile.objects.get(id=object_id)
f = Focus()
try:
f = Focus.objects.get(soundfile=soundfile)
except Focus.DoesNotExist:
f = Focus()
f.current = True
f.soundfile = soundfile
f.save()
return reverse('episode-view', kwargs={
......@@ -131,20 +147,28 @@ class FocusUnsetView(RedirectView):
raise PermissionDenied()
if object_type == 'emission':
emission = Emission.objects.get(id=object_id)
Focus.objects.get(emission=emission).delete()
focus = Focus.objects.get(emission=emission)
focus.current = False
focus.save()
return reverse('emission-view', kwargs={'slug': emission.slug})
if object_type == 'episode':
episode = Episode.objects.get(id=object_id)
Focus.objects.get(episode=episode).delete()
focus = Focus.objects.get(episode=episode)
focus.current = False
focus.save()
return reverse('episode-view', kwargs={
'emission_slug': episode.emission.slug, 'slug': episode.slug})
if object_type == 'newsitem':
newsitem = NewsItem.objects.get(id=object_id)
Focus.objects.get(newsitem=newsitem).delete()
focus = Focus.objects.get(newsitem=newsitem)
focus.current = False
focus.save()
return reverse('newsitem-view', kwargs={'slug': newsitem.slug})
if object_type == 'soundfile':
soundfile = SoundFile.objects.get(id=object_id)
Focus.objects.get(soundfile=soundfile).delete()
focus = Focus.objects.get(soundfile=soundfile)
focus.current = False
focus.save()
return reverse('episode-view', kwargs={
'slug': soundfile.episode.slug,
'emission_slug': soundfile.episode.emission.slug,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment