work on timezone

This commit is contained in:
bkfox 2017-05-10 17:19:59 +02:00
parent b3c0547ce6
commit e47e2a858e
6 changed files with 93 additions and 77 deletions

View File

@ -186,7 +186,7 @@ class Monitor:
that still have to be played. If there is not, return None that still have to be played. If there is not, return None
""" """
station = self.station station = self.station
now = tz.make_aware(tz.datetime.now()) now = tz.now()
diff_log = station.get_played(models = Diffusion) \ diff_log = station.get_played(models = Diffusion) \
.order_by('date').last() .order_by('date').last()

View File

@ -23,29 +23,6 @@ import aircox.settings as settings
logger = logging.getLogger('aircox.core') logger = logging.getLogger('aircox.core')
def as_date(date, as_datetime = True):
"""
If as_datetime, return the date with time info set to 0; else, return
a date with date informations of the given date/time.
"""
import datetime
if as_datetime:
return date.replace(hour = 0, minute = 0, second = 0, microsecond = 0)
return datetime.date(date.year, date.month, date.day)
def date_or_default(date, no_time = False):
"""
Return date or default value (now) if not defined, and remove time info
if date_only is True
"""
date = date or tz.now()
if not tz.is_aware(date):
date = tz.make_aware(date)
if no_time:
return as_date(date)
return date
# #
# Abstracts # Abstracts
# #
@ -589,7 +566,7 @@ class Schedule(models.Model):
""" """
Return True if the given datetime matches the schedule Return True if the given datetime matches the schedule
""" """
date = date_or_default(date) date = utils.date_or_default(date)
if self.date.weekday() == date.weekday() and self.match_week(date): if self.date.weekday() == date.weekday() and self.match_week(date):
return self.date.time() == date.time() if check_time else True return self.date.time() == date.time() if check_time else True
return False return False
@ -604,12 +581,12 @@ class Schedule(models.Model):
return False return False
# since we care only about the week, go to the same day of the week # since we care only about the week, go to the same day of the week
date = date_or_default(date) date = utils.date_or_default(date)
date += tz.timedelta(days = self.date.weekday() - date.weekday() ) date += tz.timedelta(days = self.date.weekday() - date.weekday() )
if self.frequency == Schedule.Frequency.one_on_two: if self.frequency == Schedule.Frequency.one_on_two:
# cf notes in date_of_month # cf notes in date_of_month
diff = as_date(date, False) - as_date(self.date, False) diff = utils.as_date(date, False) - utils.as_date(self.date, False)
return not (diff.days % 14) return not (diff.days % 14)
first_of_month = date.replace(day = 1) first_of_month = date.replace(day = 1)
@ -634,7 +611,7 @@ class Schedule(models.Model):
if self.frequency == Schedule.Frequency.ponctual: if self.frequency == Schedule.Frequency.ponctual:
return [] return []
date = date_or_default(date, True).replace(day=1) date = utils.date_or_default(date, True).replace(day=1)
freq = self.frequency freq = self.frequency
# last of the month # last of the month
@ -660,7 +637,7 @@ class Schedule(models.Model):
dates = [] dates = []
if freq == Schedule.Frequency.one_on_two: if freq == Schedule.Frequency.one_on_two:
# check date base on a diff of dates base on a 14 days delta # check date base on a diff of dates base on a 14 days delta
diff = as_date(date, False) - as_date(self.date, False) diff = utils.as_date(date, False) - utils.as_date(self.date, False)
if diff.days % 14: if diff.days % 14:
date += tz.timedelta(days = 7) date += tz.timedelta(days = 7)
@ -745,13 +722,17 @@ class DiffusionManager(models.Manager):
If date is a datetime.date object, check only against the If date is a datetime.date object, check only against the
date. date.
""" """
date = date or tz.now() date = utils.date_or_default(date)
if not issubclass(type(date), datetime.datetime): if not issubclass(type(date), datetime.datetime):
return self.filter( return self.filter(
models.Q(start__contains = date) | \ models.Q(start__contains = date) | \
models.Q(end__contains = date) models.Q(end__contains = date)
) )
if not date.is_aware():
date = make_aware(date)
if not next: if not next:
return self.filter(start__lte = date, end__gte = date) \ return self.filter(start__lte = date, end__gte = date) \
.order_by('start') .order_by('start')
@ -766,7 +747,7 @@ class DiffusionManager(models.Manager):
Return a queryset of diffusions that happen after the given Return a queryset of diffusions that happen after the given
date. date.
""" """
date = date_or_default(date) date = utils.date_or_default(date)
return self.filter( return self.filter(
start__gte = date, start__gte = date,
).order_by('start') ).order_by('start')
@ -776,7 +757,7 @@ class DiffusionManager(models.Manager):
Return a queryset of diffusions that finish before the given Return a queryset of diffusions that finish before the given
date. date.
""" """
date = date_or_default(date) date = utils.date_or_default(date)
return self.filter( return self.filter(
end__lte = date, end__lte = date,
).order_by('start') ).order_by('start')
@ -1260,7 +1241,7 @@ class Log(Related):
against the date, so it is still possible that the expiration against the date, so it is still possible that the expiration
occured because of a Stop or other source. occured because of a Stop or other source.
""" """
date = date_or_default(date) date = utils.date_or_default(date)
return self.end < date return self.end < date
def print(self): def print(self):

