Skip to content

Commit

Permalink
* Add categories to the project settings.
Browse files Browse the repository at this point in the history
  • Loading branch information
bgroff committed Aug 15, 2017
1 parent d10f8cc commit 13471ee
Show file tree
Hide file tree
Showing 13 changed files with 545 additions and 87 deletions.
22 changes: 11 additions & 11 deletions django_kala/projects/forms/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@

from .projects.settings.category import CategoryForm
from .projects.settings.details import DetailsForm
from .projects.settings.manage_access import ManageAccessForm, manage_access_forms
from .projects.settings.transfer_ownership import TransferOwnershipForm
Expand All @@ -9,16 +9,16 @@
from documents.defs import get_categories_for_mimes
from documents.models import Document


class CategoryForm(forms.Form):
def __init__(self, *args, **kwargs):
self.project = kwargs.pop('project')
super(CategoryForm, self).__init__(*args, **kwargs)

self.fields['category'] = forms.ChoiceField(choices=get_categories_for_mimes(
Document.objects.active().filter(project=self.project).distinct('mime').order_by('mime').values_list(
'mime')), widget=forms.Select(attrs={'class': 'span3'}))

#
# class SortCategoryForm(forms.Form):
# def __init__(self, *args, **kwargs):
# self.project = kwargs.pop('project')
# super(CategoryForm, self).__init__(*args, **kwargs)
#
# self.fields['category'] = forms.ChoiceField(choices=get_categories_for_mimes(
# Document.objects.active().filter(project=self.project).distinct('mime').order_by('mime').values_list(
# 'mime')), widget=forms.Select(attrs={'class': 'span3'}))
#

