Skip to content

Commit

Permalink
* Wire up the views and the buttons in the templates.
Browse files Browse the repository at this point in the history
  • Loading branch information
bgroff committed Jan 16, 2018
1 parent c318cf7 commit 5bcaf64
Show file tree
Hide file tree
Showing 6 changed files with 89 additions and 10 deletions.
4 changes: 2 additions & 2 deletions django_kala/projects/templates/documents/document.html
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@
<div class="ui container">
<div class="repo title">
<div class="repo options">
<div class="ui compact button">
<a class="ui compact button" href="{% url 'projects:export_document' project.pk document.pk %}">
Download ZIP
</div>
</a>
</div>
{% if can_create %}
<a class="ui positive compact icon button" href="{% url 'projects:new_version' project.pk document.pk %}">
Expand Down
4 changes: 2 additions & 2 deletions django_kala/projects/templates/projects/project.html
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@

<div class="repo title">
<div class="repo options">
<div class="ui compact button">
<a class="ui compact button" href="{% url 'projects:export_project' project.pk %}">
Download ZIP
</div>
</a>
<div class="ui labeled button">
<div class="ui compact floating watch dropdown button" data-content="Choose display options">
<input type="hidden" value="watching">
Expand Down
12 changes: 12 additions & 0 deletions django_kala/projects/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@
name='project'
),

url(
regex=r'^(?P<pk>\d+)/download$',
view=ExportProjectView.as_view(),
name='export_project'
),

url(
regex=r'^(?P<project_pk>\d+)/new_document$',
view=NewDocumentView.as_view(),
Expand All @@ -32,6 +38,12 @@
name='document'
),

url(
regex=r'^(?P<project_pk>\d+)/(?P<document_pk>\d+)/download$',
view=ExportDocumentView.as_view(),
name='export_document'
),

url(
regex=r'^(?P<project_pk>\d+)/(?P<document_pk>\d+)/new_version$',
view=NewDocumentVersionView.as_view(),
Expand Down
4 changes: 2 additions & 2 deletions django_kala/projects/views/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
from .documents.document import DocumentView
from .documents.new_document import NewDocumentView
from .documents.new_version import NewDocumentVersionView
from .documents.document import DocumentView
from .documents.document import DocumentView, ExportDocumentView
from .documents.download import DocumentDownload
from .documents.settings.details import DocumentDetailsView
from .documents.settings.manage_access import ManageAccessView as DocumentManageAccessView
from .documents.settings.archive import ArchiveView as DocumentArchiveView
from .projects.new_project import NewProjectView
from .projects.project import ProjectView
from .projects.project import ProjectView, ExportProjectView
from .projects.projects import ProjectsView
32 changes: 31 additions & 1 deletion django_kala/projects/views/documents/document.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
from django.contrib.auth.mixins import LoginRequiredMixin
from django.core.exceptions import PermissionDenied
from django.shortcuts import get_object_or_404
from django.shortcuts import get_object_or_404, redirect
from django.urls import reverse
from django.views import View
from django.views.generic import TemplateView
from documents.models import Document
from projects.models import Project
from projects.tasks.export_document import ExportDocumentTask


class DocumentView(LoginRequiredMixin, TemplateView):
Expand Down Expand Up @@ -31,3 +34,30 @@ def dispatch(self, request, project_pk, document_pk, *args, **kwargs):
if not self.has_create and not self.has_change and not self.document.has_delete(request.user):
raise PermissionDenied('You do not have permissions to view this document.')
return super(DocumentView, self).dispatch(request, *args, **kwargs)


class ExportDocumentView(LoginRequiredMixin, View):

def dispatch(self, request, project_pk, document_pk, *args, **kwargs):
self.project = get_object_or_404(Project.objects.active(), pk=project_pk)
self.document = get_object_or_404(
Document.objects.active(),
pk=document_pk)

has_create = self.document.has_create(request.user)
has_change = self.document.has_change(request.user)
has_delete = self.document.has_delete(request.user)
if not has_create and not has_change and not has_delete:
raise PermissionDenied('You do not have permissions to view this document.')
return super(ExportDocumentView, self).dispatch(request, *args, **kwargs)

def get(self, request, *args, **kwargs):
task = ExportDocumentTask()
task.apply_async([self.document.pk, request.user.pk])

return redirect(
reverse(
'projects:document',
args=[self.project.pk, self.document.pk]
)
)
43 changes: 40 additions & 3 deletions django_kala/projects/views/projects/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@
from django.contrib.postgres.search import SearchVector
from django.core.exceptions import PermissionDenied
from django.core.paginator import Paginator, InvalidPage
from django.shortcuts import get_object_or_404
from django.shortcuts import get_object_or_404, redirect
from django.urls import reverse
from django.views import View
from django.views.generic import TemplateView

from auth.models import Permissions
from documents.defs import get_mimes_for_category
from documents.models import Document, DocumentVersion
from projects.forms import CategoryForm, SortForm
from projects.models import Project

from projects.tasks.export_project import ExportProjectTask


class ProjectView(LoginRequiredMixin, TemplateView):
Expand Down Expand Up @@ -92,3 +93,39 @@ def dispatch(self, request, pk, *args, **kwargs):
self.documents = documents

return super(ProjectView, self).dispatch(request, *args, **kwargs)


class ExportProjectView(LoginRequiredMixin, View):
def dispatch(self, request, pk, *args, **kwargs):
self.project = get_object_or_404(Project.objects.active(), pk=pk)
if not Permissions.has_perms(
[
'change_project',
'add_project',
'delete_project'
], request.user, self.project.uuid) and not Permissions.has_perms([
'change_organization',
'add_organization',
'delete_organization'
], request.user, self.project.organization.uuid) and not self.project.document_set.filter(
uuid__in=Permissions.objects.filter(
permission__codename__in=[
'change_document',
'add_document',
'delete_document'
], user=request.user).values_list('object_uuid', flat=True)).exists():
raise PermissionDenied(
'You do not have permission to view this project.'
)
return super(ExportProjectView, self).dispatch(request, *args, **kwargs)

def get(self, request, *args, **kwargs):
task = ExportProjectTask()
task.apply_async([self.project.pk, request.user.pk])

return redirect(
reverse(
'projects:project',
args=[self.project.pk]
)
)

0 comments on commit 5bcaf64

Please sign in to comment.