-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #118 from gwu-libraries/t95-collections-list
T95 collections list
- Loading branch information
Showing
10 changed files
with
298 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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') |
Oops, something went wrong.