Exemple #1
0
def create_user(email, password):
    """
    Entrypoint for creating new users.
    
    Args:
        email:
            Personal email address of the user
        password:
            Password of the user.
            
    Returns:
        A dictionary containing the information of the newly created user
        including his identifier. A ``created`` key-value pair is added 
        indicating the success of the attempt. For example:
        
        {'created': True,
         'user': {"id": 42, 
                  "email": "*****@*****.**"}}
         
        The dictionary will only contain the created key if the attempt was not
        successful:
        
        {'created': False}
    """
    um = logic.UserManager()
    try:
        # validate if email contains actually a valid email address:
        validate_email(email)
        # create account
        user = um.create_user(email)
        if password:
            user.set_password(password)
        else:
            user.reset()
    except ex.TickeeError as e:
        transaction.abort()
        # build failed result
        return marshalling.error(e)
    except ValidationError as e:
        transaction.abort()
        return marshalling.error(e)
    else:
        user_info = marshalling.user_to_dict(user)
        transaction.commit()
        # build success result
        result = marshalling.created_success_dict.copy()
        result['user'] = user_info
        return result
Exemple #2
0
def create_location(requestor_id, location_name, latlng=None, address_dict=None,
                    account_id=None):
    """
    Handles the creation of a ``Venue`` and its ``Address`` and returns 
    the result.
    
    Args:
        requestor_id:
            Name of the OAuth2Client that requested the application.
        location_name:
            Name of the location
        latlng (optional):
            Lattitude and longtitude of location
        address_dict (optional)
            Dictionary containing address data.
            Should contain the following keys: 
                street_line1, street_line2, postal_code, city, country
                
    Returns:
        TODO: documentation
    """
    vm = logic.VenueManager()
    sm = logic.SecurityManager()
    # create venue
    try:
        if not account_id:
            account = sm.lookup_account_for_client(requestor_id)
            account_id = account.id
        venue = vm.create_venue(location_name)
        venue.created_by = account_id
    except ex.TickeeError, e:
        transaction.abort()
        return marshalling.error(e)
Exemple #3
0
def add_to_order(client_id, order_key, user_id, tickettype_id, amount):
    """
    Adds a request for an amount of tickets to an order.
    
    Args:
        client_id:
            Id of the requesting client
        order_key:
            Key of the order
        tickettype_id:
            Id of the ticket type to order
        amount:
            Amount of units to order.
            
    Returns:
        Dictionary containing an "added" field with stating that the ticket 
        was added to the order as well as an "order_key" used for checkout
        purposes.
    """
    # Security
    om.timeout_sessions(600)
    try:
        # assert permission to order tickettype
        require_tickettype_owner(client_id, tickettype_id)
        # create order if not yet available
        if not order_key:
            order = om.start_order(user_id)
            order_key = order.order_key
        # add tickets to order
        om.add_tickets(order_key, tickettype_id, amount)
    except ex.TickeeError, e:
        transaction.abort()
        return marshalling.error(e)
Exemple #4
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)
Exemple #5
0
def user_info(client_id, email):
    """
    Returns information about the user and his orders.
    """
    um = logic.UserManager()
    try:
        user = um.lookup_user_by_email(email)
        orders = om.get_orders_of_user(user.id)
    except ex.TickeeError as e:
        transaction.abort()
        return marshalling.error(e)
    except Exception as e:
        transaction.abort()
        return marshalling.internal_error(e)
    else:
        result = dict(first_name=user.first_name,
                      last_name=user.last_name,
                      email=user.email,
                      orders=map(lambda o: dict(id=o.id,
                                                tickets=map(lambda t: marshalling.ticket_to_dict(t, include_scanned=True,
                                                                                                 include_user=False), 
                                                            o.get_tickets()),
                                                status=o.status,
                                                date=marshalling.date(o.session_start)), 
                                 orders))
        return result
Exemple #6
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)
Exemple #7
0
def create_event(oauth_client_id,
                 event_name,
                 venue_id=None,
                 price=None,
                 units=None,
                 currency="EUR",
                 account_id=None):
    """
    Entrypoint for creating an event and returning its information back as a
    dictionary.
    
    Args:
        oauth_client_id
            The id of the oauth_client who will organize the event. The event 
            will be created for the account owning this client.
        event_name
            The name of the event
        venue_id
            The id of the venue object where this event will be held
        price
            Ticket price
        units
            Amount of tickets to be sold
        currency
            Currency of the price
            
    Returns:
        A dictionary containing the information of the newly created event
        including its identifier. A ``created`` key-value pair is added 
        indicating the success of the attempt. For example:
        
        {'created': True,
         'event': {"id": 42, 
                   "name": "Tickee Event"}
        }
         
        The dictionary will only contain the created key if the attempt was not
        successful:
        
        {'created': False}
    """
    em = logic.EventManager()
    tm = logic.TicketManager()
    sm = logic.SecurityManager()
    # create event
    try:
        if account_id is None:
            account = sm.lookup_account_for_client(oauth_client_id)
            account_id = account.id
        event = em.start_event(account_id, event_name)
        # add default eventpart
        event.venue_id = venue_id
        eventpart = em.add_eventpart(event.id, venue_id=venue_id)
        # add default ticket type
        tm.create_ticket_type(eventpart.id, price, units, currency=currency)
    except ex.TickeeError, e:
        transaction.abort()
        return marshalling.error(e)
