mirror of
https://gitlab.crans.org/bde/nk20
synced 2025-06-20 17:41:55 +02:00
add support for cropping image. WIP.
This commit is contained in:
@ -16,6 +16,7 @@ from django.core.exceptions import ValidationError
|
||||
from django_tables2.views import SingleTableView
|
||||
from rest_framework.authtoken.models import Token
|
||||
from dal import autocomplete
|
||||
from PIL import Image
|
||||
|
||||
from note.models import Alias, NoteUser
|
||||
from note.models.transactions import Transaction
|
||||
@ -229,8 +230,16 @@ class ProfilePictureUpdateView(LoginRequiredMixin, FormMixin, DetailView):
|
||||
return self.form_invalid(form)
|
||||
|
||||
def form_valid(self,form):
|
||||
print(form)
|
||||
self.object.note.display_image = form.cleaned_data.get("image","pic/default.png")
|
||||
image_file_field = form.cleaned_data['image']
|
||||
x = form.cleaned_data['x']
|
||||
y = form.cleaned_data['y']
|
||||
w = form.cleaned_data['width']
|
||||
h = form.cleaned_data['height']
|
||||
with Image.open(image_file_field.name) as image:
|
||||
image = image.crop((x, y, w+x, h+y))
|
||||
image.thumbnail((256, 256), Image.ANTIALIAS)
|
||||
image.save(image_file_field.name,format=image.format)
|
||||
self.object.note.display_image = image_file_field
|
||||
self.object.note.save()
|
||||
return super().form_valid(form)
|
||||
|
||||
|
@ -3,8 +3,11 @@
|
||||
|
||||
from dal import autocomplete
|
||||
from django import forms
|
||||
from django.conf import settings
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
import os
|
||||
|
||||
from crispy_forms.helper import FormHelper
|
||||
from crispy_forms.bootstrap import Div
|
||||
from crispy_forms.layout import Layout, HTML
|
||||
@ -27,8 +30,12 @@ class ImageForm(forms.Form):
|
||||
image = forms.ImageField(required = False,
|
||||
label=_('select an image'),
|
||||
help_text=_('Maximal size: 2MB'))
|
||||
x = forms.FloatField(widget=forms.HiddenInput())
|
||||
y = forms.FloatField(widget=forms.HiddenInput())
|
||||
width = forms.FloatField(widget=forms.HiddenInput())
|
||||
height = forms.FloatField(widget=forms.HiddenInput())
|
||||
|
||||
|
||||
|
||||
class TransactionTemplateForm(forms.ModelForm):
|
||||
class Meta:
|
||||
model = TransactionTemplate
|
||||
|
Reference in New Issue
Block a user