Beispiel #1
0
def annotator():
    action = request.form['action']
    if action == 'Submit':
        data = parse_upload_form()
        added = []
        if data:
            # validate data
            for index, row in enumerate(data):
                if len(row) != 3:
                    return utils.user_error(
                        'Bad data: row %d has %d elements (expecting 3)' %
                        (index + 1, len(row)))

            def tx():
                for row in data:
                    annotator = Annotator(*row)
                    added.append(annotator)
                    db.session.add(annotator)
                db.session.commit()

            with_retries(tx)
            try:
                email_invite_links(added)
            except Exception as e:
                return utils.server_error(str(e))
    elif action == 'Email':
        annotator_id = request.form['annotator_id']
        try:
            email_invite_links(Annotator.by_id(annotator_id))
        except Exception as e:
            return utils.server_error(str(e))
    elif action == 'Disable' or action == 'Enable':
        annotator_id = request.form['annotator_id']
        target_state = action == 'Enable'

        def tx():
            Annotator.by_id(annotator_id).active = target_state
            db.session.commit()

        with_retries(tx)
    elif action == 'Delete':
        annotator_id = request.form['annotator_id']
        try:

            def tx():
                db.session.execute(
                    ignore_table.delete(
                        ignore_table.c.annotator_id == annotator_id))
                Annotator.query.filter_by(id=annotator_id).delete()
                db.session.commit()

            with_retries(tx)
        except IntegrityError as e:
            if isinstance(e.orig, psycopg2.errors.ForeignKeyViolation):
                return utils.server_error(
                    "Judges can't be deleted once they have voted on a project. You can use the 'disable' functionality instead, which has a similar effect, locking out the judge and preventing them from voting on any other projects."
                )
            else:
                return utils.server_error(str(e))
    return redirect(url_for('admin'))
Beispiel #2
0
def item():
    action = request.form['action']
    if action == 'Submit':
        data = parse_upload_form()
        if data:
            # validate data
            for index, row in enumerate(data):
                if len(row) != 3:
                    return utils.user_error('Bad data: row %d has %d elements (expecting 3)' % (index + 1, len(row)))
            for row in data:
                _item = Item(*row)
                db.session.add(_item)
            db.session.commit()
    elif action == 'Prioritize' or action == 'Cancel':
        item_id = request.form['item_id']
        target_state = action == 'Prioritize'
        Item.by_id(item_id).prioritized = target_state
        db.session.commit()
    elif action == 'Disable' or action == 'Enable':
        item_id = request.form['item_id']
        target_state = action == 'Enable'
        Item.by_id(item_id).active = target_state
        db.session.commit()
    elif action == 'Delete':
        item_id = request.form['item_id']
        try:
            db.session.execute(ignore_table.delete(ignore_table.c.item_id == item_id))
            Item.query.filter_by(id=item_id).delete()
            db.session.commit()
        except IntegrityError as e:
            if isinstance(e.orig, psycopg2.errors.ForeignKeyViolation):
                return utils.server_error("Projects can't be deleted once they have been voted on by a judge. You can use the 'disable' functionality instead, which has a similar effect, preventing the project from being shown to judges.")
            else:
                return utils.server_error(str(e))
    return redirect(url_for('admin'))
Beispiel #3
0
def annotator():
    action = request.form['action']
    if action == 'Submit':
        data = parse_upload_form()
        print(data)
        added = []
        if data:
            # validate data
            for index, row in enumerate(data):
                if len(row) != 3:
                    return utils.user_error('Bad data: row %d has %d elements (expecting 3)' % (index + 1, len(row)))
            for row in data:
                annotator = Annotator(*row)
                # SET ALL ANNOTATORS INITIALLY TO INACTIVE
                annotator.active = False
                added.append(annotator)
                db.session.add(annotator)
            db.session.commit()
    elif action == 'Mass Email':
        try:
            rows = Annotator.query.all()
            email_invite_links(rows)
        except Exception as e:
            return utils.server_error(str(e))
    elif action == 'Start Judging':
        rows = Annotator.query.all()
        activate_judging(rows)
        exists = Setting.by_key("start_time") is not None
        if exists:
            Setting.set('start_time', datetime.datetime.now())
        else:
            starter = Setting(key = "start_time", value = datetime.datetime.now())
            db.session.add(starter)
        db.session.commit()
    elif action == 'Email':
        annotator_id = request.form['annotator_id']
        try:
            email_invite_links(Annotator.by_id(annotator_id))
        except Exception as e:
            return utils.server_error(str(e))
    elif action == 'Disable' or action == 'Enable':
        annotator_id = request.form['annotator_id']
        target_state = action == 'Enable'
        Annotator.by_id(annotator_id).active = target_state
        db.session.commit()
    elif action == 'Delete':
        annotator_id = request.form['annotator_id']
        try:
            db.session.execute(ignore_table.delete(ignore_table.c.annotator_id == annotator_id))
            Annotator.query.filter_by(id=annotator_id).delete()
            db.session.commit()
        except IntegrityError as e:
            if isinstance(e.orig, psycopg2.errors.ForeignKeyViolation):
                return utils.server_error("Judges can't be deleted once they have voted on a project. You can use the 'disable' functionality instead, which has a similar effect, locking out the judge and preventing them from voting on any other projects.")
            else:
                return utils.server_error(str(e))
    return redirect(url_for('admin'))
