Exemplo n.º 1
0
    def __init__(self, request, token, formation_id):
        BaseAjouterViewModel.__init__(self, request, token)
        BaseModifierViewModel.__init__(self, request, token, formation_id)
        self.formation = Formation.objects.get(pk=formation_id)
        self.form = FormationCommentaireForm()
        self.commentaires = FormationCommentaire.objects.filter(
            formation=self.formation
        ).order_by("date")

        for commentaire in self.commentaires:
            commentaire.modifier_url = reverse('commentaire_modifier', 
                                               args=[self.token, 
                                                     self.formation.id,
                                                     commentaire.id])
            commentaire.modifiable = commentaire.peut_modifier(request.user)
Exemplo n.º 2
0
    def __init__(self, request, token, formation_id):
        BaseAjouterViewModel.__init__(self, request, token)
        BaseModifierViewModel.__init__(self, request, token, formation_id)
        self.formation = Formation.objects.get(pk=formation_id)
        self.files = Fichier.objects.filter(formation=self.formation).order_by('nom')

        # Model field -> Form field
        def callback(field, **kwargs):
            form_field = field.formfield(**kwargs)

            if field.name == 'file':
                form_field.widget.token = token

            return form_field

        FichierFormSet = inlineformset_factory(Formation, Fichier, extra=1, form=FichierForm, formfield_callback=callback)

        if request.method == "POST":
            self.formset = FichierFormSet(data=request.POST, files=request.FILES, instance=self.formation)
            if self.formset.is_valid():
                self.formset.save()
        self.formset = FichierFormSet(instance=self.formation)