Skip to content

Commit

Permalink
Merge pull request #32 from gwu-libraries/t14-add-seed-seedsets-try2
Browse files Browse the repository at this point in the history
T14 add seed seedsets try2
  • Loading branch information
justinlittman committed Oct 14, 2015
2 parents 20f8859 + 87d4b2b commit 61a73ed
Show file tree
Hide file tree
Showing 25 changed files with 749 additions and 14 deletions.
3 changes: 2 additions & 1 deletion requirements/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ django>=1.8,<=1.9
django-allauth
psycopg2
pytz
appdeps
django-crispy-forms
appdeps
1 change: 1 addition & 0 deletions sfm/sfm/settings/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
'allauth', # registration
'allauth.account', # registration
'allauth.socialaccount', # registration
'crispy_forms',
]

MIDDLEWARE_CLASSES = (
Expand Down
1 change: 1 addition & 0 deletions sfm/sfm/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@
name="home"),
url(r'^admin/', include(admin.site.urls)),
url(r'^accounts/', include('allauth.urls')),
url(r'^ui/', include('ui.urls')),
]
91 changes: 89 additions & 2 deletions sfm/ui/admin.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,90 @@
from django.contrib import admin
from __future__ import absolute_import, unicode_literals

# Register your models here.
from django import forms
from django.contrib import admin as a
from ui import models as m
from django.contrib.auth.admin import UserAdmin as AuthUserAdmin
from django.contrib.auth.forms import UserChangeForm, UserCreationForm

from .models import User


class MyUserChangeForm(UserChangeForm):
class Meta(UserChangeForm.Meta):
model = User


class MyUserCreationForm(UserCreationForm):

error_message = UserCreationForm.error_messages.update({
'duplicate_local_id': 'This local_id has already been taken.'
})

class Meta(UserCreationForm.Meta):
model = User

def clean_local_id(self):
local_id = self.cleaned_data["local_id"]
try:
User.objects.get(local_id=local_id)
except User.DoesNotExist:
return local_id
raise forms.ValidationError(self.error_messages['duplicate_local_id'])


@a.register(User)
class UserAdmin(AuthUserAdmin):
form = MyUserChangeForm
add_form = MyUserCreationForm


class Credential(a.ModelAdmin):
fields = ('user', 'platform', 'token', 'is_active', 'date_added')
list_display = ['user', 'platform', 'token', 'is_active', 'date_added']
list_filter = ['user', 'platform', 'token', 'is_active', 'date_added']
search_fields = ['user', 'platform', 'token', 'is_active', 'date_added']


class Collection(a.ModelAdmin):
fields = ('group', 'name', 'description', 'is_active', 'is_visible',
'stats', 'date_added')
list_display = ['group', 'name', 'description', 'is_active', 'is_visible',
'stats', 'date_added', 'date_updated']
list_filter = ['group', 'name', 'description', 'is_active', 'is_visible',
'stats', 'date_added', 'date_updated']
search_fields = ['group', 'name', 'description', 'is_active', 'is_visible',
'stats', 'date_added', 'date_updated']


class SeedSet(a.ModelAdmin):
fields = ('collection', 'credential', 'harvest_type', 'name', 'description',
'is_active', 'schedule', 'harvest_options', 'max_count', 'stats',
'date_added', 'start_date', 'end_date')
list_display = ['collection', 'credential', 'harvest_type', 'name',
'description', 'is_active', 'schedule', 'harvest_options',
'max_count', 'stats', 'date_added', 'start_date',
'end_date']
list_filter = ['collection', 'credential', 'harvest_type', 'name',
'description', 'is_active', 'schedule', 'harvest_options',
'max_count', 'stats', 'date_added', 'start_date',
'end_date']
search_fields = ['collection', 'credential', 'harvest_type', 'name',
'description', 'is_active', 'schedule', 'harvest_options',
'max_count', 'stats', 'date_added', 'start_date',
'end_date']


class Seed(a.ModelAdmin):
fields = ('seed_set', 'token', 'uid', 'is_active',
'is_valid', 'stats', 'date_added')
list_display = ['seed_set', 'token', 'uid', 'is_active',
'is_valid', 'stats', 'date_added', 'date_updated']
list_filter = ['seed_set', 'token', 'uid', 'is_active',
'is_valid', 'stats', 'date_added', 'date_updated']
search_fields = ['seed_set', 'token', 'uid', 'is_active',
'is_valid', 'stats', 'date_added', 'date_updated']

a.site.register(m.Credential, Credential)
a.site.register(m.Collection, Collection)
a.site.register(m.SeedSet, SeedSet)
a.site.register(m.Seed, Seed)
77 changes: 77 additions & 0 deletions sfm/ui/forms.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
from django import forms
from .models import Collection, SeedSet, Seed


class CollectionForm(forms.ModelForm):

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

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

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

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

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


class SeedSetForm(forms.ModelForm):

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

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

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

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

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


class SeedForm(forms.ModelForm):

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

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

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

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

def save(self, commit=True):
return super(SeedForm, self).save(commit)
44 changes: 44 additions & 0 deletions sfm/ui/migrations/0002_auto_20151013_1522.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('ui', '0001_initial'),
]

