timezone fixed

This commit is contained in:
Stefan Kögl 2012-05-30 16:11:14 +02:00
parent a2af77f9f3
commit e626679786
7 changed files with 56 additions and 52 deletions

View File

@ -17,6 +17,7 @@ from tracbooking.model import *
from tracbooking.report import create_report
from tracbooking.utils import validate_id, time_parse, date_parse, get_tz, get_option_count, validate_email
from tracbooking.web_ui import UserUploadComponent
from ctdotools.utils import datetime_parse
def get_actions(myactions):
actions = []
@ -104,6 +105,8 @@ class BookingAdminPanel(Component):
data = {}
e_id = None
session_tzname, selected_tz = get_tz(req.session.get('tz', self.config.get("trac", "default_timezone") or None))
m = match(r'/admin/booking/events/(\d+)$', key)
if m:
e_id = int(m.group(1))
@ -113,6 +116,10 @@ class BookingAdminPanel(Component):
event = Event(self.env, 0, "", "", datetime.now(utc), datetime.now(utc))
account = EventAccount(self.env, 0, 0, "", "", "", "", "", "")
assert account
assert event
if req.method == "POST":
if req.args.get("add") and \
req.args.has_key("name") and \
@ -122,26 +129,15 @@ class BookingAdminPanel(Component):
req.args.has_key("time_end"):
name = req.args.get("name")
date_begin = date_parse(req.args.get("date_begin"))
time_begin = time_parse(req.args.get("time_begin"))
dt_begin = datetime.combine(date_begin, time_begin)
dt_begin = dt_begin.replace(tzinfo=utc)
dt_begin = datetime_parse("%s %s" % (req.args["date_begin"], req.args["time_begin"]), selected_tz)
date_end = date_parse(req.args.get("date_end"))
time_end = time_parse(req.args.get("time_end"))
dt_end = datetime.combine(date_end, time_end)
dt_end = dt_end.replace(tzinfo=utc)
dt_end = datetime_parse("%s %s" % (req.args["date_end"], req.args["time_end"]), selected_tz)
date_begin = date_parse(req.args.get("edit_deadline_date"))
time_begin = time_parse(req.args.get("edit_deadline_time"))
edit_deadline = datetime.combine(date_begin, time_begin)
edit_deadline = edit_deadline.replace(tzinfo=utc)
edit_deadline = datetime_parse("%s %s" % (req.args["edit_deadline_date"], req.args["edit_deadline_time"]), selected_tz)
payment_deadline_date = date_parse(req.args.get("payment_deadline_date"))
payment_deadline_time = time_parse(req.args.get("payment_deadline_time"))
payment_deadline = datetime.combine(payment_deadline_date, payment_deadline_time)
payment_deadline = payment_deadline.replace(tzinfo=utc)
payment_deadline = datetime_parse("%s %s" % (req.args["payment_deadline_date"], req.args["payment_deadline_time"]), selected_tz)
print req.args["date_begin"], req.args["time_begin"], dt_begin, dt_end
account_owner = req.args.get("account_owner")
account_no = req.args.get("account_no")
bank_name = req.args.get("bank_name")
@ -195,6 +191,7 @@ class BookingAdminPanel(Component):
data["event"] = event
data["event_account"] = account
data["events"] = Event.fetch_all(self.env)
data["selected_tz"] = selected_tz
return "admin_events.html", data
def _render_options(self, req, cat, page, bookingtype):

View File

