Exemple #1
0
    def post(self, request):
        user = request.user
        profile = user.profile

        form = Form(request.POST, request.FILES, include={'user': user})
        if not form.is_valid():
            return render(request, self.template, context={'form': form})

        try:
            organisation = Organisation.objects.create(**dict(
                (item, form.cleaned_data[item])
                for item in form.Meta.organisation_fields))
        except ValidationError as e:
            messages.error(request, e.__str__())
            return render(request, self.template, context={'form': form})

        creation_process(request, profile, organisation)

        form.cleaned_data.get('rattachement_process', False) \
            and member_subscribe_process(request, profile, organisation)

        # Dans le cas ou seul le role de contributeur est demandé
        form.cleaned_data.get('contributor_process', False) \
            and not form.cleaned_data.get('referent_process', False) \
            and contributor_subscribe_process(request, profile, organisation)

        # role de référent requis donc role de contributeur requis
        form.cleaned_data.get('referent_process', False) \
            and referent_subscribe_process(request, profile, organisation)

        messages.success(request, "La demande a bien été envoyée.")

        return redirect('idgo_admin:handle_show_organisation')
Exemple #2
0
def handle_pust_request(request, organisation_name=None):
    user = request.user

    organisation = None
    if organisation_name:
        organisation = get_object_or_404(Organisation, slug=organisation_name)

    query_data = getattr(request, request.method)  # QueryDict

    is_idgo_partner = query_data.pop('is_idgo_partner', ['False'])
    if is_idgo_partner and is_idgo_partner[-1] in ['True', 'true', '1', 1]:
        is_idgo_partner = True
    else:
        is_idgo_partner = False

    # Slug/Name
    slug = query_data.pop('name', organisation and [organisation.slug])
    if slug:
        query_data.__setitem__('slug', slug[-1])

    # `legal_name` est obligatoire
    legal_name = query_data.pop('legal_name', organisation
                                and [organisation.legal_name])
    if legal_name:
        query_data.__setitem__('legal_name', legal_name[-1])

    form = Form(query_data,
                request.FILES,
                instance=organisation,
                include={'user': user})
    if not form.is_valid():
        raise GenericException(details=form._errors)

    data = form.cleaned_data
    kvp = dict((item, form.cleaned_data[item])
               for item in form.Meta.organisation_fields)

    try:
        with transaction.atomic():
            if organisation_name:
                for item in form.Meta.fields:
                    if item in data:
                        setattr(organisation, item, data[item])
                setattr(organisation, 'is_crige_partner', is_idgo_partner)
                organisation.save()
            else:
                kvp['is_active'] = True
                organisation = Organisation.objects.create(**kvp)
                AccountActions.objects.create(
                    action='created_organisation_through_api',
                    organisation=organisation,
                    profile=user.profile,
                    closed=timezone.now())
    except ValidationError as e:
        return GenericException(details=e.__str__())

    return organisation
Exemple #3
0
def handle_pust_request(request, organisation_name=None):
    user = request.user

    organisation = None
    if organisation_name:
        organisation = get_object_or_404(Organisation, slug=organisation_name)

    data = getattr(request, request.method).dict()
    data_form = {
        'legal_name': data.get('legal_name'),
        'description': data.get('description'),
        'organisation_type': data.get('type'),
        'address': data.get('address'),
        'postcode': data.get('postcode'),
        'city': data.get('city'),
        'phone': data.get('phone'),
        'email': data.get('email'),
        'license': data.get('license'),
        'jurisdiction': data.get('jurisdiction'),
    }

    form = Form(data_form,
                request.FILES,
                instance=organisation,
                include={'user': user})
    if not form.is_valid():
        raise GenericException(details=form._errors)

    data = form.cleaned_data
    kvp = dict((item, form.cleaned_data[item])
               for item in form.Meta.organisation_fields)

    try:
        with transaction.atomic():
            if organisation_name:
                for item in form.Meta.fields:
                    if item in data_form:
                        setattr(organisation, item, data_form[item])
                organisation.save()
            else:
                kvp['is_active'] = True
                organisation = Organisation.objects.create(**kvp)
                AccountActions.objects.create(
                    action='created_organisation_through_api',
                    organisation=organisation,
                    profile=user.profile,
                    closed=timezone.now())
    except ValidationError as e:
        return GenericException(details=e.__str__())

    return organisation
Exemple #4
0
    def post(self, request, id=None):
        user, profile = user_and_profile(request)

        instance = get_object_or_404(Organisation, id=id)
        form = Form(request.POST,
                    request.FILES,
                    instance=instance,
                    include={
                        'user': user,
                        'id': id
                    })

        if not form.is_valid():
            return render_with_info_profile(request,
                                            self.template,
                                            context={
                                                'id': id,
                                                'form': form
                                            })

        for item in form.Meta.fields:
            setattr(instance, item, form.cleaned_data[item])
        try:
            instance.save()
        except ValidationError as e:
            messages.error(request, e.__str__())
        except CkanBaseError as e:
            form.add_error('__all__', e.__str__())
            messages.error(request, e.__str__())
        else:
            messages.success(request,
                             "L'organisation a été mise à jour avec succès.")

        if 'continue' in request.POST:
            context = {
                'id': id,
                'update': True,
                'organisation': instance,
                'form': Form(instance=instance,
                             include={
                                 'user': user,
                                 'id': id
                             })
            }
            return render_with_info_profile(request,
                                            self.template,
                                            context=context)

        return HttpResponseRedirect(
            reverse('idgo_admin:show_organisation', kwargs={'id':
                                                            instance.id}))
Exemple #5
0
    def post(self, request, id=None):
        organisation = get_object_or_404(Organisation, id=id)

        user = request.user
        profile = user.profile

        is_admin = profile.is_admin
        is_referent = LiaisonsReferents.objects.filter(
            profile=profile, organisation__id=id,
            validated_on__isnull=False) and True or False

        if not (is_referent or is_admin):
            raise Http404()

        form = Form(request.POST,
                    request.FILES,
                    instance=organisation,
                    include={
                        'user': user,
                        'id': id
                    })

        if not form.is_valid():
            return render(request,
                          self.template,
                          context={
                              'id': id,
                              'form': form
                          })

        for item in form.Meta.fields:
            setattr(organisation, item, form.cleaned_data[item])
        try:
            organisation.save()
        except ValidationError as e:
            messages.error(request, e.__str__())
        except CkanBaseError as e:
            form.add_error('__all__', e.__str__())
            messages.error(request, e.__str__())
        else:
            messages.success(request,
                             "L'organisation a été mise à jour avec succès.")

        if 'continue' in request.POST:
            context = {
                'id':
                id,
                'update':
                True,
                'organisation':
                organisation,
                'form':
                Form(instance=organisation, include={
                    'user': user,
                    'id': id
                })
            }
            return render(request, self.template, context=context)

        return HttpResponseRedirect(
            reverse('idgo_admin:show_organisation',
                    kwargs={'id': organisation.id}))