Skip to content

Commit

Permalink
* Add document archive settings page.
Browse files Browse the repository at this point in the history
* Remove the unneeded not null constraints on the organization model.
  • Loading branch information
bgroff committed Dec 19, 2017
1 parent bf2488f commit 5bc3700
Show file tree
Hide file tree
Showing 12 changed files with 169 additions and 28 deletions.
20 changes: 10 additions & 10 deletions django_kala/organizations/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,18 @@ def get_query_set(self):
class Organization(models.Model):
name = models.CharField(max_length=255, unique=True)
uuid = models.UUIDField(unique=True, db_index=True, default=uuid4)
address = models.CharField(max_length=255, null=True, blank=True)
address1 = models.CharField(max_length=255, null=True, blank=True)
city = models.CharField(max_length=255, null=True, blank=True)
state = models.CharField(null=True, blank=True, max_length=80)
zip = models.CharField(max_length=25, null=True, blank=True)
country = models.CharField(default='US', null=True, blank=True, max_length=80)
fax = PhoneNumberField(null=True, blank=True)
phone = PhoneNumberField(null=True, blank=True)
locale = models.CharField(max_length=2, null=True, blank=True, default='en')
address = models.CharField(max_length=255, blank=True)
address1 = models.CharField(max_length=255, blank=True)
city = models.CharField(max_length=255, blank=True)
state = models.CharField(blank=True, max_length=80)
zip = models.CharField(max_length=25, blank=True)
country = models.CharField(default='US', blank=True, max_length=80)
fax = PhoneNumberField(blank=True)
phone = PhoneNumberField(blank=True)
locale = models.CharField(max_length=2, blank=True, default='en')
removed = models.DateField(null=True)
timezone = TimeZoneField(default=settings.TIME_ZONE)
website = models.URLField(null=True, blank=True)
website = models.URLField(blank=True)

is_active = models.BooleanField(default=True)

Expand Down
2 changes: 0 additions & 2 deletions django_kala/organizations/views/settings/details.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ def dispatch(self, request, pk, *args, **kwargs):

def post(self, request, *args, **kwargs):
if self.form.is_valid():
self.form.save(commit=False)
self.form.save_m2m()
self.form.save()
return redirect(reverse('organizations:details', args=[self.organization.pk]))
return self.render_to_response(self.get_context_data())
12 changes: 6 additions & 6 deletions django_kala/projects/templates/documents/new_document.html
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,12 @@

