def reviewers_topic_grid(): """Grid containing the reviewers in a topic. The grid is done so that it can be easily included in a more complex page. The arguments are: - topic_id (in path) """ topic = db.topic(request.args(0)) or component_fail(T('No such topic')) q = ((db.role.topic == topic.id) & (db.role.user_email == get_user_email())) grid = SQLFORM.grid( q, args=request.args[:1], # First is topic_id orderby=~db.role.reputation, field_id=db.role.id, fields=[ db.role.reputation, db.auth_user.display_name, db.auth_user.affiliation, db.auth_user.link ], csv=False, details=True, create=False, editable=False, deletable=False, maxtextlength=48, ) return grid
def reviewers_topic_grid(): """Grid containing the reviewers in a topic. The grid is done so that it can be easily included in a more complex page. The arguments are: - topic_id (in path) """ topic = db.topic(request.args(0)) or component_fail(T('No such topic')) q = ((db.role.topic == topic.id) & (db.role.user_email == get_user_email())) grid = SQLFORM.grid(q, args = request.args[:1], # First is topic_id orderby=~db.role.reputation, field_id=db.role.id, fields=[db.role.reputation, db.auth_user.display_name, db.auth_user.affiliation, db.auth_user.link], csv=False, details=True, create=False, editable=False, deletable=False, maxtextlength=48, ) return grid
def do_review(): """Shows to a user their review of a paper, allowing them to edit it or to enter it for the first time. The arguments are: - paper_id : the paper. - topic.id : the id of the topic, or the string "primary". - v / e: view, or edit. If there is a current review, then lets the user edit that instead, keeping track of the old review. """ (paper_id, topic_id) = get_paper_and_topic_ids() is_view = request.args(2) == 'v' paper = db((db.paper.paper_id == request.args(0)) & (db.paper.end_date == None)).select().first() topic = db.topic(topic_id) #logger.info("do_review paper.id %r topic.id %r is_view %r" % (paper,topic,is_view)) if paper is None or topic is None: component_fail(T('No such paper or topic.')) # Checks whether the paper is currently in the topic. paper_in_topic = db((db.paper_in_topic.paper_id == paper.paper_id) & (db.paper_in_topic.topic == topic.id) & (db.paper_in_topic.end_date == None)).select().first() if paper_in_topic is None: component_fail(T('The paper is not in the selected topic')) # Verify permissions. if not is_view and not can_review(topic.id): component_fail(T('You do not have the permission to perform reviews in this topic')) # Fishes out the current review, if any. current_review = db((db.review.user_email == get_user_email()) & (db.review.paper_id == paper.paper_id) & (db.review.topic == topic.id) & (db.review.end_date == None)).select().first() # Sets some defaults. logger.info("My user email: %r" % get_user_email()) db.review.paper.writable = False db.review.paper_id.readable = False db.review.user_email.default = get_user_email() db.review.paper_id.default = paper.paper_id db.review.paper.default = paper.id db.review.topic.default = topic.id db.review.start_date.label = T('Review date') db.review.end_date.readable = False db.review.useful_count.readable = is_view db.review.old_score.default = paper_in_topic.score # Creates the form for editing. form = SQLFORM(db.review, record=current_review, readonly=is_view) form.vars.user_email = get_user_email() form.vars.review_content = None if current_review is None else text_store_read(current_review.review_content) if form.validate(): # We must write the review as a new review. # First, we close the old review if any. now = datetime.utcnow() if current_review is not None: current_review.update_record(end_date=now) # Builds the correct review id. review_id = current_review.review_id if current_review is not None else None if review_id is None: review_id = review_utils.get_random_id() # Then, writes the current review. db.review.insert(user_email=get_user_email(), paper_id=paper.paper_id, review_id=review_id, paper=paper.id, topic=topic.id, start_date=now, end_date=None, review_content=str(text_store_write(form.vars.content)), old_score=paper_in_topic.score, grade=form.vars.grade, ) add_reviewer_to_topic(get_user_email(), topic.id) session.flash = T('Your review has been accepted.') redirect(URL('components', 'do_review', args=[paper.paper_id, topic_id, 'v'])) button_list = [] button_list.append(A(icon_reviews, T('All reviews'), cid=request.cid, _class='btn btn-success', _href=URL('components', 'paper_reviews', args=[paper.paper_id, topic_id]))) if is_view and can_review(topic.id): button_list.append(A(icon_edit, T('Edit review'), cid=request.cid, _class='btn btn-warning', _href=URL('components', 'do_review', args=[paper.paper_id, topic_id, 'e']))) # else: # button_list.append(A(icon_your_review, T('Your review'), cid=request.cid, # _class='btn btn-success', # _href=URL('components', 'do_review', args=[paper.paper_id, topic_id, 'v']))) return dict(button_list=button_list, form=form)
def paper_topic_grid(topic_id, all_papers=False): """Produces a grid containing the papers in a topic. The grid is done so that it can be easily included in a more complex page. The arguments are: - topic_id (in path) - all_papers=y (in query): if yes, then also papers that are not primary in the topic will be included. """ topic = db.topic(topic_id) if topic is None: component_fail(T('No such topic.')) fields = [db.paper_in_topic.paper_id, db.paper.id, db.paper.paper_id, db.paper.title, db.paper.authors, db.paper_in_topic.is_primary] orderby = db.paper.start_date links = [] if all_papers: q = ((db.paper_in_topic.topic == topic.id) & (db.paper_in_topic.paper_id == db.paper.paper_id) & (db.paper_in_topic.end_date == None) & (db.paper.end_date == None) & (db.topic.id == db.paper.primary_topic) ) fields.extend([db.paper.primary_topic, db.topic.name]) # db.paper.primary_topic.represent = lambda v, r: '' if v == topic_id else v db.paper.primary_topic.label = T('Primary topic') db.topic.name.readable = False db.paper.primary_topic.represent = lambda v, r: A(r.topic.name, _href=URL('default', 'topic_index', args=[v])) links.append(dict(header='', body=lambda r: (icon_primary_paper if r.paper_in_topic.is_primary else icon_all_paper))) else: q = ((db.paper.primary_topic == topic_id) & (db.paper.end_date == None) & (db.paper.paper_id == db.paper_in_topic.paper_id) & (db.paper_in_topic.topic == topic_id) & (db.paper_in_topic.end_date == None) ) fields.extend([db.paper_in_topic.num_reviews, db.paper_in_topic.score]) orderby = ~db.paper_in_topic.score links.append(dict(header='', body=lambda r: icon_primary_paper)) db.paper.title.represent = lambda v, r: A(v, _href=URL('default', 'view_paper', args=[r.paper_in_topic.paper_id, topic.id])) # links.append(dict(header='', # body=lambda r: A('Versions', _href=URL('default', 'view_paper_versions', # args=[r.paper_in_topic.paper_id])))) # links.append(dict(header='', # body=lambda r: A('Edit', _href=URL('default', 'edit_paper', # args=[r.paper_in_topic.paper_id], vars=dict(topic=topic.id))))) grid = SQLFORM.grid(q, args=request.args[:1], # The first parameter is the topic id. orderby=orderby, fields=fields, field_id=db.paper.id, csv=False, details=False, links=links, links_placement='left', # These all have to be done with special methods. create=False, editable=False, deletable=False, maxtextlength=48, ) return grid
def do_review(): """Shows to a user their review of a paper, allowing them to edit it or to enter it for the first time. The arguments are: - paper_id : the paper. - topic.id : the id of the topic, or the string "primary". - v / e: view, or edit. If there is a current review, then lets the user edit that instead, keeping track of the old review. """ (paper_id, topic_id) = get_paper_and_topic_ids() is_view = request.args(2) == 'v' paper = db((db.paper.paper_id == request.args(0)) & (db.paper.end_date == None)).select().first() topic = db.topic(topic_id) #logger.info("do_review paper.id %r topic.id %r is_view %r" % (paper,topic,is_view)) if paper is None or topic is None: component_fail(T('No such paper or topic.')) # Checks whether the paper is currently in the topic. paper_in_topic = db((db.paper_in_topic.paper_id == paper.paper_id) & (db.paper_in_topic.topic == topic.id) & (db.paper_in_topic.end_date == None)).select().first() if paper_in_topic is None: component_fail(T('The paper is not in the selected topic')) # Verify permissions. if not is_view and not can_review(topic.id): component_fail( T('You do not have the permission to perform reviews in this topic' )) # Fishes out the current review, if any. current_review = db((db.review.user_email == get_user_email()) & (db.review.paper_id == paper.paper_id) & (db.review.topic == topic.id) & (db.review.end_date == None)).select().first() # Sets some defaults. logger.info("My user email: %r" % get_user_email()) db.review.paper.writable = False db.review.paper_id.readable = False db.review.user_email.default = get_user_email() db.review.paper_id.default = paper.paper_id db.review.paper.default = paper.id db.review.topic.default = topic.id db.review.start_date.label = T('Review date') db.review.end_date.readable = False db.review.useful_count.readable = is_view db.review.old_score.default = paper_in_topic.score # Creates the form for editing. form = SQLFORM(db.review, record=current_review, readonly=is_view) form.vars.user_email = get_user_email() form.vars.review_content = None if current_review is None else text_store_read( current_review.review_content) if form.validate(): # We must write the review as a new review. # First, we close the old review if any. now = datetime.utcnow() if current_review is not None: current_review.update_record(end_date=now) # Builds the correct review id. review_id = current_review.review_id if current_review is not None else None if review_id is None: review_id = review_utils.get_random_id() # Then, writes the current review. db.review.insert( user_email=get_user_email(), paper_id=paper.paper_id, review_id=review_id, paper=paper.id, topic=topic.id, start_date=now, end_date=None, review_content=str(text_store_write(form.vars.content)), old_score=paper_in_topic.score, grade=form.vars.grade, ) add_reviewer_to_topic(get_user_email(), topic.id) session.flash = T('Your review has been accepted.') redirect( URL('components', 'do_review', args=[paper.paper_id, topic_id, 'v'])) button_list = [] button_list.append( A(icon_reviews, T('All reviews'), cid=request.cid, _class='btn btn-success', _href=URL('components', 'paper_reviews', args=[paper.paper_id, topic_id]))) if is_view and can_review(topic.id): button_list.append( A(icon_edit, T('Edit review'), cid=request.cid, _class='btn btn-warning', _href=URL('components', 'do_review', args=[paper.paper_id, topic_id, 'e']))) # else: # button_list.append(A(icon_your_review, T('Your review'), cid=request.cid, # _class='btn btn-success', # _href=URL('components', 'do_review', args=[paper.paper_id, topic_id, 'v']))) return dict(button_list=button_list, form=form)
def paper_topic_grid(topic_id, all_papers=False): """Produces a grid containing the papers in a topic. The grid is done so that it can be easily included in a more complex page. The arguments are: - topic_id (in path) - all_papers=y (in query): if yes, then also papers that are not primary in the topic will be included. """ topic = db.topic(topic_id) if topic is None: component_fail(T('No such topic.')) fields = [ db.paper_in_topic.paper_id, db.paper.id, db.paper.paper_id, db.paper.title, db.paper.authors, db.paper_in_topic.is_primary ] orderby = db.paper.start_date links = [] if all_papers: q = ((db.paper_in_topic.topic == topic.id) & (db.paper_in_topic.paper_id == db.paper.paper_id) & (db.paper_in_topic.end_date == None) & (db.paper.end_date == None) & (db.topic.id == db.paper.primary_topic)) fields.extend([db.paper.primary_topic, db.topic.name]) # db.paper.primary_topic.represent = lambda v, r: '' if v == topic_id else v db.paper.primary_topic.label = T('Primary topic') db.topic.name.readable = False db.paper.primary_topic.represent = lambda v, r: A( r.topic.name, _href=URL('default', 'topic_index', args=[v])) links.append( dict(header='', body=lambda r: (icon_primary_paper if r.paper_in_topic.is_primary else icon_all_paper))) else: q = ((db.paper.primary_topic == topic_id) & (db.paper.end_date == None) & (db.paper.paper_id == db.paper_in_topic.paper_id) & (db.paper_in_topic.topic == topic_id) & (db.paper_in_topic.end_date == None)) fields.extend([db.paper_in_topic.num_reviews, db.paper_in_topic.score]) orderby = ~db.paper_in_topic.score links.append(dict(header='', body=lambda r: icon_primary_paper)) db.paper.title.represent = lambda v, r: A( v, _href=URL('default', 'view_paper', args=[r.paper_in_topic.paper_id, topic.id])) # links.append(dict(header='', # body=lambda r: A('Versions', _href=URL('default', 'view_paper_versions', # args=[r.paper_in_topic.paper_id])))) # links.append(dict(header='', # body=lambda r: A('Edit', _href=URL('default', 'edit_paper', # args=[r.paper_in_topic.paper_id], vars=dict(topic=topic.id))))) grid = SQLFORM.grid( q, args=request.args[:1], # The first parameter is the topic id. orderby=orderby, fields=fields, field_id=db.paper.id, csv=False, details=False, links=links, links_placement='left', # These all have to be done with special methods. create=False, editable=False, deletable=False, maxtextlength=48, ) return grid