View File

@ -1,6 +1,9 @@
{% extends "admin/base_site.html" %} {% extends "admin/base_site.html" %}
{# {% extends "aircox/controllers/base_site.html" %} #} {# {% extends "aircox/controllers/base_site.html" %} #}
{% load i18n %} {% load i18n %}
{% load tz %}
{% localtime on %}
{% block title %} {% block title %}
{% trans "Statistics of the stations" %} {% trans "Statistics of the stations" %}
@ -83,3 +86,5 @@
{% endblock %} {% endblock %}
{% endlocaltime %}

View File

@ -1,6 +1,28 @@
import datetime import datetime
import django.utils.timezone as tz
def as_date(date, as_datetime = True):
"""
If as_datetime, return the date with time info set to 0; else, return
a date with date informations of the given date/time.
"""
if as_datetime:
return date.replace(hour = 0, minute = 0, second = 0, microsecond = 0)
return datetime.date(date.year, date.month, date.day)
def date_or_default(date, no_time = False):
"""
Return date or default value (now) if not defined, and remove time info
if date_only is True
"""
date = date or tz.now()
if not tz.is_aware(date):
date = tz.make_aware(date)
if no_time:
return as_date(date)
return date
def to_timedelta (time): def to_timedelta (time):
""" """
Transform a datetime or a time instance to a timedelta, Transform a datetime or a time instance to a timedelta,

View File

@ -14,8 +14,11 @@
viewBox="0 0 744.09448819 1052.3622047" viewBox="0 0 744.09448819 1052.3622047"
id="svg2" id="svg2"
version="1.1" version="1.1"
inkscape:version="0.91 r13725" inkscape:version="0.92.1 r"
sodipodi:docname="logo.svg"> sodipodi:docname="logo.svg"
inkscape:export-filename="/home/thomas/code/aircox/aircox/static/aircox/images/logo.png"
inkscape:export-xdpi="66.611992"
inkscape:export-ydpi="66.611992">
<defs <defs
id="defs4"> id="defs4">
<clipPath <clipPath
@ -57,17 +60,17 @@
borderopacity="1.0" borderopacity="1.0"
inkscape:pageopacity="0.0" inkscape:pageopacity="0.0"
inkscape:pageshadow="2" inkscape:pageshadow="2"
inkscape:zoom="0.81249936" inkscape:zoom="3.2499974"
inkscape:cx="87.39633" inkscape:cx="208.53617"
inkscape:cy="611.94509" inkscape:cy="725.05012"
inkscape:document-units="px" inkscape:document-units="px"
inkscape:current-layer="layer1" inkscape:current-layer="g4376"
showgrid="false" showgrid="false"
showguides="false" showguides="false"
inkscape:window-width="1364" inkscape:window-width="1918"
inkscape:window-height="736" inkscape:window-height="1040"
inkscape:window-x="0" inkscape:window-x="0"
inkscape:window-y="1454" inkscape:window-y="1042"
inkscape:window-maximized="0" /> inkscape:window-maximized="0" />
<metadata <metadata
id="metadata7"> id="metadata7">
@ -77,7 +80,7 @@
<dc:format>image/svg+xml</dc:format> <dc:format>image/svg+xml</dc:format>
<dc:type <dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" /> rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title></dc:title> <dc:title />
</cc:Work> </cc:Work>
</rdf:RDF> </rdf:RDF>
</metadata> </metadata>
@ -93,47 +96,50 @@
id="g4376" id="g4376"
transform="matrix(0.97221505,-0.23408952,0.23408952,0.97221505,-73.655087,41.382345)" transform="matrix(0.97221505,-0.23408952,0.23408952,0.97221505,-73.655087,41.382345)"
clip-path="url(#clipPath4570)"> clip-path="url(#clipPath4570)">
<path <g
sodipodi:nodetypes="ccccc" id="g3740">
inkscape:connector-curvature="0" <path
id="path4155-6" style="fill:#000000;fill-opacity:1;fill-rule:evenodd;stroke:#000000;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
d="m 110.80568,266.04718 c -3.29167,-19.8207 -11.124776,-15.37046 -12.352066,-24.27303 -0.14135,-3.58896 4.663986,-8.38983 8.867286,-4.51659 7.90435,9.32416 0.41767,10.96241 14.73478,22.36105 -2.96184,1.98522 -7.49488,4.28469 -11.25,6.42857 z" d="m 110.80568,266.04718 c -3.29167,-19.8207 -11.124776,-15.37046 -12.352066,-24.27303 -0.14135,-3.58896 4.663986,-8.38983 8.867286,-4.51659 7.90435,9.32416 0.41767,10.96241 14.73478,22.36105 -2.96184,1.98522 -7.49488,4.28469 -11.25,6.42857 z"
style="fill:#000000;fill-opacity:1;fill-rule:evenodd;stroke:#000000;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1" /> id="path4155-6"
<path inkscape:connector-curvature="0"
sodipodi:nodetypes="ccccc" sodipodi:nodetypes="ccccc" />
inkscape:connector-curvature="0" <path
id="path4155-7-80" style="fill:#000000;fill-opacity:1;fill-rule:evenodd;stroke:#000000;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
d="m 97.267374,355.00848 c -19.8207,3.29167 -15.37045,11.12478 -24.27302,12.35207 -3.58896,0.14135 -8.38984,-4.66399 -4.51659,-8.86729 9.32415,-7.90435 10.96241,-0.41767 22.36104,-14.73478 1.98522,2.96184 4.28469,7.49488 6.42857,11.25 z" d="m 97.267374,355.00848 c -19.8207,3.29167 -15.37045,11.12478 -24.27302,12.35207 -3.58896,0.14135 -8.38984,-4.66399 -4.51659,-8.86729 9.32415,-7.90435 10.96241,-0.41767 22.36104,-14.73478 1.98522,2.96184 4.28469,7.49488 6.42857,11.25 z"
style="fill:#000000;fill-opacity:1;fill-rule:evenodd;stroke:#000000;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1" /> id="path4155-7-80"
<path inkscape:connector-curvature="0"
sodipodi:nodetypes="ccccc" sodipodi:nodetypes="ccccc" />
inkscape:connector-curvature="0" <path
id="path4155-7-8-6" style="fill:#000000;fill-opacity:1;fill-rule:evenodd;stroke:#000000;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
d="m 85.476584,307.73621 c -16.34291,-11.68779 -18.73496,-3.00215 -25.89785,-8.42939 -2.63773,-2.43783 -2.63457,-9.23045 3.07641,-9.46383 12.18239,1.00395 8.04693,7.45626 26.23071,5.39258 -0.69058,3.4981 -2.26995,8.32941 -3.40927,12.50064 z" d="m 85.476584,307.73621 c -16.34291,-11.68779 -18.73496,-3.00215 -25.89785,-8.42939 -2.63773,-2.43783 -2.63457,-9.23045 3.07641,-9.46383 12.18239,1.00395 8.04693,7.45626 26.23071,5.39258 -0.69058,3.4981 -2.26995,8.32941 -3.40927,12.50064 z"
style="fill:#000000;fill-opacity:1;fill-rule:evenodd;stroke:#000000;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1" /> id="path4155-7-8-6"
<path inkscape:connector-curvature="0"
sodipodi:nodetypes="ccccc" sodipodi:nodetypes="ccccc" />
inkscape:connector-curvature="0" <path
id="path4155-7-0-0" style="fill:#000000;fill-opacity:1;fill-rule:evenodd;stroke:#000000;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
d="m 139.41029,379.1225 c -11.68779,16.34292 -3.00214,18.73496 -8.42939,25.89785 -2.43783,2.63773 -9.23045,2.63458 -9.46383,-3.07641 1.00394,-12.18239 7.45626,-8.04693 5.39257,-26.23071 3.4981,0.69058 8.32942,2.26995 12.50065,3.40927 z" d="m 139.41029,379.1225 c -11.68779,16.34292 -3.00214,18.73496 -8.42939,25.89785 -2.43783,2.63773 -9.23045,2.63458 -9.46383,-3.07641 1.00394,-12.18239 7.45626,-8.04693 5.39257,-26.23071 3.4981,0.69058 8.32942,2.26995 12.50065,3.40927 z"
style="fill:#000000;fill-opacity:1;fill-rule:evenodd;stroke:#000000;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1" /> id="path4155-7-0-0"
<circle inkscape:connector-curvature="0"
id="path4136-5-5" sodipodi:nodetypes="ccccc" />
style="opacity:1;fill:#000000;fill-opacity:1;fill-rule:nonzero;stroke:#000000;stroke-width:8;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1" <circle
cx="148.58382" r="61.081726"
cy="316.89429" cy="316.89429"
r="61.081726" /> cx="148.58382"
style="opacity:1;fill:#000000;fill-opacity:1;fill-rule:nonzero;stroke:#000000;stroke-width:8;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1"
id="path4136-5-5" />
</g>
<circle <circle
r="50.376423" r="50.376423"
cy="317.04373" cy="314.68579"
cx="148.79494" cx="146.39563"
id="path4136-5-6-5" id="path4136-5-6-5"
style="opacity:1;fill:#ffffff;fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:7.40858507;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1" /> style="opacity:1;fill:#ffffff;fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:7.40858507;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1" />
</g> </g>
<flowRoot <flowRoot
xml:space="preserve" xml:space="preserve"
id="flowRoot4439" id="flowRoot4439"
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:80px;line-height:125%;font-family:Adler;-inkscape-font-specification:Adler;letter-spacing:0px;word-spacing:0px;fill:#000000;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1" style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;line-height:0.01%;font-family:Adler;-inkscape-font-specification:Adler;letter-spacing:0px;word-spacing:0px;fill:#000000;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
transform="matrix(0.96092081,0,0,0.96092081,-26.716999,5.7888348)"><flowRegion transform="matrix(0.96092081,0,0,0.96092081,-26.716999,5.7888348)"><flowRegion
id="flowRegion4441"><rect id="flowRegion4441"><rect
id="rect4443" id="rect4443"
@ -142,7 +148,8 @@
x="141.53857" x="141.53857"
y="278.20776" y="278.20776"
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:80px;font-family:Adler;-inkscape-font-specification:Adler" /></flowRegion><flowPara style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:80px;font-family:Adler;-inkscape-font-specification:Adler" /></flowRegion><flowPara
id="flowPara4445"><flowSpan id="flowPara4445"
style="font-size:80px;line-height:1.25"><flowSpan
style="fill:#ff0000" style="fill:#ff0000"
id="flowSpan4447">Air</flowSpan>cox</flowPara></flowRoot> <g id="flowSpan4447">Air</flowSpan>cox</flowPara></flowRoot> <g
id="g4492" id="g4492"

Before

Width:  |  Height:  |  Size: 7.9 KiB

After

Width:  |  Height:  |  Size: 8.2 KiB

View File

@ -39,6 +39,7 @@ cms:
- player support diffusions with multiple archive files - player support diffusions with multiple archive files
- comments -> remove/edit by the author - comments -> remove/edit by the author
# Instance's TODO # Instance's TODO
- menu_top .sections: - menu_top .sections:
- display inline block - display inline block