Skip to content

Commit

Permalink
fixed logging, imports, inheritace
Browse files Browse the repository at this point in the history
  • Loading branch information
vmaksymiv committed Mar 2, 2016
1 parent 6554048 commit 78f04e7
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 83 deletions.
25 changes: 10 additions & 15 deletions openprocurement/tender/limited/views/award.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# -*- coding: utf-8 -*-
from logging import getLogger
from datetime import timedelta
from openprocurement.api.models import Contract, get_now
from openprocurement.api.utils import (
Expand All @@ -8,15 +7,14 @@
opresource,
json_view,
context_unpack,
APIResource
)
from openprocurement.api.validation import (
validate_award_data,
validate_data,
)
from openprocurement.tender.limited.models import Award

LOGGER = getLogger(__name__)


def validate_patch_award_data(request):
return validate_data(request, Award, True)
Expand All @@ -28,10 +26,7 @@ def validate_patch_award_data(request):
description="Tender awards",
procurementMethodType='reporting',
)
class TenderAwardResource(object):
def __init__(self, request, context):
self.request = request
self.db = request.registry.db
class TenderAwardResource(APIResource):

@json_view(permission='view_tender')
def collection_get(self):
Expand Down Expand Up @@ -181,8 +176,8 @@ def collection_post(self):
award = self.request.validated['award']
tender.awards.append(award)
if save_tender(self.request):
LOGGER.info('Created tender award {}'.format(award.id),
extra=context_unpack(self.request, {'MESSAGE_ID': 'tender_award_create'}, {'award_id': award.id}))
self.LOGGER.info('Created tender award {}'.format(award.id),
extra=context_unpack(self.request, {'MESSAGE_ID': 'tender_award_create'}, {'award_id': award.id}))
self.request.response.status = 201
self.request.response.headers['Location'] = self.request.route_url('Tender Awards', tender_id=tender.id, award_id=award['id'])
return {'data': award.serialize("view")}
Expand Down Expand Up @@ -327,8 +322,8 @@ def patch(self):
return

if save_tender(self.request):
LOGGER.info('Updated tender award {}'.format(self.request.context.id),
extra=context_unpack(self.request, {'MESSAGE_ID': 'tender_award_patch'}, {'TENDER_REV': tender.rev}))
self.LOGGER.info('Updated tender award {}'.format(self.request.context.id),
extra=context_unpack(self.request, {'MESSAGE_ID': 'tender_award_patch'}, {'TENDER_REV': tender.rev}))
return {'data': award.serialize("view")}

