Exemplo n.º 1
0
def orders(request):
    message = ''
    units = ''
    address = ''
    if 'form.submitted' in request.params:
        if 'id' in request.params:
            order_id = int(request.params['id'])
            state = int(request.params['state'])

            message = order_service.update_order_state(order_id, state,
                                                       request)
        else:
            message = order_service.create_order(request)
            if message != '':
                units = request.params['units']
                address = request.params['address']

    is_admin = check_permission('admin', request)
    if is_admin:
        pending_orders = order_service.get_all_pending_orders()
        processed_orders = order_service.get_all_processed_orders()
    else:
        pending_orders = order_service.get_all_pending_orders(
            get_user_login(request))
        processed_orders = order_service.get_all_processed_orders(
            get_user_login(request))

    return dict(
        message=message,
        units=units,
        address=address,
        pending_orders=pending_orders,
        processed_orders=processed_orders,
        is_admin=is_admin,
        )
Exemplo n.º 2
0
def update_profile(request):
    message = ''

    if 'form.submitted' in request.params:
        message = user_service.update_user(request)
        login = request.params['login']
        name = request.params['name']
        email = request.params['email']
        phone = request.params['phone']
        user_id = request.params['id']
    else:
        login = get_user_login(request)
        user = user_service.get_user_by_login(login)
        user_id = user.id
        name = user.name
        email = user.email
        phone = user.phone

    return dict(
        message=message,
        id=user_id,
        login=login,
        name=name,
        email=email,
        phone=phone,
        )
Exemplo n.º 3
0
def viewer(request):
    is_admin = check_permission('admin', request)
    n_new_orders = 0
    if is_admin:
        n_new_orders = len(order_service.get_all_unprocessed_orders())
    else:
        n_new_orders = len(
            order_service.get_all_unprocessed_orders(get_user_login(request))
        )
    return dict(project=u'Ondestán',
                can_edit=check_permission('edit', request),
                is_admin=is_admin,
                orders_msg=n_new_orders)
Exemplo n.º 4
0
def json_animals(request):
    geojson = []
    if (check_permission('admin', request)):
        animals = animal_service.get_all_animals()
        if animals != None:
            logger.debug("Found " + str(len(animals)) +
                         " animals for all users")
            for animal in animals:
                if len(animal.positions) > 0:
                    popup_str = animal.name + \
                                " (" + str(animal.positions[0].battery)\
                                + "%), property of " + animal.user.name + \
                                " (" + animal.user.login + ")"
                    geojson.append({
                        "type": "Feature",
                        "properties": {
                            "name": animal.name,
                            "battery": animal.positions[0].battery,
                            "owner": animal.user.login,
                            "outside": animal.positions[0].outside,
                            "popup": popup_str
                        },
                        "geometry": eval(animal.positions[0].geojson)
                    })
        else:
            logger.debug("Found no animals for any user")
    else:
        login = get_user_login(request)
        animals = animal_service.get_all_animals(login)
        if animals != None:
            logger.debug("Found " + str(len(animals)) +
                         " animals for user " + login)
            for animal in animals:
                if len(animal.positions) > 0:
                    popup_str = animal.name + " (" + str(animal.positions[0].
                        battery) + "%)"
                    geojson.append({
                        "type": "Feature",
                        "properties": {
                            "name": animal.name,
                            "battery": animal.positions[0].battery,
                            "owner": animal.user.login,
                            "outside": animal.positions[0].outside,
                            "popup": popup_str
                        },
                        "geometry": eval(animal.positions[0].geojson)
                    })
        else:
            logger.debug("Found no animals for user " + login)
    return geojson
Exemplo n.º 5
0
def create_order(request):
    # localizer = get_localizer(request)

    login = get_user_login(request)
    units = int(request.params['units'])
    address = request.params['address']
    user = User().queryObject().filter(User.login == login).scalar()
    if (user != None):
        order = Order()
        order.units = units
        order.address = address
        order.user_id = user.id
        order.save()

        update_order_state(order.id, Order_state._STATES[0], request)

    return ''
Exemplo n.º 6
0
def json_plots(request):
    geojson = []
    if (check_permission('admin', request)):
        plots = plot_service.get_all_plots()
        if plots != None:
            logger.debug("Found " + str(len(plots)) + " plots for all users")
            for plot in plots:
                popup_str = plot.name + \
                            " property of " + plot.user.name + \
                            " (" + plot.user.login + ")"
                geojson.append({
                    "type": "Feature",
                    "properties": {
                        "name": plot.name,
                        "owner": plot.user.login,
                        "popup": popup_str
                    },
                    "geometry": eval(plot.geojson)
                })
        else:
            logger.debug("Found no plots for any user")
    else:
        login = get_user_login(request)
        plots = plot_service.get_all_plots(login)
        if plots != None:
            logger.debug("Found " + str(len(plots)) + " plots " + \
                         "for user " + login)
            for plot in plots:
                geojson.append({
                    "type": "Feature",
                    "properties": {
                        "name": plot.name,
                        "owner": plot.user.login,
                        "popup": plot.name
                    },
                    "geometry": eval(plot.geojson)
                })
        else:
            logger.debug("Found no plots for user " + login)
    return geojson