def json_api_edit(req_function): """ Wraps view function for an AJAX call which modifies data. """ return do( login_or_401, json_api_call, creates_instance_user, req_function)
def test_visit_marks_boolean_true(self): """assert that any successful view function, when wrapped with the decorator, will mark the associated boolean""" def view(request): return {} wrapped_view = do(mark_user('is_banned'), view) self.assertFalse(self.user.is_banned) view(self.request) self.assertFalse(self.user.is_banned) wrapped_view(self.request) self.assertTrue(self.user.is_banned)
def test_flatpage_marks_boolean_true(self): """like above, but test the flat page redirect in particular, with a freshly created flat page""" view = render_flatpage('/foo/') wrapped_view = do(mark_user('is_banned'), view) fp = FlatPage.objects.create(url='/foo/', content='<p>foo</p>') fp.sites.add(settings.SITE_ID) self.assertFalse(self.user.is_banned) view(self.request) self.assertFalse(self.user.is_banned) wrapped_view(self.request) self.assertTrue(self.user.is_banned)
def test_flatpage_404_does_not_mark(self): """like above, but test the flat page redirect in particular, with a nonexistent flatpage""" view = render_flatpage('/DOESNOTEXIST/') wrapped_view = do( mark_user('is_banned'), view) self.assertFalse(self.user.is_banned) with self.assertRaises(Http404): view(self.request) self.assertFalse(self.user.is_banned) with self.assertRaises(Http404): wrapped_view(self.request) self.requery_user() self.assertFalse(self.user.is_banned)
def test_404_does_not_mark(self): """assert that any failed view function, when wrapped with the decorator, will not mark the associated boolean""" def view(*args, **kwargs): raise Http404() wrapped_view = do( mark_user('is_banned'), view) self.assertFalse(self.user.is_banned) with self.assertRaises(Http404): view(self.request) self.assertFalse(self.user.is_banned) with self.assertRaises(Http404): wrapped_view(self.request) # a wrinkle - the transaction successfully rolled back, so the # database is correct, but the rr-cycle will be in a not-awesome # state unless the user is requeried. for the common use case, # this will not be a problem. self.assertTrue(self.user.is_banned) self.requery_user() self.assertFalse(self.user.is_banned)
from apps.users.views.group import group_list_page from apps.core.decorators import user_must_have_online_training from apps.home.training.decorators import render_flatpage from apps.home.training import views as v from apps.home.training.decorators import mark_user groups_to_follow = route( GET=do(login_required, user_must_have_online_training, mark_user('training_finished_groups_to_follow'), render_template('home/groups_to_follow.html'), group_list_page)) training_list_page = route(GET=do(render_template('home/training.html'), v.training_list_page)) intro_quiz = do(login_required, route(GET=do(render_template('home/quiz_page.html'), v.intro_quiz), POST=do(render_template('home/quiz_complete_page.html'), v.complete_quiz))) training_instructions = route(GET=do( render_template('home/training_instructions.html'),
def modeling_instance_request(view_fn, redirect=True): return do( partial(instance_request, redirect=redirect), requires_permission('modeling'), view_fn)
def _api_call(verb, view_fn): return do(admin_instance_request, require_http_method(verb), view_fn)
do, require_http_method("POST"), instance_request, render_template("otm_comments/partials/flagging.html")) flag_endpoint = _render_flagging_view(flag) unflag_endpoint = _render_flagging_view(unflag) hide_flags_endpoint = _admin_post_do(hide_flags) archive_endpoint = _admin_post_do(archive) unarchive_endpoint = _admin_post_do(unarchive) hide_endpoint = _admin_post_do(hide) show_endpoint = _admin_post_do(show) comments_csv_endpoint = do( require_http_method("GET"), admin_instance_request, json_api_call, queryset_as_exported_csv, comments_csv) comment_moderation_endpoint = do( require_http_method("GET"), admin_instance_request, render_template('otm_comments/moderation.html'), comment_moderation) comment_moderation_partial_endpoint = do( require_http_method("GET"), admin_instance_request, render_template('otm_comments/partials/moderation.html'), comment_moderation)
from django_tinsel.decorators import route, render_template, json_api_call from django_tinsel.utils import decorate as do from apps.core.decorators import (user_must_have_online_training, group_request, group_admin_do) from apps.event import views as v ##################################### # EVENT ROUTES ##################################### events_list_page = route( GET=do( render_template('event/event_list_page.html'), v.events_list_page)) events_list_feed = route(GET=do(json_api_call, v.events_list_feed)) future_events_geojson = route(GET=do(json_api_call, v.future_events_geojson)) ##################################### # GROUP ROUTES ##################################### add_event = group_admin_do(render_template('event/add_event.html'), route(GET=v.add_event_page, POST=v.add_event)) event_detail = do(group_request,
from django.contrib.auth.decorators import login_required from django.views.decorators.http import last_modified from django_tinsel.decorators import route, render_template, json_api_call from django_tinsel.utils import decorate as do from apps.core.decorators import (individual_mapper_do, group_request, census_admin_do, update_with) from apps.survey import views as v from apps.survey.layer_context import get_group_territory_modification_time ##################################### # PROGRESS PAGE ROUTES ##################################### progress_page = route(GET=do(render_template('survey/progress.html'), v.progress_page)) progress_page_blockface_popup = route( GET=do( render_template('survey/partials/progress_page_blockface_popup.html'), v.progress_page_blockface_popup)) group_borders_geojson = do( last_modified(get_group_territory_modification_time), route(GET=json_api_call(v.group_borders_geojson))) group_popup = route(GET=do(group_request, render_template('survey/partials/group_popup.html'), v.group_popup)) #####################################
from manage_treemap.views.udf import (udf_bulk_update, udf_create, udf_list, udf_delete_popup, udf_delete, udf_update_choice, remove_udf_notifications) from manage_treemap.views.user_roles import ( user_roles_list, update_user_roles, create_user_role, remove_invited_user_from_instance) from treemap.decorators import (require_http_method, admin_instance_request, return_400_if_validation_errors) admin_route = lambda **kwargs: admin_instance_request(route(**kwargs)) json_do = partial(do, json_api_call, return_400_if_validation_errors) management = do( require_http_method('GET'), views.management_root) admin_counts = admin_route( GET=do(json_api_call, views.admin_counts) ) site_config = admin_route( GET=do(render_template('manage_treemap/basic.html'), views.site_config_basic_info), PUT=json_do(update_instance_fields_with_validator, views.site_config_validator) ) external_link = admin_route( GET=do(render_template('manage_treemap/link.html'),
# -*- coding: utf-8 -*- from __future__ import print_function from __future__ import unicode_literals from __future__ import division from django_tinsel.decorators import route, render_template from django_tinsel.utils import decorate as do from apps.home import views as v from apps.core.decorators import individual_mapper_do home_page = route(GET=do(render_template('home/home.html'), v.home_page)) about_faq_page = route(GET=do(render_template('home/about_faq.html'), v.about_faq_page)) individual_mapper_instructions = individual_mapper_do( render_template('home/individual_mapper_instructions.html'), v.individual_mapper_instructions) trusted_mapper_request_sent = individual_mapper_do( render_template('home/trusted_mapper_request_sent.html'), v.trusted_mapper_request_sent)
from treemap.views.map_feature import ( render_map_feature_detail, render_map_feature_add, update_map_feature_detail, map_feature_detail, plot_detail, delete_map_feature, map_feature_popup, add_map_feature, map_feature_hash, rotate_map_feature_photo, add_map_feature_photo) add_map_feature_photo_do = partial( do, require_http_method("POST"), login_or_401, instance_request, creates_instance_user, render_template('treemap/partials/photo_carousel.html')) ##################################### # misc content views ##################################### edits_view = do(instance_request, requires_feature('recent_edits_report'), render_template('treemap/edits.html'), edits) index_view = instance_request(index) map_view = do(instance_request, render_template('treemap/map.html'), get_map_view_context) static_page_view = do(instance_request, render_template('treemap/staticpage.html'), static_page) instance_not_available_view = render_template( 'treemap/instance_not_available.html')() landing_view = render_template('base.html')() unsupported_view = render_template('treemap/unsupported.html')()
return {'start_status': 'OK', 'job_id': job.pk} def check_export(request, instance, job_id): job = get_object_or_404(ExportJob, pk=job_id) # if a job has a user, it means the user must # be authenticated so only the job user can # retrieve the export if job.user and job.user != request.user: return { 'status': 'ERROR', 'message': 'Job not initiated by user', 'url': None } else: return { 'status': ExportJob.STATUS_STRINGS[job.status], 'message': ExportJob.STATUS_CHOICES[job.status], 'url': job.get_url_if_ready() } begin_export_endpoint = do(json_api_call, instance_request, requires_feature('exports'), begin_export) check_export_endpoint = do(json_api_call, instance_request, check_export)
udf_delete_popup, udf_delete, udf_update_choice, remove_udf_notifications) from manage_treemap.views.user_roles import (user_roles_list, update_user_roles, create_user_role, remove_invited_user_from_instance) from treemap.decorators import (require_http_method, admin_instance_request, return_400_if_validation_errors, requires_feature) admin_route = lambda **kwargs: admin_instance_request(route(**kwargs)) json_do = partial(do, json_api_call, return_400_if_validation_errors) management = do(require_http_method('GET'), views.management_root) admin_counts = admin_route(GET=do(json_api_call, views.admin_counts)) site_config = admin_route(GET=do(render_template('manage_treemap/basic.html'), views.site_config_basic_info), PUT=json_do(update_instance_fields_with_validator, views.site_config_validator)) external_link = admin_route(GET=do(render_template('manage_treemap/link.html'), views.external_link), PUT=json_do(views.update_external_link)) branding = admin_route(GET=do(render_template('manage_treemap/branding.html'), views.branding), PUT=json_do(update_instance_fields_with_validator,
from __future__ import division from django.contrib.auth.decorators import login_required from django_tinsel.utils import decorate as do from django_tinsel.decorators import route, render_template from apps.login import views as v from apps.login.backends import NycRegistrationView ##################################### # ACCOUNTS ROUTES ##################################### logout = do(v.logout) password_reset = do(v.password_reset) activation_complete = do( login_required, render_template('registration/activation_complete.html'), route(GET=v.activation_complete, POST=v.save_optional_info)) register = NycRegistrationView.as_view() ##################################### # LOGIN ROUTES ##################################### forgot_username = do(
def make_flatpage_route(name): return route(GET=do( login_required, render_flatpage('/%s/' % name)))
def check_export(request, instance, job_id): job = get_object_or_404(ExportJob, pk=job_id) # if a job has a user, it means the user must # be authenticated so only the job user can # retrieve the export if job.user and job.user != request.user: return {'status': 'ERROR', 'message': 'Job not initiated by user', 'url': None} else: return {'status': ExportJob.STATUS_STRINGS[job.status], 'message': ExportJob.STATUS_CHOICES[job.status], 'url': job.get_url_if_ready()} begin_export_endpoint = do( json_api_call, instance_request, requires_feature('exports'), begin_export) check_export_endpoint = do( json_api_call, instance_request, check_export)
plots_closest_to_point_endpoint = instance_api_do(plots_closest_to_point) instances_closest_to_point_endpoint = api_do( instances_closest_to_point) public_instances_endpoint = api_do(public_instances) instance_info_endpoint = instance_api_do( transform_instance_info_response, instance_info) plots_endpoint = instance_api_do( route(GET=get_plot_list, POST=do( login_required, creates_instance_user, update_or_create_plot))) plot_endpoint = instance_api_do( route(GET=get_plot, ELSE=do(login_required, creates_instance_user, route( PUT=update_or_create_plot, DELETE=remove_plot)))) species_list_endpoint = instance_api_do( route(GET=species_list)) user_endpoint = api_do(
logged_in_api_do = partial(do, csrf_exempt, set_api_version, check_signature_and_require_login, json_api_call) plots_closest_to_point_endpoint = instance_api_do(plots_closest_to_point) instances_closest_to_point_endpoint = api_do(instances_closest_to_point) public_instances_endpoint = api_do(public_instances) instance_info_endpoint = instance_api_do(transform_instance_info_response, instance_info) plots_endpoint = instance_api_do( route(GET=get_plot_list, POST=do(login_required, creates_instance_user, transform_plot_update_dict, return_400_if_validation_errors, update_or_create_plot))) plot_endpoint = instance_api_do( route(GET=get_plot, ELSE=do( login_required, creates_instance_user, route(PUT=do(return_400_if_validation_errors, update_or_create_plot), DELETE=remove_plot)))) species_list_endpoint = instance_api_do(route(GET=species_list)) user_endpoint = api_do( route(GET=do(login_required, transform_user_response, user_info), POST=do(transform_user_request, return_400_if_validation_errors,
add_map_feature_photo_do = partial( do, require_http_method("POST"), login_or_401, instance_request, creates_instance_user, render_template('treemap/partials/photo_carousel.html')) ##################################### # misc content views ##################################### edits_page = do( instance_request, requires_feature('recent_edits_report'), render_template('treemap/edits.html'), misc_views.edits) index_page = instance_request(misc_views.index) map_page = do( instance_request, render_template('treemap/map.html'), misc_views.get_map_view_context) static_page = do( instance_request, render_template('treemap/staticpage.html'), misc_views.static_page)
# -*- coding: utf-8 -*- from __future__ import print_function from __future__ import unicode_literals from __future__ import division from django_tinsel.decorators import json_api_call, route from django_tinsel.utils import decorate as do from treemap.decorators import instance_request from stormwater import views polygon_for_point = route(GET=do( instance_request, json_api_call, views.polygon_for_point))
def _api_call(verb, view_fn): return do( admin_instance_request, requires_feature('bulk_upload'), require_http_method(verb), view_fn)
# -*- coding: utf-8 -*- from __future__ import print_function from __future__ import unicode_literals from __future__ import division from django_tinsel.decorators import json_api_call, route from django_tinsel.utils import decorate as do from treemap.decorators import instance_request from stormwater import views polygon_for_point = route( GET=do(instance_request, json_api_call, views.polygon_for_point))
# -*- coding: utf-8 -*- from __future__ import print_function from __future__ import unicode_literals from __future__ import division from django_tinsel.decorators import route, render_template from django_tinsel.utils import decorate as do from apps.home import views as v from apps.core.decorators import individual_mapper_do home_page = route(GET=do(render_template('home/home.html'), v.home_page)) about_faq_page = route(GET=do(render_template('home/about_faq.html'), v.about_faq_page)) retrieve_job_status = do(v.retrieve_job_status) individual_mapper_instructions = individual_mapper_do( render_template('home/individual_mapper_instructions.html'), v.individual_mapper_instructions) trusted_mapper_request_sent = individual_mapper_do( render_template('home/trusted_mapper_request_sent.html'), v.trusted_mapper_request_sent)
return {'start_status': 'OK', 'job_id': job.pk} def check_export(request, instance, job_id): job = get_object_or_404(ExportJob, pk=job_id) # if a job has a user, it means the user must # be authenticated so only the job user can # retrieve the export if job.user and job.user != request.user: return {'status': 'ERROR', 'message': 'Job not initiated by user', 'url': None} else: return {'status': ExportJob.STATUS_STRINGS[job.status], 'message': ExportJob.STATUS_CHOICES[job.status], 'url': job.get_url_if_ready()} begin_export_endpoint = do( json_api_call, instance_request, begin_export) check_export_endpoint = do( json_api_call, instance_request, check_export)
from __future__ import division from django.contrib.auth.decorators import login_required from django_tinsel.decorators import route, render_template, json_api_call from django_tinsel.utils import decorate as do from apps.core.decorators import group_request, group_admin_do, census_admin_do from apps.users.views import group as v render_follow_detail = render_template('groups/partials/follow_detail.html') group_list_page = route(GET=do(render_template('groups/list.html'), v.group_list_page)) group_detail = route(GET=do(group_request, render_template('groups/detail.html'), v.group_detail)) group_edit = group_admin_do(render_template('groups/settings.html'), route(GET=v.edit_group, POST=v.update_group_settings)) follow_group = do( login_required, group_request, route(GET=v.redirect_to_group_detail, POST=do(render_follow_detail, v.follow_group)))
async_csv_export.delay(job.pk, model, query, display_filters) return {'start_status': 'OK', 'job_id': job.pk} def check_export(request, instance, job_id): job = get_object_or_404(ExportJob, pk=job_id) # if a job has a user, it means the user must # be authenticated so only the job user can # retrieve the export if job.user and job.user != request.user: return { 'status': 'ERROR', 'message': 'Job not initiated by user', 'url': None } else: return { 'status': ExportJob.STATUS_STRINGS[job.status], 'message': ExportJob.STATUS_CHOICES[job.status], 'url': job.get_url_if_ready() } begin_export_endpoint = do(json_api_call, instance_request, begin_export) check_export_endpoint = do(json_api_call, instance_request, check_export)
from modeling.views import (get_plans_context, get_modeling_context, add_plan, update_plan, delete_plan, get_plan, run_model, get_boundaries_at_point) def modeling_instance_request(view_fn, redirect=True): return do( partial(instance_request, redirect=redirect), requires_permission('modeling'), view_fn) modeling_view = do( login_required, modeling_instance_request, render_template('modeling/modeling.html'), get_modeling_context) get_boundaries_at_point_view = do( login_or_401, json_api_call, modeling_instance_request, get_boundaries_at_point) run_model_view = do( login_or_401, json_api_call, modeling_instance_request,
import treemap.views.user as user_views import treemap.views.photo as photo_views import treemap.views.tree as tree_views import treemap.views.misc as misc_views import treemap.views.map_feature as feature_views add_map_feature_photo_do = partial( do, require_http_method("POST"), login_or_401, instance_request, creates_instance_user, render_template('treemap/partials/photo_carousel.html')) ##################################### # misc content views ##################################### edits_page = do(instance_request, requires_feature('recent_edits_report'), render_template('treemap/edits.html'), misc_views.edits) index_page = instance_request(misc_views.index) map_page = do(instance_request, render_template('treemap/map.html'), misc_views.get_map_view_context) static_page = do(instance_request, render_template('treemap/staticpage.html'), misc_views.static_page) instance_not_available = render_template( 'treemap/instance_not_available.html')() landing_page = render_template('base.html')() unsupported_page = render_template('treemap/unsupported.html')()
from __future__ import division from django.contrib.auth.decorators import login_required from django_tinsel.decorators import route, render_template from django_tinsel.utils import decorate as do from apps.users.views import user as v from apps.core.decorators import (user_must_have_field_training, user_must_have_online_training) render_user_template = render_template('users/profile.html') render_settings_template = render_template('users/settings.html') user_detail_redirect = do(login_required, route(GET=v.user_detail_redirect)) user_profile_settings = do( login_required, render_settings_template, route(GET=v.profile_settings, POST=v.update_profile_settings)) achievements = do(route(GET=do(render_template('users/achievement.html'), v.achievements_page))) user_detail = route( GET=do(render_user_template, v.user_detail), POST=do(login_required, render_user_template, v.set_privacy)) request_individual_mapper_status = do(