Пример #1
0
def update_event(client_id, event_id, values_dict):
    """
    Entrypoint for updating event information.
    
    Args:
        event_id:
            Id of the event to update
        values_dict:
            Dictionary containing information that requires updating. The 
            dictionary can contain the following information:
                -  active: Boolean for turning the event active or inactive.
    
    Returns:
        A dictionary containing a key "updated" which is True if the update
        was completed successfully and False if not. 
        
        {'updated': True}
        
        Even if nothing was updated, it will return True as a value to 
        indicate there were no problems encountered.
    """
    em = logic.EventManager()
    # check if activation is required
    try:
        require_event_owner(client_id, event_id)
        if values_dict.get('active'):
            # also activate all ticket_types connected to it.
            event = em.lookup_event_by_id(event_id)
            event.publish()
    except ex.TickeeError, e:
        transaction.abort()
        return marshalling.error(e)
Пример #2
0
def list_tickets(client_id, event_id, eventpart_id=None, tickettype_id=None):
    """
    Entrypoint for listing all tickets of an event. If eventpart is sent with,
    it will only show all attendees of the eventpart.
    
    Args:
        client_id:
            Id of the requesting client
        event_id:
            Id of the event
        eventpart_id (optional):
            Id of the eventpart to show.
        tickettype_id (optional):
            Id of the tickettype to show.
            
    Returns:
        A dictionary containing a list of user dictionaries that own a ticket 
        for the event.
    """  
    
    tm = logic.TicketManager()
    try:
        require_event_owner(client_id, event_id)
        tickets = tm.list_tickets(event_id=event_id, 
                                  eventpart_id=eventpart_id, 
                                  tickettype_id=tickettype_id)
    except ex.TickeeError, e:
        transaction.abort()
        return marshalling.error(e)
Пример #3
0
def eventpart_create(client_id, event_id, eventpart_info):
    """Adds an eventpart to the event"""
    
    if client_id is not None:
        require_event_owner(client_id, event_id)
    
    lookup_event_by_id(event_id)
    
    starts_on = datetime.datetime.utcfromtimestamp(eventpart_info.get('starts_on') or defaults.EVENTPART_START)
    minutes = eventpart_info.get('minutes') or defaults.EVENTPART_MINUTES
    ends_on = starts_on + datetime.timedelta(minutes=minutes)
    venue_id = eventpart_info.get('venue_id')
    description = eventpart_info.get('description')
    
    if venue_id is not None:
        lookup_venue_by_id(venue_id)
    
    eventpart = add_eventpart(event_id, 
                              eventpart_info.get('name'), 
                              starts_on, 
                              ends_on, 
                              venue_id)
    if description is not None:
        eventpart.set_description(description.get('text'), description.get('language'))

    return eventpart_to_dict(eventpart)
Пример #4
0
def event_statistics(client_id, event_id):
    """Returns a dictionary containing statistics of all purchased orders."""
    event = lookup_event_by_id(event_id)

    if client_id is not None:
        require_event_owner(client_id, event_id)

    return dict(total_sold=total_tickets_of_event(event),
                total_available=total_available_of_event(event),
                total_orders=orders_of_event(event),
                total_guests=total_guest_tickets_of_event(event))
Пример #5
0
def from_event(client_id, event_id, include_private=False):
    """ Returns tickettypes connected to the event. By default it only returns public tickettypes """
    if client_id:
        require_event_owner(client_id, event_id)
    event = lookup_event_by_id(event_id)

    tickettypes = event.get_ticket_types(
        include_inactive=include_private,
        include_if_sales_finished=include_private)

    return map(lambda tt: tickettype_to_dict(tt, include_availability=True),
               sorted(tickettypes, key=lambda tt: tt.id))
Пример #6
0
def event_update(client_id, event_id, event_info):
    """
    Entrypoint for updating event information.
    
    Args:
        event_id:
            Id of the event to update
        values_dict:
            Dictionary containing information that requires updating. The 
            dictionary can contain the following information:
                -  active: Boolean for turning the event active or inactive.
    
    Returns:
        A dictionary containing a key "updated" which is True if the update
        was completed successfully and False if not. 
        
        {'updated': True}
        
        Even if nothing was updated, it will return True as a value to 
        indicate there were no problems encountered.
    """    
    # check if activation is required
    if client_id:
        require_event_owner(client_id, event_id)
    event = lookup_event_by_id(event_id)
    
    for (key, value) in event_info.iteritems():
        if value is None:
            continue # skip unset fields
        elif key == "active":
            if value:
                event.publish()
            else:
                event.unpublish()
        elif key == "public":
            event.is_public = value  
        elif key == "name":
            event.name = value
        elif key == "url":
            event.url = value
        elif key == "description":
            event.set_description(value.get('text'), value.get('language'))
        elif key == "image_url":
            event.image_url = value
        elif key == "email":
            event.email = value
        elif key == "social":
            event.meta['social'] = value
            
    return event_to_dict(event)
Пример #7
0
def event_tickets(client_id, event_id, 
                  eventpart_id=None, tickettype_id=None, location_id=None, # filters
                  include_scan_state=False, include_user=False):

    if client_id is not None:
        require_event_owner(client_id, event_id)
        
    tickets = list_tickets(event_id=event_id, 
                           eventpart_id=eventpart_id, 
                           tickettype_id=tickettype_id)
    
    result = dict()
    result['tickets'] = map(lambda t: ticket_to_dict(t, include_scanned=include_scan_state,
                                                        include_user=include_user), 
                            tickets)
    result['timestamp'] = int(time.time())
    return result
Пример #8
0
def from_event(client_id, event_id, since=None, ttype=None):
    """ Lists all tickets of an event or show updates if since specified. """
    if client_id is not None:
        require_event_owner(client_id, event_id)

    # show all tickets
    if since is None:
        tickets = list_tickets(event_id, None, None, ttype)

    # show updates since a given timestamp
    else:
        since_datetime = datetime.datetime.utcfromtimestamp(float(since))
        # add updated tickets
        tickets = map(
            lambda ts: ts.ticket,
            list_ticketscans(event_id=event_id, scanned_after=since_datetime))
        # add new tickets
        tickets += list_tickets(event_id=event_id,
                                purchased_after=since_datetime)
        return map(ticket_to_dict, set(tickets))

    return map(
        lambda t: ticket_to_dict(t, include_scanned=True, include_event=False),
        tickets)
Пример #9
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)
Пример #10
0
def eventpart_list(client_id, event_id):
    """Returns a list of all eventparts of the event"""
    event = lookup_event_by_id(event_id)
    if client_id is not None:
        require_event_owner(client_id, event_id)
    return map(lambda ep: eventpart_to_dict(ep, short=True), event.parts)