Exemplo n.º 1
0
def list_tickets(event_id,
                 purchased_after=None,
                 eventpart_id=None,
                 tickettype_id=None):
    """
    Retrieves a list of all tickets registered to an event.
    
    Args:
        event_id:
            Filter by event.
        eventpart_id:
            Filter by eventpart.
        tickettype_id:
            Filter by tickettype.
    
    Returns:
        ???
    
    Raises:
        EventNotFoundError
        EventPartNotFoundError
        TicketTypeNotFoundError
    """
    event = lookup_event_by_id(event_id)
    # lookup tickets
    tickets = Session.query(Ticket).join(TicketOrder)\
                     .options(subqueryload('scans', Ticket.user))
    # filter by tickettype
    if tickettype_id:
        lookup_tickettype_by_id(tickettype_id)
        tickets = tickets.filter(TicketOrder.ticket_type_id == tickettype_id)
    # filter by creation date
    tickets = tickets.join(TicketType)
    if purchased_after:
        tickets = tickets.filter(Ticket.created_at >= purchased_after)
    tickets = tickets.join(TicketTypeEventPartAssociation)
    # filter by eventpart
    if eventpart_id:
        lookup_eventpart_by_id(eventpart_id)
        tickets = tickets.filter(
            TicketTypeEventPartAssociation.eventpart_id == eventpart_id)
    tickets = tickets.join(EventPart)
    # filter by event
    tickets = tickets.filter(EventPart.event_id == event_id)
    return tickets.all()
Exemplo n.º 2
0
def from_eventpart(client_id, eventpart_id, include_private=False):
    """ Returns tickettypes connected to the eventpart. By default it only returns public tickettypes """
    if client_id:
        require_eventpart_owner(client_id, eventpart_id)
    eventpart = lookup_eventpart_by_id(eventpart_id)

    tickettypes = eventpart.get_ticket_types(
        include_inactive=include_private,
        include_if_sales_finished=include_private)
    return map(lambda tt: tickettype_to_dict(tt, include_availability=True),
               tickettypes)
Exemplo n.º 3
0
def require_eventpart_of_event(eventpart_id, event_id):
    """Checks if the eventpart belongs to the event."""
    try:
        eventpart = lookup_eventpart_by_id(eventpart_id)
        event = lookup_event_by_id(event_id)
    except EventPartNotFoundError:
        raise PermissionDenied("The eventpart you requested does not exist.")
    except EventNotFoundError:
        raise PermissionDenied("The event you requested does not exist.")
    # validate if the eventpart is connected to the event
    if eventpart.event.id != event.id:
        raise PermissionDenied("The eventpart is not connected to the event.")
Exemplo n.º 4
0
def require_eventpart_owner(client_id, eventpart_id):
    """Checks if the account of the requesting client id is the event owner.
    """
    try:
        account = lookup_account_for_client(client_id)
        eventpart = lookup_eventpart_by_id(eventpart_id)
        event = lookup_event_by_id(eventpart.event_id)
    except AccountNotFoundError:
        raise PermissionDenied("Your client is not connected to an account.")
    except EventNotFoundError:
        raise PermissionDenied("The eventpart you requested does not exist.")
    # validate if event is connected to account
    if event.account_id != account.id:
        raise PermissionDenied("You are not the owner of the eventpart.")
Exemplo n.º 5
0
def eventpart_update(client_id, eventpart_id, eventpart_info):
    """
    Entrypoint for updating eventpart information.
    
    Args:
        eventpart_id:
            Id of the event to update
        eventpart_info:
            Dictionary containing information that requires updating. The 
            dictionary can contain the following information:
                - name: name identifying the eventpart
                - starts_on: utc timestamp when the eventpart starts
                - minutes: number of minutes until the eventpart ends
                - venue_id: id of the venue object
                - description: localization dictionary to specify a text and its language
    """    
    # check if activation is required
    if client_id:
        require_eventpart_owner(client_id, eventpart_id)
        
    eventpart = lookup_eventpart_by_id(eventpart_id)
    
    for (key, value) in eventpart_info.iteritems():
        if value is None:
            continue # skip unset fields
        elif key == "name":
            eventpart.name = value
        elif key == "starts_on":
            eventpart.starts_on = datetime.datetime.fromtimestamp(value)
        elif key == "minutes":
            minutes = datetime.timedelta(minutes=value)
            # add minutes to starts_on if available
            if eventpart_info.get('starts_on') is not None:
                eventpart.ends_on = datetime.datetime.fromtimestamp(eventpart_info.get('starts_on'))\
                                    + minutes  
            # extend existing starts_on time
            else:
                eventpart.ends_on = eventpart.starts_on + minutes
        elif key == "venue_id":
            lookup_venue_by_id(value)
            eventpart.venue_id = value
        elif key == "description":
            eventpart.set_description(value.get('text'), value.get('language'))
            
    return eventpart_to_dict(eventpart)
