示例#1
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)
示例#2
0
def single_notification_mail(event_id, user_id):
    """Sends a notification mail informing an attendee to 
    bring his or her tickets"""
    user = lookup_user_by_id(user_id)
    event = lookup_event_by_id(event_id)

    # do not send if user already received one
    if 'received_event_notification' in user.meta:
        blogger.info(
            'skipping event notification since user already has received one.')
        return

    subject = "Reminder: %s (%s)" % (event.name, event.account.name)
    html_content = env.get_template('event_in_48_hours.html').render(
        user=user, event=event)
    plain_content = env.get_template('event_in_48_hours.txt').render(
        user=user, event=event)

    blogger.info('sending event notification mail to user %s' % user_id)
    success = mail_user(user_id, subject, html_content, plain_content)
    #    success = random.choice([True, True, True, True, True, False])
    if not success:
        single_notification_mail.retry(countdown=120 + random.randint(1, 60))
    else:
        user.meta['received_event_notification'] = False
        transaction.commit()
示例#3
0
文件: entrypoints.py 项目: Tickee/BLM
def visitors_of_event(event_id):
    """ Returns a list of users who have attended the events of an account """
    event = lookup_event_by_id(event_id)
    users = Session.query(User).join(Ticket, TicketOrder, TicketType, TicketTypeEventPartAssociation, EventPart)\
                   .filter(EventPart.event_id == event.id)\
                   .distinct(User.id).all()
    return map(user_to_dict, set(users))
示例#4
0
文件: entrypoints.py 项目: Tickee/BLM
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
文件: entrypoints.py 项目: Tickee/BLM
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 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.")
示例#7
0
def require_event_owner(client_id, event_id):
    """Checks if the account of the requesting client id is the event owner.
    """
    try:
        account = lookup_account_for_client(client_id)
        event = lookup_event_by_id(event_id)
    except AccountNotFoundError:
        raise PermissionDenied("Your client is not connected to an account.")
    except EventNotFoundError:
        raise PermissionDenied("The event 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 event.")
示例#8
0
def add_eventpart(event_id, name=None, 
                  start_datetime=None, end_datetime=None, 
                  venue_id=None):
    """
    Adds an ``EventPart`` to the ``Event`` and returns the id.
    
    Args:
        event_id:
            Id of the ``Event`` where the eventpart will be added
        name:
            Name of the eventpart, e.g. "Day 1", "Marquee"
        start_datetime:
            Date and time when the eventpart will start
        end_datetime:
            Date and time when the eventpart will end
        venue_id:
            Id of the ``Venue`` where the eventpart is held
            
    Returns:
        The newly created ``EventPart``
        
    Raises:
        EventNotFoundError
        VenueNotFoundError
    """
    # check if event exists
    lookup_event_by_id(event_id)
    # optionally check if venue exists
    if venue_id:
        lookup_venue_by_id(venue_id)
    # create event part
    eventpart = EventPart(start_datetime, end_datetime, venue_id)
    eventpart.name = name
    Session.add(eventpart)
    # connect event part to event
    eventpart.event_id = event_id
    Session.flush()
    return eventpart
示例#9
0
文件: entrypoints.py 项目: Tickee/BLM
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)
示例#10
0
文件: manager.py 项目: Tickee/BLM
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()
示例#11
0
文件: entrypoints.py 项目: Tickee/BLM
def event_details(client_id, event_id, 
                  include_visitors=False, include_eventparts=False):
    """
    Entrypoint for showing the details of an event.
    
    Args:
        event_id
            The id of the event to show
        include_visitors
            Show all visitors of the event
    """
    event = lookup_event_by_id(int(event_id))
    result = event_to_dict(event, 
                           include_visitors=include_visitors, 
                           include_tickettypes=True,
                           include_handling_fee=True,
                           include_eventparts=include_eventparts)
    return result
示例#12
0
文件: entrypoints.py 项目: Tickee/BLM
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)
示例#13
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)
示例#14
0
文件: entrypoints.py 项目: Tickee/BLM
def event_delete(client_id, event_id):
    """ Deletes an eventpart """
    event = lookup_event_by_id(event_id)
    delete_event(event)
示例#15
0
文件: entrypoints.py 项目: Tickee/BLM
def from_event(client_id, event_id):
    """ Returns a list of venues connected to an event """
    event = lookup_event_by_id(event_id)
    return map(venue_to_dict, list_venues_of_event(event))