Beispiel #4
0
def annotator():
    action = request.form['action']
    if action == 'Submit':
        data = parse_upload_form()
        added = []
        if data:
            # validate data
            for index, row in enumerate(data):
                if len(row) < 3:
                    return utils.user_error(
                        'Bad data: row %d has %d elements (expecting at least 3)'
                        % (index + 1, len(row)))

            def tx():
                for row in data:
                    annotator = Annotator(*row)
                    added.append(annotator)
                    db.session.add(annotator)
                db.session.commit()

            with_retries(tx)
            try:
                email_invite_links(added)
            except Exception as e:
                return utils.server_error(str(e))
    elif action == 'Email':
        annotator_id = request.form['annotator_id']
        try:
            email_invite_links(Annotator.by_id(annotator_id))
        except Exception as e:
            return utils.server_error(str(e))
    elif action == 'Disable' or action == 'Enable':
        annotator_id = request.form['annotator_id']
        target_state = action == 'Enable'

        def tx():
            Annotator.by_id(annotator_id).active = target_state
            db.session.commit()

        with_retries(tx)
    elif action == 'Delete':
        annotator_id = request.form['annotator_id']
        try:

            def tx():
                annotator = Annotator.query.filter_by(id=annotator_id).first()
                db.session.delete(annotator)
                db.session.commit()

            with_retries(tx)
        except IntegrityError as e:
            return utils.server_error(str(e))
    return redirect(url_for('admin'))
Beispiel #5
0
def category():
    action = request.form['action']
    if action == 'Submit':
        data = parse_upload_form()
        if data:
            # validate data
            for index, row in enumerate(data):
                if len(row) != 2:
                    return utils.user_error(
                        'Bad data: row %d has %d elements (expecting 3)' %
                        (index + 1, len(row)))
            for row in data:
                _item = Category(*row)
                db.session.add(_item)
            db.session.commit()
    elif action == 'Disable' or action == 'Enable':
        category_id = request.form['category_id']
        target_state = action == 'Enable'
        Category.by_id(category_id).active = target_state
        db.session.commit()
    elif action == 'Delete':
        category_id = request.form['category_id']
        try:
            Category.query.filter_by(id=category_id).delete()
            db.session.commit()
        except IntegrityError as e:
            return utils.server_error(str(e))
    return redirect(url_for('admin'))
Beispiel #6
0
def item():
    action = request.form['action']
    if action == 'Submit':
        data = parse_upload_form()
        if data:
            # validate data
            for index, row in enumerate(data):
                if len(row) != 3:
                    return utils.user_error(
                        'Bad data: row %d has %d elements (expecting 3)' %
                        (index + 1, len(row)))
            for row in data:
                _item = Item(*row)
                db.session.add(_item)
            db.session.commit()
    elif action == 'Prioritize' or action == 'Cancel':
        item_id = request.form['item_id']
        target_state = action == 'Prioritize'
        Item.by_id(item_id).prioritized = target_state
        db.session.commit()
    elif action == 'Disable' or action == 'Enable':
        item_id = request.form['item_id']
        target_state = action == 'Enable'
        Item.by_id(item_id).active = target_state
        db.session.commit()
    elif action == 'Delete':
        item_id = request.form['item_id']
        try:
            db.session.execute(
                ignore_table.delete(ignore_table.c.item_id == item_id))
            Item.query.filter_by(id=item_id).delete()
            db.session.commit()
        except IntegrityError as e:
            return utils.server_error(str(e))
    return redirect(url_for('admin'))
