Exemplo n.º 1
0
def process_mts_group_registrations(user_order, form):
    group_discount_model = user_order.event.products.filter_by(
        type='FestivalGroupDiscountProduct').first()
    discount_product = get_product_by_model(group_discount_model)
    group_form = form.get_product_by_key(group_discount_model.product_key)
    if discount_product.is_selected(group_form) and \
            discount_product.get_total_price(group_discount_model, group_form, form):

        if group_form.group_participation.data == 'new':
            group = RegistrationGroup(
                name=group_form.group_name.data,
                location=group_form.location.data,
                description=group_form.group_description.data,
                event_id=user_order.event.id)
            db_session.add(group)
            db_session.commit()
        else:
            serialiser = GroupToken()
            group = serialiser.deserialize(group_form.group_token.data.strip())
        registrations = Registration.query.join(
            OrderProduct,
            aliased=False).filter_by(order_id=user_order.id).all()

        for reg in registrations:
            reg.registration_group = group

        db_session.commit()
Exemplo n.º 2
0
def event_order_remaining_payment_checkout(order_token):
    form = RemainingPaymentForm()
    try:
        user_order = order_deserialize(order_token)
    except BadSignature:
        return 'Incorrect order token'

    if form.validate_on_submit():
        order_summary_controller = OrderSummaryController(user_order)
        remaining_payment = order_summary_controller.remaining_payment._payment
        user_order.payments.append(remaining_payment)
        db_session.commit()
        stripe_token = form.stripe_token.data
        success, response = process_payment(remaining_payment, stripe_token,
                                            config.STRIPE_SK)
        if success:
            db_session.commit()
            email_result = send_remaining_payment_confirmation(
                remaining_payment)
            return redirect(
                url_for('payment_thankyou',
                        order_token=order_serialize(user_order)))
        else:
            # print(response)
            return render_template('event_purchase_error.html',
                                   error_message=response)
Exemplo n.º 3
0
def vote_submit():
    form = VoteForm()
    if form.validate_on_submit():
        voter_uuid = form.client_fingerprint.data
        vote = Vote(voter_id=voter_uuid, vote=form.options.data)
        db_session.add(vote)
        db_session.commit()
        return 'Success'
    else:
        return jsonify(form.errors)
Exemplo n.º 4
0
def process_payment(payment, stripe_token, stripe_sk=None):
    if payment.amount > 0:
        is_success, response = charge(payment, stripe_token, stripe_sk)
    else:
        is_success, response = True, 'Don\'t need to pay'
        payment.status = PAYMENT_STATUS_PAID

    if is_success:
        update_order(payment.order)
        db_session.commit()

    return is_success, response
Exemplo n.º 5
0
def process_partner_registrations(user_order, form):
    for product_model in user_order.event.products:
        product = get_product_by_model(product_model)
        product_form = form.get_product_by_key(product_model.product_key)
        if isinstance(product,
                      RegularPartnerWorkshop) and product_form.add.data:
            waiting_lists_couple = product.get_waiting_lists(product_model)[1]
            if product_form.partner_token.data:
                order_product = user_order.order_products.join(
                    Product,
                    aliased=True).filter_by(id=product_model.id).first()
                partner_order_product = order_product_deserialize(
                    product_form.partner_token.data)
                group = create_partners_group(order_product,
                                              partner_order_product)
                db_session.add(group)
                if partner_order_product.status == ORDER_PRODUCT_STATUS_WAITING:
                    partner_role = partner_order_product.details_as_dict[
                        'dance_role']
                    if not waiting_lists_couple[partner_role]:
                        partner_order_product.accept()
                        send_acceptance_from_waiting_list(
                            partner_order_product)
            elif product_form.add.data == 'couple':
                order_products = OrderProduct.query.filter_by(order_id=user_order.id). \
                    join(Product, aliased=True).filter_by(id=product_model.id).all()
                group = create_partners_group(order_products[0],
                                              order_products[1])
                db_session.add(group)
            db_session.commit()
        elif isinstance(product,
                        CouplesOnlyWorkshop) and product_form.add.data:
            if product_form.partner_token.data:
                order_product = user_order.order_products.join(
                    Product,
                    aliased=True).filter_by(id=product_model.id).first()
                partner_order_product = order_product_deserialize(
                    product_form.partner_token.data)
                group = create_partners_group(order_product,
                                              partner_order_product)
                db_session.add(group)

                partner_order_product.accept()
                send_acceptance_from_waiting_partner(partner_order_product)
            elif product_form.add.data == 'couple':
                order_products = OrderProduct.query.filter_by(order_id=user_order.id). \
                                    join(Product, aliased=True).filter_by(id=product_model.id).all()
                group = create_partners_group(order_products[0],
                                              order_products[1])
                db_session.add(group)
            db_session.commit()
