def create_profile():
    user = User.objects.create_user(username=core_utils.get_unique_username())
    permission = Permission.objects.get(codename=u'is_requester')
    user.user_permissions.add(permission)
    user.set_username_by_id()
    user.save()
    return Profile.objects.create(user=user)
Exemplo n.º 2
0
 def create_profile(self):
     user = User.objects.create_user(username=get_unique_username())
     #        задаем права
     permission = Permission.objects.get(codename=u"is_requester")
     user.user_permissions.add(permission)
     user.set_username_by_id()
     user.save()
     return Profile.objects.create(user=user)
Exemplo n.º 3
0
 def save(self, commit=True):
     user = super(RegistrationForm, self).save(commit=False)
     user.username = get_unique_username()
     password = self.cleaned_data.get('password1')
     if password:
         user.set_password(password)
     if commit:
         user.save()
     return user
Exemplo n.º 4
0
def create_user(backend, details, response, uid, username, user=None, *args,
                **kwargs):
    """Create user. Depends on get_username pipeline."""
    if user:
        return {'user': user}
    if not username:
        return None
    user = UserSocialAuth.create_user(username=get_unique_username(), )
    permission = Permission.objects.get(codename=u'is_requester')
    user.user_permissions.add(permission)
    profile = Profile.objects.create(user=user)
    user.set_username_by_id()
    user.save()
    return {
        'user': user,
        'is_new': True
    }
Exemplo n.º 5
0
            self.validate_admission_date(requestion)
        except ValidationError, e:
            errors.extend(e.messages)
        length_errors = []
        length_errors.extend(validate_fields_length(address))
        length_errors.extend(validate_fields_length(profile))
        length_errors.extend(validate_fields_length(requestion))
        length_errors.extend(validate_fields_length(document))
        if length_errors:
            errors.extend(length_errors)
        if errors:
            raise ValidationError(errors)
        else:
#            ошибок нет, можно сохранять объекты
            if not self.fake:
                user = User.objects.create_user(get_unique_username(), '')
                permission = Permission.objects.get(codename=u'is_requester')
                user.user_permissions.add(permission)
                profile.user = user
                profile.save()
                address.save()
                requestion.profile = profile
                requestion.save()
                document.content_object = requestion
                document.save()
                if areas:
                    requestion.areas.add(*areas)
                for sadik in preferred_sadiks:
                    requestion.pref_sadiks.add(sadik)
#                добавляем льготы
                if benefits:
    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})