コード例 #1
0
def has_paid(submit_id=None):
    response = "success"

    if not ModuleAPI.can_write('custom_form') or current_user.is_anonymous:
        return abort(403)

    # Test if user already signed up
    submission = CustomFormResult.query.filter(
        CustomFormResult.id == submit_id
    ).first()

    if not submission:
        response = "Error, submission could not be found"

    # Adjust the "has_paid"
    if submission.has_paid:
        submission.has_paid = False
    else:
        submission.has_paid = True

    db.session.add(submission)
    db.session.commit()

    copernica_data = {
        "Betaald": "Ja" if submission.has_paid else "Nee",
    }

    copernica.update_subprofile(copernica.SUBPROFILE_ACTIVITY,
                                submission.owner_id, submission.form_id,
                                copernica_data)

    return response
コード例 #2
0
def remove_response(submit_id=None):
    response = "success"

    if not ModuleAPI.can_read('custom_form'):
        return abort(403)

    # Test if user already signed up
    submission = CustomFormResult.query.filter(
        CustomFormResult.id == submit_id
    ).first()

    if not submission:
        abort(404)

    form_id = submission.form_id
    max_attendants = submission.form.max_attendants

    db.session.delete(submission)
    db.session.commit()

    all_sub = CustomFormResult.query.filter(
        CustomFormResult.form_id == form_id
    ).all()

    if max_attendants <= len(all_sub):
        from_list = all_sub[max_attendants - 1]
        copernica_data = {
            "Reserve": "Nee"
        }
        copernica.update_subprofile(
            copernica.SUBPROFILE_ACTIVITY, from_list.owner_id,
            from_list.form_id, copernica_data)

    return response
コード例 #3
0
ファイル: custom_form.py プロジェクト: viaict/viaduct
def remove_response(form_id=None, submission_id=None):

    response = "success"

    # Test if user already signed up
    submission = custom_form_service.\
        get_form_submission_by_id(form_id, submission_id)

    form_id = submission.form_id
    max_attendants = submission.form.max_attendants

    db.session.delete(submission)
    db.session.commit()

    all_sub = custom_form_service.get_form_entries_by_form_id(form_id)

    if max_attendants <= len(all_sub):
        from_list = all_sub[max_attendants - 1]
        copernica_data = {
            "Reserve": "Nee"
        }
        copernica.update_subprofile(
            app.config['COPERNICA_ACTIVITEITEN'], from_list.owner_id,
            from_list.form_id, copernica_data)

    return response
コード例 #4
0
ファイル: custom_form_service.py プロジェクト: viaict/viaduct
def toggle_form_submission_paid(form_id, submission_id):
    submission = get_form_submission_by_id(form_id, submission_id)

    paid = not submission.has_paid

    custom_form_repository.form_set_paid_status(submission, paid)

    copernica_data = {
        "Betaald": "Ja" if submission.has_paid else "Nee",
    }

    copernica.update_subprofile(app.config['COPERNICA_ACTIVITEITEN'],
                                submission.owner_id, submission.form_id,
                                copernica_data)
コード例 #5
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)
コード例 #6
0
ファイル: custom_form.py プロジェクト: viaict/viaduct
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)