Skip to content

Commit

Permalink
Merge pull request #118 from gwu-libraries/t95-collections-list
Browse files Browse the repository at this point in the history
T95 collections list
  • Loading branch information
kerchner committed Jan 7, 2016
2 parents 3662ca8 + 32daa59 commit fdf6e8e
Show file tree
Hide file tree
Showing 10 changed files with 298 additions and 76 deletions.
118 changes: 82 additions & 36 deletions docker/app-dev/fixtures.json
Original file line number Diff line number Diff line change
@@ -1,42 +1,88 @@
[
{
"fields": {
"name": "testgroup",
"permissions": []
},
"model": "auth.group",
"pk": 1
"fields": {
"name": "testgroup",
"permissions": []
},
"model": "auth.group",
"pk": 1
},
{
"fields": {
"username": "testuser",
"first_name": "",
"last_name": "",
"is_active": true,
"local_id": "",
"is_superuser": false,
"is_staff": false,
"last_login": null,
"groups": [1],
"user_permissions": [],
"password": "pbkdf2_sha256$20000$7gZDb0TxSksC$HXFliz5Vqsd+S3a6+X+iwQuZ//uvfEpYb+0+0sMD7Vk=",
"email": "",
"date_joined": "2015-12-01T19:09:21Z"
},
"model": "ui.user",
"pk": 2
}, {
"fields": {
"is_visible": true,
"stats": "",
"name": "testcollection",
"date_updated": "2015-12-01T19:10:46.000Z",
"is_active": true,
"date_added": "2015-12-01T19:10:28Z",
"group": 1,
"description": "This is a test collection."
},
"model": "ui.collection",
"pk": 1
"fields": {
"name": "testgroup2",
"permissions": []
},
"model": "auth.group",
"pk": 2
},
{
"fields": {
"is_visible": true,
"stats": "",
"name": "testcollection",
"date_updated": "2015-12-01T19:10:46Z",
"is_active": true,
"date_added": "2015-12-01T19:10:28Z",
"group": 1,
"description": "This is a test collection."
},
"model": "ui.collection",
"pk": 1
},
{
"fields": {
"is_visible": true,
"stats": "",
"name": "Test Collection 2",
"date_updated": "2015-12-30T13:18:40.392Z",
"is_active": true,
"date_added": "2015-12-29T20:24:47Z",
"group": 2,
"description": "This collection is for testing purposes."
},
"model": "ui.collection",
"pk": 2
},
{
"fields": {
"username": "testuser",
"first_name": "",
"last_name": "",
"is_active": true,
"local_id": "",
"is_superuser": false,
"is_staff": false,
"last_login": null,
"groups": [
1
],
"user_permissions": [],
"password": "pbkdf2_sha256$20000$7gZDb0TxSksC$HXFliz5Vqsd+S3a6+X+iwQuZ//uvfEpYb+0+0sMD7Vk=",
"email": "",
"date_joined": "2015-12-01T19:09:21Z"
},
"model": "ui.user",
"pk": 2
},
{
"fields": {
"username": "testuser2",
"first_name": "",
"last_name": "",
"is_active": true,
"local_id": "",
"is_superuser": false,
"is_staff": false,
"last_login": null,
"groups": [
2
],
"user_permissions": [],
"password": "pbkdf2_sha256$20000$mvf0xFj6z38i$8MTmopihB8R06iUrqZ22D0MMadsJCIR3avqdAwnpdZ0=",
"email": "",
"date_joined": "2015-12-29T15:01:22Z"
},
"model": "ui.user",
"pk": 3
}
]
1 change: 1 addition & 0 deletions requirements/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ apscheduler>=3.0,<3.0.3
git+https://github.com/gwu-libraries/sfm-utils.git@0.1.1#egg=sfmutils
mock
sqlalchemy
django-braces>=1.8,<1.9
29 changes: 28 additions & 1 deletion sfm/ui/forms.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from django import forms
from .models import Collection, SeedSet, Seed
from .models import Collection, SeedSet, Seed, Credential


class CollectionForm(forms.ModelForm):
Expand Down Expand Up @@ -86,3 +86,30 @@ def full_clean(self):

def save(self, commit=True):
return super(SeedForm, self).save(commit)


class CredentialForm(forms.ModelForm):

class Meta:
model = Credential
fields = '__all__'
exclude = []
widgets = None
localized_fields = None
labels = {}
help_texts = {}
error_messages = {}

def __init__(self, *args, **kwargs):
return super(CredentialForm, self).__init__(*args, **kwargs)

def is_valid(self):
return super(CredentialForm, self).is_valid()

def full_clean(self):
return super(CredentialForm, self).full_clean()

def save(self, commit=True):
return super(CredentialForm, self).save(commit)