operations = [
migrations.RenameField(
model_name='seed',
old_name='platform_token',
new_name='token',
),
migrations.RenameField(
model_name='seed',
old_name='platform_uid',
new_name='uid',
),
migrations.RenameField(
model_name='seedset',
old_name='date_ended',
new_name='end_date',
),
migrations.RenameField(
model_name='seedset',
old_name='crawl_options',
new_name='harvest_options',
),
migrations.RenameField(
model_name='seedset',
old_name='platform',
new_name='harvest_type',
),
migrations.RenameField(
model_name='seedset',
old_name='date_started',
new_name='start_date',
),
]
12 changes: 6 additions & 6 deletions sfm/ui/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,17 @@ class SeedSet(models.Model):

collection = models.ForeignKey(Collection, related_name='seed_sets')
credential = models.ForeignKey(Credential, related_name='seed_sets')
platform = models.CharField(max_length=255, blank=True)
harvest_type = models.CharField(max_length=255, blank=True)
name = models.CharField(max_length=255)
description = models.TextField(blank=True)
is_active = models.BooleanField(default=True)
schedule = models.CharField(max_length=255, blank=True)
crawl_options = models.TextField(blank=True)
harvest_options = models.TextField(blank=True)
max_count = models.PositiveIntegerField(default=0)
stats = models.TextField(blank=True)
date_added = models.DateTimeField(default=timezone.now)
date_started = models.DateTimeField(default=timezone.now)
date_ended = models.DateTimeField(default=timezone.now)
start_date = models.DateTimeField(default=timezone.now)
end_date = models.DateTimeField(default=timezone.now)

def __str__(self):
return '<SeedSet %s "%s">' % (self.id, self.name)
Expand All @@ -62,8 +62,8 @@ def __str__(self):
class Seed(models.Model):

seed_set = models.ForeignKey(SeedSet, related_name='seeds')
platform_token = models.TextField(blank=True)
platform_uid = models.TextField(blank=True)
token = models.TextField(blank=True)
uid = models.TextField(blank=True)
is_active = models.BooleanField(default=True)
is_valid = models.BooleanField(default=True)
stats = models.TextField(blank=True)
Expand Down
7 changes: 3 additions & 4 deletions sfm/ui/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,6 @@
<!-- This file store project specific CSS -->
{% endblock %}

{% block angular %}
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular.min.js"></script>
{% endblock %}

</head>

<body>
Expand Down Expand Up @@ -60,6 +56,9 @@

<ul class="nav navbar-nav navbar-right">
{% if request.user.is_authenticated %}
<li><a href="/ui/collections">Collections</a></li>
<li><a href="/ui/seeds">Seeds</a></li>
<li><a href="/ui/seedsets">Seed Sets</a></li>
<li><a href="/admin">Admin</a></li>
<li><a href="{% url 'account_logout' %}">{% trans "Logout" %}</a></li>
{% else %}
Expand Down
16 changes: 16 additions & 0 deletions sfm/ui/templates/ui/collection_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 Collection
{% endblock %}

{% block content %}
<h1><a href={% url "collection_list" %}>Collection</a></h1>
<h2>Create Collection</h2>

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

{% block content %}
<h1>Delete {{ collection }}</h1>

<form action="" method="post">{% csrf_token %}
<p>Are you sure you want to delete {{ collection }}?</p>
<input type="submit" value="Confirm" />
</form>

<a href={% url "collection_detail" collection.pk %}>Cancel</a>

{% endblock %}
24 changes: 24 additions & 0 deletions sfm/ui/templates/ui/collection_detail.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{% extends 'base.html' %}
{% load crispy_forms_tags %}
{% block title %}
{{ collection }}
{% endblock %}

{% block content %}
<h1><a href={% url "collection_list" %}>Collection</a></h1>
<h2>{{ collection }} | <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" />
<div>
<li>Group : {{ collection.group }}</li>
<li>Name : {{ collection.name }}</li>
<li>Description : {{ collection.description }}</li>
<li>date_updated : {{ collection.date_updated }}</li>
<li>date_added : {{ collection.date_added }}</li>
<li>is_visible : {{ collection.is_visible }}</li>
<li>is_active : {{ collection.is_active }}</li>
<li>stats : {{ collection.stats }}</li>
</div>
</form>
</h2>
{% endblock %}
19 changes: 19 additions & 0 deletions sfm/ui/templates/ui/collection_list.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{% 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>
{% endfor %}
</ul>
{% endblock %}
19 changes: 19 additions & 0 deletions sfm/ui/templates/ui/collection_update.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{% extends 'base.html' %}
{% load crispy_forms_tags %}
{% block title %}
Update {{ collection }}
{% endblock %}

{% block content %}
<h1><a href={% url "collection_list" %}>Collection</a></h1>
<h2>Update {{ collection }}</h2>

<form action="" method="post">{% csrf_token %}
{{ form|crispy }}
<input type="submit" value="Update" />
</form>
<a href={% url "collection_detail" collection.pk %}>Cancel</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>
{% endblock %}
Loading

0 comments on commit 61a73ed

Please sign in to comment.