Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
changing handling of collections from frontend to get them working pr…
…operly again now that collections are stored as separate objects
- Loading branch information
Mark MacGillivray
committed
Oct 2, 2011
1 parent
13b938b
commit 937d3e2
Showing
4 changed files
with
69 additions
and
86 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 |
---|---|---|
|
@@ -30,37 +30,37 @@ def upload(self, fileobj, format_, collection=None): | |
''' | ||
parser = Parser() | ||
record_dicts = parser.parse(fileobj, format=format_) | ||
collection_from_parser = None | ||
if collection_from_parser: | ||
collection = collection_from_parser | ||
#collection_from_parser = None | ||
#if collection_from_parser: | ||
# collection = collection_from_parser | ||
# TODO: check authz for write to this collection | ||
collection['records'] = len(record_dicts) | ||
return self.index(collection, record_dicts) | ||
|
||
def upload_from_web(self, request): | ||
''' | ||
:param request_data: Flask request.values attribute. | ||
''' | ||
pkg = dict() | ||
format = 'bibtex' | ||
source = '' | ||
if request.values.get("source"): | ||
source = urllib2.unquote(request.values.get("source", '')) | ||
fileobj = urllib2.urlopen(source) | ||
pkg["source"] = source | ||
format = self.findformat(source) | ||
elif request.files.get('upfile'): | ||
fileobj = request.files.get('upfile') | ||
format = self.findformat(fileobj.filename) | ||
elif request.values.get('data'): | ||
fileobj = StringIO(request.values['data']) | ||
|
||
if request.values.get('format'): | ||
format = request.values.get('format') | ||
pkg["format"] = format | ||
|
||
if not 'collection' in request.values: | ||
raise ValueError('You must provide a collection label') | ||
collection = { | ||
'label': request.values['collection'] | ||
'label': request.values['collection'], | ||
'source': source, | ||
'format': format | ||
} | ||
collection, records = self.upload(fileobj, format, collection) | ||
return (collection, records) | ||
|
@@ -128,7 +128,7 @@ def index(self, collection_dict, record_dicts): | |
bibserver.dao.Record.delete_by_query('collection.exact:"' + | ||
collection.id + '"') | ||
for rec in record_dicts: | ||
rec['collection'] = collection.id | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
markmacgillivray
via email
Contributor
|
||
rec['collection'] = collection["slug"] | ||
records = bibserver.dao.Record.bulk_upsert(record_dicts) | ||
return collection, records | ||
|
||
|
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
Why have we change this from storing the collection id to the collection slug? The collection slug is not unique across collections (only the tuple (userid, slug) is). I am concerned this may cause bugs e.g. the delete of records from existing collection seems to just use the slug rather than slug plus userid. In addition good practice is to use the id for "foreign keys". Why violate this for collection references from records? If it is to do with doing display then IMO it would be better to get collection out when we are doing display rather than change what we store ...
Aside: would you mind dividing up commits a bit more. This commit not only changes this attribute on records but does stuff with graph.html (is it related). In addition it also seems to have changes that should have been part of a merge (I deleted "pkg" stuff back in my commits that you in theory had merged :-) ). Smaller, more granular commits mean easier understanding :-)