Exemplo n.º 6
0
def tickettype_create(client_id,
                      tickettype_info,
                      event_id=None,
                      eventpart_id=None):
    """ Creates a tickettype and links it to either an event or eventpart"""
    # Set defaults for missing values
    name = tickettype_info.get('name')
    description = tickettype_info.get('description')
    price = tickettype_info.get('price') or defaults.TICKETTYPE_PRICE
    currency = tickettype_info.get('currency') or defaults.TICKETTYPE_CURRENCY
    units = tickettype_info.get('units') or defaults.TICKETTYPE_AMOUNT
    min_order = tickettype_info.get(
        'minimum_order') or defaults.TICKETTYPE_MIN_ORDER
    max_order = tickettype_info.get(
        'maximum_order') or defaults.TICKETTYPE_MAX_ORDER

    sales_start = tickettype_info.get('sales_start')
    sales_end = tickettype_info.get('sales_start')

    if event_id is None and eventpart_id is None:
        raise ex.TickeeError("eventpart_id or event_id required.")

    # price must not be less than zero
    if price < 0:
        raise ex.InvalidPriceError("The price must be 0 or more.")
    # units must not be less than zero
    if units < 0:
        raise ex.InvalidAmountError(
            "The quantity of tickets must be 0 or more.")
    # minimum order must not be less than zero
    if min_order and min_order < 0:
        raise ex.InvalidAmountError(
            "The minimum order limit must be 1 or more.")
    # maximum order must not be less than minimum order
    if max_order and max_order < min_order:
        raise ex.InvalidAmountError(
            "The maximum order limit must be equal or more than the minimum limit."
        )

    # decide on sales start/end times
    if event_id:
        if client_id is not None:
            require_event_owner(client_id, event_id)
        event = lookup_event_by_id(event_id)
        default_sale_start = event.get_start_date()
        default_sale_end = event.get_end_date()
    elif eventpart_id:
        if client_id is not None:
            require_eventpart_owner(client_id, eventpart_id)
        eventpart = lookup_eventpart_by_id(eventpart_id)
        default_sale_start = eventpart.starts_on
        default_sale_end = eventpart.ends_on
    else:
        raise ex.EventPartNotFoundError(
            'Tickettype needs to be connect to either an event or eventpart.')

    if sales_start is None:
        sales_start = default_sale_start
    else:
        sales_start = datetime.datetime.utcfromtimestamp(int(sales_start))

    if sales_end is None:
        sales_end = default_sale_end
    else:
        sales_end = datetime.datetime.utcfromtimestamp(int(sales_end))

    # create ticket type
    tickettype = create_tickettype(price, units, currency, name, None,
                                   min_order, max_order, sales_start,
                                   sales_end)

    # set description
    if description is not None:
        tickettype.set_description(description.get('text'),
                                   description.get('language'))

    # link new tickettype to eventpart / event
    if event_id:
        link_tickettype_to_event(tickettype, event)

    elif eventpart_id:
        link_tickettype_to_eventpart(tickettype, eventpart)

    return tickettype_to_dict2(tickettype)
Exemplo n.º 7
0
def eventpart_details(client_id, eventpart_id):
    """Returns information of the eventpart"""
    eventpart = lookup_eventpart_by_id(eventpart_id)
    if client_id is not None:
        require_eventpart_owner(client_id, eventpart_id)
    return eventpart_to_dict(eventpart)
Exemplo n.º 8
0
def eventparts_delete(client_id, eventpart_id):
    """ Deletes an eventpart """
    eventpart = lookup_eventpart_by_id(eventpart_id)
    delete_eventpart(eventpart)