@ -716,7 +716,7 @@ class EventAccount(object):
return self.ea_id != 0
class Event(object):
def __init__(self, env, e_id, name, description, time_begin, time_end, register_deadline=datetime.now(utc), edit_deadline=datetime.now(utc), payment_deadline=datetime.now(utc), fetch_options=False, only_active=False, attendee_id=None):
def __init__(self, env, e_id, name, description, time_begin, time_end, register_deadline=utc.localize(datetime.utcnow()), edit_deadline=utc.localize(datetime.utcnow()), payment_deadline=utc.localize(datetime.utcnow()), fetch_options=False, only_active=False, attendee_id=None):
self.env = env
self.e_id = e_id
self.name = name
@ -752,7 +752,7 @@ class Event(object):
if not row:
return None
e_id, name, description, time_begin, time_end, register_deadline, edit_deadline, payment_deadline = row
return Event(env, e_id, name, description, datetime.utcfromtimestamp(time_begin), datetime.utcfromtimestamp(time_end), datetime.utcfromtimestamp(register_deadline), datetime.utcfromtimestamp(edit_deadline), datetime.utcfromtimestamp(payment_deadline), fetch_options=fetch_options, only_active=only_active, attendee_id=attendee_id)
return Event(env, e_id, name, description, utc.localize(datetime.utcfromtimestamp(time_begin)), utc.localize(datetime.utcfromtimestamp(time_end)), utc.localize(datetime.utcfromtimestamp(register_deadline)), utc.localize(datetime.utcfromtimestamp(edit_deadline)), utc.localize(datetime.utcfromtimestamp(payment_deadline)), fetch_options=fetch_options, only_active=only_active, attendee_id=attendee_id)
@staticmethod
def fetch_all(env, fetch_options=False, only_active=False, attendee_id=None):
@ -765,7 +765,7 @@ class Event(object):
res = []
for row in rows:
e_id, name, description, time_begin, time_end, register_deadline, edit_deadline, payment_deadline = row
res.append(Event(env, e_id, name, description, datetime.utcfromtimestamp(time_begin), datetime.utcfromtimestamp(time_end), datetime.utcfromtimestamp(register_deadline), datetime.utcfromtimestamp(edit_deadline), datetime.utcfromtimestamp(payment_deadline), fetch_options=fetch_options, only_active=only_active, attendee_id=attendee_id))
res.append(Event(env, e_id, name, description, utc.localize(datetime.utcfromtimestamp(time_begin)), utc.localize(datetime.utcfromtimestamp(time_end)), utc.localize(datetime.utcfromtimestamp(register_deadline)), utc.localize(datetime.utcfromtimestamp(edit_deadline)), utc.localize(datetime.utcfromtimestamp(payment_deadline)), fetch_options=fetch_options, only_active=only_active, attendee_id=attendee_id))
return res
@staticmethod
@ -780,7 +780,7 @@ class Event(object):
if not row:
return None
e_id, name, description, time_begin, time_end, register_deadline, edit_deadline, payment_deadline = row
event = Event(env, e_id, "Kopie von " + name, description, datetime.utcfromtimestamp(time_begin), datetime.utcfromtimestamp(time_end), datetime.utcfromtimestamp(register_deadline), datetime.utcfromtimestamp(edit_deadline), datetime.utcfromtimestamp(payment_deadline))
event = Event(env, e_id, "Kopie von " + name, description, utc.localize(datetime.utcfromtimestamp(time_begin)), utc.localize(datetime.utcfromtimestamp(time_end)), utc.localize(datetime.utcfromtimestamp(register_deadline)), utc.localize(datetime.utcfromtimestamp(edit_deadline)), utc.localize(datetime.utcfromtimestamp(payment_deadline)))
event.commit()
event_account = EventAccount.copy_by_event(env, e_id, event.e_id)
@ -788,7 +788,7 @@ class Event(object):
for relation in relations:
print "relation", relation.ao_id, event.e_id
Option2Event.copy_by_event(env, relation.ao_id, event.e_id)
def add_options(self, attendee_id):
self.options = list()
@ -809,16 +809,14 @@ class Event(object):
def commit(self):
db = self.env.get_db_cnx()
cursor = db.cursor()
a,b,c,d,e = to_timestamp(self.time_begin), to_timestamp(self.time_end), to_timestamp(self.register_deadline), to_timestamp(self.edit_deadline), to_timestamp(self.payment_deadline)
cursor.execute("INSERT INTO booking_event " \
"(name, description, time_begin, time_end, register_deadline, edit_deadline, payment_deadline) " \
"VALUES(%s, %s, %s, %s, %s, %s, %s)", (
self.name,
self.description,
to_timestamp(self.time_begin),
to_timestamp(self.time_end),
to_timestamp(self.register_deadline),
to_timestamp(self.edit_deadline),
to_timestamp(self.payment_deadline)))
self.description, a,b,c,d,e,
))
db.commit()
self.e_id = db.get_last_id(cursor, 'booking_event')
@ -836,6 +834,7 @@ class Event(object):
def update(self):
db = self.env.get_db_cnx()
cursor = db.cursor()
a,b,c,d,e = to_timestamp(self.time_begin), to_timestamp(self.time_end), to_timestamp(self.register_deadline), to_timestamp(self.edit_deadline), to_timestamp(self.payment_deadline)
cursor.execute("""UPDATE booking_event
SET name=%s,
description=%s,
@ -847,11 +846,7 @@ class Event(object):
WHERE e_id=%s;""", (
self.name,
self.description,
to_timestamp(self.time_begin),
to_timestamp(self.time_end),
to_timestamp(self.register_deadline),
to_timestamp(self.edit_deadline),
to_timestamp(self.payment_deadline),
a,b,c,d,e,
self.e_id))
db.commit()

