Skip to content
This repository has been archived by the owner on Jun 1, 2022. It is now read-only.

Commit

Permalink
Merge pull request #232 from editorsnotes/dev
Browse files Browse the repository at this point in the history
Finish replacing form admin with JS <=> API interface.
  • Loading branch information
ptgolden committed Jun 20, 2014
2 parents 0fd763a + 359b4dc commit 8ffd2e3
Show file tree
Hide file tree
Showing 232 changed files with 25,226 additions and 17,274 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ before_script:
- psql -c "CREATE DATABASE testdb;" -U postgres

script:
- python manage.py test main api admin
- python manage.py test main api
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,9 @@ and make sure you have the following dependencies
2. Edit the generated "editorsnotes/settings\_local.py" file with your database information
3. Run `fab sync_database`
4. Start the development server with `fab runserver`

## Browser compatibility
Editors' Notes is tested against the latest versions of Firefox, Chrome, Safari, and Opera, as well as Internet Explorer 10+.

[![browser support](https://ci.testling.com/editorsnotes/editorsnotes.png)
](https://ci.testling.com/editorsnotes/editorsnotes)
11 changes: 0 additions & 11 deletions editorsnotes/admin/fields.py

This file was deleted.

3 changes: 0 additions & 3 deletions editorsnotes/admin/forms/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,2 @@
from common import *
from documents import *
from notes import *
from projects import *
from topics import *
44 changes: 0 additions & 44 deletions editorsnotes/admin/forms/common.py

This file was deleted.

132 changes: 1 addition & 131 deletions editorsnotes/admin/forms/documents.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,137 +3,7 @@
from django import forms
from django.forms.models import ModelForm, inlineformset_factory

from editorsnotes.djotero.widgets import ZoteroWidget
from editorsnotes.djotero.models import ZoteroLink
from editorsnotes.main.models import (
Document, DocumentLink, Scan, Transcript, Footnote)

from ..fields import MultipleFileInput

class DocumentForm(ModelForm):
zotero_string = forms.CharField(required=False, widget=ZoteroWidget())
class Media:
js = (
"function/admin-bootstrap-document.js",
)
class Meta:
model = Document
fields = ('description', 'edtf_date',)
widgets = {
'edtf_date': forms.widgets.HiddenInput()
}

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

if kwargs.has_key('instance'):
document = kwargs['instance']
self.initial['zotero_string'] = document.zotero_data or ''

def save_zotero_data(self):
document = self.instance
if self.data.get('zotero-data-DELETE', '') == 'DELETE':
document.zotero_data = None
document.save()
if document.zotero_link is not None:
document.zotero_link.delete()
elif self.changed_data is not None and 'zotero_string' in self.changed_data:
document.zotero_data = self.cleaned_data['zotero_string']
document.save()
if not document.zotero_link:
ZoteroLink.objects.create(zotero_item=document)
else:
document.zotero_link.save()
return document

class DocumentLinkForm(ModelForm):
class Meta:
model = DocumentLink
exclude = ('affiliated_projects',)
widgets = {
'description': forms.widgets.Textarea(
attrs={ 'cols': 80, 'rows': 2 })
}
DocumentLinkFormset = inlineformset_factory(
Document, DocumentLink, form=DocumentLinkForm, extra=1)

class ScanForm(ModelForm):
class Meta:
fields = ('image', 'ordering')
model = Scan
widgets = {
'image': MultipleFileInput(),
'ordering': forms.HiddenInput()
}

class ScanFormset(forms.models.BaseInlineFormSet):
"""
If multiple images were posted from a single file input with the attribute
"multiple", this formset will split them up into regular forms
"""
def _construct_forms(self):
self.forms = []
forms_from_multiple_input = []

for i in xrange(self.total_form_count()):
form = self._construct_form(i)

# Only pay attention to multiple files from an input if this is the
# last image field and there is something to save
if (i < self.total_form_count() - 1 or not form.files):
self.forms.append(form)
continue

# If only one image was posted from this input, treat it as a normal
# one. This allows us to treat this formset as it normally would be,
# which is beneficial for several reasons, including continued
# support for browsers that don't support the "multiple" attribute.
images = form.files.getlist('%s-image' % form.prefix)
if len(images) == 1:
self.forms.append(form)
continue

# Make a copy of the file & data dictionaries, which will be amended
# in order to make new ScanForm instances
newfiles = dict((k, v) for k, v in form.files.items())
newdata = dict((k, v) for k, v in form.data.items())

# Pretend that each image was posted individually
j = i
for image in images:
prefix = self.add_prefix(j)
newfiles['%s-image' % prefix] = image
newdata['%s-ordering' % prefix] = j
newform = self._construct_form(j, files=newfiles, data=newdata)
forms_from_multiple_input.append(newform)
j += 1

# Only add these new forms to the formset if the images are valid. This
# does go against the normal flow of validation, but it makes the
# workflow for adding scans *much* less complicated to take an
# all-or-nothing approach to accepting multiple images.
if all(map(lambda f: f.is_valid(), forms_from_multiple_input)):
self.forms += forms_from_multiple_input
else:
# Make the last form an empty one, like it was previously
self.forms.append(
self._construct_form(self.total_form_count() - 1, files=None))
self.bad_multi_images = 'One or more files uploaded were not valid images.'

# Does the management form need to be changed at all? I can't think of
# any situation where it would be, but here's how it probably would be
# done if needed.
# self.management_form['initial']['TOTAL_FORMS'] = len(self.forms)

# Display errors from a multiple upload field as a non-form error-- in the
# formset, not the individual form
def clean(self):
if hasattr(self, 'bad_multi_images'):
raise forms.ValidationError(self.bad_multi_images)

ScanFormset = inlineformset_factory(
Document, Scan,
form=ScanForm, formset=ScanFormset, extra=1)
from editorsnotes.main.models import Transcript, Footnote

class TranscriptForm(ModelForm):
class Media:
Expand Down
16 changes: 0 additions & 16 deletions editorsnotes/admin/forms/notes.py

This file was deleted.

36 changes: 0 additions & 36 deletions editorsnotes/admin/forms/topics.py

This file was deleted.

6 changes: 3 additions & 3 deletions editorsnotes/admin/static/function/admin-bootstrap-base.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ $(document).ready(function () {
.on('click', '.collapsable legend', function () {
var $this = $(this);
$this.toggleClass('.collapsed')
.find('i').toggleClass('icon-plus icon-minus');
.find('i').toggleClass('fa-plus fa-minus');
$this.siblings('.fieldset-content').toggle();
})

Expand All @@ -108,7 +108,7 @@ $(document).ready(function () {
.css('cursor', 'pointer')
.each(function () {
$('<i>', {
'class': 'icon-minus',
'class': 'fa fa-minus',
'css': {'margin': '6px 0 0 3px'}
}).appendTo(this);
})
Expand All @@ -122,7 +122,7 @@ $(document).ready(function () {
$('<a>', {
'class': 'remove-related-topic',
'href': '#',
'html': '<i class="icon-remove-sign"></i>'
'html': '<i class="fa fa-times-circle"></i>'
}).appendTo($(this).hide().parents('.topicassignment'));
});

Expand Down
33 changes: 0 additions & 33 deletions editorsnotes/admin/static/function/admin-bootstrap-document.js

This file was deleted.

Loading

0 comments on commit 8ffd2e3

Please sign in to comment.