Exemplo n.º 6
0
def crowdfunding_form(event_key):
    event = Event.query.filter_by(event_key=event_key).first()
    if not event:
        event = Event.query.\
            filter_by(active=True, event_type='crowdfunding').\
            filter(Event.name.startswith(event_key)).first()
        if event:
            return redirect(
                url_for('crowdfunding_form', event_key=event.event_key))
        else:
            return redirect(url_for('crowdfunding_index'))

    form = create_crowdfunding_form(event)()

    total_stats = get_total_raised(event)

    if form.validate_on_submit():
        registration = get_crowdfunding_registration_from_form(form)
        registration.crowdfunding_registration_properties = \
                CrowdfundingRegistrationProperties(anonymous=form.anonymous.data)
        # partner_registration = get_partner_registration_from_form(form)
        user_order = get_order_for_crowdfunding_event(event, form,
                                                      registration, None)
        user_order.registration = registration
        event.orders.append(user_order)
        db_session.commit()
        success, response = process_payment(user_order.payments[0],
                                            form.stripe_token.data)
        if success:
            return redirect(
                url_for('crowdfunding_thankyou', event_key=event.event_key))
        else:
            # print(response)
            return render_template('event_purchase_error.html',
                                   error_message=response)

    contributors = Registration.query.\
        join(Order, aliased=True).join(Event, aliased=True).filter_by(event_key=event_key).\
        order_by(desc(Registration.registered_datetime)).all()
    return render_template('events/{}/crowdfunding.html'.format(event_key),
                           event=event,
                           form=form,
                           total_stats=total_stats,
                           contributors=contributors,
                           config=config)
Exemplo n.º 7
0
def event_order_product_cancel(event_key, order_product_token):
    form = OrderProductCancelForm()
    order_product_controller = OrderProductController.from_token(
        order_product_token)

    if form.validate_on_submit():
        refund_request = RefundRequest()
        refund_request.product_order = order_product_controller._order_product
        db_session.add(refund_request)
        db_session.commit()
        send_cancellation_request_confirmation(
            order_product_controller._order_product)
        return 'Cancel request has been submitted'
    else:
        return render_template(
            'cancel_order_product.html',
            form=form,
            order_product_controller=order_product_controller)
Exemplo n.º 8
0
def vote_admin():
    form = VoteAdminForm()
    voting_session = VotingSession.query.order_by(
        VotingSession.id.desc()).first()
    if form.validate_on_submit():

        if form.start_voting.data:
            voting_session = VotingSession(name=form.name.data)
            db_session.add(voting_session)
            db_session.commit()

        elif form.stop_voting.data:
            voting_session.stop()
            db_session.commit()

    if voting_session:
        form.name.data = voting_session.name

        if voting_session.end_timestamp:
            form.stop_voting.data = True

        votes_query = Vote.query.filter(
            Vote.vote_timestamp > voting_session.start_timestamp)
        if voting_session.end_timestamp:
            votes_query = votes_query.filter(
                Vote.vote_timestamp < voting_session.end_timestamp)
        all_votes = votes_query.all()
        all_votes_dict = {v.voter_id: v.vote for v in all_votes}

        res_left = len([k for k, v in all_votes_dict.items() if v == 'left'])
        res_right = len([k for k, v in all_votes_dict.items() if v == 'right'])
        results_data = {'left': res_left, 'right': res_right}
        progess_max = max(20, max(res_left, res_right))
        progress_data = {
            'total_max': progess_max,
            'left_pcnt': int(res_left * 100 / progess_max),
            'right_pcnt': int(res_right * 100 / progess_max),
        }
    else:
        results_data = None
    return render_template('voting/admin.html',
                           form=form,
                           results_data=results_data,
                           progress_data=progress_data)
