Exemplo n.º 1
0
def vote():
    """This pretty much covers voting! Love it."""
    entity_cls = classes.get(request.args.get('entity'), None)
    entity_id = request.args.get('id').strip(lowercase)
    if not entity_cls:
        abort(404)
    if not issubclass(entity_cls, classes['VotableMixin']):
        abort(501)
    entity = entity_cls.query.get_or_404(entity_id)
    redirect_url = generate_next(entity.url)
    if isinstance(entity, classes['Annotation']) and not entity.active:
        flash("You cannot vote on deactivated annotations.")
        return redirect(redirect_url)
    if isinstance(entity, classes['Edit'])\
            and not entity.annotation.active\
            and not current_user.is_authorized(
                'review_deactivated_annotation_edits'):
        flash("You cannot vote on deactivated annotations edits.")
        return redirect(redirect_url)
    up = True if request.args.get('up').lower() == 'true' else False
    if up:
        entity.upvote(current_user)
    else:
        entity.downvote(current_user)
    db.session.commit()
    return redirect(redirect_url)
Exemplo n.º 2
0
 def is_authorized(self):
     return current_user.is_authenticated() and \
         current_user.is_authorized('usemessages')
Exemplo n.º 3
0
def edit(annotation_id):
    annotation = Annotation.query.get_or_404(annotation_id)
    form = AnnotationForm()
    redirect_url = generate_next(
        url_for('main.annotation', annotation_id=annotation_id))
    if (annotation.locked
            and not current_user.is_authorized('edit_locked_annotations')):
        flash("That annotation is locked from editing.")
        return redirect(redirect_url)
    elif annotation.edit_pending:
        flash("There is an edit still pending peer review.")
        return redirect(redirect_url)
    elif not annotation.active:
        current_user.authorize('edit_deactivated_annotations')

    lines = annotation.HEAD.lines
    context = annotation.HEAD.context
    if form.validate_on_submit():
        fl, ll = line_check(form.first_line.data, form.last_line.data)

        tagsuccess, tags = process_tags(form.tags.data)
        try:
            editsuccess = annotation.edit(editor=current_user,
                                          reason=form.reason.data,
                                          fl=fl,
                                          ll=ll,
                                          fc=form.first_char_idx.data,
                                          lc=form.last_char_idx.data,
                                          body=form.annotation.data,
                                          tags=tags)
        except Exception as e:
            print(e)
            editsuccess = False

        # rerender the template with the work already filled
        if not (editsuccess and tagsuccess):
            db.session.rollback()
            return render_template('forms/annotation.html',
                                   form=form,
                                   title=annotation.text.title,
                                   lines=lines,
                                   text=annotation.text,
                                   edition=annotation.edition,
                                   annotation=annotation,
                                   context=context)
        else:
            db.session.commit()
        return redirect(redirect_url)

    elif not annotation.edit_pending:
        tag_strings = []
        for t in annotation.HEAD.tags:
            tag_strings.append(t.tag)
        form.first_line.data = annotation.HEAD.first_line_num
        form.last_line.data = annotation.HEAD.last_line_num
        form.first_char_idx.data = annotation.HEAD.first_char_idx
        form.last_char_idx.data = annotation.HEAD.last_char_idx
        form.annotation.data = annotation.HEAD.body
        form.tags.data = ' '.join(tag_strings)
    return render_template('forms/annotation.html',
                           form=form,
                           title=f"Edit Annotation {annotation.id}",
                           edition=annotation.edition,
                           lines=lines,
                           annotation=annotation,
                           context=context)
Exemplo n.º 4
0
 def is_authorized(self):
     return current_user.is_authenticated() and \
            current_user.is_authorized('usebaskets')
Exemplo n.º 5
0
 def is_authorized(self):
     return current_user.is_authenticated() and current_user.is_authorized("usealerts")
Exemplo n.º 6
0
def index():
    if not current_user.is_authorized():
        return redirect('/login')
    else:
        return redirect('/spell_check')
Exemplo n.º 7
0
 def is_authorized(self):
     return current_user.is_authenticated() and \
            current_user.is_authorized('usegroups')
Exemplo n.º 8
0
 def is_authorized(self):
     return current_user.is_authenticated() and \
            current_user.is_authorized('usemessages')