def map_feature_detail(request, instance, feature_id, render=False, edit=False): feature = get_map_feature_or_404(feature_id, instance) ctx_fn = (context_dict_for_plot if feature.is_plot else context_dict_for_resource) context = ctx_fn(request, feature, edit=edit) add_map_info_to_context(context, instance) if render: if feature.is_plot: template = 'treemap/plot_detail.html' else: app = feature.__module__.split('.')[0] try: template = '%s/%s_detail.html' % (app, feature.feature_type) get_template(template) except TemplateDoesNotExist: template = 'treemap/resource_detail.html' return render_to_response(template, context, RequestContext(request)) else: return context
def _add_map_feature_photo_helper(request, instance, feature_id): feature = get_map_feature_or_404(feature_id, instance) data = get_image_from_request(request) photo = feature.add_photo(data, request.user) # We must update a rev so that missing photo searches are up to date instance.update_universal_rev() return photo
def delete_map_feature(request, instance, feature_id): feature = get_map_feature_or_404(feature_id, instance) if not map_feature_is_deletable(request.user.get_instance_user(instance), feature): raise ValidationError("map feature not deletable") feature.delete_with_user(request.user) update_hide_at_zoom_after_delete(feature) return {"ok": True}
def delete_map_feature(request, instance, feature_id, type='Plot'): feature = get_map_feature_or_404(feature_id, instance, type) try: feature.delete_with_user(request.user) return {'ok': True} except ValidationError as ve: return "; ".join(ve.messages)
def _add_map_feature_photo_helper(request, instance, feature_id): feature = get_map_feature_or_404(feature_id, instance) data = get_image_from_request(request) photo = feature.add_photo(data, request.user) # We must update a rev so that missing photo searches are up to date instance.update_universal_rev() return photo
def delete_map_feature(request, instance, feature_id, type='Plot'): feature = get_map_feature_or_404(feature_id, instance, type) try: feature.delete_with_user(request.user) return {'ok': True} except ValidationError as ve: return "; ".join(ve.messages)
def add_tree_photo_helper(request, instance, feature_id, tree_id=None): plot = get_map_feature_or_404(feature_id, instance, 'Plot') tree_ids = [t.pk for t in plot.tree_set.all()] if tree_id and int(tree_id) in tree_ids: tree = Tree.objects.get(pk=tree_id) elif tree_id is None: # See if a tree already exists on this plot tree = plot.current_tree() if tree is None: # A tree doesn't exist, create a new tree create a # new tree, and attach it to this plot tree = Tree(plot=plot, instance=instance) # TODO: it is possible that a user has the ability to # 'create tree photos' but not trees. In this case we # raise an authorization exception here. # It is, however, possible to have both a pending # tree and a pending tree photo # This will be added later, when auth/admin work # correctly with this system tree.save_with_user(request.user) else: # Tree id is invalid or not in this plot raise Http404('Tree id %s not found on plot %s' % (tree_id, feature_id)) #TODO: Auth Error data = get_image_from_request(request) treephoto = tree.add_photo(data, request.user) return treephoto, tree
def delete_map_feature(request, instance, feature_id): feature = get_map_feature_or_404(feature_id, instance) if not map_feature_is_deletable(request.user.get_instance_user(instance), feature): raise ValidationError("map feature not deletable") feature.delete_with_user(request.user) return {'ok': True}
def map_feature_popup(request, instance, feature_id): feature = get_map_feature_or_404(feature_id, instance) context = context_dict_for_map_feature(request, feature) if instance.canopy_enabled: context['boundaries_with_canopy'] = \ _get_boundaries_with_canopy(instance, feature.geom) return context
def map_feature_popup(request, instance, feature_id): feature = get_map_feature_or_404(feature_id, instance) context = context_dict_for_map_feature(request, feature) if instance.canopy_enabled: context['boundaries_with_canopy'] = \ _get_boundaries_with_canopy(instance, feature.geom) return context
def map_feature_popup(request, instance, feature_id): feature = get_map_feature_or_404(feature_id, instance) context = {} context['features'] = [feature] + list(feature.nearby_map_features()) if instance.canopy_enabled: context['boundaries_with_canopy'] = \ _get_boundaries_with_canopy(instance, feature.geom) return context
def delete_map_feature(request, instance, feature_id): feature = get_map_feature_or_404(feature_id, instance) if not map_feature_is_deletable(request.user.get_instance_user(instance), feature): raise ValidationError("map feature not deletable") feature.delete_with_user(request.user) update_hide_at_zoom_after_delete(feature) return {'ok': True}
def map_feature_popup(request, instance, feature_id): feature = get_map_feature_or_404(feature_id, instance) context = {} context['features'] = [feature] + list(feature.nearby_map_features()) if instance.canopy_enabled: context['boundaries_with_canopy'] = \ _get_boundaries_with_canopy(instance, feature.geom) return context
def wrapper(request, instance, feature_id, *args, **kwargs): error = None try: fn(request, instance, feature_id, *args, **kwargs) except ValidationError as e: error = "; ".join(e.messages) feature = get_map_feature_or_404(feature_id, instance) photos = feature.photos() return {"photos": [context_dict_for_photo(request, photo) for photo in photos], "error": error}
def add_map_feature_photo(request, instance, feature_id): error = None try: _add_map_feature_photo_helper(request, instance, feature_id) except ValidationError as e: error = '; '.join(e.messages) feature = get_map_feature_or_404(feature_id, instance) photos = feature.photos() return {'photos': map(context_dict_for_photo, photos), 'error': error}
def wrapper(request, instance, feature_id, *args, **kwargs): error = None try: fn(request, instance, feature_id, *args, **kwargs) except ValidationError as e: error = '; '.join(e.messages) feature = get_map_feature_or_404(feature_id, instance) photos = feature.photos() return {'photos': map(context_dict_for_photo, photos), 'error': error}
def wrapper(request, instance, feature_id, *args, **kwargs): error = None try: fn(request, instance, feature_id, *args, **kwargs) except ValidationError as e: error = '; '.join(e.messages) feature = get_map_feature_or_404(feature_id, instance) photos = feature.photos() return {'photos': map(context_dict_for_photo, photos), 'error': error}
def add_map_feature_photo(request, instance, feature_id): error = None try: _add_map_feature_photo_helper(request, instance, feature_id) except ValidationError as e: error = '; '.join(e.messages) feature = get_map_feature_or_404(feature_id, instance) photos = feature.photos() return {'photos': map(context_dict_for_photo, photos), 'error': error}
def rotate_map_feature_photo(request, instance, feature_id, photo_id): orientation = request.REQUEST.get("degrees", None) if orientation not in {"90", "180", "270", "-90", "-180", "-270"}: raise ValidationError('"degrees" must be a multiple of 90°') degrees = int(orientation) feature = get_map_feature_or_404(feature_id, instance) mf_photo = get_object_or_404(MapFeaturePhoto, pk=photo_id, map_feature=feature) image_data = mf_photo.image.read(settings.MAXIMUM_IMAGE_SIZE) mf_photo.set_image(image_data, degrees_to_rotate=degrees) mf_photo.save_with_user(request.user)
def _map_feature_detail_context(request, instance, feature_id, edit=False): feature = get_map_feature_or_404(feature_id, instance) ctx_fn = (context_dict_for_plot if feature.is_plot else context_dict_for_resource) context = ctx_fn(request, feature, edit=edit) if feature.is_plot: partial = 'treemap/partials/plot_detail.html' else: app = feature.__module__.split('.')[0] partial = '%s/%s_detail.html' % (app, feature.feature_type) return context, partial
def _map_feature_detail_context(request, instance, feature_id, edit=False): feature = get_map_feature_or_404(feature_id, instance) ctx_fn = (context_dict_for_plot if feature.is_plot else context_dict_for_resource) context = ctx_fn(request, feature, edit=edit) if feature.is_plot: partial = 'treemap/partials/plot_detail.html' _add_plot_field_groups(context, instance) else: app = feature.__module__.split('.')[0] partial = '%s/%s_detail.html' % (app, feature.feature_type) return context, partial
def rotate_map_feature_photo(request, instance, feature_id, photo_id): orientation = request.REQUEST.get('degrees', None) if orientation not in {'90', '180', '270', '-90', '-180', '-270'}: raise ValidationError('"degrees" must be a multiple of 90°') degrees = int(orientation) feature = get_map_feature_or_404(feature_id, instance) mf_photo = get_object_or_404(MapFeaturePhoto, pk=photo_id, map_feature=feature) image_data = mf_photo.image.read(settings.MAXIMUM_IMAGE_SIZE) mf_photo.set_image(image_data, degrees_to_rotate=degrees) mf_photo.save_with_user(request.user)
def map_feature_detail(request, instance, feature_id, render=False): feature = get_map_feature_or_404(feature_id, instance) ctx_fn = context_dict_for_plot if feature.is_plot else context_dict_for_resource context = ctx_fn(request, feature) if render: if feature.is_plot: template = "treemap/plot_detail.html" else: template = "map_features/%s_detail.html" % feature.feature_type return render_to_response(template, context, RequestContext(request)) else: return context
def map_feature_detail(request, instance, feature_id, render=False): feature = get_map_feature_or_404(feature_id, instance) ctx_fn = (context_dict_for_plot if feature.is_plot else context_dict_for_resource) context = ctx_fn(request, feature) if render: if feature.is_plot: template = 'treemap/plot_detail.html' else: template = 'map_features/%s_detail.html' % feature.feature_type return render_to_response(template, context, RequestContext(request)) else: return context
def map_feature_hash(request, instance, feature_id, edit=False, tree_id=None): """ Compute a unique hash for a given plot or tree tree_id is ignored since trees are included as a subset of the plot's hash. It is present here because this function is wrapped around views that can take tree_id as an argument """ feature = get_map_feature_or_404(feature_id, instance) if request.user: pk = request.user.pk or '' return hashlib.md5(feature.hash + ':' + str(pk)).hexdigest()
def map_feature_hash(request, instance, feature_id, edit=False, tree_id=None): """ Compute a unique hash for a given plot or tree tree_id is ignored since trees are included as a subset of the plot's hash. It is present here because this function is wrapped around views that can take tree_id as an argument """ feature = get_map_feature_or_404(feature_id, instance) if request.user: pk = request.user.pk or '' return hashlib.md5(feature.hash + ':' + str(pk)).hexdigest()
def map_feature_detail(request, instance, feature_id, render=False, edit=False): feature = get_map_feature_or_404(feature_id, instance) ctx_fn = context_dict_for_plot if feature.is_plot else context_dict_for_resource context = ctx_fn(request, feature, edit=edit) add_map_info_to_context(context, instance) if render: if feature.is_plot: template = "treemap/plot_detail.html" else: app = feature.__module__.split(".")[0] template = "%s/%s_detail.html" % (app, feature.feature_type) return render_to_response(template, context, RequestContext(request)) else: return context
def map_feature_detail(request, instance, feature_id, render=False, edit=False): feature = get_map_feature_or_404(feature_id, instance) ctx_fn = (context_dict_for_plot if feature.is_plot else context_dict_for_resource) context = ctx_fn(request, feature, edit=edit) add_map_info_to_context(context, instance) if render: if feature.is_plot: template = 'treemap/plot_detail.html' else: app = feature.__module__.split('.')[0] try: template = '%s/%s_detail.html' % (app, feature.feature_type) get_template(template) except TemplateDoesNotExist: template = 'treemap/resource_detail.html' return render_to_response(template, context, RequestContext(request)) else: return context
def add_tree_photo_helper(request, instance, feature_id, tree_id=None): plot = get_map_feature_or_404(feature_id, instance, 'Plot') tree_ids = [t.pk for t in plot.tree_set.all()] if tree_id and int(tree_id) in tree_ids: tree = Tree.objects.get(pk=tree_id) elif tree_id is None: # See if a tree already exists on this plot tree = plot.current_tree() if tree is None: # A tree doesn't exist, create a new tree create a # new tree, and attach it to this plot tree = Tree(plot=plot, instance=instance) # TODO: it is possible that a user has the ability to # 'create tree photos' but not trees. In this case we # raise an authorization exception here. # It is, however, possible to have both a pending # tree and a pending tree photo # This will be added later, when auth/admin work # correctly with this system tree.save_with_user(request.user) else: # Tree id is invalid or not in this plot raise Http404('Tree id %s not found on plot %s' % (tree_id, feature_id)) #TODO: Auth Error data = get_image_from_request(request) treephoto = tree.add_photo(data, request.user) # We must update a rev so that missing photo searches are up to date instance.update_universal_rev() return treephoto, tree
def favorite_map_feature(request, instance, feature_id): feature = get_map_feature_or_404(feature_id, instance) Favorite.objects.get_or_create(user=request.user, map_feature=feature) return {'success': True}
def delete_photo(request, instance, feature_id, photo_id): feature = get_map_feature_or_404(feature_id, instance) photo_class = TreePhoto if feature.is_plot else MapFeaturePhoto mf_photo = get_object_or_404(photo_class, pk=photo_id, map_feature=feature) mf_photo.delete_with_user(request.user) # may raise AuthorizeException
def delete_photo(request, instance, feature_id, photo_id): feature = get_map_feature_or_404(feature_id, instance) photo_class = TreePhoto if feature.is_plot else MapFeaturePhoto mf_photo = get_object_or_404(photo_class, pk=photo_id, map_feature=feature) mf_photo.delete_with_user(request.user) # may raise AuthorizeException
def map_feature_popup(request, instance, feature_id): feature = get_map_feature_or_404(feature_id, instance) context = context_dict_for_map_feature(request, feature) return context
def map_feature_popup(request, instance, feature_id): feature = get_map_feature_or_404(feature_id, instance) context = context_dict_for_map_feature(request, feature) return context
def update_map_feature_detail(request, instance, feature_id): feature = get_map_feature_or_404(feature_id, instance) return _request_to_update_map_feature(request, feature)
def delete_map_feature(request, instance, feature_id): feature = get_map_feature_or_404(feature_id, instance) feature.delete_with_user(request.user) # may raise AuthorizeException update_hide_at_zoom_after_delete(feature) return {'ok': True}
def map_feature_photo_detail(request, instance, feature_id, photo_id): feature = get_map_feature_or_404(feature_id, instance) photo = get_object_or_404(MapFeaturePhoto, pk=photo_id, map_feature=feature) return {'photo': context_dict_for_photo(request, photo)}
def plot_detail(request, instance, feature_id, edit=False, tree_id=None): feature = get_map_feature_or_404(feature_id, instance, 'Plot') return context_dict_for_plot(request, feature, edit=edit, tree_id=tree_id)
def plot_detail(request, instance, feature_id, edit=False, tree_id=None): feature = get_map_feature_or_404(feature_id, instance, 'Plot') return context_dict_for_plot(request, feature, edit=edit, tree_id=tree_id)
def map_feature_photo_detail(request, instance, feature_id, photo_id): feature = get_map_feature_or_404(feature_id, instance) photo = get_object_or_404(MapFeaturePhoto, pk=photo_id, map_feature=feature) return {'photo': context_dict_for_photo(request, photo)}
def _add_map_feature_photo_helper(request, instance, feature_id): feature = get_map_feature_or_404(feature_id, instance) data = get_image_from_request(request) return feature.add_photo(data, request.user)
def unfavorite_map_feature(request, instance, feature_id): feature = get_map_feature_or_404(feature_id, instance) Favorite.objects.filter(user=request.user, map_feature=feature).delete() return {'success': True}
def update_map_feature_detail(request, instance, feature_id): feature = get_map_feature_or_404(feature_id, instance) return _request_to_update_map_feature(request, feature)
def unfavorite_map_feature(request, instance, feature_id): feature = get_map_feature_or_404(feature_id, instance) Favorite.objects.filter(user=request.user, map_feature=feature).delete() return {'success': True}
def delete_map_feature(request, instance, feature_id): feature = get_map_feature_or_404(feature_id, instance) feature.delete_with_user(request.user) # may raise AuthorizeException update_hide_at_zoom_after_delete(feature) return {'ok': True}
def _add_map_feature_photo_helper(request, instance, feature_id): feature = get_map_feature_or_404(feature_id, instance) data = get_image_from_request(request) return feature.add_photo(data, request.user)
def favorite_map_feature(request, instance, feature_id): feature = get_map_feature_or_404(feature_id, instance) Favorite.objects.get_or_create(user=request.user, map_feature=feature) return {'success': True}