Skip to content

Commit

Permalink
Merge branch 'a222684882524832_put_json'
Browse files Browse the repository at this point in the history
  • Loading branch information
kroman0 committed Dec 20, 2016
2 parents 14baf38 + c7a18ed commit a5179fb
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
3 changes: 3 additions & 0 deletions src/openprocurement/api/tests/bidder.py
Original file line number Diff line number Diff line change
Expand Up @@ -974,9 +974,11 @@ def test_put_tender_bidder_document_json(self):
'url': self.generate_docservice_url(),
'hash': 'md5:' + '0' * 32,
'format': 'application/msword',
'description': 'test description',
}})
self.assertEqual(response.status, '200 OK')
self.assertEqual(response.content_type, 'application/json')
self.assertEqual('test description', response.json["data"]["description"])
self.assertEqual(doc_id, response.json["data"]["id"])
key = response.json["data"]["url"].split('?')[-1]

Expand Down Expand Up @@ -1004,6 +1006,7 @@ def test_put_tender_bidder_document_json(self):
}})
self.assertEqual(response.status, '200 OK')
self.assertEqual(response.content_type, 'application/json')
self.assertEqual('test description', response.json["data"]["description"])
self.assertEqual(doc_id, response.json["data"]["id"])
key = response.json["data"]["url"].split('?')[-1]

Expand Down
9 changes: 6 additions & 3 deletions src/openprocurement/api/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
VERSION = '{}.{}'.format(int(PKG.parsed_version[0]), int(PKG.parsed_version[1]) if PKG.parsed_version[1].isdigit() else 0)
ROUTE_PREFIX = '/api/{}'.format(VERSION)
DOCUMENT_BLACKLISTED_FIELDS = ('title', 'format', 'url', 'dateModified', 'hash')
DOCUMENT_WHITELISTED_FIELDS = ('id', 'datePublished', 'author', '__parent__')
ACCELERATOR_RE = compile(r'.accelerator=(?P<accelerator>\d+)')
SESSION = Session()
json_view = partial(view, renderer='json')
Expand Down Expand Up @@ -97,13 +98,15 @@ def generate_docservice_url(request, doc_id, temporary=True, prefix=None):
return urlunsplit((parsed_url.scheme, parsed_url.netloc, '/get/{}'.format(doc_id), urlencode(query), ''))


def upload_file(request, blacklisted_fields=DOCUMENT_BLACKLISTED_FIELDS):
first_document = request.validated['documents'][0] if 'documents' in request.validated and request.validated['documents'] else None
def upload_file(request, blacklisted_fields=DOCUMENT_BLACKLISTED_FIELDS, whitelisted_fields=DOCUMENT_WHITELISTED_FIELDS):
first_document = request.validated['documents'][-1] if 'documents' in request.validated and request.validated['documents'] else None
if 'data' in request.validated and request.validated['data']:
document = check_document(request, request.validated['document'], 'body', {})
if first_document:
for attr_name in type(first_document)._fields:
if attr_name not in blacklisted_fields:
if attr_name in whitelisted_fields:
setattr(document, attr_name, getattr(first_document, attr_name))
elif attr_name not in blacklisted_fields and getattr(document, attr_name) == type(first_document)._fields[attr_name].default:
setattr(document, attr_name, getattr(first_document, attr_name))
return document
if request.content_type == 'multipart/form-data':
Expand Down

0 comments on commit a5179fb

Please sign in to comment.