Beispiel #7
0
def item():
    action = request.form['action']
    if action == 'Submit':
        data = parse_upload_form()
        if data:
            # validate data
            for index, row in enumerate(data):
                if len(row) != 3:
                    return utils.user_error('Bad data: row %d has %d elements (expecting 3)' % (index + 1, len(row)))
            for row in data:
                _item = Item(*row)
                db.session.add(_item)
            db.session.commit()
    elif action == 'Prioritize' or action == 'Cancel':
        item_id = request.form['item_id']
        target_state = action == 'Prioritize'
        Item.by_id(item_id).prioritized = target_state
        db.session.commit()
    elif action == 'Disable' or action == 'Enable':
        item_id = request.form['item_id']
        target_state = action == 'Enable'
        Item.by_id(item_id).active = target_state
        db.session.commit()
    elif action == 'Delete':
        item_id = request.form['item_id']
        try:
            db.session.execute(ignore_table.delete(ignore_table.c.item_id == item_id))
            Item.query.filter_by(id=item_id).delete()
            db.session.commit()
        except IntegrityError as e:
            return utils.server_error(str(e))
    return redirect(url_for('admin'))
Beispiel #8
0
def annotator():
    action = request.form['action']
    if action == 'Submit':
        data = parse_upload_form()
        added = []
        if data:
            # validate data
            for index, row in enumerate(data):
                if len(row) != 3:
                    return utils.user_error('Bad data: row %d has %d elements (expecting 3)' % (index + 1, len(row)))
            for row in data:
                annotator = Annotator(*row)
                added.append(annotator)
                db.session.add(annotator)
            db.session.commit()
            try:
                email_invite_links(added)
            except Exception as e:
                return utils.server_error(str(e))
    elif action == 'Email':
        annotator_id = request.form['annotator_id']
        try:
            email_invite_links(Annotator.by_id(annotator_id))
        except Exception as e:
            return utils.server_error(str(e))
    elif action == 'Disable' or action == 'Enable':
        annotator_id = request.form['annotator_id']
        target_state = action == 'Enable'
        Annotator.by_id(annotator_id).active = target_state
        db.session.commit()
    elif action == 'Delete':
        annotator_id = request.form['annotator_id']
        try:
            db.session.execute(ignore_table.delete(ignore_table.c.annotator_id == annotator_id))
            Annotator.query.filter_by(id=annotator_id).delete()
            db.session.commit()
        except IntegrityError as e:
            return utils.server_error(str(e))
    return redirect(url_for('admin'))
Beispiel #9
0
def annotator():
  action = request.form['action']
  if action == 'Submit':
    data = parse_upload_form()
    added = []
    if data:
      # validate data
      for index, row in enumerate(data):
        if len(row) != 3:
          return utils.user_error('Bad data: row %d has %d elements (expecting 3)' % (index + 1, len(row)))
      for row in data:
        annotator = Annotator(*row)
        added.append(annotator)
        db.session.add(annotator)
      db.session.commit()
      try:
        email_invite_links(added)
      except Exception as e:
        return utils.server_error(str(e))
  elif action == 'Email':
    annotator_id = request.form['annotator_id']
    try:
      email_invite_links(Annotator.by_id(annotator_id))
    except Exception as e:
      return utils.server_error(str(e))
  elif action == 'Disable' or action == 'Enable':
    annotator_id = request.form['annotator_id']
    target_state = action == 'Enable'
    Annotator.by_id(annotator_id).active = target_state
    db.session.commit()
  elif action == 'Delete':
    annotator_id = request.form['annotator_id']
    try:
      db.session.execute(ignore_table.delete(ignore_table.c.annotator_id == annotator_id))
      Annotator.query.filter_by(id=annotator_id).delete()
      db.session.commit()
    except IntegrityError as e:
      return utils.server_error(str(e))
  elif action == 'BatchDisable':
    annotator_ids = request.form.getlist('ids')
    errored = []
    for annotator_id in annotator_ids:
      try:
        Annotator.by_id(annotator_id).active = False
        db.session.commit()
      except:
        db.session.rollback()
        errored.append(annotator_id)
        continue
  elif action == 'BatchDelete':
    annotator_ids = request.form.getlist('ids')
    errored = []
    for annotator_id in annotator_ids:
      try:
        db.session.execute(ignore_table.delete(ignore_table.c.annotator_id == annotator_id))
        Annotator.query.filter_by(id=annotator_id).delete()
        db.session.commit()
      except:
        db.session.rollback()
        errored.append(annotator_id)
        continue
  return redirect(url_for('admin'))
