Exemple #1
0
def update_profile(request):
    notifications = []

    if 'form.submitted' in request.params:
        if 'email' in request.params:
            notifications.append(user_service.update_user(request))
            name = request.params['name']
            email = request.params['email']
            phone = request.params['phone']
            user_id = request.params['id']
            headers = remember(request, email)
            request.response.headerlist.extend(headers)

        else:
            if 'password' in request.params:
                notifications.append(user_service.update_password(request))
            user = user_service.get_user_by_email(get_user_email(request))
            user_id = user.id
            name = user.name
            email = user.email
            phone = user.phone
    else:
        user = user_service.get_user_by_email(get_user_email(request))
        user_id = user.id
        name = user.name
        email = user.email
        phone = user.phone

    return dict(notifications=notifications,
                id=user_id,
                name=name,
                email=email,
                phone=phone)
Exemple #2
0
def delete_plot(request):
    plot_id = request.GET['id']
    if check_permission('admin', request):
        return {'success': plot_service.delete_plot(plot_id)}
    else:
        user = user_service.get_user_by_email(get_user_email(request))
        return {'success': plot_service.delete_plot(plot_id, user.id)}
Exemple #3
0
def update_plot_geom(request):
    points = []
    i = 0
    while ('x' + str(i)) in request.GET and ('y' + str(i)) in request.GET:
        points.append([
            float(request.GET['x' + str(i)]),
            float(request.GET['y' + str(i)])
        ])
        i += 1
    plot_id = request.GET['id']
    if check_permission('admin', request):
        plot = plot_service.update_plot_geom(points, plot_id)
    else:
        user = user_service.get_user_by_email(get_user_email(request))
        plot = plot_service.update_plot_geom(points, plot_id, user.id)

    if plot == None:
        return {'success': False}
    else:
        feature = {
            "type": "Feature",
            "properties": {
                "id": plot_id,
                "name": plot.name,
                "owner": plot.user.email,
                "popup": plot.name
            },
            "geometry": eval(plot.geojson)
        }
        return {'success': True, 'feature': feature}
Exemple #4
0
def create_plot(request):
    points = []
    i = 0
    while ('x' + str(i)) in request.GET and ('y' + str(i)) in request.GET:
        points.append([
            float(request.GET['x' + str(i)]),
            float(request.GET['y' + str(i)])
        ])
        i += 1

    if 'name' in request.GET:
        name = request.GET['name']
    else:
        name = ''
    if 'userid' in request.GET and check_permission('admin', request):
        userid = request.GET['userid']
    else:
        userid = user_service.get_user_by_email(get_user_email(request)).id

    plot = plot_service.create_plot(points, name, userid)

    if plot == None:
        return {'success': False}
    else:
        feature = {
            "type": "Feature",
            "properties": {
                "id": plot.id,
                "name": plot.name,
                "owner": plot.user.email,
                "popup": plot.name
            },
            "geometry": eval(plot.geojson)
        }
        return {'success': True, 'feature': feature}
Exemple #5
0
def plot_manager(request):
    user = user_service.get_user_by_email(get_user_email(request))
    is_admin = check_permission('admin', request)
    return dict(
        is_admin=is_admin,
        non_admin_users=user_service.get_non_admin_users() if is_admin else [],
        view=user.get_plots_bounding_box_as_json())
Exemple #6
0
def animal_viewer(request):
    user = user_service.get_user_by_email(get_user_email(request))
    view = user.get_animals_bounding_box_as_json()
    return dict(
        view=view if view != None else user.get_plots_bounding_box_as_json(),
        notifications=notification_service.\
            get_new_web_notifications_for_logged_user(request)
    )
Exemple #7
0
def update_animal_name(request):
    if 'name' in request.params and 'id' in request.params:
        if check_permission('admin', request):
            animal_service.update_animal_name(request.params['id'],
                                              request.params['name'])
        else:
            user = user_service.get_user_by_email(get_user_email(request))
            animal_service.update_animal_name(request.params['id'],
                                              request.params['name'], user.id)
    return HTTPFound(location=request.route_url('map'))
Exemple #8
0
def check_email(request):
    if 'email' in request.params:
        email = request.params['email']
        user = user_service.get_user_by_email(email)
        if (user == None):
            return True
        if 'id' in request.params:
            if user.id == int(request.params['id']):
                return True
    localizer = get_localizer(request)
    message_ts = _('email_already_use', domain='Ondestan')
    return localizer.translate(message_ts)
Exemple #9
0
def check_user_email(request):
    if 'email' in request.params:
        email = request.params['email']
        user = user_service.get_user_by_email(email)
        if (user == None):
            return True
        if 'id' in request.params:
            if user.id == int(request.params['id']):
                return True
    localizer = get_localizer(request)
    message_ts = _('user_email_already_use', domain='Ondestan')
    return localizer.translate(message_ts)
Exemple #10
0
def animals_list(request):
    is_admin = check_permission('admin', request)
    if 'form.submitted' in request.params:
        if 'id' in request.params:
            user_id = None if is_admin else user_service.get_user_by_email(
                get_user_email(request)).id
            animal_id = int(request.params['id'])
            plot_id = None if request.params['plot'] == '' or\
                request.params['plot'] == None else int(request.params['plot'])
            animal_service.update_animal_plot(animal_id, plot_id, user_id)
    if is_admin:
        animals = animal_service.get_all_animals()
    else:
        email = get_user_email(request)
        animals = animal_service.get_all_animals(email)

    return dict(
        is_admin=is_admin,
        animals=animals,
    )