def __init__(self, semid=None, semctr=None, data=None, seminar=None, editing=False, showing=False, saving=False): if data is None and not editing: data = talks_lookup(semid, semctr) if data is None: raise ValueError("Talk %s/%s does not exist" % (semid, semctr)) data = dict(data.__dict__) if seminar is None: seminar = WebSeminar(semid) self.seminar = seminar self.new = (data is None) if self.new: self.seminar_id = semid self.seminar_ctr = None self.token = '%016x' % random.randrange(16**16) self.display = current_user.is_creator() self.online = getattr(seminar, 'online', bool(getattr(seminar, 'live_link'))) self.deleted=False for key, typ in db.talks.col_type.items(): if key == 'id' or hasattr(self, key): continue elif db.seminars.col_type.get(key) == typ and getattr(seminar, key, None) and key != "description": # carry over from seminar setattr(self, key, getattr(seminar, key)) elif typ == 'text': setattr(self, key, '') elif typ == 'text[]': setattr(self, key, []) elif typ == 'timestamp with time zone': setattr(self, key, None) else: raise ValueError("Need to update talk code to account for schema change") else: self.__dict__.update(data)
def index(): # TODO: use a join for the following query seminars = [] for semid in db.seminar_organizers.search({'username': current_user._uid}, 'seminar_id'): seminars.append((semid, db.seminars.lucky({'id': semid}, 'name'))) return render_template("create_index.html", seminars=seminars, user_is_creator=current_user.is_creator())
def create_seminar(): info = to_dict(request.args) if info: # What sanitation needs to be done here? # We override any display input info["display"] = current_user.is_creator() data = {} for col in db.seminars.search_cols: try: data[col] = process_user_input(info.pop(col, None), db.seminars.col_type[col]) except Exception: return render_template( "create_seminar.html", err=col, info=info, user_is_creator=current_user.is_creator()) db.seminars.insert_many([data], resort=False, restat=False) return redirect(url_for(".index"), 301) return render_template("create_seminar.html", info=info, user_is_creator=current_user.is_creator())
def __init__(self, shortname, data=None, organizer_data=None, editing=False, showing=False, saving=False): if data is None and not editing: data = seminars_lookup(shortname) if data is None: raise ValueError("Seminar %s does not exist" % shortname) data = dict(data.__dict__) self.new = (data is None) if self.new: self.shortname = shortname self.display = current_user.is_creator() self.online = True # default self.access = "open" # default self.archived = False # don't start out archived self.is_conference = False # seminar by default self.frequency = 7 self.schedule_len = 15 # currently no way to edit this default on the website for key, typ in db.seminars.col_type.items(): if key == 'id' or hasattr(self, key): continue elif typ == 'text': setattr(self, key, '') elif typ == 'text[]': setattr(self, key, []) else: raise ValueError( "Need to update seminar code to account for schema change" ) if organizer_data is None: organizer_data = [{ 'seminar_id': self.shortname, 'email': current_user.email, 'full_name': current_user.name, 'order': 0, 'curator': True, 'display': False, 'contact': False }] else: self.__dict__.update(data) if organizer_data is None: organizer_data = list( db.seminar_organizers.search({'seminar_id': self.shortname}, sort=['order'])) self.organizer_data = organizer_data
def show_live_link(self): if not self.live_link: return "" success = 'Access <a href="%s">online</a>.' % self.live_link if self.access == "open": return success elif self.access == "users": if current_user.is_authenticated: return success else: return 'To see access link, please <a href="%s">log in</a> (anti-spam measure).' % (url_for('user.info')) elif self.access == "endorsed": if current_user.is_creator(): return success else: # TODO: add link to an explanation of endorsement return 'To see access link, you must be endorsed by another user.' else: # should never happen return ""
def index(): # TODO: use a join for the following query seminars = [] conferences = [] for semid in db.seminar_organizers.search({'email': current_user.email}, 'seminar_id'): seminar = WebSeminar(semid) if seminar.is_conference: conferences.append(seminar) else: seminars.append(seminar) menu = basic_top_menu() menu.pop(-3) return render_template("create_index.html", seminars=seminars, conferences=conferences, top_menu=menu, title="Create", user_is_creator=current_user.is_creator())
def decorated_view(*args, **kwargs): logger.info("creator access attempt by %s" % current_user.get_id()) if not current_user.is_creator(): return flask.abort(403) # access denied return fn(*args, **kwargs)
def save_seminar(): raw_data = request.form shortname = raw_data["shortname"] new = (raw_data.get("new") == "yes") resp, seminar = can_edit_seminar(shortname, new) if resp is not None: return resp def make_error(err): flash_error("Error processing %s: %s" % (col, err)) seminar = WebSeminar(shortname, data=raw_data) return render_template("edit_seminar.html", seminar=seminar, title="Edit seminar error", top_menu=basic_top_menu(), categories=categories(), institutions=institutions(), lock=None) if seminar.new: data = { 'shortname': shortname, 'display': current_user.is_creator(), 'owner': current_user.email, 'archived': False } else: data = { 'shortname': shortname, 'display': seminar.display or current_user.is_creator(), 'owner': seminar.owner } for col in db.seminars.search_cols: if col in data: continue try: val = raw_data.get(col) if not val: data[col] = None else: data[col] = process_user_input(val, db.seminars.col_type[col]) except Exception as err: return make_error(err) if not data['timezone'] and data['institutions']: # Set time zone from institution data['timezone'] = WebInstitution(data['institutions'][0]).timezone organizer_data = [] for i in range(6): D = {'seminar_id': seminar.shortname} for col in db.seminar_organizers.search_cols: if col in D: continue name = "org_%s%s" % (col, i) try: val = raw_data.get(name) if val == '': D[col] = None elif val is None: D[col] = False # checkboxes else: D[col] = process_user_input( val, db.seminar_organizers.col_type[col]) if col == 'homepage' and val and not val.startswith("http"): data[col] = "http://" + data[col] except Exception as err: return make_error(err) if D.get('email') or D.get('full_name'): D['order'] = len(organizer_data) organizer_data.append(D) new_version = WebSeminar(shortname, data=data, organizer_data=organizer_data) if seminar.new or new_version != seminar: new_version.save() if seminar.organizer_data != new_version.organizer_data: new_version.save_organizers() edittype = "created" if new else "edited" flash("Seminar successfully %s!" % edittype) return redirect(url_for("show_seminar", shortname=shortname), 301)