Esempio n. 1
0
def view(page_nr=1):
    if not ModuleAPI.can_read('custom_form'):
        return abort(403)

    followed_forms = CustomForm.qry_followed().all()
    active_forms = CustomForm.qry_active().all()
    archived_paginate = CustomForm.qry_archived().paginate(page_nr, 10)

    return render_template('custom_form/overview.htm',
                           followed_forms=followed_forms,
                           active_forms=active_forms,
                           archived_paginate=archived_paginate,
                           page_nr=page_nr)
Esempio n. 2
0
def loader():
    try:
        current = int(request.args.get('current'))
    except ValueError:
        current = None

    return jsonify(forms=serialize_sqla(CustomForm.aslist(current)))
Esempio n. 3
0
def loader(current):
    try:
        current = int(current)
    except ValueError:
        return abort(404)

    return jsonify(forms=serialize_sqla(CustomForm.aslist(current)))
Esempio n. 4
0
def create(form_id=None):
    if not ModuleAPI.can_write('custom_form') or current_user.is_anonymous:
        return abort(403)

    if form_id:
        custom_form = CustomForm.query.get_or_404(form_id)
        prev_max = custom_form.max_attendants
    else:
        custom_form = CustomForm()

    form = CreateForm(request.form, custom_form)

    if request.method == 'POST':
        custom_form.name = form.name.data
        custom_form.origin = form.origin.data
        custom_form.html = form.html.data
        custom_form.msg_success = form.msg_success.data
        custom_form.max_attendants = form.max_attendants.data
        if form.price.data is None:
            form.price.data = 0.0
        custom_form.price = form.price.data
        custom_form.transaction_description = form.transaction_description.data
        custom_form.terms = form.terms.data

        follower = None

        if not form_id:
            follower = CustomFormFollower(owner_id=current_user.id)
            flash('You\'ve created a form successfully.', 'success')

        else:
            flash('You\'ve updated a form successfully.', 'success')
            cur_max = int(custom_form.max_attendants)
            # print("Current maximum: " + cur_max)
            # print("Previous maximum: " + prev_max)
            # print("Current submissions: " + len(all_sub))
            if cur_max > prev_max:
                all_sub = CustomFormResult.query.filter(
                    CustomFormResult.form_id == form_id
                ).all()
                # Update for users that were on the reserve list that they
                # can now attend.
                if prev_max < len(all_sub):
                    for x in range(prev_max, max(cur_max, len(all_sub) - 1)):
                        sub = all_sub[x]
                        copernica_data = {
                            "Reserve": "Nee"
                        }
                        copernica.update_subprofile(
                            copernica.SUBPROFILE_ACTIVITY, sub.owner_id,
                            sub.form_id, copernica_data)
            elif cur_max < prev_max:
                all_sub = CustomFormResult.query.filter(
                    CustomFormResult.form_id == form_id
                ).all()
                if cur_max < len(all_sub):
                    for x in range(cur_max, max(prev_max, len(all_sub) - 1)):
                        sub = all_sub[x]
                        copernica_data = {
                            "Reserve": "Ja"
                        }
                        copernica.update_subprofile(
                            copernica.SUBPROFILE_ACTIVITY, sub.owner_id,
                            sub.form_id, copernica_data)

        db.session.add(custom_form)
        db.session.commit()

        if follower is not None:
            follower.form_id = custom_form.id
            db.session.add(follower)
            db.session.commit()

        return redirect(url_for('custom_form.view'))
    else:
        flash_form_errors(form)

    return render_template('custom_form/create.htm', form=form)
Esempio n. 5
0
def create(form_id=None):
    if form_id:
        custom_form = custom_form_service.get_form_by_form_id(form_id)
        prev_max = custom_form.max_attendants
    else:
        custom_form = CustomForm()

    form = init_form(CreateForm, obj=custom_form)

    if request.method == 'POST':
        custom_form.name = form.name.data
        custom_form.origin = form.origin.data
        custom_form.group = form.group.data
        custom_form.html = form.html.data
        custom_form.msg_success = form.msg_success.data
        custom_form.max_attendants = form.max_attendants.data
        custom_form.introductions = form.introductions.data
        if form.price.data is None:
            form.price.data = 0.0
        custom_form.price = form.price.data
        custom_form.terms = form.terms.data
        custom_form.requires_direct_payment = form.requires_direct_payment.data

        if form_id:
            flash('You\'ve updated a form successfully.', 'success')
            cur_max = int(custom_form.max_attendants)
            # print("Current maximum: " + cur_max)
            # print("Previous maximum: " + prev_max)
            # print("Current submissions: " + len(all_sub))
            if cur_max > prev_max:
                all_sub = CustomFormResult.query.filter(
                    CustomFormResult.form_id == form_id
                ).all()
                # Update for users that were on the reserve list that they
                # can now attend.
                if prev_max < len(all_sub):
                    for x in range(prev_max, min(cur_max, len(all_sub))):
                        sub = all_sub[x]
                        copernica_data = {
                            "Reserve": "Nee"
                        }
                        copernica.update_subprofile(
                            app.config['COPERNICA_ACTIVITEITEN'], sub.owner_id,
                            sub.form_id, copernica_data)
            elif cur_max < prev_max:
                all_sub = CustomFormResult.query.filter(
                    CustomFormResult.form_id == form_id
                ).all()
                if cur_max < len(all_sub):
                    for x in range(cur_max, max(prev_max, len(all_sub) - 1)):
                        sub = all_sub[x]
                        copernica_data = {
                            "Reserve": "Ja"
                        }
                        copernica.update_subprofile(
                            app.config['COPERNICA_ACTIVITEITEN'], sub.owner_id,
                            sub.form_id, copernica_data)

        db.session.add(custom_form)
        db.session.commit()

        if form_id is None:
            flash('You\'ve created a form successfully.', 'success')
            custom_form_service.follow_form(
                form=custom_form, user_id=current_user.id)

        return redirect(url_for('custom_form.view'))
    else:
        flash_form_errors(form)

    return render_template('custom_form/create.htm', form=form)