def main(): try: form = CGIgetForm() user = CGIlogin(form) if user == "admin" or user in GetEditors(): message = "Contact added" if form.has_key("firstname") and form.has_key("lastname"): c = Contact() c.firstname = form["firstname"] c.lastname = form["lastname"] c.user = c.firstname + " " + c.lastname c.name = c.user else: raise CalendarError, "No full name specified" if form.has_key("phone"): c.phone = form["phone"] if form.has_key("email"): if IsEmail(form["email"]): c.email = form["email"] else: message = "Invalid email address" #Set an initial password at random c.password = SetPassword() c.Store() print c.ContactPage(message) else: print LoginPage("Not authorized for this operation", script="AddContact.py", form=form) except CalendarError, errorText: print AdminPage(errorText)
def main(): try: form = CGIgetForm() user = CGIlogin(form) if user: if form.has_key("contact"): username = form["contact"] if username not in GetContacts(): raise CalendarError, "Invalid contact" c = Contact(username) print c.ContactPage() else: raise CalendarError, "No editor specified" else: print LoginPage(script="EditContact.py", form=form) except CalendarError, errorText: print ErrorPage(errorText)
def main(): try: form = CGIgetForm() user = CGIlogin(form) if user == "admin" or user in GetSupervisors(): supervisor = True else: supervisor = False if user is None: print LoginPage(script="ModifyEvent.py", form=form) return if form.has_key("ID"): ID = form["ID"] if not IDexists(ID): raise CalendarError, "No event to edit" if ID.find("tmp") >= 0: e = TemporaryEvent(ID) else: e = TemporaryEvent() e.Copy(Event(ID)) e.oldID = ID e.oldDate = e.start[0:3] else: e = TemporaryEvent() if form.has_key("title"): e.title = form["title"] if form.has_key("type"): e.type = form["type"] else: e.type = "Event" if form.has_key("description"): e.description = ConvertCRLFs(form["description"]) else: e.description = "" if form.has_key("location"): if form["location"] == "Location...": e.location = "" else: e.location = form["location"] try: if type == "Banner" or type == "Holiday": e.start = ReadTime(form["startyear"], form["startmonth"], form["startday"], 12, 0, "AM") e.end = e.start else: e.start = ReadTime(form["startyear"], form["startmonth"], form["startday"], form["starthour"], form["startminute"], form["startampm"].upper()) e.end = ReadTime(form["startyear"], form["startmonth"], form["startday"], form["endhour"], form["endminute"], form["endampm"].upper(), end=True) except KeyError: if not hasattr(e, "oldID"): raise CalendarError, "Invalid date/time entry" if form.has_key("cancel"): if e.start: y, m, d = e.start[0:3] else: y, m, d = Today() print DayView(y, m, d) return if form.has_key("name") and form["name"] <> "Name...": if form["name"] in GetEditors(name=True): c = GetEditor(form["name"]) else: c = Contact(form["name"]) e.organizer = c.name e.phone = c.phone e.email = c.email elif form.has_key("organizer"): e.organizer = form["organizer"] if form.has_key("phone") and form.has_key("email"): e.phone = form["phone"] e.email = form["email"] else: if e.organizer in GetEditors(name=True): c = GetEditor(e.organizer) elif e.organizer in GetContacts(): c = Contact(e.organizer) else: c = None if form.has_key("phone"): e.phone = form["phone"] elif c: e.phone = c.phone if form.has_key("email"): e.email = form["email"] elif c: e.email = c.email else: e.organizer = "" try: e.reservation["option"] = form["reserve"] if e.reservation["option"] == "Same as Event": e.reservation["start"] = e.start e.reservation["end"] = e.end elif e.reservation["option"] == "All Day": e.reservation["start"] = ReadTime(form["startyear"], form["startmonth"], form["startday"], "12", "00", "AM") e.reservation["end"] = ReadTime(form["startyear"], form["startmonth"], form["startday"], "12", "00", "AM", end=True) else: e.reservation["start"] = ReadTime(form["startyear"], form["startmonth"], form["startday"], form["resstarthour"], form["resstartminute"], form["resstartampm"].upper()) e.reservation["end"] = ReadTime(form["startyear"], form["startmonth"], form["startday"], form["resendhour"], form["resendminute"], form["resendampm"].upper(), end=True) if e.reservation["start"] > e.start: e.reservation["start"] = e.start if e.reservation["end"] < e.end: e.reservation["end"] = e.end except KeyError: if not hasattr(e, "oldID"): raise CalendarError, "Invalid reservation time" if form.has_key("locations"): if isinstance(form["locations"], list): e.locations = form["locations"] else: e.locations = [form["locations"]] if "Locations..." in e.locations: e.locations.remove("Locations...") else: e.locations = [] if e.location: try: e.locations.remove(e.location) except ValueError: pass e.locations.insert(0, e.location) if form.has_key("resources"): if isinstance(form["resources"], list): e.resources = form["resources"] else: e.resources = [form["resources"]] if "Resources..." in e.resources: e.resources.remove("Resources...") else: e.resources = [] if form.has_key("categories"): if isinstance(form["categories"], list): e.categories = form["categories"] else: e.categories = [form["categories"]] if "Categories..." in e.categories: e.categories.remove("Categories...") else: e.categories = [] if form.has_key("setup"): e.setup = ConvertCRLFs(form["setup"]) else: e.setup = "" if form.has_key("status"): e.status = form["status"] if form.has_key("editor"): e.editor = form["editor"] if form.has_key("pattern"): e.pattern = form["pattern"] if form["pattern"] <> "Once Only": e.number, e.final = None, None if form.has_key("number"): e.number = int(form["number"]) if form.has_key("endyear"): e.final = ReadDate(form["endyear"], form["endmonth"], form["endday"]) e.repeats = MakeRepeats(e.pattern, e.start, e.final, e.number) else: e.repeats = [] elif form.has_key("repeat"): if form["repeat"] == "single": e.repeats = [] e.pattern = "Once Only" elif form.has_key("repeats"): if isinstance(form["repeats"], list): e.repeats = form["repeats"] else: e.repeats = [form["repeats"]] if form["repeat"] == "future": e.repeats = filter(lambda ID:IDdate(ID)>=Today(), e.repeats) else: e.repeats = [] message = None if e.type <> "Banner" and e.type <> "Holiday" and e.end < e.start: message = "Warning: End of event precedes the start." elif e.type <> "Banner" and e.type <> "Holiday" and e.end == e.start: message = "Warning: Event has no duration." elif e.start < Now(): message = "Warning: This event is in the past." elif not e.title: message = "Warning: No title given for event." if hasattr(e, "oldDate"): if e.oldDate <> e.start[0:3] and e.repeats: message = \ "Warning: Changing the date will break the link with event repeats." e.repeats = [] e.pattern = "Once Only" e.Store() print e.EventView(message=message, updating=True) except CalendarError, errorText: print ErrorPage(errorText)
def main(): try: form = CGIgetForm() user = CGIlogin(form) if user: if form.has_key("cancel"): print ContactsPage() elif form.has_key("delete"): if form.has_key("username"): c = Contact(form["username"]) c.Delete() message = "Contact deleted" else: message = "Contact not specified" print ContactsPage(message) elif form.has_key("firstname") and form.has_key("lastname"): name = "%s %s" % (form["firstname"], form["lastname"]) if name == form["username"]: c = Contact(name) else: c = Contact() c.user = name c.name = name c.firstname = form["firstname"] c.lastname = form["lastname"] oldContact = Contact(form["username"]) c.phone = oldContact.phone c.email = oldContact.email oldContact.Delete() message = "Contact details successfully updated" if form.has_key("email"): if IsEmail(form["email"]): c.email = form["email"] else: message = "Invalid email address" else: c.email = "" if form.has_key("phone"): c.phone = form["phone"] else: c.phone = "" c.Store() print ContactsPage(message) else: print ContactsPage("Name not fully specified") else: print LoginPage(script="ModifyContact.py", form=form) except CalendarError, errorText: print ErrorPage(errorText)