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