View File

@ -29,8 +29,8 @@
<tr py:for="idx, event in enumerate(events)"
class="${idx % 2 and 'odd' or 'even'}">
<td><a href="${req.href.admin('booking', 'events', event.e_id)}">${event.name}</a></td>
<td><a href="${req.href.admin('booking', 'events', event.e_id)}">${event.time_begin}</a></td>
<td><a href="${req.href.admin('booking', 'events', event.e_id)}">${event.time_end}</a></td>
<td><a href="${req.href.admin('booking', 'events', event.e_id)}">${event.time_begin.astimezone(selected_tz)}</a></td>
<td><a href="${req.href.admin('booking', 'events', event.e_id)}">${event.time_end.astimezone(selected_tz)}</a></td>
<td><input type="checkbox" name="rsel" value="${event.e_id}"/></td>
<td><input type="radio" name="copy" value="${event.e_id}"/></td>
<td><input type="radio" name="finish" value="${event.e_id}"/></td>
@ -54,22 +54,22 @@
<tr class="field">
<th><label for="gp_date_begin">Datum Begin:</label></th>
<td><input id="gp_date_begin" type="text" name="date_begin" size="10" maxlength="10" value="${event and event.time_begin.strftime('%d.%m.%Y') or None}"/>
<input id="gp_time_begin" type="text" name="time_begin" size="5" maxlength="5" value="${event and event.time_begin.strftime('%H:%M') or None}"/></td>
<input id="gp_time_begin" type="text" name="time_begin" size="5" maxlength="5" value="${event and event.time_begin.astimezone(selected_tz).strftime('%H:%M') or None}"/></td>
</tr>
<tr class="field">
<th><label for="gp_date_end">Datum Ende:</label></th>
<td><input id="gp_date_end" type="text" name="date_end" size="10" maxlength="10" value="${event and event.time_end.strftime('%d.%m.%Y') or None}"/>
<input type="text" name="time_end" size="5" maxlength="5" value="${event and event.time_end.strftime('%H:%M') or None}"/></td>
<input type="text" name="time_end" size="5" maxlength="5" value="${event and event.time_end.astimezone(selected_tz).strftime('%H:%M') or None}"/></td>
</tr>
<tr class="field">
<th><label for="gp_edit_deadline">Edit Deadline:</label></th>
<td><input id="gp_edit_deadline" type="text" size="10" maxlength="10" name="edit_deadline_date" value="${event and event.edit_deadline.strftime('%d.%m.%Y') or None}"/>
<input type="text" name="edit_deadline_time" size="5" maxlength="5" value="${event and event.edit_deadline.strftime('%H:%M') or None}"/></td>
<input type="text" name="edit_deadline_time" size="5" maxlength="5" value="${event and event.edit_deadline.astimezone(selected_tz).strftime('%H:%M') or None}"/></td>
</tr>
<tr class="field">
<th><label for="gp_payment_deadline">Bezahl Deadline:</label></th>
<td><input id="gp_payment_deadline" type="text" size="10" maxlength="10" name="payment_deadline_date" value="${event and event.payment_deadline.strftime('%d.%m.%Y') or None}"/>
<input type="text" name="payment_deadline_time" size="5" maxlength="5" value="${event and event.payment_deadline.strftime('%H:%M') or None}"/></td>
<input type="text" name="payment_deadline_time" size="5" maxlength="5" value="${event and event.payment_deadline.astimezone(selected_tz).strftime('%H:%M') or None}"/></td>
</tr>
<tr class="field">
<th><label for="gp_desc">Beschreibung:</label></th>

