forked from rc/aircox
fix issues with categories and so on
This commit is contained in:
parent
45ffdd1b53
commit
917fe43629
|
@ -21,7 +21,7 @@ from aircox.models import Station, Diffusion, Track, Sound, Log #, DiffusionLog,
|
|||
|
||||
# force using UTC
|
||||
import pytz
|
||||
timezone.activate(pytz.UTC)
|
||||
tz.activate(pytz.UTC)
|
||||
|
||||
|
||||
class Tracer:
|
||||
|
@ -140,8 +140,10 @@ class Monitor:
|
|||
log = self.get_last_log(models.Q(diffusion__isnull = False) |
|
||||
models.Q(sound__isnull = False))
|
||||
|
||||
# check if sound on air changed
|
||||
if log:
|
||||
# check if sound on air changed compared to logged one
|
||||
try:
|
||||
# FIXME: TO-check liquidsoap ensure we have utc time
|
||||
on_air = current_source.metadata and \
|
||||
current_source.metadata.get('on_air')
|
||||
on_air = tz.datetime.strptime(on_air, "%Y/%m/%d %H:%M:%S")
|
||||
|
@ -152,14 +154,18 @@ class Monitor:
|
|||
on_air = None
|
||||
is_diff = log.source != current_source.id or \
|
||||
(log.sound and log.sound.path != current_sound)
|
||||
else:
|
||||
# no log: sound is different
|
||||
is_diff = True
|
||||
|
||||
if is_diff:
|
||||
sound = Sound.objects.filter(path = current_sound).first()
|
||||
|
||||
# find an eventual diff
|
||||
# find an eventual diffusion associated to current sound
|
||||
# => check using last (started) diffusion's archives
|
||||
last_diff = self.last_diff_start
|
||||
diff = None
|
||||
if not last_diff.is_expired():
|
||||
if last_diff and not last_diff.is_expired():
|
||||
archives = last_diff.diffusion.get_archives()
|
||||
if archives.filter(pk = sound.pk).exists():
|
||||
diff = last_diff.diffusion
|
||||
|
@ -344,8 +350,8 @@ class Monitor:
|
|||
# enable dealer
|
||||
if not source.active:
|
||||
source.active = True
|
||||
last_start = self.last_start
|
||||
if last_start.diffusion_id != diff.pk:
|
||||
last_start = self.last_diff_start
|
||||
if not last_start or last_start.diffusion_id != diff.pk:
|
||||
# log triggered diffusion
|
||||
self.log(type = Log.Type.start, source = source.id,
|
||||
diffusion = diff, date = date)
|
||||
|
|
|
@ -991,6 +991,7 @@ class Sound(Nameable):
|
|||
.replace('.', r'\.') + ')$',
|
||||
recursive = True,
|
||||
blank = True, null = True,
|
||||
unique = True,
|
||||
max_length = 256
|
||||
)
|
||||
embed = models.TextField(
|
||||
|
|
|
@ -286,6 +286,13 @@ class BasePage(Page):
|
|||
).order_by('-date')
|
||||
|
||||
# methods
|
||||
def get_list_page(self):
|
||||
"""
|
||||
Return the page that should be used for lists related to this
|
||||
page. If None is returned, use a default one.
|
||||
"""
|
||||
return None
|
||||
|
||||
def get_context(self, request, *args, **kwargs):
|
||||
from aircox_cms.forms import CommentForm
|
||||
|
||||
|
@ -659,14 +666,24 @@ class DiffusionPage(Publication):
|
|||
#
|
||||
|
||||
class CategoryPage(BasePage, BaseList):
|
||||
# TODO: hide related in panels?
|
||||
content_panels = BasePage.content_panels + BaseList.panels
|
||||
|
||||
def get_list_page(self):
|
||||
return self
|
||||
|
||||
def get_context(self, request, *args, **kwargs):
|
||||
context = super().get_context(request, *args, **kwargs)
|
||||
context.update(BaseList.get_context(self, request, paginate = True))
|
||||
context['view'] = 'list'
|
||||
return context
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
# we force related attribute
|
||||
if not self.related:
|
||||
self.related = self
|
||||
|
||||
|
||||
class DynamicListPage(BasePage):
|
||||
"""
|
||||
|
|
|
@ -300,6 +300,8 @@ class BaseList(models.Model):
|
|||
Get queryset based on the arguments. This class is intended to be
|
||||
reusable by other classes if needed.
|
||||
"""
|
||||
# FIXME: check if related is published
|
||||
|
||||
from aircox_cms.models import Publication
|
||||
# model
|
||||
if self.model:
|
||||
|
@ -359,12 +361,7 @@ class BaseList(models.Model):
|
|||
# keep empty queryset
|
||||
context['object_list'] = qs
|
||||
context['list_url_args'] = self.to_url(full_url = False)
|
||||
#context['list_selector'] = {
|
||||
# attr: getattr(self, attr) for attr in (
|
||||
# 'asc', 'date_filter', 'model', 'related', 'relation',
|
||||
# 'tags', 'search',
|
||||
# )
|
||||
#}
|
||||
context['list_selector'] = self
|
||||
return context
|
||||
|
||||
def paginate(self, request, qs):
|
||||
|
@ -381,7 +378,7 @@ class BaseList(models.Model):
|
|||
'object_list': qs
|
||||
}
|
||||
|
||||
def to_url(self, page = None, full_url = True, **kwargs):
|
||||
def to_url(self, page = None, **kwargs):
|
||||
"""
|
||||
Return a url to a given page with GET corresponding to this
|
||||
list's parameters.
|
||||
|
@ -403,21 +400,14 @@ class BaseList(models.Model):
|
|||
params.update(kwargs)
|
||||
|
||||
if self.related:
|
||||
params['related'] = True
|
||||
params['related'] = self.related.pk
|
||||
|
||||
params = '&'.join([
|
||||
key if value == True else '{}={}'.format(key, value)
|
||||
for key, value in params.items() if value
|
||||
])
|
||||
if not full_url:
|
||||
return params
|
||||
|
||||
page = page or self.page
|
||||
if not page:
|
||||
raise ValueError(
|
||||
"full_url = True requires either list.related or "
|
||||
"method's argument `page` to be given"
|
||||
)
|
||||
return params
|
||||
return page.url + '?' + params
|
||||
|
||||
@classmethod
|
||||
|
@ -438,18 +428,26 @@ class BaseList(models.Model):
|
|||
* date_filter: one of DateFilter attribute's key.
|
||||
* model: ['program','diffusion','event'] type of the publication
|
||||
* relation: one of RelationFilter attribute's key
|
||||
* related: list is related to the method's argument `related`
|
||||
* related: list is related to the method's argument `related`.
|
||||
It can be a page id.
|
||||
|
||||
* tag: tag to search for
|
||||
* search: query to search in the publications
|
||||
* page: page number
|
||||
"""
|
||||
# FIXME: page argument to select a page
|
||||
# FIXME: related
|
||||
date_filter = request.GET.get('date_filter')
|
||||
model = request.GET.get('model')
|
||||
relation = request.GET.get('relation')
|
||||
|
||||
related_= request.GET.get('related')
|
||||
if related_:
|
||||
try:
|
||||
related_ = int(related_)
|
||||
related_ = Page.objects.filter(pk = related_).first()
|
||||
related_ = related_ and related_.specific
|
||||
except:
|
||||
related_ = None
|
||||
|
||||
kwargs = {
|
||||
'asc': 'asc' in request.GET,
|
||||
'date_filter':
|
||||
|
@ -460,7 +458,7 @@ class BaseList(models.Model):
|
|||
ProgramPage if model == 'program' else
|
||||
DiffusionPage if model == 'diffusion' else
|
||||
EventPage if model == 'event' else None,
|
||||
'related': 'related' in request.GET and related,
|
||||
'related': related_,
|
||||
'relation':
|
||||
int(getattr(cl.RelationFilter, relation))
|
||||
if relation and hasattr(cl.RelationFilter, relation)
|
||||
|
@ -908,7 +906,8 @@ class SectionList(BaseList, SectionRelativeItem):
|
|||
|
||||
def get_context(self, request, page):
|
||||
import aircox_cms.models as cms
|
||||
if self.is_related:
|
||||
if self.is_related and not self.related:
|
||||
# set current page if there is not yet a related page only
|
||||
self.related = page
|
||||
|
||||
context = BaseList.get_context(self, request, paginate = False)
|
||||
|
@ -917,10 +916,15 @@ class SectionList(BaseList, SectionRelativeItem):
|
|||
|
||||
context.update(SectionRelativeItem.get_context(self, request, page))
|
||||
if self.url_text:
|
||||
if not self.is_related or not page:
|
||||
self.related = self.related.specific
|
||||
target = None
|
||||
if self.related and hasattr(self.related, 'get_list_page'):
|
||||
target = self.related.get_list_page()
|
||||
|
||||
if not target:
|
||||
settings = cms.WebsiteSettings.for_site(request.site)
|
||||
page = settings.list_page
|
||||
context['url'] = self.to_url(page = page) + '&view=list'
|
||||
target = settings.list_page
|
||||
context['url'] = self.to_url(page = target) + '&view=list'
|
||||
return context
|
||||
|
||||
SectionList._meta.get_field('count').default = 5
|
||||
|
|
|
@ -31,7 +31,7 @@ class TemplateMixin(models.Model):
|
|||
from django.template.loader import get_template
|
||||
get_template(cl.template_name)
|
||||
except TemplateDoesNotExist:
|
||||
cl.template = 'aircox_cms/sections/section_item.html'
|
||||
cl.template_name = 'aircox_cms/sections/section_item.html'
|
||||
return cl.template_name
|
||||
|
||||
def get_context(self, request, page):
|
||||
|
|
|
@ -14,9 +14,9 @@
|
|||
{% blocktrans with terms=list_selector.terms trimmed %}
|
||||
Search in publications for <i>{{ terms }}</i>
|
||||
{% endblocktrans %}
|
||||
{% elif list_selector.filter_related %}
|
||||
{% elif list_selector.related %}
|
||||
{# should never happen #}
|
||||
{% blocktrans with title=list_selector.filter_related.title url=list_selector.filter_related.url trimmed %}
|
||||
{% blocktrans with title=list_selector.related.title url=list_selector.related.url trimmed %}
|
||||
Related to <a href="{{ url }}">{{ title }}</a>
|
||||
{% endblocktrans %}
|
||||
{% else %}
|
||||
|
@ -27,7 +27,8 @@
|
|||
|
||||
|
||||
{% block content %}
|
||||
{% with related=list_selector.filter_related %}
|
||||
{# if there is a related, print related content, otherwise use dynpage #}
|
||||
{% with related=list_selector.related %}
|
||||
{% if related %}
|
||||
<div class="body headline">
|
||||
{% image related.cover fill-128x128 class="cover item_cover" %}
|
||||
|
@ -36,6 +37,7 @@
|
|||
</div>
|
||||
{% elif page.body %}
|
||||
<div class="body">
|
||||
{% image page.cover fill-128x128 class="cover item_cover" %}
|
||||
{{ page.body|richtext }}
|
||||
</div>
|
||||
{% endif %}
|
||||
|
|
Loading…
Reference in New Issue
Block a user