Beispiel #10
0
def item():
    action = request.form['action']
    if action == 'Submit':
        data = parse_upload_form()
        if data:
            # validate data
            for index, row in enumerate(data):
                if len(row) < len(DEVPOST_COLUMNS):
                    return utils.user_error(
                        'Bad data: row %d has %d elements (expecting %d+)' %
                        (index + 1, len(row), len(DEVPOST_COLUMNS)))

            def tx():
                for (i, row) in enumerate(data):
                    if i == 0 and row[0] == DEVPOST_COLUMNS[0]:
                        continue  # skip header row
                    _item = Item(name=row[0],
                                 location=row[1],
                                 url=row[2],
                                 description="",
                                 categories=row[10])
                    db.session.add(_item)
                db.session.commit()

            with_retries(tx)
    elif action == 'Prioritize' or action == 'Cancel':
        item_id = request.form['item_id']
        target_state = action == 'Prioritize'

        def tx():
            Item.by_id(item_id).prioritized = target_state
            db.session.commit()

        with_retries(tx)
    elif action == 'Disable' or action == 'Enable':
        item_id = request.form['item_id']
        target_state = action == 'Enable'

        def tx():
            Item.by_id(item_id).active = target_state
            db.session.commit()

        with_retries(tx)
    elif action == 'Delete':
        item_id = request.form['item_id']
        try:

            def tx():
                db.session.execute(
                    ignore_table.delete(ignore_table.c.item_id == item_id))
                Item.query.filter_by(id=item_id).delete()
                db.session.commit()

            with_retries(tx)
        except IntegrityError as e:
            if isinstance(e.orig, psycopg2.errors.ForeignKeyViolation):
                return utils.server_error(
                    "Projects can't be deleted once they have been voted on by a judge. You can use the 'disable' functionality instead, which has a similar effect, preventing the project from being shown to judges."
                )
            else:
                return utils.server_error(str(e))
    return redirect(url_for('admin'))
Beispiel #11
0
def item():
    action = request.form['action']
    if action == 'Submit':
        data = parse_upload_form()
        if data:
            # validate data
            for index, row in enumerate(data):
                if settings.VIRTUAL_EVENT:
                    if len(row) != 6:
                        return utils.user_error(
                            'Bad data: row %d has %d elements (expecting 6)' %
                            (index + 1, len(row)))
                else:
                    if len(row) != 3:
                        return utils.user_error(
                            'Bad data: row %d has %d elements (expecting 3)' %
                            (index + 1, len(row)))

            def tx():
                for row in data:
                    # This is REALLY REALLY bad I know...
                    # TODO: Tech Debt
                    if settings.VIRTUAL_EVENT:
                        row.insert(1, "N/A")
                    _item = Item(*row)
                    db.session.add(_item)
                db.session.commit()

            with_retries(tx)
    elif action == 'Prioritize' or action == 'Cancel':
        item_id = request.form['item_id']
        target_state = action == 'Prioritize'

        def tx():
            Item.by_id(item_id).prioritized = target_state
            db.session.commit()

        with_retries(tx)
    elif action == 'Disable' or action == 'Enable':
        item_id = request.form['item_id']
        target_state = action == 'Enable'

        def tx():
            Item.by_id(item_id).active = target_state
            db.session.commit()

        with_retries(tx)
    elif action == 'Delete':
        item_id = request.form['item_id']
        try:

            def tx():
                db.session.execute(
                    ignore_table.delete(ignore_table.c.item_id == item_id))
                Item.query.filter_by(id=item_id).delete()
                db.session.commit()

            with_retries(tx)
        except IntegrityError as e:
            return utils.server_error(str(e))
    elif action == 'BatchDisable':
        item_ids = request.form.getlist('ids')
        error = []
        for item_id in item_ids:
            try:

                def tx():
                    Item.by_id(item_id).active = False
                    db.session.commit()

                with_retries(tx)
            except:
                error.append(item_id)

                def tx():
                    db.session.rollback()

                with_retries(tx)
    elif action == 'BatchDelete':
        db.Session.autocommit = True
        item_ids = request.form.getlist('ids')
        error = []
        for item_id in item_ids:
            try:

                def tx():
                    db.session.execute(
                        ignore_table.delete(ignore_table.c.item_id == item_id))
                    Item.query.filter_by(id=item_id).delete()
                    db.session.commit()

                with_retries(tx)
            except Exception as e:
                error.append(str(e))

                def tx():
                    db.session.rollback()

                with_retries(tx)
                continue
    return redirect(url_for('admin'))