View File

@ -32,12 +32,12 @@
</tr>-->
<tr>
<th id="edit-deadline">Bestellungen können verändert werden bis zum:</th>
<td headers="edit-deadline" id="edit-deadline-data">${event.edit_deadline.strftime('%d.%m.%Y %H:%M')} Uhr.</td>
<td headers="edit-deadline" id="edit-deadline-data">${event.edit_deadline.astimezone(selected_tz).strftime('%d.%m.%Y %H:%M')} Uhr.</td>
</tr>
<!--</py:if> -->
<tr>
<th id="payment-deadline">Geld bitte auf unten angebenes Konto einzahlen bis zum:</th>
<td headers="payment-deadline" id="payment-deadline-data">${event.payment_deadline.strftime('%d.%m.%Y %H:%M')} Uhr.</td>
<td headers="payment-deadline" id="payment-deadline-data">${event.payment_deadline.astimezone(selected_tz).strftime('%d.%m.%Y %H:%M')} Uhr.</td>
</tr>
<tr>
<td colspan="2">Der Liefertermin wird per Mail bekannt gegeben, sofern Du eine Mailaddresse angegeben hast.</td>

View File

@ -87,7 +87,7 @@ class BookingComponent(Component):
if self.env.config.get("booking", "autoregister"):
event = Event.fetch_one(self.env, e_id)
nick = req.authname
rd = Attendee(self.env, 0, event.e_id, 0, nick, None, 0, 0, datetime.now(utc), 0)
rd = Attendee(self.env, 0, event.e_id, 0, nick, None, 0, 0, utc.localize(datetime.utcnow()), 0)
rd.commit()
return self._process_status(req, rd)
return self._process_register(req)
@ -113,7 +113,7 @@ class BookingComponent(Component):
def _process_register(self, req):
'''process add,change,delete actions for dates'''
data = {"now" : datetime.now(utc)}
data = {"now" : utc.localize(datetime.utcnow())}
#a = Attendee.fetch_one(self.env, nick=req.authname)
#if a:
#req.redirect(req.href.booking("status"))
@ -130,7 +130,7 @@ class BookingComponent(Component):
if email and not validate_email(email):
add_warning(req, u"email ungültig")
return "booking_register.html", data, None
rd = Attendee(self.env, 0, event.e_id, 0, nick, email, 0, 0, datetime.now(utc), 0)
rd = Attendee(self.env, 0, event.e_id, 0, nick, email, 0, 0, utc.localize(datetime.utcnow()), 0)
rd.commit()
req.redirect(req.href.booking(e_id))
return 'booking_register.html', data, None
@ -150,6 +150,7 @@ class BookingComponent(Component):
req.session.save()
#attendee.finished = False
#attendee.update()
session_tzname, selected_tz = get_tz(req.session.get("tz", self.env.config.get("trac", "default_timezone") or None))
if req.method == "POST":
if not attendee.finished:
failure = False
@ -269,7 +270,8 @@ class BookingComponent(Component):
get_option_count(attendee, i)
data = {"event" : event,
"attendee" : attendee,
"now" : datetime.now(utc),
"selected_tz" : selected_tz,
"now" : utc.localize(datetime.utcnow()),
"account_data" : EventAccount.fetch_by_event(self.env, event.e_id)}
return 'booking_status.html', data, None
@ -498,7 +500,7 @@ class UploadComponent(Component):
#def process_scheduled_task(self, parent):
#sqlString = "SELECT edit_deadline FROM booking_event;"
#rows = parent.queryDb(sqlString)
#n = datetime.now(utc)
#n = utc.localize(datetime.utcnow())
#for i in rows:
#d = datetime.utcfromtimestamp(i[0])
#dt = d - n