37 changes: 26 additions & 11 deletions sfm/ui/templates/ui/collection_list.html
Original file line number Diff line number Diff line change
@@ -1,19 +1,34 @@
{% extends 'base.html' %}
{% load crispy_forms_tags %}
{% block title %}
Collections
{% endblock %}

{% block content %}
<h1>Collections</h1>
<h2><a href={% url "collection_create" %}>Create new Collection</h2>
<ul>
{% for collection in collection_list %}
<li><a href={% url "collection_detail" collection.pk %}>{{ collection }}</a> | <a href={% url "collection_update" collection.pk %}>Update</a> | <form style="display:inline;" action={% url "collection_delete" collection.pk %} method="post" onsubmit="return confirm('Are you sure you want to delete {{ collection }}?')">{% csrf_token %}
<input type="submit" value="Delete" />
</form></li>
{% empty %}
<li>No Collections yet.</li>
<div class="row">
<h1>My Collections</h1>
</div>
{% regroup collection_list by is_active as collections %}
{% for is_active in collections %}
<div class="row">
<div class="col-md-12">
<h2>{% if is_active.grouper == True %}Active{% else %}Inactive{% endif %}</h2>
</div>
</div>
<div class="row">
{% for collection in is_active.list %}
<div class="col-md-4"><a href={% url "collection_detail" collection.pk %}>{{ collection.name }}</a></div>
<div class="col-md-3">{{ collection.num_seedsets }} seedset{{ collection.num_seedsets|pluralize}}</div>
<div class="col-md-4">Created {{ collection.date_added }}</div>
<!-- later add date of most recent harvest from among colelction's seedsets -->
<div class="col-md-1">{{ collection.group }}</div>
{% empty %}
<div class="col-md-12">No collections yet.</div>
{% endfor %}
</div>
{% endfor %}
</ul>
<div class="row">
<div class="col-md-12">
<a href={% url "collection_create" %} class="btn btn-default">Add New Collection</a>
</div>
</div>
{% endblock %}
16 changes: 16 additions & 0 deletions sfm/ui/templates/ui/credential_create.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@

{% extends 'base.html' %}
{% load crispy_forms_tags %}
{% block title %}
Create Credential
{% endblock %}

{% block content %}
<h2>Create Credential</h2>

<form action="" method="post">{% csrf_token %}
{{ form|crispy }}
<input type="submit" value="Create" />
</form>
<a href={% url "seedset_list" %}>Cancel</a>
{% endblock %}
16 changes: 16 additions & 0 deletions sfm/ui/templates/ui/credential_detail.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{% extends 'base.html' %}
{% load crispy_forms_tags %}
{% block title %}
{{ credential }}
{% endblock %}

{% block content %}
<h2>{{ credential }}
<div>
<li>Platform : {{ credential.platform }}</li>
<li>Platform Token : {{ credential.token }}</li>
<li>date_added : {{ credential.date_added }}</li>
<li>is_active : {{ credential.is_active }}</li>
</div>
</h2>
{% endblock %}
18 changes: 18 additions & 0 deletions sfm/ui/templates/ui/credential_list.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{% extends 'base.html' %}
{% load crispy_forms_tags %}
{% block title %}
Credentials
{% endblock %}

{% block content %}
<h1>Credentials</h1>
<h2><a href={% url "credential_create" %}>Create new Credential</h2>
<ul>
{% for credential in credential_list %}
<li><a href={% url "credential_detail" credential.pk %}>{{ credential }}</a>
</li>
{% empty %}
<li>No Credentials yet.</li>
{% endfor %}
</ul>
{% endblock %}
48 changes: 48 additions & 0 deletions sfm/ui/test_views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
from django.contrib.auth.models import Group
from django.test import TestCase

from ui.models import Collection, User


def create_collection(name, is_active, group):
return Collection.objects.create(name=name, is_active=is_active,
group=group)


def create_group(name):
return Group.objects.create(name=name)


def create_new_user(name, email, password):
return User.objects.create_user(name, email, password)


class CollectionViewTests(TestCase):
def setUp(self):
group = create_group(name='testgroup1')
create_collection(name='Test Collection One', is_active=True,
group=group)
group2 = create_group(name='testgroup2')
create_collection(name='Test Collection Two', is_active=False,
group=group2)
user = create_new_user('testuser', 'testuser@example.com', 'password')
user.groups.add(group)

def test_collections_list_anonymous(self):
'''
anonymous user should get the login page instead of a
collections list.
'''
response = self.client.get('/ui/collections/', follow=True)
self.assertRedirects(response,
'/accounts/login/?next=/ui/collections/')

def test_correct_collection_list_for_usergroup(self):
'''
logged in user should see collections in belonging to the same group
as the user and not see collections from other groups
'''
response = self.client.login(username='testuser', password='password')
response = self.client.get('/ui/collections/')
self.assertContains(response, 'Test Collection One')
self.assertNotContains(response, 'Test Collection Two')

0 comments on commit fdf6e8e

Please sign in to comment.