Commit 05df31e8 authored by fred's avatar fred

update to focus objects

parent 550114f7
......@@ -8,6 +8,7 @@ import uuid
from django import template
from django.conf import settings
from django.core.urlresolvers import reverse
from django.db.models.query import QuerySet
from django.utils import simplejson
from datetime import datetime, timedelta
......@@ -278,3 +279,19 @@ def rfc822(datetime):
def related_objects(object):
sqs = search.MoreLikeThisSearchQuerySet().models(Emission, Episode, NewsItem)
return {'more_like_this': sqs.more_like_this(object)[:12]}
@register.filter
def get_focus_url(object):
if object.newsitem:
return reverse('newsitem-view', kwargs={'slug': object.newsitem.slug})
if object.emission:
return reverse('emission-view', kwargs={'slug': object.emission.slug})
if object.episode:
return reverse('episode-view', kwargs={
'slug': object.episode.slug, 'emission_slug': object.episode.emission.slug})
if object.soundfile:
return reverse('episode-view', kwargs={
'slug': object.soundfile.episode.slug,
'emission_slug': object.soundfile.emission.episode.slug})
return ''
......@@ -23,7 +23,7 @@ from haystack.query import SearchQuerySet
from jsonresponse import to_json
from emissions.models import Category, Emission, Episode, Diffusion, SoundFile, \
Schedule, Nonstop, NewsItem, NewsCategory
Schedule, Nonstop, NewsItem, NewsCategory, Focus
from emissions.utils import whatsonair, period_program
......@@ -406,8 +406,8 @@ class Home(TemplateView):
def get_context_data(self, **kwargs):
context = super(Home, self).get_context_data(**kwargs)
context['sectionName'] = "Home"
context['focus'] = NewsItem.objects.select_related('category').filter(
focus=True).exclude(image__isnull=True).exclude(image__exact='').order_by('?')[:12]
context['focus'] = Focus.objects.select_related('emission', 'newsitem',
'soundfile', 'episode', 'newsitem__category').order_by('?')[:12]
context['emissions'] = Emission.objects.filter(archived=False,
creation_timestamp__gte=datetime(2013, 9, 13)).order_by('title')
......@@ -432,7 +432,6 @@ class NewsItemView(DetailView):
def get_context_data(self, **kwargs):
context = super(NewsItemView, self).get_context_data(**kwargs)
context['sectionName'] = "News"
context['focus'] = list(NewsItem.objects.select_related('category').filter(focus=True).exclude(image__isnull=True).exclude(image__exact='').order_by('-date')[0:9])
context['categories'] = NewsCategory.objects.all()
context['news'] = NewsItem.objects.all().exclude(image__isnull=True).exclude(image__exact='').order_by('-date')[:10]
return context
......@@ -443,7 +442,8 @@ class News(TemplateView):
def get_context_data(self, **kwargs):
context = super(News, self).get_context_data(**kwargs)
context['sectionName'] = "News"
context['focus'] = list(NewsItem.objects.select_related('category').filter(focus=True).exclude(image__isnull=True).exclude(image__exact='').order_by('-date')[0:9])
newsitem_ids = [x.newsitem_id for x in Focus.objects.filter(newsitem__isnull=False)]
context['focus'] = NewsItem.objects.filter(id__in=newsitem_ids).select_related('category').order_by('-date')[0:9]
context['news'] = NewsItem.objects.all().exclude(image__isnull=True).exclude(image__exact='').order_by('-date')[:30]
return context
......
{% load thumbnails %}{% load i18n %}
{% load thumbnails %}{% load i18n %}{% load paniktags %}
<div id="newsRoll">
<div class="newsRoll center cf">
<ul id="ticker" class="custom bigNews marged" style="height:300px;overflow:hidden;">
{% for content in news %}
{% for focus in news %}
<li
id="newsRollId-{{ content.slug }}"
id="newsRollId-{{ focus.id }}"
class="">
<a
style="max-width:100%;height:300px;background: no-repeat 50% 50% url('{{ content.image|thumbnail:'800x600' }}');"
class="block news relative"
href="{% url 'newsitem-view' slug=content.slug %}">
{% if content.category %}
style="max-width:100%;height:300px;background: no-repeat 50% 50% url('{{ focus.content_image|thumbnail:'800x600' }}');"
class="block news relative"
href="{{ focus|get_focus_url }}">
{% if focus.content_category_title %}
<div class="label labels absolute">
<span class="item inBlock">{{ content.category.title }}</span>
<span class="item inBlock">{{ focus.content_category_title }}</span>
</div>
{% endif %}
<div class="title"><div>{{ content.title }}</div></div>
<div class="title"><div>{{ focus.focus_title }}</div></div>
</a>
</li>
{% endfor %}
</ul>
<div class="marged">
<ul class="custom distributed by3 padded" id="roller">
{% for content in news|slice:'0:3' %}
{% for focus in news|slice:'0:3' %}
<li style="width:30%;" class="num-{{ forloop.counter }} padded">
<button class="inBlock" data-about="#newsRollId-{{ content.slug }}">
<img style="width:95%;" src="{{ content.image|thumbnail:'160x120' }}" />
<button class="inBlock" data-about="#newsRollId-{{ focus.id }}">
<img style="width:95%;" src="{{ focus.content_image|thumbnail:'160x120' }}" />
</button>
</li>
{% endfor %}
......
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