Example #1
0
def _workshops_get(var=None):
    """
        Returns upcoming workshops as XML or JSON depending on the extension used
        Variables required:
        - user: OpenStudio API user
        - key: Key for OpenStudio API user
    """
    from openstudio.os_workshop import Workshop

    ws = WorkshopSchedule(TODAY_LOCAL,
                          filter_only_public=True)
    rows = ws.get_workshops_rows()

    workshops = []
    for i, row in enumerate(rows):
        repr_row = list(rows[i:i + 1].render())[0]

        workshop = Workshop(row.workshops.id)

        thumblarge_url = _get_url_image(row.workshops.thumblarge)
        thumbsmall_url = _get_url_image(row.workshops.thumbsmall)
        picture_url = _get_url_image(row.workshops.picture)

        teacher = _workshop_get_teacher(row.workshops.auth_teacher_id)
        teacher2 = _workshop_get_teacher(row.workshops.auth_teacher_id2)

        data = {
            'id': row.workshops.id,
            'Name': row.workshops.Name,
            'Tagline': row.workshops.Tagline,
            'Startdate': row.workshops.Startdate,
            'Enddate': row.workshops.Enddate,
            'Starttime': row.workshops.Starttime,
            'Endtime': row.workshops.Endtime,
            'LevelID': row.workshops.school_levels_id,
            'Level': repr_row.workshops.school_levels_id,
            'LocationID': row.workshops.school_locations_id,
            'Location': repr_row.workshops.school_locations_id,
            'Teacher': teacher,
            'Teacher2': teacher2,
            'Preview': repr_row.workshops.Preview,
            'Description': repr_row.workshops.Description,
            'Price': workshop.get_full_workshop_price(),
            'LinkThumbLarge': thumblarge_url,
            'LinkThumbSmall': thumbsmall_url,
            'LinkImage': picture_url,
            'LinkShop': workshop_get_url_shop(row.workshops.id)
        }

        workshops.append(data)


    return dict(data=workshops)
Example #2
0
def workshop_get():
    """
        Returns workshop as XML or JSON depending on the extension used
        Variables required:
        - user: OpenStudio API user
        - key: Key for OpenStudio API user
        - id: Workshops id
    """
    # forget session
    session.forget(response)

    # check extension
    result = call_check_extension()
    if result['error']:
        return result['error_msg']
    else:
        response.view = result['view']

    # check vars
    try:
        user = request.vars['user']
        key = request.vars['key']
    except:
        return T(
            "Missing value: user and key are required values, one or more was missing in your request. "
        )

    # check auth
    auth_result = do_auth(user, key)
    if not auth_result['authenticated']:
        return auth_result['message']

    wsID = request.vars['id']
    workshop = Workshop(wsID)

    teacher = _workshop_get_teacher(workshop.auth_teacher_id)
    teacher2 = _workshop_get_teacher(workshop.auth_teacher_id2)

    # Check if the workshop is allowed over the API / in the shop
    if not workshop.PublicWorkshop:
        return 'Not found'

    # Ok, return stuff
    shop_url = workshop_get_url_shop(wsID)
    thumblarge_url = _get_url_image(workshop.thumblarge)
    thumbsmall_url = _get_url_image(workshop.thumbsmall)
    picture_url = _get_url_image(workshop.picture)

    activities = []
    rows = workshop.get_activities()
    for i, row in enumerate(rows):
        repr_row = list(rows[i:i + 1].render())[0]

        activity = {
            'id': row.id,
            'Name': row.Activity,
            'Date': row.Activitydate,
            'LocationID': row.school_locations_id,
            'Location': repr_row.school_locations_id,
            'Starttime': repr_row.Starttime,
            'Endtime': repr_row.Endtime,
            'TeacherID': row.auth_teacher_id,
            'Teacher': repr_row.auth_teacher_id,
            'TeacherID2': row.auth_teacher_id2,
            'Teacher2': repr_row.auth_teacher_id2,
        }

        activities.append(activity)

    tickets = []
    rows = workshop.get_products(filter_public=True)
    for i, row in enumerate(rows):
        link_shop = URL('shop',
                        'event_add_to_cart',
                        vars={'wspID': row.id},
                        host=True,
                        scheme=True,
                        extension='')

        ticket = {
            'Name': row.Name,
            'Price': row.Price,
            'Description': row.Description,
            'LinkAddToCart': link_shop,
            'ExternalShopURL': row.ExternalShopURL,
            'AddToCartText': row.AddToCartText,
            'DonationBased': row.Donation
        }
        tickets.append(ticket)

    tickets = []
    p_rows = workshop.get_products()
    for i, product in enumerate(p_rows):
        if not product.PublicProduct:
            continue

        included_activities = []
        workshop_product = WorkshopProduct(product.id)
        for j, activity in enumerate(workshop_product.get_activities()):
            included_activities.append(activity.id)

        ticket = {
            'Name': product.Name,
            'Price': product.Price,
            'Donation': product.Donation,
            'IncludedActivities': included_activities
        }
        tickets.append(ticket)

    workshop = {
        'id': workshop.wsID,
        'Name': workshop.Name,
        'Tagline': workshop.Tagline,
        'Startdate': workshop.Startdate,
        'Enddate': workshop.Enddate,
        'Starttime': workshop.Starttime,
        'Endtime': workshop.Endtime,
        'LevelID': workshop.school_levels_id,
        'Level': workshop.school_level,
        'LocationID': workshop.school_locations_id,
        'Location': workshop.school_location,
        'Teacher': teacher,
        'Teacher2': teacher2,
        'Preview': workshop.Preview,
        'Description': workshop.Description,
        'Price': workshop.get_full_workshop_price(),
        'Tickets': tickets,
        'LinkThumbLarge': thumblarge_url,
        'LinkThumbSmall': thumbsmall_url,
        'LinkImage': picture_url,
        'LinkShop': workshop_get_url_shop(workshop.wsID),
        'Activities': activities,
        'Tickets': tickets,
    }

    return dict(data=workshop)