def submit(): # Gets the information on the venue. c = db.venue(request.args[0]) or redirect(URL('default', 'index')) # Gets information on the user. props = db(db.user_properties.email == auth.user.email).select().first() if props == None: venue_ids = [] venues_has_submitted = [] else: venue_ids = util.get_list(props.venues_can_submit) venues_has_submitted = util.get_list(props.venues_has_submitted) # Is the venue open for submission? if not (c.submit_constraint == None or c.id in venue_ids): session.flash = T('You cannot submit to this venue.') redirect(URL('venues', 'view_venue', args=[c.id])) t = datetime.utcnow() if not (c.is_active and c.is_approved and c.open_date <= t and c.close_date >= t): session.flash = T('The submission deadline has passed; submissions are closed.') redirect(URL('venues', 'view_venue', args=[c.id])) # Ok, the user can submit. Looks for previous submissions. sub = db((db.submission.author == auth.user_id) & (db.submission.venue_id == c.id)).select().first() if sub != None and not c.allow_multiple_submissions: session.flash = T('You have already submitted to this venue.') redirect(URL('my_submissions_index', args=[c.id])) # The author can access the title. db.submission.title.readable = db.submission.title.writable = True # Check whether link submission is allowed. db.submission.link.readable = db.submission.link.writable = c.allow_link_submission db.submission.n_completed_reviews.readable = False db.submission.n_rejected_reviews.readable = False db.submission.feedback.readable = db.submission.feedback.writable = False # Produces an identifier for the submission. db.submission.identifier.default = util.get_random_id() db.submission.email.default = auth.user.email # Assigns default quality to the submission. avg, stdev = ranker.get_init_average_stdev() db.submission.quality.default = avg db.submission.error.default = stdev # No percentile readable. db.submission.percentile.readable = False # TODO(luca): check that it is fine to do the download link without parameters. form = SQLFORM(db.submission, upload=URL('download_auhor', args=[None])) form.vars.venue_id = c.id if request.vars.content != None and request.vars.content != '': form.vars.original_filename = request.vars.content.filename if form.process().accepted: # Adds the venue to the list of venues where the user submitted. # TODO(luca): Enable users to delete submissions. But this is complicated; we need to # delete also their quality information etc. For the moment, no deletion. submitted_ids = util.id_list(venues_has_submitted) submitted_ids = util.list_append_unique(submitted_ids, c.id) if props == None: db.user_properties.insert(email = auth.user.email, venues_has_submitted = submitted_ids) else: props.update_record(venues_has_submitted = submitted_ids) db.commit() session.flash = T('Your submission has been accepted.') redirect(URL('feedback', 'index', args=['all'])) return dict(form=form, venue=c)
def get_new_name(n): if n == '*****@*****.**' or n == '*****@*****.**': return n if n in name_dict: return name_dict[n] else: while True: m = util.get_random_id(n_sections=1) + '@example.com' if m not in name_dict: break name_dict[n] = m return m
def manager_submit(): """This function is used by venue managers to do submissions on behalf of others. It can be used even when the submission deadline is past.""" # Gets the information on the venue. c = db.venue(request.args[0]) or redirect(URL('default', 'index')) # Checks that the user is a manager for the venue. manager_props = db(db.user_properties.email == auth.user.email).select().first() can_manage = c.id in util.get_list(manager_props.venues_can_manage) if not can_manage: session.flash = T('Not authorized!') redirect(URL('default', 'index')) # Prepares the submission. db.submission.email.writable = db.submission.email.readable = True db.submission.author.readable = db.submission.author.writable = False db.submission.feedback.readable = db.submission.feedback.writable = False db.submission.email.label = T('Author') # Assigns default quality to the submission. avg, stdev = ranker.get_init_average_stdev() db.submission.quality.default = avg db.submission.error.default = stdev # Produces an identifier for the submission. db.submission.identifier.default = util.get_random_id() form = SQLFORM(db.submission, upload=URL('download_manager', args=[None])) form.vars.venue_id = c.id if request.vars.content != None and request.vars.content != '': form.vars.original_filename = request.vars.content.filename if form.process(onvalidation=manager_submit_validation).accepted: # Fixes the author field of the submission. db(db.submission.id == form.vars.id).update(author=form.vars.author) # Adds the venue to the list of venues where the user submitted. # TODO(luca): Enable users to delete submissions. But this is complicated; we need to # delete also their quality information etc. For the moment, no deletion. props = db(db.user_properties.email == form.vars.email).select().first() if props == None: venues_has_submitted = [] else: venues_has_submitted = util.get_list(props.venues_has_submitted) submitted_ids = util.id_list(venues_has_submitted) submitted_ids = util.list_append_unique(submitted_ids, c.id) if props == None: db(db.user_properties.email == form.vars.email).update(venues_has_submitted = submitted_ids) else: props.update_record(venues_has_submitted = submitted_ids) db.commit() session.flash = T('The submission has been accepted.') redirect(URL('ranking', 'view_venue', args=[c.id])) return dict(form=form, venue=c)
def manager_submit(): """This function is used by venue managers to do submissions on behalf of others. It can be used even when the submission deadline is past.""" # Gets the information on the venue. c = db.venue(request.args(0)) or redirect(URL('default', 'index')) # Checks that the user is a manager for the venue. manager_props = db( db.user_properties.user == auth.user.email).select().first() can_manage = c.id in util.get_list(manager_props.venues_can_manage) if not can_manage: session.flash = T('Not authorized!') redirect(URL('default', 'index')) # Prepares the submission. db.submission.user.readable = db.submission.user.writable = True db.submission.user.default = '' db.submission.feedback.readable = db.submission.feedback.writable = False # Assigns default quality to the submission. avg, stdev = ranker.get_init_average_stdev() db.submission.quality.default = avg db.submission.error.default = stdev # Produces an identifier for the submission. db.submission.identifier.default = util.get_random_id() # Prepares the submission form. form = SQLFORM(db.submission, upload=URL('download_manager', args=[None])) form.vars.venue_id = c.id if request.vars.content != None and request.vars.content != '': form.vars.original_filename = request.vars.content.filename if form.process().accepted: # Adds the venue to the list of venues where the user submitted. props = db(db.user_properties.user == form.vars.email).select().first() if props == None: venues_has_submitted = [] else: venues_has_submitted = util.get_list(props.venues_has_submitted) submitted_ids = util.id_list(venues_has_submitted) submitted_ids = util.list_append_unique(submitted_ids, c.id) if props == None: db(db.user_properties.user == form.vars.user).update( venues_has_submitted=submitted_ids) else: props.update_record(venues_has_submitted=submitted_ids) # If there is a prior submission of the same author to this venue, replaces the content. is_there_another = False other_subms = db(db.submission.user == form.vars.user).select() for other_subm in other_subms: if other_subm.id != form.vars.id: is_there_another = True other_subm.update_record( date_updated=datetime.utcnow(), title=form.vars.title, original_filename=form.vars.original_filename, content=new_content, link=form.vars.link, comment=form.vars.comment, ) # And deletes this submission. if is_there_another: db(db.submission.id == form.vars.id).delete() session.flash = T( 'The previous submission by the same author has been updated.') else: session.flash = T('The submission has been added.') db.commit() redirect(URL('ranking', 'view_venue', args=[c.id])) return dict(form=form, venue=c)
def submit(): # Gets the information on the venue. c = db.venue(request.args(0)) or redirect(URL('default', 'index')) # Gets information on the user. props = db(db.user_properties.user == auth.user.email).select().first() if props == None: venue_ids = [] venues_has_submitted = [] else: venue_ids = util.get_list(props.venues_can_submit) venues_has_submitted = util.get_list(props.venues_has_submitted) # Is the venue open for submission? if not (c.submit_constraint == None or c.id in venue_ids): session.flash = T('You cannot submit to this venue.') redirect(URL('venues', 'view_venue', args=[c.id])) t = datetime.utcnow() if not (c.is_active and c.is_approved and c.open_date <= t and c.close_date >= t): session.flash = T( 'The submission deadline has passed; submissions are closed.') redirect(URL('venues', 'view_venue', args=[c.id])) # Ok, the user can submit. Looks for previous submissions. sub = db((db.submission.user == auth.user.email) & (db.submission.venue_id == c.id)).select().first() if sub != None and not c.allow_multiple_submissions: session.flash = T('You have already submitted to this venue.') redirect(URL('venues', 'view_venue', args=[c.id])) # The author can access the title. db.submission.title.readable = db.submission.title.writable = True # Check whether link submission is allowed. db.submission.link.readable = db.submission.link.writable = c.allow_link_submission db.submission.n_completed_reviews.readable = False db.submission.n_rejected_reviews.readable = False db.submission.feedback.readable = db.submission.feedback.writable = False db.submission.date_updated.readable = False # Produces an identifier for the submission. db.submission.identifier.default = util.get_random_id() db.submission.user.default = auth.user.email # Assigns default quality to the submission. avg, stdev = ranker.get_init_average_stdev() db.submission.quality.default = avg db.submission.error.default = stdev # No percentile readable. db.submission.percentile.readable = False # TODO(luca): check that it is fine to do the download link without parameters. form = SQLFORM(db.submission, upload=URL('download_auhor', args=[None])) form.vars.venue_id = c.id if request.vars.content != None and request.vars.content != '': form.vars.original_filename = request.vars.content.filename if form.process().accepted: # Adds the venue to the list of venues where the user submitted. # TODO(luca): Enable users to delete submissions. But this is complicated; we need to # delete also their quality information etc. For the moment, no deletion. submitted_ids = util.id_list(venues_has_submitted) submitted_ids = util.list_append_unique(submitted_ids, c.id) if props == None: db.user_properties.insert(user=auth.user.email, venues_has_submitted=submitted_ids) else: props.update_record(venues_has_submitted=submitted_ids) db.commit() session.flash = T('Your submission has been accepted.') redirect(URL('feedback', 'index', args=['all'])) return dict(form=form, venue=c)
def manager_submit(): """This function is used by venue managers to do submissions on behalf of others. It can be used even when the submission deadline is past.""" # Gets the information on the venue. c = db.venue(request.args(0)) or redirect(URL('default', 'index')) # Checks that the user is a manager for the venue. manager_props = db(db.user_properties.user == auth.user.email).select().first() can_manage = c.id in util.get_list(manager_props.venues_can_manage) if not can_manage: session.flash = T('Not authorized!') redirect(URL('default', 'index')) # Prepares the submission. db.submission.user.readable = db.submission.user.writable = True db.submission.user.default = '' db.submission.feedback.readable = db.submission.feedback.writable = False # Assigns default quality to the submission. avg, stdev = ranker.get_init_average_stdev() db.submission.quality.default = avg db.submission.error.default = stdev # Produces an identifier for the submission. db.submission.identifier.default = util.get_random_id() # Prepares the submission form. form = SQLFORM(db.submission, upload=URL('download_manager', args=[None])) form.vars.venue_id = c.id if request.vars.content != None and request.vars.content != '': form.vars.original_filename = request.vars.content.filename if form.process().accepted: # Adds the venue to the list of venues where the user submitted. props = db(db.user_properties.user == form.vars.email).select().first() if props == None: venues_has_submitted = [] else: venues_has_submitted = util.get_list(props.venues_has_submitted) submitted_ids = util.id_list(venues_has_submitted) submitted_ids = util.list_append_unique(submitted_ids, c.id) if props == None: db(db.user_properties.user == form.vars.user).update(venues_has_submitted = submitted_ids) else: props.update_record(venues_has_submitted = submitted_ids) # If there is a prior submission of the same author to this venue, replaces the content. is_there_another = False other_subms = db(db.submission.user == form.vars.user).select() for other_subm in other_subms: if other_subm.id != form.vars.id: is_there_another = True other_subm.update_record( date_updated = datetime.utcnow(), title = form.vars.title, original_filename = form.vars.original_filename, content = new_content, link = form.vars.link, comment = form.vars.comment, ) # And deletes this submission. if is_there_another: db(db.submission.id == form.vars.id).delete() session.flash = T('The previous submission by the same author has been updated.') else: session.flash = T('The submission has been added.') db.commit() redirect(URL('ranking', 'view_venue', args=[c.id])) return dict(form=form, venue=c)
def anonimize_all_venues(): name_dict = {} def get_new_name(n): if n == '*****@*****.**' or n == '*****@*****.**': return n if n in name_dict: return name_dict[n] else: while True: m = util.get_random_id(n_sections=1) + '@example.com' if m not in name_dict: break name_dict[n] = m return m if not is_user_admin(): session.flash = T('Not authorized') redirect(URL('default', 'index')) form = FORM.confirm(T('This will anonymize all venues; the original data WILL BE LOST.')) if form.accepted: # Builds a dictionary for anonymization. new_names = {} # Convert user lists. rows = db().select(db.user_list.ALL) for ul in rows: ul.update_record(managers = [get_new_name(x) for x in ul.managers], user_list = [get_new_name(x) for x in ul.user_list]) # Convert venues. rows = db().select(db.venue.ALL) for r in rows: r.update_record(created_by = get_new_name(r.created_by), managers = [get_new_name(x) for x in r.managers], observers = [get_new_name(x) for x in r.observers]) # Convert submissions. rows = db().select(db.submission.ALL) for r in rows: r.update_record(user = get_new_name(r.user), title = util.get_random_id(n_sections=1), ) db.commit() # Convert comparisons. rows = db().select(db.comparison.ALL) for r in rows: # Creates a new nickname dictionary. nicks = {} for subm_id in r.ordering: s = db.submission(subm_id) if s is not None: nicks[subm_id] = util.produce_submission_nickname(s) r.update_record(user = get_new_name(r.user), submission_nicknames = simplejson.dumps(nicks)) # Converts tasks. rows = db().select(db.task.ALL) for r in rows: r.update_record(user = get_new_name(r.user)) # Converts final grades. rows = db().select(db.grades.ALL) for r in rows: r.update_record(user = get_new_name(r.user)) db.commit() # Now for the hard part: the system tables. rows = db().select(db.auth_user.ALL) for r in rows: u = get_new_name(r.email) r.update_record(first_name = u, last_name = u, email = u, password = db.auth_user.password.requires[0]('hello')[0]) db.commit() session.flash = T('done') redirect(URL('default', 'index')) return dict(form=form)
def random_id(self): if self.__random_id is None: self.__random_id = get_random_id() return self.__random_id