View File

@ -344,7 +344,8 @@ class EventRRule(object):
@staticmethod
def to_rrule(row, time_begin):
err_id, e_id, exclude, freq, interval, count, until, bysetpos, bymonth, bymonthday, byyearday, byweeknumber, byweekday, byweekdayocc = row
(err_id, e_id, exclude, freq, interval, count, until, bysetpos, bymonth,
bymonthday, byyearday, byweeknumber, byweekday, byweekdayocc) = row
args = {"dtstart" : time_begin, "interval" : interval}
if count!=None:
args["count"] = count
@ -384,7 +385,9 @@ class EventRRule(object):
@staticmethod
def to_ical(row):
ttypes = ("YEARLY","MONTHLY","WEEKLY","DAILY")
err_id, e_id, exclude, freq, interval, count, until, bysetpos, bymonth, bymonthday, byyearday, byweeknumber, byweekday, byweekdayocc = row
(err_id, e_id, exclude, freq, interval, count, until, bysetpos,
bymonth, bymonthday, byyearday, byweeknumber, byweekday,
byweekdayocc) = row
s = ["RRULE:FREQ=%s;INTERVAL=%s" % (ttypes[freq], interval),]
if until:
s.append("UNTIL=%s" % datetime.utcfromtimestamp(until).strftime("%Y%m%dT%H%M%SZ"))
@ -436,8 +439,11 @@ class EventRRule(object):
#data.append((d, o))
data = map(None, map(int, byweekday), map(int, byweekdayocc))
s.append("BYDAY=%s" % ",".join(
map(lambda x:"%s%s" % (x[1] != None and EventRRule.selectkeys[x[1]] or '', EventRRule.day_enum[x[0]]),
data)))
map(lambda x:"%s%s" % (x[1] != None and
EventRRule.selectkeys[x[1]] or
'', EventRRule.day_enum[x[0]]), data)
)
)
return ";".join(s)
def explain(self):
@ -461,7 +467,8 @@ class EventRRule(object):
res = list()
for x0, x1 in tmp:
if x1:
res.append("%s %s" % (unicode(self.weekday_names[x1]), unicode(self.day_names[x0])))
res.append("%s %s" % (unicode(self.weekday_names[x1]),
unicode(self.day_names[x0])))
else:
res.append(unicode(self.day_names[x0]))
#tmp = ", ".join(res)
@ -501,7 +508,9 @@ class EventRRule(object):
"self.byweekdayocc %s" % self.byweekdayocc))
class Event(object):
def __init__(self, env, e_id, name, author, time_created, time_modified, time_begin, time_end, location_id, initial_e_id=None, tags=None, attendees=None, is_periodic=False, wikipage=None):
def __init__(self, env, e_id, name, author, time_created, time_modified,
time_begin, time_end, location_id, initial_e_id=None,
tags=None, attendees=None, is_periodic=False, wikipage=None):
"""maps an relation of the 'events' table to a python object
@type e_id: int
@ -544,6 +553,7 @@ class Event(object):
@type wikipage: unicode
@param wikipage: the link as plaintext without 'wiki' prefix, e.g: "events/wikipage-of-that-event", or "foo"
"""
self.env = env
self.e_id = e_id
self.name = unicode(name)

View File

@ -25,4 +25,4 @@
</div>
</div>
</body>
</html>
</html>