Exemplo n.º 9
0
registration2.crowdfunding_registration_properties = \
                CrowdfundingRegistrationProperties(anonymous=0)
order2 = Order(total_price=25,
               transaction_fee=0.575,
               status='paid',
               order_datetime='2017-05-29 13:41:31',
               stripe_charge_id='ch_1AOo7iHQoe2Uj5fJ78wy9Z3p')
order2.registration = registration2
order2_product = OrderProduct(price=order2.total_price, product=donate_product)
order2.order_products.append(order2_product)
event.orders.append(order2)

registration3 = Registration(name='Chott Andersen',
                             email='*****@*****.**',
                             comment='',
                             registered_datetime='2017-05-30 11:54:43')
registration3.crowdfunding_registration_properties = \
                CrowdfundingRegistrationProperties(anonymous=1)
order3 = Order(total_price=35,
               transaction_fee=0.725,
               status='paid',
               order_datetime='2017-05-30 11:54:43',
               stripe_charge_id='ch_1AP8vuHQoe2Uj5fJqsHAUKvo')
order3.registration = registration3
order3_product = OrderProduct(price=order3.total_price,
                              product=patrick_private)
order3.order_products.append(order3_product)
event.orders.append(order3)

db_session.commit()
Exemplo n.º 10
0
def register_form(event_key):
    event = Event.query.filter_by(event_key=event_key).first()
    if not event:
        event = Event.query.\
            filter_by(active=True, event_type='dance').\
            filter(Event.name.startswith(event_key)).first()
        if event:
            return redirect(url_for('register_form',
                                    event_key=event.event_key))
        else:
            return redirect(url_for('register_index'))

    form = create_event_form(event)()

    if form.validate_on_submit():
        registration = get_registration_from_form(form)
        registration.event_id = event.id
        partner_registration = get_partner_registration_from_form(form)
        partner_registration.event_id = event.id
        if event_key == 'mind_the_shag_2018':
            user_order = mts_get_order_for_event(event, form, registration,
                                                 partner_registration)
            if form.comment.data and form.comment.data.lower().strip() in [
                    'sunny side of the street'
            ]:
                user_order.payments[0].amount = 0
        else:
            user_order = get_order_for_event(event, form, registration,
                                             partner_registration)
        user_order.registration = registration
        event.orders.append(user_order)
        db_session.commit()
        success, response = process_payment(user_order.payments[0],
                                            form.stripe_token.data)
        if success:
            process_partner_registrations(user_order, form)
            if event_key == 'mind_the_shag_2018':
                process_mts_group_registrations(user_order, form)
            balance_results = balance_event_waiting_lists(event)
            email_result = send_registration_confirmation(user_order)
            # order_summary_controller = OrderSummaryController(user_order)
            # return render_template('signup_thankyou.html', order_summary_controller=order_summary_controller,
            #                        event_key=event.event_key)
            return redirect(
                url_for('signup_thankyou',
                        order_token=order_serialize(user_order)))
        else:
            # print(response)
            return render_template('event_purchase_error.html',
                                   error_message=response)

    # tokens = request.args.get('tokens')
    # if tokens:
    #     tokens = tokens.split(',')
    #     for token in tokens:
    #         try:
    #             order_product = order_product_deserialize(token)
    #             if order_product.order.event.id == event.id:
    #                 form[order_product.product.product_key].partner_token.data = token
    #                 form[order_product.product.product_key].dance_role.data = flip_role(order_product.details_as_dict['dance_role'])
    #                 form[order_product.product.product_key].add.data = 1
    #         except BadSignature:
    #             pass
    form_controller = MtsSignupFormController(form)
    return render_template('events/{}/signup_vue.html'.format(event_key),
                           event=event,
                           form=form,
                           config=config,
                           form_controller=form_controller)
Exemplo n.º 11
0
 def accept_from_waiting_list(cls, order_product):
     order_product.status = ORDER_PRODUCT_STATUS_ACCEPTED
     db_session.commit()