class SortForm(forms.Form):
search = forms.ChoiceField(choices=(('DATE', 'Sort by Date'), ('AZ', 'Sort Alphabetically')),
Expand Down
17 changes: 17 additions & 0 deletions django_kala/projects/forms/projects/settings/category.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from django import forms

from projects.models import Category


class CategoryForm(forms.ModelForm):
def __init__(self, *args, **kwargs):
self.project = kwargs.pop('project')
super(CategoryForm, self).__init__(*args, **kwargs)

class Meta:
model = Category
fields = ['name']

def save(self, commit=True):
self.instance.project = self.project
super(CategoryForm, self).save(commit)
2 changes: 1 addition & 1 deletion django_kala/projects/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def __str__(self):
class Category(models.Model):
name = models.CharField(max_length=255)
project = models.ForeignKey(Project)
type = models.CharField(max_length=20, db_index=True)
type = models.CharField(max_length=20, db_index=True, null=True, blank=True)

def __str__(self):
return '{0}'.format(self.name)
7 changes: 7 additions & 0 deletions django_kala/projects/templates/projects/settings/archive.html
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,13 @@
<a class="item" href="{% url 'projects:transfer_ownership' project.pk %}">Transfer ownership</a>
</div>
</div>
<div class="item">
<div class="header">Categories</div>
<div class="menu">
<a class="item" href="{% url 'projects:categories' project.pk %}">Manage categories</a>
<a class="item" href="{% url 'projects:new_category' project.pk %}">New category</a>
</div>
</div>
</div>
</div>
<div class="twelve wide column">
Expand Down
154 changes: 154 additions & 0 deletions django_kala/projects/templates/projects/settings/categories.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
{% 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">{{ project.organization }}</a>
<div class="divider"> /</div>
<a class="active section">{{ project }}</a>
</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="ui vertical menu">
<div class="item">
<div class="header">Project</div>
<div class="menu">
<a class="item" href="{% url 'projects:details' project.pk %}">Details</a>
<a class="item" href="{% url 'projects:archive' project.pk %}">Archive</a>
</div>
</div>
<div class="item">
<div class="header">People</div>
<div class="menu">
<a class="item" href="{% url 'projects:manage_access' project.pk %}">Manage access</a>
</div>
</div>
<div class="item">
<div class="header">Organizations</div>
<div class="menu">
<a class="item" href="{% url 'projects:transfer_ownership' project.pk %}">Transfer ownership</a>
</div>
</div>
<div class="item">
<div class="header">Categories</div>
<div class="menu">
<a class="active item" href="{% url 'projects:categories' project.pk %}">Manage categories</a>
<a class="item" href="{% url 'projects:new_category' project.pk %}">New category</a>
</div>
</div>
</div>
</div>
<div class="twelve wide column">
<table class="ui celled table">
<thead>
<tr>
<th>Name</th>
<th>Edit</th>
<th>Delete</th>
</tr>
</thead>
<tbody>
{% for category in categories %}
<tr>
<td>
{{ category.name }}
</td>
<td>
<a href="{% url 'projects:edit_category' project.pk category.pk %}">
<button class="ui primary button">Edit</button>
</a>
</td>
<td>
<button onclick="deleteCategory({{ category.pk }});" class="ui negative button">Delete</button>
</td>
</tr>
{% empty %}
<tr>
<td colspan="3">There are no categories for this project.</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</div>
<div class="ui basic modal">
<div class="ui icon header">
<i class="organization icon"></i>
Delete Category
</div>
<div class="content">
<p>Are you sure that you want to delete this category?</p>
</div>
<div class="actions">
<div class="ui green cancel inverted button">
<i class="stop icon"></i>
No
</div>
<div class="ui red basic ok inverted button">
<i class="trashcan icon"></i>
Yes
</div>
</div>
</div>
{% csrf_token %}
{% endblock content %}

{% block scripts %}
<script>
var csrftoken = jQuery("[name=csrfmiddlewaretoken]").val();
function csrfSafeMethod(method) {
// these HTTP methods do not require CSRF protection
return (/^(GET|HEAD|OPTIONS|TRACE)$/.test(method));
}
$.ajaxSetup({
beforeSend: function(xhr, settings) {
if (!csrfSafeMethod(settings.type) && !this.crossDomain) {
xhr.setRequestHeader("X-CSRFToken", csrftoken);
}
}
});

function deleteCategory(pk) {
$('.ui.basic.modal')
.modal({
onApprove: function () {
$.ajax({
url: '{% url 'projects:categories' project.pk %}' + '/' + pk,
type: 'DELETE',
success: function () {
location.reload();
},
error: $.noop
});
}
})
.modal('show')
;
}
</script>
{% endblock %}
7 changes: 7 additions & 0 deletions django_kala/projects/templates/projects/settings/details.html
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,13 @@
<a class="item" href="{% url 'projects:transfer_ownership' project.pk %}">Transfer ownership</a>
</div>
</div>
<div class="item">
<div class="header">Categories</div>
<div class="menu">
<a class="item" href="{% url 'projects:categories' project.pk %}">Manage categories</a>
<a class="item" href="{% url 'projects:new_category' project.pk %}">New category</a>
</div>
</div>
</div>
</div>
<div class="twelve wide column">
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
{% 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">{{ project.organization }}</a>
<div class="divider"> /</div>
<a class="active section">{{ project }}</a>
</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="ui vertical menu">
<div class="item">
<div class="header">Project</div>
<div class="menu">
<a class="item" href="{% url 'projects:details' project.pk %}">Details</a>
<a class="item" href="{% url 'projects:archive' project.pk %}">Archive</a>
</div>
</div>
<div class="item">
<div class="header">People</div>
<div class="menu">
<a class="item" href="{% url 'projects:manage_access' project.pk %}">Manage access</a>
</div>
</div>
<div class="item">
<div class="header">Organizations</div>
<div class="menu">
<a class="item" href="{% url 'projects:transfer_ownership' project.pk %}">Transfer ownership</a>
</div>
</div>
<div class="item">
<div class="header">Categories</div>
<div class="menu">
<a class="item" href="{% url 'projects:categories' project.pk %}">Manage categories</a>
<a class="active item" href="{% url 'projects:new_category' project.pk %}">New category</a>
</div>
</div>
</div>
</div>
<div class="twelve wide column">
<form class="ui form" method="post">
{% csrf_token %}
<div class="field">
<label>{{ form.name.label }}</label>
<input id={{ form.name.auto_id }} type="text" name="{{ form.name.name }}" placeholder="Category Name" value="{{ form.name.value }}" maxlength="{{ form.fields.name.max_length }} required">
</div>
<div class="field">
<label>{{ form.type.label }}</label>
{{ form.type }}
</div>
<button class="ui button primary" type="submit">Edit category</button>
</form>
</div>
</div>
{% endblock content %}
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,14 @@
<div class="item">
<div class="header">Organizations</div>
<div class="menu">
<a class="item" href="{% url 'projects:transfer_ownership' project.pk %}">Transfer
ownership</a>
<a class="item" href="{% url 'projects:transfer_ownership' project.pk %}">Transfer ownership</a>
</div>
</div>
<div class="item">
<div class="header">Categories</div>
<div class="menu">
<a class="item" href="{% url 'projects:categories' project.pk %}">Manage categories</a>
<a class="item" href="{% url 'projects:new_category' project.pk %}">New category</a>
</div>
</div>
</div>
Expand Down

0 comments on commit 13471ee

Please sign in to comment.