Created
April 10, 2013 16:28
-
-
Save iolloyd/5356194 to your computer and use it in GitHub Desktop.
delegate pain game
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from __future__ import absolute_import | |
from flask import Blueprint, g, request, Response | |
from administrate.utils.jsonify import jsonify | |
from administrate.utils.create_filter import create_filter | |
from administrate.models.mapping import get_model_from_map | |
from administrate.models.crm.contact import Contact | |
from administrate.models.system.company import Company | |
from administrate.models.events.registration import Registration | |
def create_delegate(contact, event): | |
delegate = Delegate() | |
delegate.contact = contact | |
delegate.event = event | |
return delegate | |
def create_registration(account, company): | |
registration = Registration() | |
registration.account = account | |
registration.company = company | |
registration.currency = company.currency | |
return registration | |
def create_registration_entry(contact, event): | |
registration_entry = RegistrationEntry() | |
registration_entry.contact = contact | |
registration_entry.event = event | |
return registration_entry | |
@blueprint.route('/delegates', methods=['POST', 'OPTIONS']) | |
def api_add_delegate(): | |
contact_id = request.json['contact_id'] | |
event_id = request.json['event_id'] | |
contact = g.db.query(Contact).filter_by(id = contact_id).first() | |
event = g.db.query(Event).filter_by(id = event_id).first() | |
custom_discount_id = SOME_ID? | |
custom_discount_rate = SOME_RATE? | |
delegate = create_delegate(contact, event) | |
registration = create_registration(account, company, custom_discount_id, custom_discount_rate) | |
registration_entry = create_registration_entry(contact, event, registration) | |
if event.disposition in ['multisession', 'normal']: | |
for child_event in get_children_of_event(event_id): | |
child_registration_entry = create_registration_entry(contact, child_event, registration) | |
g.db.add(child_registration_entry) | |
g.db.add(delegate) | |
g.db.add(registration) | |
g.db.add(registration_entry) | |
g.db.commit() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment