Esempio n. 1
0
 def form_valid_formset(self, form: ModelForm,
                        formset: ProfileFormSet) -> HttpResponseRedirect:
     if formset.is_valid():
         formset.save(commit=False)
         formset.save()
     else:
         return HttpResponseRedirect(self.get_success_url())
     form.save()
     return HttpResponseRedirect(self.get_success_url())
Esempio n. 2
0
 def save_existing(self, form: ModelForm, instance: Page,
                   commit: bool = True) -> Page:
     """Replace an existing chapter page."""
     with form.instance.image.open('rb') as img:
         dgst = blake2b(img.read(), digest_size=16)
         ext = form.instance.image.name.split(".")[-1]
         path = form.instance.chapter.get_directory()
         name = str(path / f'{dgst.hexdigest()}.{ext}')
         form.instance.image.name = name
         return form.save(commit=commit)
Esempio n. 3
0
    def save(self, commit=True):

        instance = ModelForm.save(self, commit=False)
        return UrlShortener.objects.get_or_create_short(
            url_long=instance.url_long, automatico=False, link_absoluto=True)
Esempio n. 4
0
 def save(self, user, commit=True):
     self.instance.user = user        
     return ModelForm.save(self, commit=commit)
Esempio n. 5
0
 def save(self):
     return ModelForm.save(self)
Esempio n. 6
0
 def save(self, commit=True):
     inst = ModelForm.save(self, commit=True)
     return inst