Commit 05df31e8 authored by fred's avatar fred

update to focus objects

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