From e62667978666003beb250d19e1e3c4c3d7312857 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20K=C3=B6gl?= Date: Wed, 30 May 2012 16:11:14 +0200 Subject: [PATCH] timezone fixed --- TracBooking/tracbooking/admin.py | 29 +++++++++---------- TracBooking/tracbooking/model.py | 27 +++++++---------- .../tracbooking/templates/admin_events.html | 12 ++++---- .../tracbooking/templates/booking_status.html | 4 +-- TracBooking/tracbooking/web_ui.py | 12 ++++---- TracRendezVous/tracrendezvous/event/model.py | 22 ++++++++++---- .../event/templates/event_list.html | 2 +- 7 files changed, 56 insertions(+), 52 deletions(-) diff --git a/TracBooking/tracbooking/admin.py b/TracBooking/tracbooking/admin.py index 875ec9e..005f4e5 100644 --- a/TracBooking/tracbooking/admin.py +++ b/TracBooking/tracbooking/admin.py @@ -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): diff --git a/TracBooking/tracbooking/model.py b/TracBooking/tracbooking/model.py index e225fe6..cb7bd6d 100644 --- a/TracBooking/tracbooking/model.py +++ b/TracBooking/tracbooking/model.py @@ -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() diff --git a/TracBooking/tracbooking/templates/admin_events.html b/TracBooking/tracbooking/templates/admin_events.html index 8978f6f..9a56236 100644 --- a/TracBooking/tracbooking/templates/admin_events.html +++ b/TracBooking/tracbooking/templates/admin_events.html @@ -29,8 +29,8 @@ ${event.name} - ${event.time_begin} - ${event.time_end} + ${event.time_begin.astimezone(selected_tz)} + ${event.time_end.astimezone(selected_tz)} @@ -54,22 +54,22 @@ - + - + - + - + diff --git a/TracBooking/tracbooking/templates/booking_status.html b/TracBooking/tracbooking/templates/booking_status.html index 72a6189..f5a2a6b 100644 --- a/TracBooking/tracbooking/templates/booking_status.html +++ b/TracBooking/tracbooking/templates/booking_status.html @@ -32,12 +32,12 @@ --> Bestellungen können verändert werden bis zum: - ${event.edit_deadline.strftime('%d.%m.%Y %H:%M')} Uhr. + ${event.edit_deadline.astimezone(selected_tz).strftime('%d.%m.%Y %H:%M')} Uhr. Geld bitte auf unten angebenes Konto einzahlen bis zum: - ${event.payment_deadline.strftime('%d.%m.%Y %H:%M')} Uhr. + ${event.payment_deadline.astimezone(selected_tz).strftime('%d.%m.%Y %H:%M')} Uhr. Der Liefertermin wird per Mail bekannt gegeben, sofern Du eine Mailaddresse angegeben hast. diff --git a/TracBooking/tracbooking/web_ui.py b/TracBooking/tracbooking/web_ui.py index 960453d..53396c5 100644 --- a/TracBooking/tracbooking/web_ui.py +++ b/TracBooking/tracbooking/web_ui.py @@ -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 diff --git a/TracRendezVous/tracrendezvous/event/model.py b/TracRendezVous/tracrendezvous/event/model.py index 6b26fb7..2d7aa91 100644 --- a/TracRendezVous/tracrendezvous/event/model.py +++ b/TracRendezVous/tracrendezvous/event/model.py @@ -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) diff --git a/TracRendezVous/tracrendezvous/event/templates/event_list.html b/TracRendezVous/tracrendezvous/event/templates/event_list.html index 23084d7..8e93397 100644 --- a/TracRendezVous/tracrendezvous/event/templates/event_list.html +++ b/TracRendezVous/tracrendezvous/event/templates/event_list.html @@ -25,4 +25,4 @@ - \ No newline at end of file +