@opresource(name='Tender Negotiation Awards',
Expand Down Expand Up @@ -434,8 +429,8 @@ def collection_post(self):
award.complaintPeriod = {'startDate': get_now().isoformat()}
tender.awards.append(award)
if save_tender(self.request):
LOGGER.info('Created tender award {}'.format(award.id),
extra=context_unpack(self.request, {'MESSAGE_ID': 'tender_award_create'}, {'award_id': award.id}))
self.LOGGER.info('Created tender award {}'.format(award.id),
extra=context_unpack(self.request, {'MESSAGE_ID': 'tender_award_create'}, {'award_id': award.id}))
self.request.response.status = 201
self.request.response.headers['Location'] = self.request.route_url('Tender Awards', tender_id=tender.id, award_id=award['id'])
return {'data': award.serialize("view")}
Expand Down Expand Up @@ -530,8 +525,8 @@ def patch(self):
return

if save_tender(self.request):
LOGGER.info('Updated tender award {}'.format(self.request.context.id),
extra=context_unpack(self.request, {'MESSAGE_ID': 'tender_award_patch'}, {'TENDER_REV': tender.rev}))
self.LOGGER.info('Updated tender award {}'.format(self.request.context.id),
extra=context_unpack(self.request, {'MESSAGE_ID': 'tender_award_patch'}, {'TENDER_REV': tender.rev}))
return {'data': award.serialize("view")}


Expand Down
23 changes: 8 additions & 15 deletions openprocurement/tender/limited/views/award_document.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# -*- coding: utf-8 -*-
from logging import getLogger
from openprocurement.api.utils import (
get_file,
save_tender,
Expand All @@ -9,6 +8,7 @@
opresource,
json_view,
context_unpack,
APIResource
)
from openprocurement.api.validation import (
validate_file_update,
Expand All @@ -17,19 +17,12 @@
)


LOGGER = getLogger(__name__)


@opresource(name='Tender Limited Award Documents',
collection_path='/tenders/{tender_id}/awards/{award_id}/documents',
path='/tenders/{tender_id}/awards/{award_id}/documents/{document_id}',
procurementMethodType='reporting',
description="Tender award documents")
class TenderAwardDocumentResource(object):

def __init__(self, request, context):
self.request = request
self.db = request.registry.db
class TenderAwardDocumentResource(APIResource):

@json_view(permission='view_tender')
def collection_get(self):
Expand Down Expand Up @@ -59,8 +52,8 @@ def collection_post(self):
document = upload_file(self.request)
self.request.validated['award'].documents.append(document)
if save_tender(self.request):
LOGGER.info('Created tender award document {}'.format(document.id),
extra=context_unpack(self.request, {'MESSAGE_ID': 'tender_award_document_create'}, {'document_id': document.id}))
self.LOGGER.info('Created tender award document {}'.format(document.id),
extra=context_unpack(self.request, {'MESSAGE_ID': 'tender_award_document_create'}, {'document_id': document.id}))
self.request.response.status = 201
document_route = self.request.matched_route.name.replace("collection_", "")
self.request.response.headers['Location'] = self.request.current_route_url(_route_name=document_route, document_id=document.id, _query={})
Expand Down Expand Up @@ -90,8 +83,8 @@ def put(self):
document = upload_file(self.request)
self.request.validated['award'].documents.append(document)
if save_tender(self.request):
LOGGER.info('Updated tender award document {}'.format(self.request.context.id),
extra=context_unpack(self.request, {'MESSAGE_ID': 'tender_award_document_put'}))
self.LOGGER.info('Updated tender award document {}'.format(self.request.context.id),
extra=context_unpack(self.request, {'MESSAGE_ID': 'tender_award_document_put'}))
return {'data': document.serialize("view")}

@json_view(content_type="application/json", validators=(validate_patch_document_data,), permission='edit_tender')
Expand All @@ -103,8 +96,8 @@ def patch(self):
return
if apply_patch(self.request, src=self.request.context.serialize()):
update_file_content_type(self.request)
LOGGER.info('Updated tender award document {}'.format(self.request.context.id),
extra=context_unpack(self.request, {'MESSAGE_ID': 'tender_award_document_patch'}))
self.LOGGER.info('Updated tender award document {}'.format(self.request.context.id),
extra=context_unpack(self.request, {'MESSAGE_ID': 'tender_award_document_patch'}))
return {'data': self.request.context.serialize("view")}


Expand Down
20 changes: 6 additions & 14 deletions openprocurement/tender/limited/views/cancellation.py
Original file line number Diff line number Diff line change
@@ -1,32 +1,24 @@
# -*- coding: utf-8 -*-
from logging import getLogger
from openprocurement.api.utils import (
apply_patch,
save_tender,
check_tender_status,
opresource,
json_view,
context_unpack,
APIResource
)
from openprocurement.api.validation import (
validate_cancellation_data,
validate_patch_cancellation_data,
)


LOGGER = getLogger(__name__)


@opresource(name='Tender Limited Cancellations',
collection_path='/tenders/{tender_id}/cancellations',
path='/tenders/{tender_id}/cancellations/{cancellation_id}',
procurementMethodType='reporting',
description="Tender cancellations")
class TenderCancellationResource(object):

def __init__(self, request, context):
self.request = request
self.db = request.registry.db
class TenderCancellationResource(APIResource):

@json_view(content_type="application/json", validators=(validate_cancellation_data,), permission='edit_tender')
def collection_post(self):
Expand All @@ -42,8 +34,8 @@ def collection_post(self):
tender.status = 'cancelled'
tender.cancellations.append(cancellation)
if save_tender(self.request):
LOGGER.info('Created tender cancellation {}'.format(cancellation.id),
extra=context_unpack(self.request, {'MESSAGE_ID': 'tender_cancellation_create'}, {'cancellation_id': cancellation.id}))
self.LOGGER.info('Created tender cancellation {}'.format(cancellation.id),
extra=context_unpack(self.request, {'MESSAGE_ID': 'tender_cancellation_create'}, {'cancellation_id': cancellation.id}))
self.request.response.status = 201
self.request.response.headers['Location'] = self.request.route_url('Tender Cancellations', tender_id=tender.id, cancellation_id=cancellation.id)
return {'data': cancellation.serialize("view")}
Expand Down Expand Up @@ -73,8 +65,8 @@ def patch(self):
if self.request.context.status == 'active':
tender.status = 'cancelled'
if save_tender(self.request):
LOGGER.info('Updated tender cancellation {}'.format(self.request.context.id),
extra=context_unpack(self.request, {'MESSAGE_ID': 'tender_cancellation_patch'}))
self.LOGGER.info('Updated tender cancellation {}'.format(self.request.context.id),
extra=context_unpack(self.request, {'MESSAGE_ID': 'tender_cancellation_patch'}))
return {'data': self.request.context.serialize("view")}


Expand Down
16 changes: 6 additions & 10 deletions openprocurement/tender/limited/views/contract.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# -*- coding: utf-8 -*-
from logging import getLogger
from openprocurement.api.models import get_now
from openprocurement.api.utils import (
apply_patch,
Expand All @@ -15,9 +14,6 @@
from openprocurement.api.views.contract import TenderAwardContractResource as BaseTenderAwardContractResource


LOGGER = getLogger(__name__)


def check_tender_status(request):
tender = request.validated['tender']
if tender.contracts and tender.contracts[-1].status == 'active':
Expand All @@ -43,8 +39,8 @@ def collection_post(self):
contract = self.request.validated['contract']
tender.contracts.append(contract)
if save_tender(self.request):
LOGGER.info('Created tender contract {}'.format(contract.id),
extra=context_unpack(self.request, {'MESSAGE_ID': 'tender_contract_create'}, {'contract_id': contract.id}))
self.LOGGER.info('Created tender contract {}'.format(contract.id),
extra=context_unpack(self.request, {'MESSAGE_ID': 'tender_contract_create'}, {'contract_id': contract.id}))
self.request.response.status = 201
self.request.response.headers['Location'] = self.request.route_url('Tender Contracts', tender_id=tender.id, contract_id=contract['id'])
return {'data': contract.serialize()}
Expand All @@ -71,8 +67,8 @@ def patch(self):

check_tender_status(self.request)
if save_tender(self.request):
LOGGER.info('Updated tender contract {}'.format(self.request.context.id),
extra=context_unpack(self.request, {'MESSAGE_ID': 'tender_contract_patch'}))
self.LOGGER.info('Updated tender contract {}'.format(self.request.context.id),
extra=context_unpack(self.request, {'MESSAGE_ID': 'tender_contract_patch'}))
return {'data': self.request.context.serialize()}


Expand Down Expand Up @@ -114,8 +110,8 @@ def patch(self):

check_tender_status(self.request)
if save_tender(self.request):
LOGGER.info('Updated tender contract {}'.format(self.request.context.id),
extra=context_unpack(self.request, {'MESSAGE_ID': 'tender_contract_patch'}))
self.LOGGER.info('Updated tender contract {}'.format(self.request.context.id),
extra=context_unpack(self.request, {'MESSAGE_ID': 'tender_contract_patch'}))
return {'data': self.request.context.serialize()}


Expand Down
16 changes: 6 additions & 10 deletions openprocurement/tender/limited/views/contract_document.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# -*- coding: utf-8 -*-
from logging import getLogger
from openprocurement.api.utils import (
get_file,
save_tender,
Expand All @@ -18,9 +17,6 @@
from openprocurement.api.views.contract_document import TenderAwardContractDocumentResource as BaseTenderAwardContractDocumentResource


LOGGER = getLogger(__name__)


@opresource(name='Tender Limited Contract Documents',
collection_path='/tenders/{tender_id}/contracts/{contract_id}/documents',
path='/tenders/{tender_id}/contracts/{contract_id}/documents/{document_id}',
Expand Down Expand Up @@ -57,8 +53,8 @@ def collection_post(self):
document = upload_file(self.request)
self.request.validated['contract'].documents.append(document)
if save_tender(self.request):
LOGGER.info('Created tender contract document {}'.format(document.id),
extra=context_unpack(self.request, {'MESSAGE_ID': 'tender_contract_document_create'}, {'document_id': document.id}))
self.LOGGER.info('Created tender contract document {}'.format(document.id),
extra=context_unpack(self.request, {'MESSAGE_ID': 'tender_contract_document_create'}, {'document_id': document.id}))
self.request.response.status = 201
document_route = self.request.matched_route.name.replace("collection_", "")
self.request.response.headers['Location'] = self.request.current_route_url(_route_name=document_route, document_id=document.id, _query={})
Expand All @@ -79,8 +75,8 @@ def put(self):
document = upload_file(self.request)
self.request.validated['contract'].documents.append(document)
if save_tender(self.request):
LOGGER.info('Created tender contract document {}'.format(self.request.context.id),
extra=context_unpack(self.request, {'MESSAGE_ID': 'tender_contract_document_put'}))
self.LOGGER.info('Created tender contract document {}'.format(self.request.context.id),
extra=context_unpack(self.request, {'MESSAGE_ID': 'tender_contract_document_put'}))
return {'data': document.serialize("view")}

@json_view(content_type="application/json", validators=(validate_patch_document_data,), permission='edit_tender')
Expand All @@ -96,8 +92,8 @@ def patch(self):
return
if apply_patch(self.request, src=self.request.context.serialize()):
update_file_content_type(self.request)
LOGGER.info('Created tender contract document {}'.format(self.request.context.id),
extra=context_unpack(self.request, {'MESSAGE_ID': 'tender_contract_document_patch'}))
self.LOGGER.info('Created tender contract document {}'.format(self.request.context.id),
extra=context_unpack(self.request, {'MESSAGE_ID': 'tender_contract_document_patch'}))
return {'data': self.request.context.serialize("view")}


Expand Down
7 changes: 2 additions & 5 deletions openprocurement/tender/limited/views/tender.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# -*- coding: utf-8 -*-
from logging import getLogger
from openprocurement.api.views.tender import TenderResource as BaseTenderResource
from openprocurement.api.validation import validate_patch_tender_data
from openprocurement.api.utils import (
Expand All @@ -9,8 +8,6 @@
context_unpack,
)

LOGGER = getLogger(__name__)


@opresource(name='TenderLimited',
path='/tenders/{tender_id}',
Expand Down Expand Up @@ -81,8 +78,8 @@ def patch(self):
else:
data = self.request.validated['data']
apply_patch(self.request, data=data, src=self.request.validated['tender_src'])
LOGGER.info('Updated tender {}'.format(tender.id),
extra=context_unpack(self.request, {'MESSAGE_ID': 'tender_patch'}))
self.LOGGER.info('Updated tender {}'.format(tender.id),
extra=context_unpack(self.request, {'MESSAGE_ID': 'tender_patch'}))
return {'data': tender.serialize(tender.status)}


Expand Down
22 changes: 8 additions & 14 deletions openprocurement/tender/limited/views/tender_document.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# -*- coding: utf-8 -*-
from logging import getLogger
from openprocurement.api.utils import (
get_file,
save_tender,
Expand All @@ -9,6 +8,7 @@
opresource,
json_view,
context_unpack,
APIResource
)
from openprocurement.api.validation import (
validate_file_update,
Expand All @@ -17,19 +17,13 @@
)


LOGGER = getLogger(__name__)


@opresource(name='Tender Limited Documents',
collection_path='/tenders/{tender_id}/documents',
path='/tenders/{tender_id}/documents/{document_id}',
procurementMethodType='reporting',
description="Tender related binary files (PDFs, etc.)")
class TenderDocumentResource(object):

def __init__(self, request, context):
self.request = request
self.db = request.registry.db
class TenderDocumentResource(APIResource):

@json_view(permission='view_tender')
def collection_get(self):
Expand All @@ -54,8 +48,8 @@ def collection_post(self):
document = upload_file(self.request)
self.request.validated['tender'].documents.append(document)
if save_tender(self.request):
LOGGER.info('Created tender document {}'.format(document.id),
extra=context_unpack(self.request, {'MESSAGE_ID': 'tender_document_create'}, {'document_id': document.id}))
self.LOGGER.info('Created tender document {}'.format(document.id),
extra=context_unpack(self.request, {'MESSAGE_ID': 'tender_document_create'}, {'document_id': document.id}))
self.request.response.status = 201
document_route = self.request.matched_route.name.replace("collection_", "")
self.request.response.headers['Location'] = self.request.current_route_url(_route_name=document_route, document_id=document.id, _query={})
Expand Down Expand Up @@ -85,8 +79,8 @@ def put(self):
document = upload_file(self.request)
self.request.validated['tender'].documents.append(document)
if save_tender(self.request):
LOGGER.info('Updated tender document {}'.format(self.request.context.id),
extra=context_unpack(self.request, {'MESSAGE_ID': 'tender_document_put'}))
self.LOGGER.info('Updated tender document {}'.format(self.request.context.id),
extra=context_unpack(self.request, {'MESSAGE_ID': 'tender_document_put'}))
return {'data': document.serialize("view")}

@json_view(content_type="application/json", permission='upload_tender_documents', validators=(validate_patch_document_data,))
Expand All @@ -98,8 +92,8 @@ def patch(self):
return
if apply_patch(self.request, src=self.request.context.serialize()):
update_file_content_type(self.request)
LOGGER.info('Updated tender document {}'.format(self.request.context.id),
extra=context_unpack(self.request, {'MESSAGE_ID': 'tender_document_patch'}))
self.LOGGER.info('Updated tender document {}'.format(self.request.context.id),
extra=context_unpack(self.request, {'MESSAGE_ID': 'tender_document_patch'}))
return {'data': self.request.context.serialize("view")}

@opresource(name='Tender Negotiation Documents',
Expand Down

0 comments on commit 78f04e7

Please sign in to comment.