Exemple #8
0
def start_order_session(user_id, application_key):
    """
    Starts a new order session or retrieves one that was still active.
    
    Args:
        user_id: 
            Id of the user to start a session for.
        application_key:
            Id of the application requesting the information.
    """
    try:
        # start an order or get current one.
        order = om.start_order(user_id)
    except ex.UserNotFoundError, e:
        blogger.error("Order session failed to start for user %s" % user_id)
        tlogger.error("start_order_session failure: %s" % e)
        transaction.abort()
        # build failed result
        return marshalling.error(e.error())
Exemple #9
0
def create_account(user_id, account_name, email):
    """
    Entrypoint for creating an account and returning its information back as a
    dictionary. 
    
    Args:
        user_id:
            Id of the user who will own the account
        account_name
            Name of the account to create
        email
            Email of the account. This should be a general email address
            and not a user-specific one.

    Returns:
        A dictionary containing the information of the newly created account
        including its identifier. A ``created`` key-value pair is added 
        indicating the success of the attempt. For example:
        
        {'created': True,
         'account': {"id": 42, "name": "Tickee", "email": "*****@*****.**"}}
         
        The dictionary will only contain the created key if the attempt was not
        successful:
        
        {'created': False}
    """
    am = logic.AccountManager()
    sm = logic.SecurityManager()
    try:
        # find user
        um = logic.UserManager()
        user = um.lookup_user_by_id(user_id)
        # create account
        account = am.create_account(account_name, email)
        # create default oauth2 client
        client = sm.create_oauth_client()
        account.client_id = client.id
    except ex.TickeeError, e:
        transaction.abort()
        # build failed result
        return marshalling.error(e)
Exemple #10
0
def account_info(oauth_client_id, account_id, include_events=False):
    """
    Entrypoint for viewing account information. If the account_id contains None,
    it will return the info of the account attached to the oauth client.
    
    Args:
        oauth_client_id
            Id of the OAuth2 client asking for the information.
        account_id
            The id of the account to return
        include_events
            If specified also returns a list of events owned by the account.
        
    Returns:
        A dictionary containing the information of the account
        including its identifier.
        
        {'account': 
            {"id": 42, 
             "name": "Tickee", 
             "email": "*****@*****.**",
             "events": [{'id': 1, 'name': 'Tickee Event'}, .. ]}}
         
        The dictionary will contain a null account if no account found:
        
        {'account': null}
    """
    am = logic.AccountManager()
    sm = logic.SecurityManager()
    try:
        if account_id:
            account = am.lookup_account_by_id(account_id)
        else:
            account = sm.lookup_account_for_client(oauth_client_id)
    except ex.TickeeError as e:
        return marshalling.error(e)
    else:
        return dict(
            account=marshalling.account_to_dict(account, include_events))
Exemple #11
0
def scan_ticket(client_id, ticket_code, scan_datetime, list_timestamp, 
                list_event_id, list_eventpart_id=None, list_tickettype_id=None, extra_info={}):
    """
    Entrypoint for marking tickets as scanned and returning new updates to the
    attendees list
    
    Args:
        ticket_code:
            Hex string representing the ticket id that was scanned in.
        scan_datetime:
            Datetime the ticket was scanned in 
        list_timestamp:
            Datetime containing the time the attendees list was last updated
        list_event_id:
            Id of the event to return updates from
        list_eventpart_id (optinal):
            Id of the eventpart to return updates from
        list_tickettype_id (optional):
            Id of the tickettype to return updates from
        extra_info (optional):
            Dictionary containing additional information of the device.
    """
    
    tm = logic.TicketManager()
    # add ticket as scanned
    try:
        scan_datetime = datetime.datetime.strptime(scan_datetime, "%Y-%m-%dT%H:%M:%S")
        list_timestamp = datetime.datetime.fromtimestamp(float(list_timestamp))
        # lookup ticket
        ticket = tm.lookup_ticket_by_code(ticket_code)
        # assert permission to scan ticket
        require_tickettype_owner(client_id, ticket.get_tickettype().id)
        # scan ticket
        tm.scan_ticket(ticket_code, scan_datetime, extra_info)
    except ex.TickeeError, e:
        transaction.abort()
        result = marshalling.error(e)
Exemple #12
0
def order_info(client_id, order_id):
    """
    Retrieves order information
    """
    try:
        order = om.lookup_order_by_id(order_id)
    except ex.TickeeError as e:
        transaction.abort()
        return marshalling.error(e)
    except Exception as e:
        transaction.abort()
        return marshalling.internal_error(e)
    else:
        result = dict(id=order.id,
                      status=order.status,
                      user=order.user.get_full_name(),
                      user_mail=order.user.email,
                      tickets=map(
                          lambda t: marshalling.ticket_to_dict(
                              t, include_scanned=True, include_user=False),
                          order.get_tickets()))
        if order.status == PURCHASED:
            result['purchased_on'] = marshalling.date(order.purchased_on)
        return result
Exemple #13
0
            account = sm.lookup_account_for_client(requestor_id)
            account_id = account.id
        venue = vm.create_venue(location_name)
        venue.created_by = account_id
    except ex.TickeeError, e:
        transaction.abort()
        return marshalling.error(e)
    else:
        venue_info = marshalling.venue_to_dict(venue)
    # create address if available
    if address_dict:
        try:
            address = vm.create_address(**address_dict)
        except ex.TickeeError, e:
            transaction.abort()
            return marshalling.error(e)
        else:
            venue.address = address
            venue_info = marshalling.venue_to_dict(venue, include_address=True)
            
    transaction.commit()
    # build result
    result = marshalling.created_success_dict.copy()
    result['location'] = venue_info
    return result


@task
def show_location(location_id, use_address=True):
    """
    Returns information about the requested location.