Пример #1
0
 def create_document(self, requestion, commit=True):
     document = EvidienceDocument(
         template=self.cleaned_data.get('template'),
         document_number=self.cleaned_data.get('document_number'),
         object_id=self.instance.id,
         content_type=ContentType.objects.get_for_model(self.instance)
         )
     if commit:
         document.save()
     return document
def create_document(requestion, document_number, document_type):
    if document_type == BIRTH_DOC_SIMPLE:
        template = BIRTH_DOC_SIMPLE_TEMPLATE
    else:
        template = BIRTH_DOC_FOREIGN_TEMPLATE
    document = EvidienceDocument(
        template=template,
        document_number=document_number,
        object_id=requestion.id,
        content_type=ContentType.objects.get_for_model(requestion)
    )
    document.save()
    return document
def create_document(requestion, document_number, document_type):

    BIRTH_DOC_SIMPLE = 0
    BIRTH_DOC_SIMPLE_TEMPLATE = EvidienceDocumentTemplate.objects.get(
        destination=REQUESTION_IDENTITY,
        regex=ur'^[A-Z]{1,3}-[А-Я]{1,2} \d{6,7}$')
    BIRTH_DOC_FOREIGN = 1
    BIRTH_DOC_FOREIGN_TEMPLATE = EvidienceDocumentTemplate.objects.filter(
        destination=REQUESTION_IDENTITY,
        regex=ur'.*')[0]
    if document_type == BIRTH_DOC_SIMPLE:
        template = BIRTH_DOC_SIMPLE_TEMPLATE
    else:
        template = BIRTH_DOC_FOREIGN_TEMPLATE
    document = EvidienceDocument(
        template=template,
        document_number=document_number,
        object_id=requestion.id,
        content_type=ContentType.objects.get_for_model(requestion)
    )
    document.save()
    return document
    def save_requestion(self, requestion_data):
        from sadiki.core.workflow import IMPORT_PROFILE, REQUESTION_IMPORT
        coords = requestion_data["requestion_data"].pop("coords")
        requestion = Requestion(**requestion_data['requestion_data'])
        requestion.set_location(coords)
        requestion.status = STATUS_REQUESTER
        profile = Profile()
        user = User.objects.create_user(get_unique_username(), '')
        user.set_username_by_id()
        user.save()
        permission = Permission.objects.get(codename=u'is_requester')
        user.user_permissions.add(permission)
        profile.user = user
        profile.save()
        requestion.profile = profile
        requestion.cast = REQUESTION_TYPE_IMPORTED
        requestion.save()
        document = requestion_data['document']
        if document:
            document_template = EvidienceDocumentTemplate.objects.get(
                name=document['template_name'], import_involved=True,
                destination=REQUESTION_IDENTITY)
            document = EvidienceDocument(
                template=document_template,
                document_number=document['document_number'], confirmed=True,
                fake=document['fake'])
        document.content_object = requestion
        document.save()
        areas_names = requestion_data['areas']
        areas = []
        for area_name in areas_names:
            area = Area.objects.get(name=area_name)
            areas.append(area)
        if areas:
            requestion.areas.add(*areas)
        preferred_sadiks = []
        for sadik_identifier in requestion_data['sadiks_identifiers_list']:
            sadik = Sadik.objects.get(identifier=sadik_identifier)
            preferred_sadiks.append(sadik)
        for sadik in preferred_sadiks:
            requestion.pref_sadiks.add(sadik)
#                добавляем льготы
        benefits_names = requestion_data["benefits_names"]
        benefits = []
        if benefits_names:
            for benefit_name in benefits_names:
                benefit = Benefit.objects.get(name=benefit_name)
                benefits.append(benefit)
        if benefits:
            for benefit in benefits:
                requestion.benefits.add(benefit)
                requestion.save()

        self.try_to_save_personal_data(requestion, profile, requestion_data['personal_data'])
        context_dict = {'user': user, 'profile': profile,
                        'requestion': requestion,
                        'pref_sadiks': preferred_sadiks,
                        'areas': areas, 'benefits': benefits}
        from sadiki.logger.models import Logger
        Logger.objects.create_for_action(IMPORT_PROFILE,
            context_dict={'user': user, 'profile': profile},
            extra={'obj': profile})
        Logger.objects.create_for_action(REQUESTION_IMPORT,
            context_dict=context_dict,
            extra={'obj': requestion,
                'added_pref_sadiks': preferred_sadiks})