Skip to content

Commit

Permalink
Merge pull request #62 from diging/develop
Browse files Browse the repository at this point in the history
Pre-release merge for 0.3.2
  • Loading branch information
erickpeirson authored Nov 17, 2016
2 parents e2133f1 + 8c550f9 commit b2e71aa
Show file tree
Hide file tree
Showing 16 changed files with 89 additions and 31 deletions.
1 change: 1 addition & 0 deletions concepts/goat.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import requests
35 changes: 22 additions & 13 deletions cookies/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@
from cookies import authorization


class CustomModelChoiceField(forms.ModelChoiceField):
"""
Overriding label_from_instance function in ModelChoiceField
"""

def label_from_instance(self, obj):
return obj.name

class ContenteditableInput(forms.TextInput):
"""
A contenteditable widget to include in your form
Expand Down Expand Up @@ -78,7 +86,7 @@ def __init__(self, *args, **kwargs):


class BulkResourceForm(forms.Form):
collection = forms.ModelChoiceField(**{
collection = CustomModelChoiceField(**{
'queryset': Collection.objects.all(),
'empty_label': u'Create a new collection',
'required': False,
Expand All @@ -102,7 +110,7 @@ class BulkResourceForm(forms.Form):
+ u' be generated for each file in the archive.'
})

default_type = forms.ModelChoiceField(**{
default_type = CustomModelChoiceField(**{
'queryset': Type.objects.all(),
'required': False,
'help_text': u'All resources in this upload will be assigned the' \
Expand Down Expand Up @@ -137,7 +145,7 @@ def __init__(self, *args, **kwargs):

class UserResourceForm(forms.Form):
name = forms.CharField(help_text='Give your resource a unique name')
resource_type = forms.ModelChoiceField(**{
resource_type = CustomModelChoiceField(**{
'queryset': Type.objects.all().order_by('name'),
'help_text': 'Types help JARS determine what metadata fields are' \
+ ' appropriate for your resource.',
Expand All @@ -160,15 +168,15 @@ class UserResourceForm(forms.Form):
# + u' namespace for this resource.',
# 'required': False,
# })
collection = forms.ModelChoiceField(**{
collection = CustomModelChoiceField(**{
'queryset': Collection.objects.all().order_by('name'),
'required': False
})


class UserEditResourceForm(forms.Form):
name = forms.CharField(help_text='Give your resource a unique name')
resource_type = forms.ModelChoiceField(**{
resource_type = CustomModelChoiceField(**{
'queryset': Type.objects.all().order_by('name'),
'help_text': 'Types help JARS determine what metadata fields are' \
+ ' appropriate for your resource.',
Expand Down Expand Up @@ -206,7 +214,7 @@ class UserResourceURLForm(forms.Form):


class ChooseCollectionForm(forms.Form):
collection = forms.ModelChoiceField(**{
collection = CustomModelChoiceField(**{
'queryset': Collection.objects.all(),
'empty_label': u'Create a new collection',
'required': False,
Expand Down Expand Up @@ -237,17 +245,17 @@ class MetadatumValueDateForm(forms.Form):
value = forms.DateField()

class MetadatumConceptEntityForm(forms.Form):
value = forms.ModelChoiceField(queryset=ConceptEntity.objects.all().order_by('-name'))
value = CustomModelChoiceField(queryset=ConceptEntity.objects.all().order_by('-name'))

class MetadatumResourceForm(forms.Form):
value = forms.ModelChoiceField(queryset=Resource.objects.all().order_by('-name'))
value = CustomModelChoiceField(queryset=Resource.objects.all().order_by('-name'))

class MetadatumTypeForm(forms.Form):
value = forms.ModelChoiceField(queryset=Type.objects.all().order_by('-name'))
value = CustomModelChoiceField(queryset=Type.objects.all().order_by('-name'))


class MetadatumForm(forms.Form):
predicate = forms.ModelChoiceField(queryset=Field.objects.all().order_by('-name'))
predicate = CustomModelChoiceField(queryset=Field.objects.all().order_by('-name'))
value_type = forms.ChoiceField(choices=(
('Int', 'Integer'),
('Float', 'Float'),
Expand All @@ -261,12 +269,12 @@ class MetadatumForm(forms.Form):


class AuthorizationForm(forms.Form):
for_user = forms.ModelChoiceField(queryset=User.objects.all().order_by('-username'))
for_user = CustomModelChoiceField(queryset=User.objects.all().order_by('-username'))
authorizations = forms.MultipleChoiceField(choices=[('', 'None')] + authorization.AUTHORIZATIONS, required=False)


class CollectionAuthorizationForm(forms.Form):
for_user = forms.ModelChoiceField(queryset=User.objects.all().order_by('-username'))
for_user = CustomModelChoiceField(queryset=User.objects.all().order_by('-username'))
authorizations = forms.MultipleChoiceField(choices=[('', 'None')] + authorization.COLLECTION_AUTHORIZATIONS)
propagate = forms.BooleanField(required=False, help_text="If selected,"
" these authorizations will also be applied"
Expand All @@ -293,10 +301,11 @@ class UserAddCollectionForm(forms.ModelForm):
uri = forms.CharField(**{
'required': False,
})
part_of = CustomModelChoiceField(queryset=Collection.objects.all().order_by('name'))

class Meta:
model = Collection
fields = ['name', 'public', 'uri', 'content_type', 'content_resource']
fields = ['name', 'public', 'uri', 'content_type', 'content_resource', 'part_of']

def __init__(self, *args, **kwargs):
super(UserAddCollectionForm, self).__init__(*args, **kwargs)
21 changes: 21 additions & 0 deletions cookies/migrations/0030_collection_part_of.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.9.6 on 2016-11-08 17:53
from __future__ import unicode_literals

from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

dependencies = [
('cookies', '0029_gilesupload_fail'),
]

operations = [
migrations.AddField(
model_name='collection',
name='part_of',
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='cookies.Collection'),
),
]
2 changes: 2 additions & 0 deletions cookies/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,8 @@ class Collection(ResourceBase):
resources = models.ManyToManyField('Resource', related_name='part_of',
blank=True, null=True )

part_of = models.ForeignKey('Collection', blank=True, null=True)

def get_absolute_url(self):
return reverse("cookies.views.collection", args=(self.id,))

Expand Down
4 changes: 2 additions & 2 deletions cookies/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,12 @@
data-title="Upload Resource">
</a>
{% endif %}
<a href="{% url "collections" %}{% if request.user.id > 0 %}?created_by={{ request.user.id }}{% endif %}"
<a href="{% url "collections" %}"
class="btn btn-lg glyphicon glyphicon-folder-close"
data-toggle="tooltip"
data-title="Collections">
</a>
<a href="{% url "resources" %}{% if request.user.id > 0 %}?created_by={{ request.user.id }}{% endif %}"
<a href="{% url "resources" %}"
class="btn btn-lg glyphicon glyphicon-list"
data-toggle="tooltip"
data-title="Resources">
Expand Down
13 changes: 13 additions & 0 deletions cookies/templates/collection.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,15 @@
</span>
<h2 class="collection_name">{{ collection.name }}</h1>
<div class="collection_uri"><strong>URI:</strong> {{ collection.uri }}</div>
{% if collections %}
Sub-collections:
{% endif %}
{% for collection_element in collections %}
<a class="text-info" href="{{ collection_element.get_absolute_url }}">{{ collection_element.name }}</a>
{% endfor %}
{% if collection.part_of %}
<div>Parent collection: <a class="text-info" href="{{ collection.part_of.get_absolute_url }}">{{ collection.part_of.name }}</a></div>
{% endif %}
</div>

<div class="row">
Expand Down Expand Up @@ -127,4 +136,8 @@ <h3>Metadata</h2>
</div>
{% endif %}

<div class="text-center">
<a class="btn btn-success" href="{% url "create-collection" %}?parent_collection={{ collection.id }}">Create a sub collection</a>
</div>

{% endblock %}
2 changes: 1 addition & 1 deletion cookies/templates/collection_authorization_create.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
{% endblock %}

{% block content %}
<span class="h3 text-warning">{{ collection }}</span>
<span class="h3 text-warning">{{ collection.name }}</span>
<div class="h2">Authorizations</div>
<p class="text-info">
Select a user to authorize.
Expand Down
2 changes: 1 addition & 1 deletion cookies/templates/collection_authorization_list.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
{% endblock %}

{% block content %}
<span class="h3 text-warning">{{ collection }}</span>
<span class="h3 text-warning">{{ collection.name }}</span>
<div class="h2">Authorizations</div>

<p>
Expand Down
2 changes: 1 addition & 1 deletion cookies/templates/collections.html
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ <h4 class="panel-title">
{% paginate %}
</div>
<div class="text-center">
<a class="btn btn-success" href="{% url "create-collection" %}">Create collection</a>
<a class="btn btn-success" href="{% url "create-collection" %}?parent_collection=">Create collection</a>
</div>
{% endblock %}
4 changes: 2 additions & 2 deletions cookies/templates/entity_details.html
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
id="target_{{ relation.target.id }}"
uri="{{ relation.target.uri }}">
{% with relation.target.get_absolute_url as resource_url %}
{% if resource_url %}<a href="{{resource_url}}">{% endif %}{{ relation.target|truncatechars:100 }}{% if resource_url %}</a>{% endif %}
{% if resource_url %}<a href="{{resource_url}}">{% endif %}{{ relation.target.name|truncatechars:100 }}{% if resource_url %}</a>{% endif %}
<span class="label label-default" data-toggle="tooltip" data-title="{{ relation.target.entity_type.schema }}">{{ relation.target.entity_type.name }}</span>
{% endwith %}
</li>
Expand All @@ -96,7 +96,7 @@
id="source_{{ relation.source.id }}"
uri="{{ relation.source.uri }}">
{% with relation.source.get_absolute_url as resource_url %}
{% if resource_url %}<a href="{{resource_url}}">{% endif %}{{ relation.source|truncatechars:100 }}{% if resource_url %}</a>{% endif %}
{% if resource_url %}<a href="{{resource_url}}">{% endif %}{{ relation.source.name|truncatechars:100 }}{% if resource_url %}</a>{% endif %}
<span class="label label-default" data-toggle="tooltip" data-title="{{ relation.source.entity_type.schema }}">{{ relation.source.entity_type.name }}</span>
{% endwith %}
</li>
Expand Down
10 changes: 5 additions & 5 deletions cookies/templates/list_metadata.html
Original file line number Diff line number Diff line change
Expand Up @@ -41,28 +41,28 @@
<table class="table table-responsive table-striped">
<tr>
<td class="col-xs-4">
<input class="form-control" name="source" placeholder="Subject (text or URI)" {% if source %}value="{{ source }}"{% endif %}/>
<input class="form-control" name="source" placeholder="Subject (text or URI)" {% if source %}value="{{ source.name }}"{% endif %}/>
</td>
<td class="col-xs-4">
<input class="form-control" name="predicate" placeholder="Predicate (text or URI)", {% if predicate %}value="{{ predicate }}"{% endif %}/>
<input class="form-control" name="predicate" placeholder="Predicate (text or URI)", {% if predicate %}value="{{ predicate.name }}"{% endif %}/>
</td>
<td class="col-xs-4">
<input class="form-control" name="target" placeholder="Object (text or URI)", {% if target %}value="{{target}}"{% endif %} />
<input class="form-control" name="target" placeholder="Object (text or URI)", {% if target %}value="{{target.name}}"{% endif %} />
</td>
</tr>

{% for relation in relations %}
<tr style="cursor: default;">
<td class="text-center">
<a href="{{relation.source.get_absolute_url}}">
{{ relation.source|truncatechars:100 }} <span class="label label-default" data-toggle="tooltip" data-title="{{ relation.source.entity_type.schema }}">{{ relation.source.entity_type.name }}</span>
{{ relation.source.name|truncatechars:100 }} <span class="label label-default" data-toggle="tooltip" data-title="{{ relation.source.entity_type.schema }}">{{ relation.source.entity_type.name }}</span>
</a>
</td>
<td class="text-center"><span data-toggle="tooltip" data-title="{{ relation.predicate.schema }}">{{ relation.predicate.name }}</span></td>
<td class="text-center">
{% with relation.target.get_absolute_url as resource_url %}
{% if resource_url %}<a href="{{resource_url}}">{% endif %}
{{ relation.target|truncatechars:100 }} <span class="label label-default" data-toggle="tooltip" data-title="{{ relation.target.entity_type.schema }}">{{ relation.target.entity_type.name }}</span>
{{ relation.target.name|truncatechars:100 }} <span class="label label-default" data-toggle="tooltip" data-title="{{ relation.target.entity_type.schema }}">{{ relation.target.entity_type.name }}</span>
{% if resource_url %}</a>{% endif %}
{% endwith %}
</td>
Expand Down
2 changes: 1 addition & 1 deletion cookies/templates/resource.html
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ <h3>Metadata</h2>
id="target_{{ relation.target.id }}"
uri="{{ relation.target.uri }}">
{% with relation.target.get_absolute_url as resource_url %}
{% if resource_url %}<a href="{{resource_url}}">{% endif %}{{ relation.target }}{% if resource_url %}</a>{% endif %}
{% if resource_url %}<a href="{{resource_url}}">{% endif %}{{ relation.target.name }}{% if resource_url %}</a>{% endif %}
<span class="label label-default" data-toggle="tooltip" data-title="{{ relation.target.entity_type.schema }}">{{ relation.target.entity_type.name }}</span>
{% endwith %}
</dd>
Expand Down
2 changes: 1 addition & 1 deletion cookies/templates/resource_authorization_create.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
{% endblock %}

{% block content %}
<span class="h3 text-warning">{{ resource }}</span>
<span class="h3 text-warning">{{ resource.name }}</span>
<div class="h2">Authorizations</div>
<p class="text-info">
Select a user to authorize.
Expand Down
2 changes: 1 addition & 1 deletion cookies/templates/resource_authorization_list.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
{% endblock %}

{% block content %}
<span class="h3 text-warning">{{ resource }}</span>
<span class="h3 text-warning">{{ resource.name }}</span>
<div class="h2">Authorizations</div>

<p>
Expand Down
18 changes: 15 additions & 3 deletions cookies/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ def check_authorization(request, instance, permission):
@authorization.authorization_required('view_resource', _get_resource_by_id)
def resource(request, obj_id):
resource = _get_resource_by_id(request, obj_id)

# Get a fresh Giles auth token, if needed.
giles.get_user_auth_token(resource.created_by)
context = {
'resource':resource,
'request': request,
Expand Down Expand Up @@ -120,7 +123,7 @@ def resource_list(request):
# TODO: implement a real search backend.
filtered_objects = ResourceFilter(request.GET, queryset=qset_resources)
qset_collections = Collection.objects.filter(
Q(content_resource=False) & Q(hidden=False)
Q(content_resource=False) & Q(hidden=False) & Q(part_of__isnull=True)
)
qset_collections = authorization.apply_filter(request.user,
'view_collection',
Expand All @@ -142,18 +145,20 @@ def collection(request, obj_id):
resources = collection.resources.filter(content_resource=False, hidden=False)
resources = authorization.apply_filter(request.user, 'view_resource', resources)
filtered_objects = ResourceFilter(request.GET, queryset=resources)

qset_collections = Collection.objects.filter(part_of=collection)
collections = CollectionFilter(request.GET, queryset=qset_collections)
context = RequestContext(request, {
'filtered_objects': filtered_objects,
'collection': collection,
'request': request,
'collections': collections,
})
template = loader.get_template('collection.html')
return HttpResponse(template.render(context))


def collection_list(request):
queryset = Collection.objects.filter(content_resource=False, hidden=False)
queryset = Collection.objects.filter(content_resource=False, hidden=False, part_of__isnull=True)
queryset = authorization.apply_filter(request.user, 'view_resource', queryset)
filtered_objects = CollectionFilter(request.GET, queryset=queryset)
context = RequestContext(request, {
Expand Down Expand Up @@ -1121,10 +1126,17 @@ def create_collection(request):
"""
context = RequestContext(request, {})

parent_id = request.GET.get('parent_collection', None)
template = loader.get_template('create_collection.html')

if request.method == 'GET':
form = UserAddCollectionForm()
if parent_id:
parent_collection = _get_collection_by_id(request, int(parent_id))
check_auth = authorization.check_authorization('change_collection', request.user, parent_collection)
if not check_auth:
return HttpResponse('You do not have permission to edit this collection', status=401)
form.fields['part_of'].initial = parent_collection
if request.method == 'POST':
form = UserAddCollectionForm(request.POST)
if form.is_valid():
Expand Down
Binary file modified dump.rdb
Binary file not shown.

0 comments on commit b2e71aa

Please sign in to comment.