diff --git a/cadasta/organization/views/default.py b/cadasta/organization/views/default.py index 46cb98169..77d49b4ca 100644 --- a/cadasta/organization/views/default.py +++ b/cadasta/organization/views/default.py @@ -1,11 +1,10 @@ import os import json -from django.http import Http404, HttpResponse +from django.http import HttpResponse from django.db import transaction from django.shortcuts import redirect, get_object_or_404 import django.views.generic as base_generic from django.core.urlresolvers import reverse -from django.utils.translation import gettext as _ from django.contrib import messages import formtools.wizard.views as wizard @@ -294,6 +293,7 @@ def get(self, request, *args, **kwargs): class ProjectDashboard(PermissionRequiredMixin, mixins.ProjectAdminCheckMixin, + mixins.ProjectMixin, generic.DetailView): def get_actions(view, request): if view.get_object().public(): @@ -324,15 +324,7 @@ def get_context_data(self, **kwargs): return context def get_object(self, queryset=None): - queryset = Project.objects.filter( - organization__slug=self.kwargs.get('organization'), - slug=self.kwargs.get('project') - ) - try: - obj = queryset.get() - except queryset.model.DoesNotExist: - raise Http404(_("No projects found matching the query")) - return obj + return self.get_project() PROJECT_ADD_FORMS = [('extents', forms.ProjectAddExtents), @@ -475,6 +467,7 @@ def done(self, form_list, form_dict, **kwargs): class ProjectEdit(mixins.ProjectMixin, + mixins.ProjectAdminCheckMixin, LoginPermissionRequiredMixin): model = Project permission_required = 'project.update' @@ -545,6 +538,7 @@ class ProjectUnarchive(ProjectEdit, ArchiveMixin, generic.DetailView): class ProjectDataDownload(mixins.ProjectMixin, LoginPermissionRequiredMixin, + mixins.ProjectAdminCheckMixin, base_generic.edit.FormMixin, generic.DetailView): template_name = 'organization/project_download.html' diff --git a/cadasta/organization/views/mixins.py b/cadasta/organization/views/mixins.py index f0a81afe2..4227b2e21 100644 --- a/cadasta/organization/views/mixins.py +++ b/cadasta/organization/views/mixins.py @@ -96,13 +96,13 @@ def is_administrator(self): su_role = Role.objects.filter(name='superuser') org_admins = [ role.user for role in OrganizationRole.objects.filter( - organization=self.get_object().organization, + organization=self.get_project().organization, admin=True ) ] proj_managers = [ role.user for role in ProjectRole.objects.filter( - project=self.get_object(), + project=self.get_project(), role='PM' ) diff --git a/cadasta/party/views/default.py b/cadasta/party/views/default.py index 8fd07823a..fb389048b 100644 --- a/cadasta/party/views/default.py +++ b/cadasta/party/views/default.py @@ -4,6 +4,7 @@ from jsonattrs.mixins import JsonAttrsMixin from core.mixins import LoginPermissionRequiredMixin +from organization.views import mixins as organization_mixins from resources.forms import AddResourceFromLibraryForm from resources.views.mixins import ProjectHasResourcesMixin from . import mixins @@ -40,6 +41,7 @@ def get_form_kwargs(self, *args, **kwargs): class PartiesDetail(LoginPermissionRequiredMixin, JsonAttrsMixin, mixins.PartyObjectMixin, + organization_mixins.ProjectAdminCheckMixin, ProjectHasResourcesMixin, generic.DetailView): template_name = 'party/party_detail.html' @@ -50,6 +52,7 @@ class PartiesDetail(LoginPermissionRequiredMixin, class PartiesEdit(LoginPermissionRequiredMixin, mixins.PartyObjectMixin, + organization_mixins.ProjectAdminCheckMixin, generic.UpdateView): template_name = 'party/party_edit.html' form_class = forms.PartyForm @@ -59,6 +62,7 @@ class PartiesEdit(LoginPermissionRequiredMixin, class PartiesDelete(LoginPermissionRequiredMixin, mixins.PartyObjectMixin, + organization_mixins.ProjectAdminCheckMixin, generic.DeleteView): template_name = 'party/party_delete.html' permission_required = 'party.delete' @@ -72,6 +76,7 @@ def get_success_url(self): class PartyResourcesAdd(LoginPermissionRequiredMixin, mixins.PartyResourceMixin, + organization_mixins.ProjectAdminCheckMixin, base_generic.edit.FormMixin, generic.DetailView): template_name = 'party/resources_add.html' @@ -89,6 +94,7 @@ def post(self, request, *args, **kwargs): class PartyResourcesNew(LoginPermissionRequiredMixin, mixins.PartyResourceMixin, + organization_mixins.ProjectAdminCheckMixin, ProjectHasResourcesMixin, generic.CreateView): template_name = 'party/resources_new.html' @@ -99,6 +105,7 @@ class PartyResourcesNew(LoginPermissionRequiredMixin, class PartyRelationshipDetail(LoginPermissionRequiredMixin, JsonAttrsMixin, mixins.PartyRelationshipObjectMixin, + organization_mixins.ProjectAdminCheckMixin, ProjectHasResourcesMixin, generic.DetailView): template_name = 'party/relationship_detail.html' @@ -109,6 +116,7 @@ class PartyRelationshipDetail(LoginPermissionRequiredMixin, class PartyRelationshipEdit(LoginPermissionRequiredMixin, mixins.PartyRelationshipObjectMixin, + organization_mixins.ProjectAdminCheckMixin, generic.UpdateView): template_name = 'party/relationship_edit.html' form_class = forms.TenureRelationshipEditForm @@ -121,6 +129,7 @@ def get_success_url(self): class PartyRelationshipDelete(LoginPermissionRequiredMixin, mixins.PartyRelationshipObjectMixin, + organization_mixins.ProjectAdminCheckMixin, generic.DeleteView): template_name = 'party/relationship_delete.html' permission_required = 'tenure_rel.delete' @@ -134,6 +143,7 @@ def get_success_url(self): class PartyRelationshipResourceNew(LoginPermissionRequiredMixin, mixins.PartyRelationshipResourceMixin, + organization_mixins.ProjectAdminCheckMixin, ProjectHasResourcesMixin, generic.CreateView): template_name = 'party/relationship_resources_new.html' @@ -143,6 +153,7 @@ class PartyRelationshipResourceNew(LoginPermissionRequiredMixin, class PartyRelationshipResourceAdd(LoginPermissionRequiredMixin, mixins.PartyRelationshipResourceMixin, + organization_mixins.ProjectAdminCheckMixin, base_generic.edit.FormMixin, generic.DetailView): template_name = 'party/relationship_resources_add.html' diff --git a/cadasta/resources/views/default.py b/cadasta/resources/views/default.py index 335382f11..6fc0c33bd 100644 --- a/cadasta/resources/views/default.py +++ b/cadasta/resources/views/default.py @@ -5,6 +5,7 @@ from core.mixins import LoginPermissionRequiredMixin from . import mixins +from organization.views import mixins as organization_mixins from ..forms import AddResourceFromLibraryForm from .. import messages as error_messages @@ -12,6 +13,7 @@ class ProjectResources(LoginPermissionRequiredMixin, mixins.ProjectResourceMixin, mixins.ProjectHasResourcesMixin, + organization_mixins.ProjectAdminCheckMixin, generic.ListView): template_name = 'resources/project_list.html' permission_required = 'resource.list' @@ -22,6 +24,7 @@ class ProjectResources(LoginPermissionRequiredMixin, class ProjectResourcesAdd(LoginPermissionRequiredMixin, mixins.ProjectResourceMixin, base_generic.edit.FormMixin, + organization_mixins.ProjectAdminCheckMixin, generic.DetailView): template_name = 'resources/project_add_existing.html' form_class = AddResourceFromLibraryForm @@ -42,6 +45,7 @@ def post(self, request, *args, **kwargs): class ProjectResourcesNew(LoginPermissionRequiredMixin, mixins.ProjectResourceMixin, mixins.ProjectHasResourcesMixin, + organization_mixins.ProjectAdminCheckMixin, generic.CreateView): template_name = 'resources/project_add_new.html' permission_required = 'resource.add' @@ -53,6 +57,7 @@ def get_perms_objects(self): class ProjectResourcesDetail(LoginPermissionRequiredMixin, mixins.ResourceObjectMixin, + organization_mixins.ProjectAdminCheckMixin, generic.DetailView): template_name = 'resources/project_detail.html' permission_required = 'resource.view' @@ -66,6 +71,7 @@ def get_context_data(self, *args, **kwargs): class ProjectResourcesEdit(LoginPermissionRequiredMixin, mixins.ResourceObjectMixin, + organization_mixins.ProjectAdminCheckMixin, generic.UpdateView): template_name = 'resources/edit.html' permission_required = 'resource.edit' diff --git a/cadasta/spatial/views/default.py b/cadasta/spatial/views/default.py index 76d39bc09..53be1a412 100644 --- a/cadasta/spatial/views/default.py +++ b/cadasta/spatial/views/default.py @@ -10,6 +10,7 @@ from resources.views.mixins import ProjectHasResourcesMixin from party.messages import TENURE_REL_CREATE from . import mixins +from organization.views import mixins as organization_mixins from .. import forms from ..serializers import SpatialUnitGeoJsonSerializer from .. import messages as error_messages @@ -17,6 +18,7 @@ class LocationsList(LoginPermissionRequiredMixin, mixins.SpatialQuerySetMixin, + organization_mixins.ProjectAdminCheckMixin, generic.ListView): template_name = 'spatial/location_map.html' permission_required = 'spatial.list' @@ -26,6 +28,7 @@ class LocationsList(LoginPermissionRequiredMixin, class LocationsAdd(LoginPermissionRequiredMixin, mixins.SpatialQuerySetMixin, + organization_mixins.ProjectAdminCheckMixin, generic.CreateView): form_class = forms.LocationForm template_name = 'spatial/location_add.html' @@ -59,6 +62,7 @@ def get_form_kwargs(self): class LocationDetail(LoginPermissionRequiredMixin, JsonAttrsMixin, mixins.SpatialUnitObjectMixin, + organization_mixins.ProjectAdminCheckMixin, ProjectHasResourcesMixin, generic.DetailView): template_name = 'spatial/location_detail.html' @@ -74,6 +78,7 @@ def get_context_data(self, *args, **kwargs): class LocationEdit(LoginPermissionRequiredMixin, mixins.SpatialUnitObjectMixin, + organization_mixins.ProjectAdminCheckMixin, generic.UpdateView): template_name = 'spatial/location_edit.html' form_class = forms.LocationForm @@ -83,6 +88,7 @@ class LocationEdit(LoginPermissionRequiredMixin, class LocationDelete(LoginPermissionRequiredMixin, mixins.SpatialUnitObjectMixin, + organization_mixins.ProjectAdminCheckMixin, generic.DeleteView): template_name = 'spatial/location_delete.html' permission_required = 'spatial.delete' @@ -97,6 +103,7 @@ def get_success_url(self): class LocationResourceAdd(LoginPermissionRequiredMixin, mixins.SpatialUnitResourceMixin, base_generic.edit.FormMixin, + organization_mixins.ProjectAdminCheckMixin, generic.DetailView): template_name = 'spatial/resources_add.html' form_class = AddResourceFromLibraryForm @@ -113,6 +120,7 @@ def post(self, request, *args, **kwargs): class LocationResourceNew(LoginPermissionRequiredMixin, mixins.SpatialUnitResourceMixin, + organization_mixins.ProjectAdminCheckMixin, ProjectHasResourcesMixin, generic.CreateView): template_name = 'spatial/resources_new.html' @@ -132,6 +140,7 @@ def get_context_data(self, *args, **kwargs): class TenureRelationshipAdd(LoginPermissionRequiredMixin, mixins.SpatialUnitRelationshipMixin, + organization_mixins.ProjectAdminCheckMixin, generic.CreateView): template_name = 'spatial/relationship_add.html' form_class = forms.TenureRelationshipForm