def post(self, id): event = Event.get_by_id(int(id)) user = users.get_current_user() access_rights = UserRights(user, event) state = self.request.get("state") if state: desc = "" if state.lower() == "approve" and access_rights.can_approve: event.approve() desc = "Approved event" if state.lower() == "staff" and access_rights.can_staff: event.add_staff(user) desc = "Added self as staff" if state.lower() == "unstaff" and access_rights.can_unstaff: event.remove_staff(user) desc = "Removed self as staff" if state.lower() == "cancel" and access_rights.can_cancel: event.cancel() desc = "Cancelled event" if state.lower() == "delete" and access_rights.is_admin: event.delete() desc = "Deleted event" if state.lower() == "undelete" and access_rights.is_admin: event.undelete() desc = "Undeleted event" if state.lower() == "expire" and access_rights.is_admin: event.expire() desc = "Expired event" if event.status == "approved": notify_owner_approved(event) if desc != "": log = HDLog(event=event, description=desc) log.put() self.redirect(event_path(event))
def post(self): user = users.get_current_user() try: start_time = datetime.strptime('%s %s:%s %s' % ( self.request.get('date'), self.request.get('start_time_hour'), self.request.get('start_time_minute'), self.request.get('start_time_ampm')), '%m/%d/%Y %I:%M %p') end_time = datetime.strptime('%s %s:%s %s' % ( self.request.get('date'), self.request.get('end_time_hour'), self.request.get('end_time_minute'), self.request.get('end_time_ampm')), '%m/%d/%Y %I:%M %p') conflicts = Event.check_conflict(start_time,end_time,self.request.get_all('rooms')) if conflicts: raise ValueError('Room conflict detected') if not self.request.get('estimated_size').isdigit(): raise ValueError('Estimated number of people must be a number') if not int(self.request.get('estimated_size')) > 0: raise ValueError('Estimated number of people must be greater then zero') if (end_time-start_time).days < 0: raise ValueError('End time must be after start time') if ( self.request.get( 'contact_phone' ) and not is_phone_valid( self.request.get( 'contact_phone' ) ) ): raise ValueError( 'Phone number does not appear to be valid' ) else: event = Event( name = cgi.escape(self.request.get('name')), start_time = start_time, end_time = end_time, type = cgi.escape(self.request.get('type')), estimated_size = cgi.escape(self.request.get('estimated_size')), contact_name = cgi.escape(self.request.get('contact_name')), contact_phone = cgi.escape(self.request.get('contact_phone')), details = cgi.escape(self.request.get('details')), url = cgi.escape(self.request.get('url')), fee = cgi.escape(self.request.get('fee')), notes = cgi.escape(self.request.get('notes')), rooms = self.request.get_all('rooms'), expired = local_today() + timedelta(days=PENDING_LIFETIME), # Set expected expiration date ) event.put() log = HDLog(event=event,description="Created new event") log.put() notify_owner_confirmation(event) notify_new_event(event) set_cookie(self.response.headers, 'formvalues', None) self.redirect('/event/%s-%s' % (event.key().id(), slugify(event.name))) except Exception, e: message = str(e) if 'match format' in message: message = 'Date is required.' if message.startswith('Property'): message = message[9:].replace('_', ' ').capitalize() # This is NOT a reliable way to handle erorrs #set_cookie(self.response.headers, 'formerror', message) #set_cookie(self.response.headers, 'formvalues', dict(self.request.POST)) #self.redirect('/new') error = message self.response.out.write(template.render('templates/error.html', locals()))
def post(self, id): event = Event.get_by_id(int(id)) user = users.get_current_user() access_rights = UserRights(user, event) if access_rights.can_edit: try: srg_date = self.request.get("date") if event.start_time == srg_date: start_time = start_time else: st_date = srg_date[0 : len(srg_date) - 9] start_time = datetime.strptime( "%s %s:%s %s" % ( st_date, self.request.get("start_time_hour"), self.request.get("start_time_minute"), self.request.get("start_time_ampm"), ), "%Y-%m-%d %I:%M %p", ) end_time = datetime.strptime( "%s %s:%s %s" % ( st_date, self.request.get("end_time_hour"), self.request.get("end_time_minute"), self.request.get("end_time_ampm"), ), "%Y-%m-%d %I:%M %p", ) if not self.request.get("estimated_size").isdigit(): raise ValueError("Estimated number of people must be a number") if not int(self.request.get("estimated_size")) > 0: raise ValueError("Estimated number of people must be greater then zero") if self.request.get("contact_phone") and not is_phone_valid(self.request.get("contact_phone")): raise ValueError("Phone number does not appear to be valid") else: event.name = self.request.get("name") event.start_time = start_time event.end_time = end_time event.estimated_size = cgi.escape(self.request.get("estimated_size")) event.contact_name = cgi.escape(self.request.get("contact_name")) event.contact_phone = cgi.escape(self.request.get("contact_phone")) event.details = cgi.escape(self.request.get("details")) event.url = cgi.escape(self.request.get("url")) event.fee = cgi.escape(self.request.get("fee")) event.notes = cgi.escape(self.request.get("notes")) event.rooms = self.request.get_all("rooms") event.put() log = HDLog(event=event, description="Edited event") log.put() self.redirect(event_path(event)) except ValueError, e: error = str(e) self.response.out.write(template.render("templates/error.html", locals()))
def post(self, id): event = Event.get_by_id(int(id)) user = users.get_current_user() access_rights = UserRights(user, event) state = self.request.get('state') if state: desc = '' if state.lower() == 'approve' and access_rights.can_approve: event.approve() desc = 'Approved event' if state.lower( ) == 'notapproved' and access_rights.can_not_approve: event.not_approved() desc = 'Event marked not approved' if state.lower() == 'rsvp' and user: event.rsvp() notify_owner_rsvp(event, user) if state.lower() == 'staff' and access_rights.can_staff: event.add_staff(user) desc = 'Added self as staff' if state.lower() == 'unstaff' and access_rights.can_unstaff: event.remove_staff(user) desc = 'Removed self as staff' if state.lower() == 'onhold' and access_rights.can_cancel: event.on_hold() desc = 'Put event on hold' if state.lower() == 'cancel' and access_rights.can_cancel: event.cancel() desc = 'Cancelled event' if state.lower() == 'delete' and access_rights.can_delete: event.delete() desc = 'Deleted event' notify_deletion(event, user) if state.lower() == 'undelete' and access_rights.can_undelete: event.undelete() desc = 'Undeleted event' if state.lower() == 'expire' and access_rights.is_admin: event.expire() desc = 'Expired event' if event.status == 'approved' and state.lower() == 'approve': notify_owner_approved(event) if desc != '': log = HDLog(event=event, description=desc) log.put() event.details = db.Text(event.details.replace('\n', '<br/>')) show_all_nav = user event.notes = db.Text(event.notes.replace('\n', '<br/>')) self.response.out.write( template.render('templates/event.html', locals()))
def post(self, id): event = Event.get_by_id(int(id)) user = users.get_current_user() access_rights = UserRights(user, event) if access_rights.can_edit: try: srg_date = self.request.get('date') if event.start_time == srg_date: start_time = start_time else: st_date = srg_date[0:len(srg_date)-9] start_time = datetime.strptime('%s %s:%s %s' % ( st_date, self.request.get('start_time_hour'), self.request.get('start_time_minute'), self.request.get('start_time_ampm')), '%Y-%m-%d %I:%M %p') end_time = datetime.strptime('%s %s:%s %s' % ( st_date, self.request.get('end_time_hour'), self.request.get('end_time_minute'), self.request.get('end_time_ampm')), '%Y-%m-%d %I:%M %p') conflicts = Event.check_conflict(start_time,end_time,self.request.get_all('rooms'), id) if conflicts: raise ValueError('Room conflict detected') if not self.request.get('estimated_size').isdigit(): raise ValueError('Estimated number of people must be a number') if not int(self.request.get('estimated_size')) > 0: raise ValueError('Estimated number of people must be greater then zero') if ( self.request.get( 'contact_phone' ) and not is_phone_valid( self.request.get( 'contact_phone' ) ) ): raise ValueError( 'Phone number does not appear to be valid' ) else: event.name = self.request.get('name') event.start_time = start_time event.end_time = end_time event.estimated_size = cgi.escape(self.request.get('estimated_size')) event.contact_name = cgi.escape(self.request.get('contact_name')) event.contact_phone = cgi.escape(self.request.get('contact_phone')) event.details = cgi.escape(self.request.get('details')) event.url = cgi.escape(self.request.get('url')) event.fee = cgi.escape(self.request.get('fee')) event.notes = cgi.escape(self.request.get('notes')) event.rooms = self.request.get_all('rooms') event.put() log = HDLog(event=event,description="Edited event") log.put() self.redirect(event_path(event)) except ValueError, e: error = str(e) self.response.out.write(template.render('templates/error.html', locals()))
def post(self, id): event = Event.get_by_id(int(id)) user = users.get_current_user() access_rights = UserRights(user, event) state = self.request.get('state') if state: desc = '' if state.lower() == 'approve' and access_rights.can_approve: event.approve() desc = 'Approved event' if state.lower() == 'notapproved' and access_rights.can_not_approve: event.not_approved() desc = 'Event marked not approved' if state.lower() == 'rsvp' and user: event.rsvp() notify_owner_rsvp(event,user) if state.lower() == 'staff' and access_rights.can_staff: event.add_staff(user) desc = 'Added self as staff' if state.lower() == 'unstaff' and access_rights.can_unstaff: event.remove_staff(user) desc = 'Removed self as staff' if state.lower() == 'onhold' and access_rights.can_cancel: event.on_hold() desc = 'Put event on hold' if state.lower() == 'cancel' and access_rights.can_cancel: event.cancel() desc = 'Cancelled event' if state.lower() == 'delete' and access_rights.can_delete: event.delete() desc = 'Deleted event' notify_deletion(event,user) if state.lower() == 'undelete' and access_rights.can_undelete: event.undelete() desc = 'Undeleted event' if state.lower() == 'expire' and access_rights.is_admin: event.expire() desc = 'Expired event' if event.status == 'approved' and state.lower() == 'approve': notify_owner_approved(event) if desc != '': log = HDLog(event=event,description=desc) log.put() event.details = db.Text(event.details.replace('\n','<br/>')) show_all_nav = user event.notes = db.Text(event.notes.replace('\n','<br/>')) self.response.out.write(template.render('templates/event.html', locals()))
def __restore_user_events(self, user): # event_qu ery = db.GqlQuery("SELECT * FROM Event WHERE member = :1" \ # " AND original_status != NULL", user) events = Event.get_future_suspended_events_by_member(member=user) future_puts = [] for event in events.run(): logging.debug("Restoring event '%s'." % (event.name)) event.status = event.original_status event.original_status = None event.owner_suspended_time = None event_future = db.put_async(event) future_puts.append(event_future) # Write a log of it. log_entry = HDLog(event=event, description="Restoring event because \ owner is now active.") log_entry_future = db.put_async(log_entry) future_puts.append(log_entry_future) # Wait for all the writes to finish. logging.debug("Waiting for all writes to finish...") for future_put in future_puts: future_put.get_result()
def __hold_user_events(self, user): events = Event.get_future_events_by_member(member=user) # event_query = db.GqlQuery("SELECT * FROM Event WHERE member = :1" \ # " AND status IN :2 AND start_time > :3", # user, ["pending", "approved"], local_today()) future_puts = [] for event in events: logging.debug("Suspending event '%s'." % (event.name)) event.original_status = event.status event.status = "suspended" event.owner_suspended_time = datetime.datetime.now() event_future = db.put_async(event) future_puts.append(event_future) # Write a log of it. log_entry = HDLog(event=event, description="Suspended event \ because owner was suspended.") log_entry_future = db.put_async(log_entry) future_puts.append(log_entry_future) # Wait for all the writes to finish. logging.debug("Waiting for all writes to finish...") for future_put in future_puts: future_put.get_result()
def post(self, id): event = Event.get_by_id(int(id)) user = users.get_current_user() access_rights = UserRights(user, event) state = self.request.get("state") if state: desc = "" if state.lower() == "approve" and access_rights.can_approve: event.approve() desc = "Approved event" if state.lower() == "notapproved" and access_rights.can_not_approve: event.not_approved() desc = "Event marked not approved" if state.lower() == "rsvp" and user: event.rsvp() notify_owner_rsvp(event, user) if state.lower() == "staff" and access_rights.can_staff: event.add_staff(user) desc = "Added self as staff" if state.lower() == "unstaff" and access_rights.can_unstaff: event.remove_staff(user) desc = "Removed self as staff" if state.lower() == "onhold" and access_rights.can_cancel: event.on_hold() desc = "Put event on hold" if state.lower() == "cancel" and access_rights.can_cancel: event.cancel() desc = "Cancelled event" if state.lower() == "delete" and access_rights.is_admin: event.delete() desc = "Deleted event" if state.lower() == "undelete" and access_rights.is_admin: event.undelete() desc = "Undeleted event" if state.lower() == "expire" and access_rights.is_admin: event.expire() desc = "Expired event" if event.status == "approved" and state.lower() == "approve": notify_owner_approved(event) if desc != "": log = HDLog(event=event, description=desc) log.put() event.details = db.Text(event.details.replace("\n", "<br/>")) show_all_nav = user event.notes = db.Text(event.notes.replace("\n", "<br/>")) self.response.out.write(template.render("templates/event.html", locals()))
def post(self, id): user = users.get_current_user() event = Event.get_by_id(int(id)) try: if self.request.get("rating"): feedback = Feedback( event=event, rating=int(self.request.get("rating")), comment=cgi.escape(self.request.get("comment")) ) feedback.put() log = HDLog(event=event, description="Posted feedback") log.put() self.redirect("/event/%s-%s" % (event.key().id(), slugify(event.name))) else: raise ValueError("Please select a rating") except Exception: set_cookie(self.response.headers, "formvalues", dict(self.request.POST)) self.redirect("/feedback/new/" + id)
def post(self, id): user = users.get_current_user() event = Event.get_by_id(int(id)) try: if self.request.get('rating'): feedback = Feedback( event = event, rating = int(self.request.get('rating')), comment = cgi.escape(self.request.get('comment'))) feedback.put() log = HDLog(event=event,description="Posted feedback") log.put() self.redirect('/event/%s-%s' % (event.key().id(), slugify(event.name))) else: raise ValueError('Please select a rating') except Exception: set_cookie(self.response.headers, 'formvalues', dict(self.request.POST)) self.redirect('/feedback/new/' + id)
def get(self): user = users.get_current_user() logs = HDLog.get_logs_list() if user: logout_url = users.create_logout_url('/') else: login_url = users.create_login_url('/') show_all_nav = user self.response.out.write(template.render('templates/logs.html', locals()))
def post(self, id): event = Event.get_by_id(int(id)) user = users.get_current_user() access_rights = UserRights(user, event) state = self.request.get('state') if state: desc = '' if state.lower() == 'approve' and access_rights.can_approve: event.approve() desc = 'Approved event' if state.lower() == 'notapproved' and access_rights.can_not_approve: event.not_approved() desc = 'Event marked not approved' if state.lower() == 'rsvp' and user: event.rsvp() notify_owner_rsvp(event,user) if state.lower() == 'staff' and access_rights.can_staff: event.add_staff(user) desc = 'Added self as staff' if state.lower() == 'unstaff' and access_rights.can_unstaff: event.remove_staff(user) desc = 'Removed self as staff' if state.lower() == 'onhold' and access_rights.can_cancel: event.on_hold() desc = 'Put event on hold' if state.lower() == 'cancel' and access_rights.can_cancel: event.cancel() desc = 'Cancelled event' if state.lower() == 'delete' and access_rights.is_admin: event.delete() desc = 'Deleted event' if state.lower() == 'undelete' and access_rights.is_admin: event.undelete() desc = 'Undeleted event' if state.lower() == 'expire' and access_rights.is_admin: event.expire() desc = 'Expired event' if event.status == 'approved' and state.lower() == 'approve': notify_owner_approved(event) if desc != '': log = HDLog(event=event,description=desc) log.put() self.redirect(event_path(event))
def get(self): user = users.get_current_user() logs = HDLog.get_logs_list() if user: logout_url = users.create_logout_url("/") else: login_url = users.create_login_url("/") show_all_nav = user # this is not the permanent answer but just for now cdn = "http://cdn.hackerdojo.com" self.response.out.write(template.render("templates/logs.html", locals()))
def get(self): user = users.get_current_user() logs = HDLog.get_logs_list() if user: logout_url = users.create_logout_url('/') else: login_url = users.create_login_url('/') show_all_nav = user # this is not the permanent answer but just for now cdn = 'http://cdn.hackerdojo.com' self.response.out.write( template.render('templates/logs.html', locals()))
def post(self, id): event = Event.get_by_id(int(id)) user = users.get_current_user() access_rights = UserRights(user, event) if access_rights.can_edit: try: start_time = datetime.strptime('%s %s:%s %s' % ( self.request.get('start_date'), self.request.get('start_time_hour'), self.request.get('start_time_minute'), self.request.get('start_time_ampm')), '%m/%d/%Y %I:%M %p') end_time = datetime.strptime('%s %s:%s %s' % ( self.request.get('end_date'), self.request.get('end_time_hour'), self.request.get('end_time_minute'), self.request.get('end_time_ampm')), '%m/%d/%Y %I:%M %p') conflicts = Event.check_conflict(start_time,end_time,self.request.get_all('rooms'), int(id)) if conflicts: if "Deck" in self.request.get_all('rooms') or "Savanna" in self.request.get_all('rooms'): raise ValueError('Room conflict detected <small>(Note: Deck & Savanna share the same area, two events cannot take place at the same time in these rooms.)</small>') else: raise ValueError('Room conflict detected') if not self.request.get('estimated_size').isdigit(): raise ValueError('Estimated number of people must be a number') if not int(self.request.get('estimated_size')) > 0: raise ValueError('Estimated number of people must be greater then zero') if ( self.request.get( 'contact_phone' ) and not is_phone_valid( self.request.get( 'contact_phone' ) ) ): raise ValueError( 'Phone number does not appear to be valid' ) else: log_desc = "Event edited<br />" previous_object = Event.get_by_id(int(id)) event.name = self.request.get('name') if (previous_object.name != event.name): log_desc = log_desc + "<strong>Title:</strong> " + previous_object.name + " to " + event.name + "<br />" event.start_time = start_time if (previous_object.start_time != event.start_time): log_desc = log_desc + "<strong>Start time:</strong> " + str(previous_object.start_time) + " to " + str(event.start_time) + "<br />" event.end_time = end_time if (previous_object.end_time != event.end_time): log_desc = log_desc + "<strong>End time:</strong> " + str(previous_object.end_time) + " to " + str(event.end_time) + "<br />" event.estimated_size = cgi.escape(self.request.get('estimated_size')) if (previous_object.estimated_size != event.estimated_size): log_desc = log_desc + "<strong>Est. size:</strong> " + previous_object.estimated_size + " to " + event.estimated_size + "<br />" event.contact_name = cgi.escape(self.request.get('contact_name')) if (previous_object.contact_name != event.contact_name): log_desc = log_desc + "<strong>Contact:</strong> " + previous_object.contact_name + " to " + event.contact_name + "<br />" event.contact_phone = cgi.escape(self.request.get('contact_phone')) if (previous_object.contact_phone != event.contact_phone): log_desc = log_desc + "<strong>Contact phone:</strong> " + previous_object.contact_phone + " to " + event.contact_phone + "<br />" event.details = cgi.escape(self.request.get('details')) if (previous_object.details != event.details): log_desc = log_desc + "<strong>Details:</strong> " + previous_object.details + " to " + event.details + "<br />" event.url = cgi.escape(self.request.get('url')) if (previous_object.url != event.url): log_desc = log_desc + "<strong>Url:</strong> " + previous_object.url + " to " + event.url + "<br />" event.fee = cgi.escape(self.request.get('fee')) if (previous_object.fee != event.fee): log_desc = log_desc + "<strong>Fee:</strong> " + previous_object.fee + " to " + event.fee + "<br />" event.notes = cgi.escape(self.request.get('notes')) if (previous_object.notes != event.notes): log_desc = log_desc + "<strong>Notes:</strong> " + previous_object.notes + " to " + event.notes + "<br />" event.rooms = self.request.get_all('rooms') if (previous_object.rooms != event.rooms): log_desc = log_desc + "<strong>Rooms changed</strong><br />" log_desc = log_desc + "<strong>Old room:</strong> " + previous_object.roomlist() + "<br />" log_desc = log_desc + "<strong>New room:</strong> " + event.roomlist() + "<br />" event.put() log = HDLog(event=event,description=log_desc) log.put() self.redirect(event_path(event)) except ValueError, e: error = str(e) self.response.out.write(template.render('templates/error.html', locals()))
def post(self): user = users.get_current_user() try: start_time = datetime.strptime( '%s %s:%s %s' % (self.request.get('start_date'), self.request.get('start_time_hour'), self.request.get('start_time_minute'), self.request.get('start_time_ampm')), '%m/%d/%Y %I:%M %p') end_time = datetime.strptime( '%s %s:%s %s' % (self.request.get('end_date'), self.request.get('end_time_hour'), self.request.get('end_time_minute'), self.request.get('end_time_ampm')), '%m/%d/%Y %I:%M %p') conflicts = Event.check_conflict(start_time, end_time, self.request.get_all('rooms')) if conflicts: if "Deck" in self.request.get_all( 'rooms') or "Savanna" in self.request.get_all('rooms'): raise ValueError( 'Room conflict detected <small>(Note: Deck & Savanna share the same area, two events cannot take place at the same time in these rooms.)</small>' ) else: raise ValueError('Room conflict detected') if not self.request.get('details'): raise ValueError('You must provide a description of the event') if not self.request.get('estimated_size').isdigit(): raise ValueError('Estimated number of people must be a number') if not int(self.request.get('estimated_size')) > 0: raise ValueError( 'Estimated number of people must be greater then zero') if (end_time - start_time).days < 0: raise ValueError('End time must be after start time') if (self.request.get('contact_phone') and not is_phone_valid(self.request.get('contact_phone'))): raise ValueError('Phone number does not appear to be valid') else: event = Event( name=cgi.escape(self.request.get('name')), start_time=start_time, end_time=end_time, type=cgi.escape(self.request.get('type')), estimated_size=cgi.escape( self.request.get('estimated_size')), contact_name=cgi.escape(self.request.get('contact_name')), contact_phone=cgi.escape( self.request.get('contact_phone')), details=cgi.escape(self.request.get('details')), url=cgi.escape(self.request.get('url')), fee=cgi.escape(self.request.get('fee')), notes=cgi.escape(self.request.get('notes')), rooms=self.request.get_all('rooms'), expired=local_today() + timedelta( days=PENDING_LIFETIME), # Set expected expiration date ) event.put() log = HDLog(event=event, description="Created new event") log.put() notify_owner_confirmation(event) notify_new_event(event) set_cookie(self.response.headers, 'formvalues', None) rules = memcache.get("rules") if (rules is None): try: rules = urlfetch.fetch( "http://wiki.hackerdojo.com/api_v2/op/GetPage/page/Event+Policies/_type/html", "GET").content memcache.add("rules", rules, 86400) except Exception, e: rules = "Error fetching rules. Please report this error to [email protected]." self.response.out.write( template.render('templates/confirmation.html', locals())) except Exception, e: message = str(e) if 'match format' in message: message = 'Date is required.' if message.startswith('Property'): message = message[9:].replace('_', ' ').capitalize() # This is NOT a reliable way to handle erorrs #set_cookie(self.response.headers, 'formerror', message) #set_cookie(self.response.headers, 'formvalues', dict(self.request.POST)) #self.redirect('/new') error = message # this is not the permanent answer but just for now cdn = 'http://cdn.hackerdojo.com' self.response.out.write( template.render('templates/error.html', locals()))
def post(self, id): event = Event.get_by_id(int(id)) user = users.get_current_user() # this is not the permanent answer but just for now cdn = 'http://cdn.hackerdojo.com' access_rights = UserRights(user, event) formatted_url = cgi.escape(self.request.get('url')) if ("http://" not in event.url and "https://" not in event.url): formatted_url = "http://" + formatted_url if access_rights.can_edit: try: start_time = datetime.strptime( '%s %s:%s %s' % (self.request.get('start_date'), self.request.get('start_time_hour'), self.request.get('start_time_minute'), self.request.get('start_time_ampm')), '%m/%d/%Y %I:%M %p') end_time = datetime.strptime( '%s %s:%s %s' % (self.request.get('end_date'), self.request.get('end_time_hour'), self.request.get('end_time_minute'), self.request.get('end_time_ampm')), '%m/%d/%Y %I:%M %p') conflicts = Event.check_conflict(start_time, end_time, self.request.get_all('rooms'), int(id)) if conflicts: if "Deck" in self.request.get_all( 'rooms') or "Savanna" in self.request.get_all( 'rooms'): raise ValueError( 'Room conflict detected <small>(Note: Deck & Savanna share the same area, two events cannot take place at the same time in these rooms.)</small>' ) else: raise ValueError('Room conflict detected') if not self.request.get('details'): raise ValueError( 'You must provide a description of the event') if not self.request.get('estimated_size').isdigit(): raise ValueError( 'Estimated number of people must be a number') if not int(self.request.get('estimated_size')) > 0: raise ValueError( 'Estimated number of people must be greater then zero') if (self.request.get('contact_phone') and not is_phone_valid(self.request.get('contact_phone'))): raise ValueError( 'Phone number does not appear to be valid') else: log_desc = "" previous_object = Event.get_by_id(int(id)) event.name = self.request.get('name') if (previous_object.name != event.name): log_desc = log_desc + "<strong>Title:</strong> " + previous_object.name + " to " + event.name + "<br />" event.start_time = start_time if (previous_object.start_time != event.start_time): log_desc = log_desc + "<strong>Start time:</strong> " + str( previous_object.start_time) + " to " + str( event.start_time) + "<br />" event.end_time = end_time if (previous_object.end_time != event.end_time): log_desc = log_desc + "<strong>End time:</strong> " + str( previous_object.end_time) + " to " + str( event.end_time) + "<br />" event.estimated_size = cgi.escape( self.request.get('estimated_size')) if (previous_object.estimated_size != event.estimated_size): log_desc = log_desc + "<strong>Est. size:</strong> " + previous_object.estimated_size + " to " + event.estimated_size + "<br />" event.contact_name = cgi.escape( self.request.get('contact_name')) if (previous_object.contact_name != event.contact_name): log_desc = log_desc + "<strong>Contact:</strong> " + previous_object.contact_name + " to " + event.contact_name + "<br />" event.contact_phone = cgi.escape( self.request.get('contact_phone')) if (previous_object.contact_phone != event.contact_phone): log_desc = log_desc + "<strong>Contact phone:</strong> " + previous_object.contact_phone + " to " + event.contact_phone + "<br />" event.details = cgi.escape(self.request.get('details')) if (previous_object.details != event.details): log_desc = log_desc + "<strong>Details:</strong> " + previous_object.details + " to " + event.details + "<br />" event.url = formatted_url if (previous_object.url != event.url): log_desc = log_desc + "<strong>Url:</strong> " + previous_object.url + " to " + event.url + "<br />" event.fee = cgi.escape(self.request.get('fee')) if (previous_object.fee != event.fee): log_desc = log_desc + "<strong>Fee:</strong> " + previous_object.fee + " to " + event.fee + "<br />" event.notes = cgi.escape(self.request.get('notes')) if (previous_object.notes != event.notes): log_desc = log_desc + "<strong>Notes:</strong> " + previous_object.notes + " to " + event.notes + "<br />" event.rooms = self.request.get_all('rooms') if (previous_object.rooms != event.rooms): log_desc = log_desc + "<strong>Rooms changed</strong><br />" log_desc = log_desc + "<strong>Old room:</strong> " + previous_object.roomlist( ) + "<br />" log_desc = log_desc + "<strong>New room:</strong> " + event.roomlist( ) + "<br />" event.put() log = HDLog(event=event, description="Event edited<br />" + log_desc) log.put() show_all_nav = user access_rights = UserRights(user, event) if access_rights.can_edit: logout_url = users.create_logout_url('/') rooms = ROOM_OPTIONS hours = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12] if log_desc: edited = "<u>Saved changes:</u><br>" + log_desc self.response.out.write( template.render('templates/edit.html', locals())) else: self.response.out.write("Access denied") except ValueError, e: error = str(e) # this is not the permanent answer but just for now cdn = 'http://cdn.hackerdojo.com' self.response.out.write( template.render('templates/error.html', locals()))
def post(self): user = users.get_current_user() try: start_time = datetime.strptime('%s %s:%s %s' % ( self.request.get('start_date'), self.request.get('start_time_hour'), self.request.get('start_time_minute'), self.request.get('start_time_ampm')), '%m/%d/%Y %I:%M %p') end_time = datetime.strptime('%s %s:%s %s' % ( self.request.get('end_date'), self.request.get('end_time_hour'), self.request.get('end_time_minute'), self.request.get('end_time_ampm')), '%m/%d/%Y %I:%M %p') conflicts = Event.check_conflict( start_time,end_time, self.request.get('setup'), self.request.get('teardown'), self.request.get_all('rooms') ) if conflicts: if "Deck" in self.request.get_all('rooms') or "Savanna" in self.request.get_all('rooms'): raise ValueError('Room conflict detected <small>(Note: Deck & Savanna share the same area, two events cannot take place at the same time in these rooms.)</small>') else: raise ValueError('Room conflict detected') if not self.request.get('details'): raise ValueError('You must provide a description of the event') if not self.request.get('estimated_size').isdigit(): raise ValueError('Estimated number of people must be a number') if not int(self.request.get('estimated_size')) > 0: raise ValueError('Estimated number of people must be greater then zero') if (end_time-start_time).days < 0: raise ValueError('End time must be after start time') if ( self.request.get( 'contact_phone' ) and not is_phone_valid( self.request.get( 'contact_phone' ) ) ): raise ValueError( 'Phone number does not appear to be valid' ) else: event = Event( name = cgi.escape(self.request.get('name')), start_time = start_time, end_time = end_time, type = cgi.escape(self.request.get('type')), estimated_size = cgi.escape(self.request.get('estimated_size')), contact_name = cgi.escape(self.request.get('contact_name')), contact_phone = cgi.escape(self.request.get('contact_phone')), details = cgi.escape(self.request.get('details')), url = cgi.escape(self.request.get('url')), fee = cgi.escape(self.request.get('fee')), notes = cgi.escape(self.request.get('notes')), rooms = self.request.get_all('rooms'), expired = local_today() + timedelta(days=PENDING_LIFETIME), # Set expected expiration date setup = int(self.request.get('setup') or 0), teardown = int(self.request.get('teardown') or 0) ) event.put() log = HDLog(event=event,description="Created new event") log.put() notify_owner_confirmation(event) notify_event_change(event) set_cookie(self.response.headers, 'formvalues', None) rules = memcache.get("rules") if(rules is None): try: rules = urlfetch.fetch("http://wiki.hackerdojo.com/api_v2/op/GetPage/page/Event+Policies/_type/html", "GET").content memcache.add("rules", rules, 86400) except Exception, e: rules = "Error fetching rules. Please report this error to [email protected]." self.response.out.write(template.render('templates/confirmation.html', locals())) except ValueError, e: message = str(e) if 'match format' in message: message = 'Date is required.' if message.startswith('Property'): message = message[9:].replace('_', ' ').capitalize() # This is NOT a reliable way to handle erorrs #set_cookie(self.response.headers, 'formerror', message) #set_cookie(self.response.headers, 'formvalues', dict(self.request.POST)) #self.redirect('/new') error = message self.response.out.write(template.render('templates/error.html', locals()))
def post(self, id): event = Event.get_by_id(int(id)) user = users.get_current_user() access_rights = UserRights(user, event) if access_rights.can_edit: try: start_time = datetime.strptime( '%s %s:%s %s' % (self.request.get('start_date'), self.request.get('start_time_hour'), self.request.get('start_time_minute'), self.request.get('start_time_ampm')), '%m/%d/%Y %I:%M %p') end_time = datetime.strptime( '%s %s:%s %s' % (self.request.get('end_date'), self.request.get('end_time_hour'), self.request.get('end_time_minute'), self.request.get('end_time_ampm')), '%m/%d/%Y %I:%M %p') conflicts = Event.check_conflict(start_time, end_time, self.request.get('setup'), self.request.get('teardown'), self.request.get_all('rooms'), int(id)) if conflicts: raise ValueError('Room conflict detected') if not self.request.get('details'): raise ValueError( 'You must provide a description of the event') if not self.request.get('estimated_size').isdigit(): raise ValueError( 'Estimated number of people must be a number') if not int(self.request.get('estimated_size')) > 0: raise ValueError( 'Estimated number of people must be greater then zero') if (self.request.get('contact_phone') and not is_phone_valid(self.request.get('contact_phone'))): raise ValueError( 'Phone number does not appear to be valid') if start_time == end_time: raise ValueError( 'End time for the event cannot be the same as the start time' ) else: log_desc = "" previous_object = Event.get_by_id(int(id)) event.status = 'pending' event.name = self.request.get('name') if (previous_object.name != event.name): log_desc += "<strong>Title:</strong> " + previous_object.name + " to " + event.name + "<br />" event.start_time = start_time if (previous_object.start_time != event.start_time): log_desc += "<strong>Start time:</strong> " + str( previous_object.start_time) + " to " + str( event.start_time) + "<br />" event.end_time = end_time if (previous_object.end_time != event.end_time): log_desc += "<strong>End time:</strong> " + str( previous_object.end_time) + " to " + str( event.end_time) + "<br />" event.estimated_size = cgi.escape( self.request.get('estimated_size')) if (previous_object.estimated_size != event.estimated_size): log_desc += "<strong>Est. size:</strong> " + previous_object.estimated_size + " to " + event.estimated_size + "<br />" event.contact_name = cgi.escape( self.request.get('contact_name')) if (previous_object.contact_name != event.contact_name): log_desc += "<strong>Contact:</strong> " + previous_object.contact_name + " to " + event.contact_name + "<br />" event.contact_phone = cgi.escape( self.request.get('contact_phone')) if (previous_object.contact_phone != event.contact_phone): log_desc += "<strong>Contact phone:</strong> " + previous_object.contact_phone + " to " + event.contact_phone + "<br />" event.details = cgi.escape(self.request.get('details')) if (previous_object.details != event.details): log_desc += "<strong>Details:</strong> " + previous_object.details + " to " + event.details + "<br />" event.url = cgi.escape(self.request.get('url')) if (previous_object.url != event.url): log_desc += "<strong>Url:</strong> " + previous_object.url + " to " + event.url + "<br />" event.fee = cgi.escape(self.request.get('fee')) if (previous_object.fee != event.fee): log_desc += "<strong>Fee:</strong> " + previous_object.fee + " to " + event.fee + "<br />" event.notes = cgi.escape(self.request.get('notes')) if (previous_object.notes != event.notes): log_desc += "<strong>Notes:</strong> " + previous_object.notes + " to " + event.notes + "<br />" event.rooms = self.request.get_all('rooms') if (previous_object.rooms != event.rooms): log_desc += "<strong>Rooms changed</strong><br />" log_desc += "<strong>Old room:</strong> " + previous_object.roomlist( ) + "<br />" log_desc += "<strong>New room:</strong> " + event.roomlist( ) + "<br />" setup = cgi.escape(self.request.get('setup')) or 0 event.setup = int(setup) if (previous_object.setup != event.setup): log_desc += "<strong>Setup time changed</strong><br />" log_desc += "<strong>Old time:</strong> %s minutes<br/>" % previous_object.setup log_desc += "<strong>New time:</strong> %s minutes<br/>" % event.setup teardown = cgi.escape(self.request.get('teardown')) or 0 event.teardown = int(teardown) if (previous_object.teardown != event.teardown): log_desc += "<strong>Teardown time changed</strong><br />" log_desc += "<strong>Old time:</strong> %s minutes<br/>" % previous_object.teardown log_desc += "<strong>New time:</strong> %s minutes<br/>" % event.teardown log = HDLog(event=event, description="Event edited<br />" + log_desc) log.put() show_all_nav = user access_rights = UserRights(user, event) if access_rights.can_edit: logout_url = users.create_logout_url('/') rooms = ROOM_OPTIONS hours = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12] if log_desc: edited = "<u>Saved changes:</u><br>" + log_desc notify_event_change(event=event, modification=1) event.put() self.response.out.write( template.render('templates/edit.html', locals())) else: self.response.out.write("Access denied") except NameError, e: logging.log(e) self.response.out.write( template.render('templates/error.html', locals()))
def post(self): user = users.get_current_user() try: start_time = datetime.strptime( "%s %s:%s %s" % ( self.request.get("start_date"), self.request.get("start_time_hour"), self.request.get("start_time_minute"), self.request.get("start_time_ampm"), ), "%m/%d/%Y %I:%M %p", ) end_time = datetime.strptime( "%s %s:%s %s" % ( self.request.get("end_date"), self.request.get("end_time_hour"), self.request.get("end_time_minute"), self.request.get("end_time_ampm"), ), "%m/%d/%Y %I:%M %p", ) conflicts = Event.check_conflict(start_time, end_time, self.request.get_all("rooms")) if conflicts: if "Deck" in self.request.get_all("rooms") or "Savanna" in self.request.get_all("rooms"): raise ValueError( "Room conflict detected <small>(Note: Deck & Savanna share the same area, two events cannot take place at the same time in these rooms.)</small>" ) else: raise ValueError("Room conflict detected") if not self.request.get("details"): raise ValueError("You must provide a description of the event") if not self.request.get("estimated_size").isdigit(): raise ValueError("Estimated number of people must be a number") if not int(self.request.get("estimated_size")) > 0: raise ValueError("Estimated number of people must be greater then zero") if (end_time - start_time).days < 0: raise ValueError("End time must be after start time") if self.request.get("contact_phone") and not is_phone_valid(self.request.get("contact_phone")): raise ValueError("Phone number does not appear to be valid") else: event = Event( name=cgi.escape(self.request.get("name")), start_time=start_time, end_time=end_time, type=cgi.escape(self.request.get("type")), estimated_size=cgi.escape(self.request.get("estimated_size")), contact_name=cgi.escape(self.request.get("contact_name")), contact_phone=cgi.escape(self.request.get("contact_phone")), details=cgi.escape(self.request.get("details")), url=cgi.escape(self.request.get("url")), fee=cgi.escape(self.request.get("fee")), notes=cgi.escape(self.request.get("notes")), rooms=self.request.get_all("rooms"), expired=local_today() + timedelta(days=PENDING_LIFETIME), # Set expected expiration date ) event.put() log = HDLog(event=event, description="Created new event") log.put() notify_owner_confirmation(event) notify_new_event(event) set_cookie(self.response.headers, "formvalues", None) rules = memcache.get("rules") if rules is None: try: rules = urlfetch.fetch( "http://wiki.hackerdojo.com/api_v2/op/GetPage/page/Event+Policies/_type/html", "GET" ).content memcache.add("rules", rules, 86400) except Exception, e: rules = "Error fetching rules. Please report this error to [email protected]." self.response.out.write(template.render("templates/confirmation.html", locals())) except Exception, e: message = str(e) if "match format" in message: message = "Date is required." if message.startswith("Property"): message = message[9:].replace("_", " ").capitalize() # This is NOT a reliable way to handle erorrs # set_cookie(self.response.headers, 'formerror', message) # set_cookie(self.response.headers, 'formvalues', dict(self.request.POST)) # self.redirect('/new') error = message # this is not the permanent answer but just for now cdn = "http://cdn.hackerdojo.com" self.response.out.write(template.render("templates/error.html", locals()))
def post(self, id): event = Event.get_by_id(int(id)) user = users.get_current_user() access_rights = UserRights(user, event) if access_rights.can_edit: try: start_time = datetime.strptime('%s %s:%s %s' % ( self.request.get('start_date'), self.request.get('start_time_hour'), self.request.get('start_time_minute'), self.request.get('start_time_ampm')), '%m/%d/%Y %I:%M %p') end_time = datetime.strptime('%s %s:%s %s' % ( self.request.get('end_date'), self.request.get('end_time_hour'), self.request.get('end_time_minute'), self.request.get('end_time_ampm')), '%m/%d/%Y %I:%M %p') conflicts = Event.check_conflict(start_time,end_time,self.request.get_all('rooms'), int(id)) if conflicts: if "Deck" in self.request.get_all('rooms') or "Savanna" in self.request.get_all('rooms'): raise ValueError('Room conflict detected <small>(Note: Deck & Savanna share the same area, two events cannot take place at the same time in these rooms.)</small>') else: raise ValueError('Room conflict detected') if not self.request.get('estimated_size').isdigit(): raise ValueError('Estimated number of people must be a number') if not int(self.request.get('estimated_size')) > 0: raise ValueError('Estimated number of people must be greater then zero') if int(self.request.get('estimated_size')) > 47: raise ValueError('Hacker Dojo temporarily is under order of the City of Mountain View to not allow assemblies larger than 49 persons. Sorry, your event exceeds this size. <p>NOTE: Lying about the event size to get around this restriction will result in membership ban plus possible legal action. We will be fined $1500 for each violation, which will be passed on to the event host.') if ( self.request.get( 'contact_phone' ) and not is_phone_valid( self.request.get( 'contact_phone' ) ) ): raise ValueError( 'Phone number does not appear to be valid' ) else: log_desc = "Event edited<br />" previous_object = Event.get_by_id(int(id)) event.name = self.request.get('name') if (previous_object.name != event.name): log_desc = log_desc + "<strong>Title:</strong> " + previous_object.name + " to " + event.name + "<br />" event.start_time = start_time if (previous_object.start_time != event.start_time): log_desc = log_desc + "<strong>Start time:</strong> " + str(previous_object.start_time) + " to " + str(event.start_time) + "<br />" event.end_time = end_time if (previous_object.end_time != event.end_time): log_desc = log_desc + "<strong>End time:</strong> " + str(previous_object.end_time) + " to " + str(event.end_time) + "<br />" event.estimated_size = cgi.escape(self.request.get('estimated_size')) if (previous_object.estimated_size != event.estimated_size): log_desc = log_desc + "<strong>Est. size:</strong> " + previous_object.estimated_size + " to " + event.estimated_size + "<br />" event.contact_name = cgi.escape(self.request.get('contact_name')) if (previous_object.contact_name != event.contact_name): log_desc = log_desc + "<strong>Contact:</strong> " + previous_object.contact_name + " to " + event.contact_name + "<br />" event.contact_phone = cgi.escape(self.request.get('contact_phone')) if (previous_object.contact_phone != event.contact_phone): log_desc = log_desc + "<strong>Contact phone:</strong> " + previous_object.contact_phone + " to " + event.contact_phone + "<br />" event.details = cgi.escape(self.request.get('details')) if (previous_object.details != event.details): log_desc = log_desc + "<strong>Details:</strong> " + previous_object.details + " to " + event.details + "<br />" event.url = cgi.escape(self.request.get('url')) if (previous_object.url != event.url): log_desc = log_desc + "<strong>Url:</strong> " + previous_object.url + " to " + event.url + "<br />" event.fee = cgi.escape(self.request.get('fee')) if (previous_object.fee != event.fee): log_desc = log_desc + "<strong>Fee:</strong> " + previous_object.fee + " to " + event.fee + "<br />" event.notes = cgi.escape(self.request.get('notes')) if (previous_object.notes != event.notes): log_desc = log_desc + "<strong>Notes:</strong> " + previous_object.notes + " to " + event.notes + "<br />" event.rooms = self.request.get_all('rooms') if (previous_object.rooms != event.rooms): log_desc = log_desc + "<strong>Rooms changed</strong><br />" log_desc = log_desc + "<strong>Old room:</strong> " + previous_object.roomlist() + "<br />" log_desc = log_desc + "<strong>New room:</strong> " + event.roomlist() + "<br />" event.put() log = HDLog(event=event,description=log_desc) log.put() self.redirect(event_path(event)) except ValueError, e: error = str(e) self.response.out.write(template.render('templates/error.html', locals()))
def post(self, id): event = Event.get_by_id(int(id)) user = users.get_current_user() # this is not the permanent answer but just for now cdn = "http://cdn.hackerdojo.com" access_rights = UserRights(user, event) formatted_url = cgi.escape(self.request.get("url")) if "http://" not in event.url and "https://" not in event.url: formatted_url = "http://" + formatted_url if access_rights.can_edit: try: start_time = datetime.strptime( "%s %s:%s %s" % ( self.request.get("start_date"), self.request.get("start_time_hour"), self.request.get("start_time_minute"), self.request.get("start_time_ampm"), ), "%m/%d/%Y %I:%M %p", ) end_time = datetime.strptime( "%s %s:%s %s" % ( self.request.get("end_date"), self.request.get("end_time_hour"), self.request.get("end_time_minute"), self.request.get("end_time_ampm"), ), "%m/%d/%Y %I:%M %p", ) conflicts = Event.check_conflict(start_time, end_time, self.request.get_all("rooms"), int(id)) if conflicts: if "Deck" in self.request.get_all("rooms") or "Savanna" in self.request.get_all("rooms"): raise ValueError( "Room conflict detected <small>(Note: Deck & Savanna share the same area, two events cannot take place at the same time in these rooms.)</small>" ) else: raise ValueError("Room conflict detected") if not self.request.get("details"): raise ValueError("You must provide a description of the event") if not self.request.get("estimated_size").isdigit(): raise ValueError("Estimated number of people must be a number") if not int(self.request.get("estimated_size")) > 0: raise ValueError("Estimated number of people must be greater then zero") if self.request.get("contact_phone") and not is_phone_valid(self.request.get("contact_phone")): raise ValueError("Phone number does not appear to be valid") else: log_desc = "" previous_object = Event.get_by_id(int(id)) event.name = self.request.get("name") if previous_object.name != event.name: log_desc = ( log_desc + "<strong>Title:</strong> " + previous_object.name + " to " + event.name + "<br />" ) event.start_time = start_time if previous_object.start_time != event.start_time: log_desc = ( log_desc + "<strong>Start time:</strong> " + str(previous_object.start_time) + " to " + str(event.start_time) + "<br />" ) event.end_time = end_time if previous_object.end_time != event.end_time: log_desc = ( log_desc + "<strong>End time:</strong> " + str(previous_object.end_time) + " to " + str(event.end_time) + "<br />" ) event.estimated_size = cgi.escape(self.request.get("estimated_size")) if previous_object.estimated_size != event.estimated_size: log_desc = ( log_desc + "<strong>Est. size:</strong> " + previous_object.estimated_size + " to " + event.estimated_size + "<br />" ) event.contact_name = cgi.escape(self.request.get("contact_name")) if previous_object.contact_name != event.contact_name: log_desc = ( log_desc + "<strong>Contact:</strong> " + previous_object.contact_name + " to " + event.contact_name + "<br />" ) event.contact_phone = cgi.escape(self.request.get("contact_phone")) if previous_object.contact_phone != event.contact_phone: log_desc = ( log_desc + "<strong>Contact phone:</strong> " + previous_object.contact_phone + " to " + event.contact_phone + "<br />" ) event.details = cgi.escape(self.request.get("details")) if previous_object.details != event.details: log_desc = ( log_desc + "<strong>Details:</strong> " + previous_object.details + " to " + event.details + "<br />" ) event.url = formatted_url if previous_object.url != event.url: log_desc = ( log_desc + "<strong>Url:</strong> " + previous_object.url + " to " + event.url + "<br />" ) event.fee = cgi.escape(self.request.get("fee")) if previous_object.fee != event.fee: log_desc = ( log_desc + "<strong>Fee:</strong> " + previous_object.fee + " to " + event.fee + "<br />" ) event.notes = cgi.escape(self.request.get("notes")) if previous_object.notes != event.notes: log_desc = ( log_desc + "<strong>Notes:</strong> " + previous_object.notes + " to " + event.notes + "<br />" ) event.rooms = self.request.get_all("rooms") if previous_object.rooms != event.rooms: log_desc = log_desc + "<strong>Rooms changed</strong><br />" log_desc = log_desc + "<strong>Old room:</strong> " + previous_object.roomlist() + "<br />" log_desc = log_desc + "<strong>New room:</strong> " + event.roomlist() + "<br />" event.put() log = HDLog(event=event, description="Event edited<br />" + log_desc) log.put() show_all_nav = user access_rights = UserRights(user, event) if access_rights.can_edit: logout_url = users.create_logout_url("/") rooms = ROOM_OPTIONS hours = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12] if log_desc: edited = "<u>Saved changes:</u><br>" + log_desc self.response.out.write(template.render("templates/edit.html", locals())) else: self.response.out.write("Access denied") except ValueError, e: error = str(e) # this is not the permanent answer but just for now cdn = "http://cdn.hackerdojo.com" self.response.out.write(template.render("templates/error.html", locals()))
def post(self): user = users.get_current_user() try: start_time = datetime.strptime( "%s %s:%s %s" % ( self.request.get("start_date"), self.request.get("start_time_hour"), self.request.get("start_time_minute"), self.request.get("start_time_ampm"), ), "%m/%d/%Y %I:%M %p", ) end_time = datetime.strptime( "%s %s:%s %s" % ( self.request.get("end_date"), self.request.get("end_time_hour"), self.request.get("end_time_minute"), self.request.get("end_time_ampm"), ), "%m/%d/%Y %I:%M %p", ) conflicts = Event.check_conflict(start_time, end_time, self.request.get_all("rooms")) if conflicts: if "Deck" in self.request.get_all("rooms") or "Savanna" in self.request.get_all("rooms"): raise ValueError( "Room conflict detected <small>(Note: Deck & Savanna share the same area, two events cannot take place at the same time in these rooms.)</small>" ) else: raise ValueError("Room conflict detected") if not self.request.get("estimated_size").isdigit(): raise ValueError("Estimated number of people must be a number") if not int(self.request.get("estimated_size")) > 0: raise ValueError("Estimated number of people must be greater then zero") if (end_time - start_time).days < 0: raise ValueError("End time must be after start time") if self.request.get("contact_phone") and not is_phone_valid(self.request.get("contact_phone")): raise ValueError("Phone number does not appear to be valid") else: event = Event( name=cgi.escape(self.request.get("name")), start_time=start_time, end_time=end_time, type=cgi.escape(self.request.get("type")), estimated_size=cgi.escape(self.request.get("estimated_size")), contact_name=cgi.escape(self.request.get("contact_name")), contact_phone=cgi.escape(self.request.get("contact_phone")), details=cgi.escape(self.request.get("details")), url=cgi.escape(self.request.get("url")), fee=cgi.escape(self.request.get("fee")), notes=cgi.escape(self.request.get("notes")), rooms=self.request.get_all("rooms"), expired=local_today() + timedelta(days=PENDING_LIFETIME), # Set expected expiration date ) event.put() log = HDLog(event=event, description="Created new event") log.put() notify_owner_confirmation(event) notify_new_event(event) set_cookie(self.response.headers, "formvalues", None) # self.redirect('/event/%s-%s' % (event.key().id(), slugify(event.name))) self.redirect("/confirm/%s-%s" % (event.key().id(), slugify(event.name))) except Exception, e: message = str(e) if "match format" in message: message = "Date is required." if message.startswith("Property"): message = message[9:].replace("_", " ").capitalize() # This is NOT a reliable way to handle erorrs # set_cookie(self.response.headers, 'formerror', message) # set_cookie(self.response.headers, 'formvalues', dict(self.request.POST)) # self.redirect('/new') error = message self.response.out.write(template.render("templates/error.html", locals()))
def post(self, id): event = Event.get_by_id(int(id)) user = users.get_current_user() access_rights = UserRights(user, event) if access_rights.can_edit: try: start_time = datetime.strptime( "%s %s:%s %s" % ( self.request.get("start_date"), self.request.get("start_time_hour"), self.request.get("start_time_minute"), self.request.get("start_time_ampm"), ), "%m/%d/%Y %I:%M %p", ) end_time = datetime.strptime( "%s %s:%s %s" % ( self.request.get("end_date"), self.request.get("end_time_hour"), self.request.get("end_time_minute"), self.request.get("end_time_ampm"), ), "%m/%d/%Y %I:%M %p", ) conflicts = Event.check_conflict(start_time, end_time, self.request.get_all("rooms"), int(id)) if conflicts: if "Deck" in self.request.get_all("rooms") or "Savanna" in self.request.get_all("rooms"): raise ValueError( "Room conflict detected <small>(Note: Deck & Savanna share the same area, two events cannot take place at the same time in these rooms.)</small>" ) else: raise ValueError("Room conflict detected") if not self.request.get("estimated_size").isdigit(): raise ValueError("Estimated number of people must be a number") if not int(self.request.get("estimated_size")) > 0: raise ValueError("Estimated number of people must be greater then zero") if self.request.get("contact_phone") and not is_phone_valid(self.request.get("contact_phone")): raise ValueError("Phone number does not appear to be valid") else: log_desc = "Event edited<br />" previous_object = Event.get_by_id(int(id)) event.name = self.request.get("name") if previous_object.name != event.name: log_desc = ( log_desc + "<strong>Title:</strong> " + previous_object.name + " to " + event.name + "<br />" ) event.start_time = start_time if previous_object.start_time != event.start_time: log_desc = ( log_desc + "<strong>Start time:</strong> " + str(previous_object.start_time) + " to " + str(event.start_time) + "<br />" ) event.end_time = end_time if previous_object.end_time != event.end_time: log_desc = ( log_desc + "<strong>End time:</strong> " + str(previous_object.end_time) + " to " + str(event.end_time) + "<br />" ) event.estimated_size = cgi.escape(self.request.get("estimated_size")) if previous_object.estimated_size != event.estimated_size: log_desc = ( log_desc + "<strong>Est. size:</strong> " + previous_object.estimated_size + " to " + event.estimated_size + "<br />" ) event.contact_name = cgi.escape(self.request.get("contact_name")) if previous_object.contact_name != event.contact_name: log_desc = ( log_desc + "<strong>Contact:</strong> " + previous_object.contact_name + " to " + event.contact_name + "<br />" ) event.contact_phone = cgi.escape(self.request.get("contact_phone")) if previous_object.contact_phone != event.contact_phone: log_desc = ( log_desc + "<strong>Contact phone:</strong> " + previous_object.contact_phone + " to " + event.contact_phone + "<br />" ) event.details = cgi.escape(self.request.get("details")) if previous_object.details != event.details: log_desc = ( log_desc + "<strong>Details:</strong> " + previous_object.details + " to " + event.details + "<br />" ) event.url = cgi.escape(self.request.get("url")) if previous_object.url != event.url: log_desc = ( log_desc + "<strong>Url:</strong> " + previous_object.url + " to " + event.url + "<br />" ) event.fee = cgi.escape(self.request.get("fee")) if previous_object.fee != event.fee: log_desc = ( log_desc + "<strong>Fee:</strong> " + previous_object.fee + " to " + event.fee + "<br />" ) event.notes = cgi.escape(self.request.get("notes")) if previous_object.notes != event.notes: log_desc = ( log_desc + "<strong>Notes:</strong> " + previous_object.notes + " to " + event.notes + "<br />" ) event.rooms = self.request.get_all("rooms") if previous_object.rooms != event.rooms: log_desc = log_desc + "<strong>Rooms changed</strong><br />" log_desc = log_desc + "<strong>Old room:</strong> " + previous_object.roomlist() + "<br />" log_desc = log_desc + "<strong>New room:</strong> " + event.roomlist() + "<br />" event.put() log = HDLog(event=event, description=log_desc) log.put() self.redirect(event_path(event)) except ValueError, e: error = str(e) self.response.out.write(template.render("templates/error.html", locals()))
def post(self): user = users.get_current_user() try: start_time = datetime.strptime('%s %s:%s %s' % ( self.request.get('start_date'), self.request.get('start_time_hour'), self.request.get('start_time_minute'), self.request.get('start_time_ampm')), '%m/%d/%Y %I:%M %p') end_time = datetime.strptime('%s %s:%s %s' % ( self.request.get('end_date'), self.request.get('end_time_hour'), self.request.get('end_time_minute'), self.request.get('end_time_ampm')), '%m/%d/%Y %I:%M %p') conflicts = Event.check_conflict(start_time,end_time,self.request.get_all('rooms')) if conflicts: if "Deck" in self.request.get_all('rooms') or "Savanna" in self.request.get_all('rooms'): raise ValueError('Room conflict detected <small>(Note: Deck & Savanna share the same area, two events cannot take place at the same time in these rooms.)</small>') else: raise ValueError('Room conflict detected') if not self.request.get('estimated_size').isdigit(): raise ValueError('Estimated number of people must be a number') if not int(self.request.get('estimated_size')) > 0: raise ValueError('Estimated number of people must be greater then zero') if (end_time-start_time).days < 0: raise ValueError('End time must be after start time') if ( self.request.get( 'contact_phone' ) and not is_phone_valid( self.request.get( 'contact_phone' ) ) ): raise ValueError( 'Phone number does not appear to be valid' ) else: event = Event( name = cgi.escape(self.request.get('name')), start_time = start_time, end_time = end_time, type = cgi.escape(self.request.get('type')), estimated_size = cgi.escape(self.request.get('estimated_size')), contact_name = cgi.escape(self.request.get('contact_name')), contact_phone = cgi.escape(self.request.get('contact_phone')), details = cgi.escape(self.request.get('details')), url = cgi.escape(self.request.get('url')), fee = cgi.escape(self.request.get('fee')), notes = cgi.escape(self.request.get('notes')), rooms = self.request.get_all('rooms'), expired = local_today() + timedelta(days=PENDING_LIFETIME), # Set expected expiration date ) event.put() log = HDLog(event=event,description="Created new event") log.put() notify_owner_confirmation(event) notify_new_event(event) set_cookie(self.response.headers, 'formvalues', None) #self.redirect('/event/%s-%s' % (event.key().id(), slugify(event.name))) self.redirect('/confirm/%s-%s' % (event.key().id(), slugify(event.name))) except Exception, e: message = str(e) if 'match format' in message: message = 'Date is required.' if message.startswith('Property'): message = message[9:].replace('_', ' ').capitalize() # This is NOT a reliable way to handle erorrs #set_cookie(self.response.headers, 'formerror', message) #set_cookie(self.response.headers, 'formvalues', dict(self.request.POST)) #self.redirect('/new') error = message self.response.out.write(template.render('templates/error.html', locals()))
def post(self, id): event = Event.get_by_id(int(id)) user = users.get_current_user() access_rights = UserRights(user, event) if access_rights.can_edit: try: start_time = datetime.strptime('%s %s:%s %s' % ( self.request.get('start_date'), self.request.get('start_time_hour'), self.request.get('start_time_minute'), self.request.get('start_time_ampm')), '%m/%d/%Y %I:%M %p') end_time = datetime.strptime('%s %s:%s %s' % ( self.request.get('end_date'), self.request.get('end_time_hour'), self.request.get('end_time_minute'), self.request.get('end_time_ampm')), '%m/%d/%Y %I:%M %p') conflicts = Event.check_conflict( start_time,end_time, self.request.get('setup'), self.request.get('teardown'), self.request.get_all('rooms'), int(id) ) if conflicts: raise ValueError('Room conflict detected') if not self.request.get('details'): raise ValueError('You must provide a description of the event') if not self.request.get('estimated_size').isdigit(): raise ValueError('Estimated number of people must be a number') if not int(self.request.get('estimated_size')) > 0: raise ValueError('Estimated number of people must be greater then zero') if ( self.request.get( 'contact_phone' ) and not is_phone_valid( self.request.get( 'contact_phone' ) ) ): raise ValueError( 'Phone number does not appear to be valid' ) if start_time == end_time: raise ValueError('End time for the event cannot be the same as the start time') else: log_desc = "" previous_object = Event.get_by_id(int(id)) event.status = 'pending' event.name = self.request.get('name') if (previous_object.name != event.name): log_desc += "<strong>Title:</strong> " + previous_object.name + " to " + event.name + "<br />" event.start_time = start_time if (previous_object.start_time != event.start_time): log_desc += "<strong>Start time:</strong> " + str(previous_object.start_time) + " to " + str(event.start_time) + "<br />" event.end_time = end_time if (previous_object.end_time != event.end_time): log_desc += "<strong>End time:</strong> " + str(previous_object.end_time) + " to " + str(event.end_time) + "<br />" event.estimated_size = cgi.escape(self.request.get('estimated_size')) if (previous_object.estimated_size != event.estimated_size): log_desc += "<strong>Est. size:</strong> " + previous_object.estimated_size + " to " + event.estimated_size + "<br />" event.contact_name = cgi.escape(self.request.get('contact_name')) if (previous_object.contact_name != event.contact_name): log_desc += "<strong>Contact:</strong> " + previous_object.contact_name + " to " + event.contact_name + "<br />" event.contact_phone = cgi.escape(self.request.get('contact_phone')) if (previous_object.contact_phone != event.contact_phone): log_desc += "<strong>Contact phone:</strong> " + previous_object.contact_phone + " to " + event.contact_phone + "<br />" event.details = cgi.escape(self.request.get('details')) if (previous_object.details != event.details): log_desc += "<strong>Details:</strong> " + previous_object.details + " to " + event.details + "<br />" event.url = cgi.escape(self.request.get('url')) if (previous_object.url != event.url): log_desc += "<strong>Url:</strong> " + previous_object.url + " to " + event.url + "<br />" event.fee = cgi.escape(self.request.get('fee')) if (previous_object.fee != event.fee): log_desc += "<strong>Fee:</strong> " + previous_object.fee + " to " + event.fee + "<br />" event.notes = cgi.escape(self.request.get('notes')) if (previous_object.notes != event.notes): log_desc += "<strong>Notes:</strong> " + previous_object.notes + " to " + event.notes + "<br />" event.rooms = self.request.get_all('rooms') if (previous_object.rooms != event.rooms): log_desc += "<strong>Rooms changed</strong><br />" log_desc += "<strong>Old room:</strong> " + previous_object.roomlist() + "<br />" log_desc += "<strong>New room:</strong> " + event.roomlist() + "<br />" setup = cgi.escape(self.request.get('setup')) or 0 event.setup = int(setup) if (previous_object.setup != event.setup): log_desc += "<strong>Setup time changed</strong><br />" log_desc += "<strong>Old time:</strong> %s minutes<br/>" % previous_object.setup log_desc += "<strong>New time:</strong> %s minutes<br/>" % event.setup teardown = cgi.escape(self.request.get('teardown')) or 0 event.teardown = int(teardown) if (previous_object.teardown != event.teardown): log_desc += "<strong>Teardown time changed</strong><br />" log_desc += "<strong>Old time:</strong> %s minutes<br/>" % previous_object.teardown log_desc += "<strong>New time:</strong> %s minutes<br/>" % event.teardown log = HDLog(event=event,description="Event edited<br />"+log_desc) log.put() show_all_nav = user access_rights = UserRights(user, event) if access_rights.can_edit: logout_url = users.create_logout_url('/') rooms = ROOM_OPTIONS hours = [1,2,3,4,5,6,7,8,9,10,11,12] if log_desc: edited = "<u>Saved changes:</u><br>"+log_desc notify_event_change(event=event,modification=1) event.put() self.response.out.write(template.render('templates/edit.html', locals())) else: self.response.out.write("Access denied") except NameError, e: logging.log(e) self.response.out.write(template.render('templates/error.html', locals()))
def post(self, id): event = Event.get_by_id(int(id)) user = users.get_current_user() access_rights = UserRights(user, event) if access_rights.can_edit: try: start_time = datetime.strptime('%s %s:%s %s' % ( self.request.get('date'), self.request.get('start_time_hour'), self.request.get('start_time_minute'), self.request.get('start_time_ampm')), '%m/%d/%Y %I:%M %p') end_time = datetime.strptime('%s %s:%s %s' % ( self.request.get('date'), self.request.get('end_time_hour'), self.request.get('end_time_minute'), self.request.get('end_time_ampm')), '%m/%d/%Y %I:%M %p') conflicts = Event.check_conflict(start_time,end_time,self.request.get_all('rooms'), int(id)) if conflicts: raise ValueError('Room conflict detected') if not self.request.get('estimated_size').isdigit(): raise ValueError('Estimated number of people must be a number') if not int(self.request.get('estimated_size')) > 0: raise ValueError('Estimated number of people must be greater then zero') if ( self.request.get( 'contact_phone' ) and not is_phone_valid( self.request.get( 'contact_phone' ) ) ): raise ValueError( 'Phone number does not appear to be valid' ) else: log_desc = "Event edited<br />" previous_object = Event.get_by_id(int(id)) event.name = self.request.get('name') if (previous_object.name != event.name): log_desc = log_desc + "<strong>Title:</strong> " + previous_object.name + " to " + event.name + "<br />" event.start_time = start_time if (previous_object.start_time != event.start_time): log_desc = log_desc + "<strong>Start time:</strong> " + str(previous_object.start_time) + " to " + str(event.start_time) + "<br />" event.end_time = end_time if (previous_object.end_time != event.end_time): log_desc = log_desc + "<strong>End time:</strong> " + str(previous_object.end_time) + " to " + str(event.end_time) + "<br />" event.estimated_size = cgi.escape(self.request.get('estimated_size')) if (previous_object.estimated_size != event.estimated_size): log_desc = log_desc + "<strong>Est. size:</strong> " + previous_object.estimated_size + " to " + event.estimated_size + "<br />" event.contact_name = cgi.escape(self.request.get('contact_name')) if (previous_object.contact_name != event.contact_name): log_desc = log_desc + "<strong>Contact:</strong> " + previous_object.contact_name + " to " + event.contact_name + "<br />" event.contact_phone = cgi.escape(self.request.get('contact_phone')) if (previous_object.contact_phone != event.contact_phone): log_desc = log_desc + "<strong>Contact phone:</strong> " + previous_object.contact_phone + " to " + event.contact_phone + "<br />" event.details = cgi.escape(self.request.get('details')) if (previous_object.details != event.details): log_desc = log_desc + "<strong>Details:</strong> " + previous_object.details + " to " + event.details + "<br />" event.url = cgi.escape(self.request.get('url')) if (previous_object.url != event.url): log_desc = log_desc + "<strong>Url:</strong> " + previous_object.url + " to " + event.url + "<br />" event.fee = cgi.escape(self.request.get('fee')) if (previous_object.fee != event.fee): log_desc = log_desc + "<strong>Fee:</strong> " + previous_object.fee + " to " + event.fee + "<br />" event.notes = cgi.escape(self.request.get('notes')) if (previous_object.notes != event.notes): log_desc = log_desc + "<strong>Notes:</strong> " + previous_object.notes + " to " + event.notes + "<br />" event.rooms = self.request.get_all('rooms') if (previous_object.rooms != event.rooms): log_desc = log_desc + "<strong>Rooms changed</strong><br />" log_desc = log_desc + "<strong>Old room:</strong> " + previous_object.roomlist() + "<br />" log_desc = log_desc + "<strong>New room:</strong> " + event.roomlist() + "<br />" event.put() log = HDLog(event=event,description=log_desc) log.put() self.redirect(event_path(event)) except ValueError, e: error = str(e) self.response.out.write(template.render('templates/error.html', locals()))
def post(self): user = users.get_current_user() try: start_time = datetime.strptime('%s %s:%s %s' % ( self.request.get('start_date'), self.request.get('start_time_hour'), self.request.get('start_time_minute'), self.request.get('start_time_ampm')), '%m/%d/%Y %I:%M %p') end_time = datetime.strptime('%s %s:%s %s' % ( self.request.get('end_date'), self.request.get('end_time_hour'), self.request.get('end_time_minute'), self.request.get('end_time_ampm')), '%m/%d/%Y %I:%M %p') conflicts = Event.check_conflict(start_time,end_time,self.request.get_all('rooms')) if conflicts: if "Deck" in self.request.get_all('rooms') or "Savanna" in self.request.get_all('rooms'): raise ValueError('Room conflict detected <small>(Note: Deck & Savanna share the same area, two events cannot take place at the same time in these rooms.)</small>') else: raise ValueError('Room conflict detected') if not self.request.get('estimated_size').isdigit(): raise ValueError('Estimated number of people must be a number') if not int(self.request.get('estimated_size')) > 0: raise ValueError('Estimated number of people must be greater then zero') if int(self.request.get('estimated_size')) > 47: raise ValueError('Hacker Dojo temporarily is under order of the City of Mountain View to not allow assemblies larger than 49 persons. Sorry, your event exceeds this size. <p>NOTE: Lying about the event size to get around this restriction will result in membership ban plus possible legal action. We will be fined $1500 for each violation, which will be passed on to the event host.') if (end_time-start_time).days < 0: raise ValueError('End time must be after start time') if ( self.request.get( 'contact_phone' ) and not is_phone_valid( self.request.get( 'contact_phone' ) ) ): raise ValueError( 'Phone number does not appear to be valid' ) else: event = Event( name = cgi.escape(self.request.get('name')), start_time = start_time, end_time = end_time, type = cgi.escape(self.request.get('type')), estimated_size = cgi.escape(self.request.get('estimated_size')), contact_name = cgi.escape(self.request.get('contact_name')), contact_phone = cgi.escape(self.request.get('contact_phone')), details = cgi.escape(self.request.get('details')), url = cgi.escape(self.request.get('url')), fee = cgi.escape(self.request.get('fee')), notes = cgi.escape(self.request.get('notes')), rooms = self.request.get_all('rooms'), expired = local_today() + timedelta(days=PENDING_LIFETIME), # Set expected expiration date ) event.put() log = HDLog(event=event,description="Created new event") log.put() notify_owner_confirmation(event) notify_new_event(event) set_cookie(self.response.headers, 'formvalues', None) #self.redirect('/event/%s-%s' % (event.key().id(), slugify(event.name))) self.redirect('/confirm/%s-%s' % (event.key().id(), slugify(event.name))) except Exception, e: message = str(e) if 'match format' in message: message = 'Date is required.' if message.startswith('Property'): message = message[9:].replace('_', ' ').capitalize() # This is NOT a reliable way to handle erorrs #set_cookie(self.response.headers, 'formerror', message) #set_cookie(self.response.headers, 'formvalues', dict(self.request.POST)) #self.redirect('/new') error = message self.response.out.write(template.render('templates/error.html', locals()))