{% block scripts %}
<script>
$('.ui.basic.modal')
.modal({
closable : false
})
.modal('attach events', '#submit-button', 'show')
;
{# $('.ui.basic.modal')#}
{# .modal({#}
{# closable: false#}
{# })#}
{# .modal('attach events', '#submit-button', 'show')#}
{# ;#}

$('select.search.dropdown')
.dropdown()
Expand Down
12 changes: 6 additions & 6 deletions django_kala/projects/templates/documents/new_version.html
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@ <h2>

{% block scripts %}
<script>
$('.ui.basic.modal')
.modal({
closable: false
})
.modal('attach events', '#submit-button', 'show')
;
{# $('.ui.basic.modal')#}
{# .modal({#}
{# closable: false#}
{# })#}
{# .modal('attach events', '#submit-button', 'show')#}
{# ;#}
</script>
{% endblock scripts %}
88 changes: 88 additions & 0 deletions django_kala/projects/templates/documents/settings/archive.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
{% extends 'base.html' %}
{% load static %}
{% load kala_tags %}

{% block content %}
<div class="repo ribbon">
<div class="ui container">
<div class="ui big breadcrumb">
<a class="section" href="{% url 'organizations:organization' project.organization.pk %}">{{ project.organization }}</a>
<div class="divider"> /</div>
<a class="section" href="{% url 'projects:project' project.pk %}">{{ project }}</a>
<div class="divider"> /</div>
<span class="active section">{{ document }}</span>
</div>
</div>
</div>

<div class="ui tabular menu">
<div class="ui container">
<a class="item" href="{% url 'projects:project' project.pk %}">
<i class="book icon"></i>
Documents
</a>
{# <a class="item">#}
{# <i class="issue opened icon"></i>#}
{# Issues#}
{# <span class="ui small label">593</span>#}
{# </a>#}
<a class="active item" href="{% url 'projects:details' project.pk %}">
<i class="gear icon"></i>
Settings
</a>
</div>
</div>


<div class="ui two column grid container">
<div class="four wide column">
<div class="four wide column">
<div class="ui vertical menu">
<div class="item">
<div class="header">Document</div>
<div class="menu">
<a class="item" href="{% url 'projects:document_details' document.project.pk document.pk %}">Details</a>
<a class="item active" href="{% url 'projects:document_archive' document.project.pk document.pk %}">Archive</a>
</div>
</div>
<div class="item">
<div class="header">People</div>
<div class="menu">
<a class="item" href="{% url 'projects:document_manage_access' document.project.pk document.pk %}">Manage access</a>
</div>
</div>
</div>
</div>
</div>
<div class="twelve wide column">
<form class="ui form" method="post">
{% csrf_token %}
<div class="field">
<label>Re-enter projects name to archive the project</label>
<input id="projectName" type="text" name="documentName" placeholder="Document Name" required>
</div>
<div class="ui error message"></div>
<div class="ui submit button primary">Archive document</div>
</form>
</div>
</div>
{% endblock content %}

{% block scripts %}
<script>
$('.ui.form')
.form({
fields: {
projectName: {
rules: [
{
type: 'isExactly[{{ document.name }}]',
prompt: 'You must enter the documentpytho name as it appears in the application.'
}
]
}
}
})
;
</script>
{% endblock scripts %}
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
<div class="header">Document</div>
<div class="menu">
<a class="active item" href="{% url 'projects:document_details' document.project.pk document.pk %}">Details</a>
<a class="item" href="">Archive</a>
<a class="item" href="{% url 'projects:document_archive' document.project.pk document.pk %}"">Archive</a>
</div>
</div>
<div class="item">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
<div class="header">Document</div>
<div class="menu">
<a class="item" href="{% url 'projects:document_details' document.project.pk document.pk %}">Details</a>
<a class="item" href="">Archive</a>
<a class="item" href="{% url 'projects:document_archive' document.project.pk document.pk %}"">Archive</a>
</div>
</div>
<div class="item">
Expand Down
7 changes: 7 additions & 0 deletions django_kala/projects/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,13 @@
),


url(
regex=r'^(?P<project_pk>\d+)/(?P<document_pk>\d+)/settings/archive',
view=DocumentArchiveView.as_view(),
name='document_archive'
),


url(
regex=r'^(?P<project_pk>\d+)/(?P<document_pk>\d+)/settings/manage_access$',
view=DocumentManageAccessView.as_view(),
Expand Down
1 change: 1 addition & 0 deletions django_kala/projects/views/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
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.projects import ProjectsView
45 changes: 45 additions & 0 deletions django_kala/projects/views/documents/settings/archive.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
from django.contrib.auth.mixins import LoginRequiredMixin
from django.core.exceptions import PermissionDenied
from django.shortcuts import get_object_or_404, redirect
from django.urls import reverse
from django.views.generic.base import TemplateView

from documents.models import Document


class ArchiveView(LoginRequiredMixin, TemplateView):
template_name = 'documents/settings/archive.html'

def get_context_data(self, **kwargs):
return {
'document': self.document,
'project': self.project,
'can_create': self.project.has_change(self.request.user) or self.project.has_create(self.request.user),
'can_invite': self.project.organization.has_change(self.request.user) or self.project.organization.has_create(self.request.user)
}

def dispatch(self, request, project_pk, document_pk, *args, **kwargs):
self.document = get_object_or_404(
Document.objects.active().select_related(
'project',
'project__organization'
),
pk=document_pk
)
if not self.document.has_delete(request.user):
raise PermissionDenied('You do not have permission to archive this document')
self.project = self.document.project

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

def post(self, request, *args, **kwargs):
self.document.set_active(False)
return redirect(
reverse(
'projects:document_archive',
args=[
self.document.project.pk,
self.document.pk
]
)
)
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ def get_context_data(self, **kwargs):
return {
'forms': self.forms,
'document': self.document,
'project': self.project,
'can_create': self.project.has_change(self.request.user) or self.project.has_create(self.request.user),
'can_invite': self.project.organization.has_change(self.request.user) or self.project.organization.has_create(self.request.user)

Expand All @@ -33,6 +34,7 @@ def dispatch(self, request, project_pk, document_pk, *args, **kwargs):
raise PermissionDenied('You do not have permission to edit this project')

self.forms = manage_access_forms(request, self.document)
self.project = self.document.project
return super(ManageAccessView, self).dispatch(request, *args, **kwargs)

def post(self, request, *args, **kwargs):
Expand Down
4 changes: 2 additions & 2 deletions django_kala/projects/views/projects/settings/archive.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ def get_context_data(self, **kwargs):

def dispatch(self, request, pk, *args, **kwargs):
self.project = get_object_or_404(Project.objects.active(), pk=pk)
if not self.project.has_change(request.user):
raise PermissionDenied('You do not have permission to edit this project')
if not self.project.has_delete(request.user):
raise PermissionDenied('You do not have permission to archive this project')

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

Expand Down

0 comments on commit 5bc3700

Please sign in to comment.