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 @@