def create_edit_discount_code(form, event_id, discount_code_id=None):
        if not discount_code_id:
            discount_code = DiscountCode()
        else:
            discount_code = TicketingManager.get_discount_code(event_id, discount_code_id)
        discount_code.code = form.get('code')
        discount_code.value = form.get('value')
        discount_code.type = form.get('value_type')
        discount_code.discount_url = form.get('discount_url')
        discount_code.min_quantity = form.get('min_quantity', None)
        discount_code.max_quantity = form.get('max_quantity', None)
        discount_code.tickets_number = form.get('tickets_number')
        discount_code.event_id = event_id
        discount_code.used_for = TICKET
        discount_code.is_active = form.get('status', 'in_active') == 'active'

        if discount_code.min_quantity == "":
            discount_code.min_quantity = None
        if discount_code.max_quantity == "":
            discount_code.max_quantity = None
        if discount_code.tickets_number == "":
            discount_code.tickets_number = None

        try:
            discount_code.valid_from = datetime.strptime(form.get('start_date', None) + ' ' +
                                                         form.get('start_time', None), '%m/%d/%Y %H:%M')
        except:
            discount_code.valid_from = None

        try:
            discount_code.valid_till = datetime.strptime(form.get('end_date', None) + ' ' +
                                                         form.get('end_time', None), '%m/%d/%Y %H:%M')
        except:
            discount_code.valid_till = None

        discount_code.tickets = ",".join(form.getlist('tickets[]'))

        save_to_db(discount_code)

        return discount_code
示例#2
0
    def create_edit_discount_code(form, discount_code_id=None):
        if not discount_code_id:
            discount_code = DiscountCode()
        else:
            discount_code = InvoicingManager.get_discount_code(
                discount_code_id)
        discount_code.code = form.get('code')
        discount_code.value = form.get('value')
        discount_code.type = 'percent'
        discount_code.max_quantity = form.get('max_quantity', None)
        discount_code.tickets_number = form.get('tickets_number')
        discount_code.used_for = EVENT
        discount_code.marketer_id = form.get('marketer')
        discount_code.is_active = form.get('status', 'in_active') == 'active'

        if discount_code.max_quantity == "":
            discount_code.max_quantity = None

        try:
            discount_code.valid_from = datetime.strptime(
                form.get('start_date', None) + ' ' +
                form.get('start_time', None), '%m/%d/%Y %H:%M')
        except:
            discount_code.valid_from = None

        try:
            discount_code.valid_till = datetime.strptime(
                form.get('end_date', None) + ' ' + form.get('end_time', None),
                '%m/%d/%Y %H:%M')
        except:
            discount_code.valid_till = None

        save_to_db(discount_code)

        return discount_code
    def create_edit_discount_code(form, event_id, discount_code_id=None):
        if not discount_code_id:
            discount_code = DiscountCode()
        else:
            discount_code = TicketingManager.get_discount_code(event_id, discount_code_id)
        discount_code.code = form.get('code')
        discount_code.value = form.get('value')
        discount_code.type = form.get('value_type')
        discount_code.discount_url = form.get('discount_url')
        discount_code.min_quantity = form.get('min_quantity', None)
        discount_code.max_quantity = form.get('max_quantity', None)
        discount_code.tickets_number = form.get('tickets_number')
        discount_code.event_id = event_id
        discount_code.used_for = TICKET
        discount_code.is_active = form.get('status', 'in_active') == 'active'

        if discount_code.min_quantity == "":
            discount_code.min_quantity = None
        if discount_code.max_quantity == "":
            discount_code.max_quantity = None
        if discount_code.tickets_number == "":
            discount_code.tickets_number = None

        try:
            discount_code.valid_from = datetime.strptime(form.get('start_date', None) + ' ' +
                                                         form.get('start_time', None), '%m/%d/%Y %H:%M')
        except:
            discount_code.valid_from = None

        try:
            discount_code.valid_till = datetime.strptime(form.get('end_date', None) + ' ' +
                                                         form.get('end_time', None), '%m/%d/%Y %H:%M')
        except:
            discount_code.valid_till = None

        discount_code.tickets = ",".join(form.getlist('tickets[]'))

        save_to_db(discount_code)

        return discount_code
    def create_edit_discount_code(form, discount_code_id=None):
        if not discount_code_id:
            discount_code = DiscountCode()
        else:
            discount_code = InvoicingManager.get_discount_code(discount_code_id)
        discount_code.code = form.get('code')
        discount_code.value = form.get('value')
        discount_code.type = 'percent'
        discount_code.max_quantity = form.get('max_quantity', None)
        discount_code.tickets_number = form.get('tickets_number')
        discount_code.used_for = EVENT
        discount_code.marketer_id = form.get('marketer')
        discount_code.is_active = form.get('status', 'in_active') == 'active'

        if discount_code.max_quantity == "":
            discount_code.max_quantity = None

        try:
            discount_code.valid_from = datetime.strptime(form.get('start_date', None) + ' ' +
                                                         form.get('start_time', None), '%m/%d/%Y %H:%M')
        except:
            discount_code.valid_from = None

        try:
            discount_code.valid_till = datetime.strptime(form.get('end_date', None) + ' ' +
                                                         form.get('end_time', None), '%m/%d/%Y %H:%M')
        except:
            discount_code.valid_till = None

        save_to_db(discount_code)

        return discount_code