<commit_before># -*- coding: utf-8 -*-
from openprocurement.api.views.tender import TenderResource
from openprocurement.tender.openeu.views.tender import TenderEUResource
from openprocurement.tender.openua.validation import validate_patch_tender_ua_data
from openprocurement.tender.competitivedialogue.utils import patch_eu, set_ownership
from openprocurement.api.utils import opresource, json_view, save_tender, context_unpack, APIResource
from openprocurement.tender.competitivedialogue.models import CD_EU_TYPE, CD_UA_TYPE, STAGE_2_EU_TYPE, STAGE_2_UA_TYPE
from openprocurement.tender.competitivedialogue.validation import validate_patch_tender_stage2_data


@opresource(name='Competitive Dialogue for EU procedure',
            path='/tenders/{tender_id}',
            procurementMethodType=CD_EU_TYPE,
            description="Open Contracting compatible data exchange format. See  for more info")
class CompetitiveDialogueEUResource(TenderEUResource):
    """ Resource handler for Competitive Dialogue EU"""

    @json_view(content_type="application/json", validators=(validate_patch_tender_ua_data,), permission='edit_tender')
    def patch(self):
        return patch_eu(self)


@opresource(name='Competitive Dialogue for UA procedure',
            path='/tenders/{tender_id}',
            procurementMethodType=CD_UA_TYPE,
            description="Open Contracting compatible data exchange format. See # for more info")
class CompetitiveDialogueUAResource(TenderResource):
    """ Resource handler for Competitive Dialogue UA"""

    @json_view(content_type="application/json", validators=(validate_patch_tender_ua_data,), permission='edit_tender')
    def patch(self):
        return patch_eu(self)


@opresource(name='Tender Stage 2 for UA procedure',
            path='/tenders/{tender_id}',
            procurementMethodType=STAGE_2_UA_TYPE,
            description="")
class TenderStage2UAResource(TenderEUResource):
    """ Resource handler for tender stage 2 UA"""

    @json_view(content_type="application/json", validators=(validate_patch_tender_stage2_data,), permission='edit_tender')
    def patch(self):
        return patch_eu(self)


@opresource(name='Tender Stage 2 for EU procedure',
            path='/tenders/{tender_id}',
            procurementMethodType=STAGE_2_EU_TYPE,
            description="")
class TenderStage2UEResource(TenderEUResource):
    """ Resource handler for tender stage 2 EU"""

    @json_view(content_type="application/json", validators=(validate_patch_tender_stage2_data,), permission='edit_tender')
    def patch(self):
        return patch_eu(self)


@opresource(name='Tender stage2 EU credentials',
            path='/tenders/{tender_id}/credentials',
            procurementMethodType=STAGE_2_EU_TYPE,
            description="Tender stage2 UE credentials")
class TenderStage2EUCredentialsResource(APIResource):

    @json_view(permission='generate_credentials')
    def patch(self):
        tender = self.request.validated['tender']
        if tender.status != "draft":
            self.request.errors.add('body', 'data',
                                    'Can\'t generate credentials in current ({}) contract status'.format(
                                        tender.status))
            self.request.errors.status = 403
            return

        set_ownership(tender)
        if save_tender(self.request):<commit_msg>generate new token only if tender status is draft.stage2<commit_after># -*- coding: utf-8 -*-
from openprocurement.api.views.tender import TenderResource
from openprocurement.tender.openeu.views.tender import TenderEUResource
from openprocurement.tender.openua.validation import validate_patch_tender_ua_data
from openprocurement.tender.competitivedialogue.utils import patch_eu, set_ownership
from openprocurement.api.utils import opresource, json_view, save_tender, context_unpack, APIResource
from openprocurement.tender.competitivedialogue.models import CD_EU_TYPE, CD_UA_TYPE, STAGE_2_EU_TYPE, STAGE_2_UA_TYPE
from openprocurement.tender.competitivedialogue.validation import validate_patch_tender_stage2_data


@opresource(name='Competitive Dialogue for EU procedure',
            path='/tenders/{tender_id}',
            procurementMethodType=CD_EU_TYPE,
            description="Open Contracting compatible data exchange format. See  for more info")
class CompetitiveDialogueEUResource(TenderEUResource):
    """ Resource handler for Competitive Dialogue EU"""

    @json_view(content_type="application/json", validators=(validate_patch_tender_ua_data,), permission='edit_tender')
    def patch(self):
        return patch_eu(self)


@opresource(name='Competitive Dialogue for UA procedure',
            path='/tenders/{tender_id}',
            procurementMethodType=CD_UA_TYPE,
            description="Open Contracting compatible data exchange format. See # for more info")
class CompetitiveDialogueUAResource(TenderResource):
    """ Resource handler for Competitive Dialogue UA"""

    @json_view(content_type="application/json", validators=(validate_patch_tender_ua_data,), permission='edit_tender')
    def patch(self):
        return patch_eu(self)


@opresource(name='Tender Stage 2 for UA procedure',
            path='/tenders/{tender_id}',
            procurementMethodType=STAGE_2_UA_TYPE,
            description="")
class TenderStage2UAResource(TenderEUResource):
    """ Resource handler for tender stage 2 UA"""

    @json_view(content_type="application/json", validators=(validate_patch_tender_stage2_data,), permission='edit_tender')
    def patch(self):
        return patch_eu(self)


@opresource(name='Tender Stage 2 for EU procedure',
            path='/tenders/{tender_id}',
            procurementMethodType=STAGE_2_EU_TYPE,
            description="")
class TenderStage2UEResource(TenderEUResource):
    """ Resource handler for tender stage 2 EU"""

    @json_view(content_type="application/json", validators=(validate_patch_tender_stage2_data,), permission='edit_tender')
    def patch(self):
        return patch_eu(self)


@opresource(name='Tender stage2 EU credentials',
            path='/tenders/{tender_id}/credentials',
            procurementMethodType=STAGE_2_EU_TYPE,
            description="Tender stage2 UE credentials")
class TenderStage2EUCredentialsResource(APIResource):

    @json_view(permission='generate_credentials')
    def patch(self):
        tender = self.request.validated['tender']
        if tender.status != "draft.stage2":
            self.request.errors.add('body', 'data',
                                    'Can\'t generate credentials in current ({}) contract status'.format(
                                        tender.status))
            self.request.errors.status = 403
            return

        set_ownership(tender)
        if save_tender(self.request):
{'fraction_non_alphanumeric': 0.09501466275659824, 'fraction_numerical': 0.0064516129032258064, 'mean_word_length': 3.9463379260333573, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '825450', 'n_tokens_mistral': 1985, 'n_tokens_neox': 1940, 'n_words': 385}