Example #1
0
    def get(self):
        username = _request_ctx_stack.top.current_user['sub']

        try:
            settings = models.Settings.objects.get({'username': username})
            return settings.data
        except DoesNotExist:
            settings = models.Settings(username=username, data=DEFAULT_SETTINGS, last_modified=datetime.utcnow())
            settings.save()

            return DEFAULT_SETTINGS
Example #2
0
    def post(self):
        username = _request_ctx_stack.top.current_user['sub']
        args = self.parser.parse_args()

        try:
            settings = models.Settings.objects.get({'username': username})
            settings.last_modified = datetime.utcnow()
            settings.data = args.settings
        except DoesNotExist:
            settings = models.Settings(username=username, data=args.settings, last_modified=datetime.utcnow())

        settings.save()

        return settings.data
Example #3
0
def settings_post(email):
    try:
        data = request.get_json()
    except BadRequest as e:
        app.logger.info("Error parsing JSON request body: %s", e)
        abort(400)

    query = (models.db.session.query(models.Settings).join(
        models.User).filter(models.User.email == email))

    if not models.db.session.query(query.exists()).scalar():
        user = models.db.session.query(
            models.User).filter_by(email=email).first()

        autocomplete_sheet = data.get("autocompleteSheet")
        if autocomplete_sheet is not None:
            autocomplete_sheet = autocomplete_sheet.strip()

        user_settings = models.Settings(
            spreadsheet_id=data["spreadsheetId"].strip(),
            attendance_sheet=data["attendanceSheet"].strip(),
            user_id=user.id,
            autocomplete_sheet=autocomplete_sheet,
        )

        models.db.session.add(user_settings)
        models.db.session.commit()
        app.logger.debug("New settings: %s", user_settings)

        return jsonify(data), 201

    user = models.db.session.query(models.User).filter_by(email=email).first()

    user_settings = query.first()
    user_settings.spreadsheet_id = data["spreadsheetId"].strip()
    user_settings.attendance_sheet = data["attendanceSheet"].strip()
    autocomplete_sheet = data.get("autocompleteSheet")
    if autocomplete_sheet is not None:
        autocomplete_sheet = autocomplete_sheet.strip()
    user_settings.autocomplete_sheet = autocomplete_sheet
    user_settings.user_id = user.id
    app.logger.debug("Updated settings: %s", user_settings)
    models.db.session.commit()

    return jsonify(data)
Example #4
0
    def put(self):

        print('I\'m here')

        parsed_args = settings_parser.parse_args()

        print("parsed_args are", parsed_args)

        participant_name = parsed_args['participant_name']
        participant_number = parsed_args['participant_number']
        game_variant = parsed_args['game_variant']
        condition = parsed_args['condition']

        settings = models.Settings(participant_name=participant_name,
                                   participant_number=participant_number,
                                   game_variant=game_variant,
                                   condition=condition)

        session.add(settings)
        session.commit()

        return settings
def update_settings(db: SQLAlchemy):
    to_save = request.form.to_dict()

    settings = db.session.query(models.Settings).first()
    updating = settings is not None
    if not updating:
        settings = models.Settings()

    settings.cbb_path = to_save['cbb_path']

    try:
        if updating:
            db.session.merge(settings)
        else:
            db.session.add(settings)
        db.session.commit()
        flash('Settings saved', category='success')
        return redirect(url_for('config_settings.settings'))
    except IntegrityError:
        db.session.rollback()
        flash('Settings save failed', category='error')
    return redirect(url_for('config_settings.settings'))