Fotobug behoben

This commit is contained in:
holger.trampe 2019-12-12 21:39:01 +01:00
parent ab3f761ca6
commit 57e47e9234
14 changed files with 20 additions and 31 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 49 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 49 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 49 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 49 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 49 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 49 KiB

View File

@ -31,7 +31,7 @@ class Agency(models.Model):
city = models.CharField(default="", max_length=200, blank=True)
email = models.EmailField(default="", blank=True)
phone = models.CharField(default="", max_length=20, blank=True)
agencypic = models.ImageField(default='default.jpg', upload_to='agencymain', blank=True, null="default.jpg")
agencypic = models.ImageField(default='default.jpg', upload_to='agencymain', blank=True)
def __str__(self):
return f'{self.name}'
@ -84,7 +84,7 @@ class Profile(models.Model):
func = models.CharField(choices=agency_task, default="", max_length=50)
# Wenn dieses Profil gelöscht wird, wird NICHT die Agency geslöscht
agency = models.ForeignKey(Agency, on_delete=models.PROTECT)
image = models.ImageField(default='default.jpg', upload_to='userprofilepics', blank=True, null="default.jpg")
image = models.ImageField(default='default.jpg', upload_to='userprofilepics', blank=True)
compfunc = models.CharField(max_length=60, blank=True)
@ -100,26 +100,27 @@ class Profile(models.Model):
def save(self, **kwargs):
super().save()
img = Image.open(self.image.path)
# Bildspeichergröße
#if(img.height > 300 or img.width > 300):
# output_size = (300,300)
# img.thumbnail(output_size)
# img.save(self.image.path)
baseheight = 560
hpercent = (baseheight / float(img.size[1]))
wsize = int((float(img.size[0]) * float(hpercent)))
img = img.resize((wsize, baseheight), Image.ANTIALIAS)
img.save(self.image.path)
if self.image:
img = Image.open(self.image.path)
# Bildspeichergröße
if(img.height > 300 or img.width > 300):
output_size = (300,300)
img.thumbnail(output_size)
img.save(self.image.path)
baseheight = 560
hpercent = (baseheight / float(img.size[1]))
wsize = int((float(img.size[0]) * float(hpercent)))
img = img.resize((wsize, baseheight), Image.ANTIALIAS)
img.save(self.image.path)
@property
def get_photo_url(self):
if self.image and hasattr(self.image, 'url'):
return self.image.url
else:
return "/media/userprofilepics/default.jpg"
# PERMISSIONS - Über alle Modelle hinweg, in der url.py wird dann die route verhindert!
# Im template: if perms.users.PERMISSION
class Meta:

View File

@ -37,15 +37,6 @@ class UsersAddProfileForm(forms.ModelForm):
}
fields = ['phoneland','phonemobile','func', 'compfunc', 'image']
#class UsersAddProfileFormParents(forms.ModelForm):
# def __init__(self, user, *args, **kwargs):
# super().__init__(*args, **kwargs)
# possibleUsers = Profile
# Formular zum hinzufügen neuer Agentur-Mitglieder
class AgencyUpdateForm(forms.ModelForm):

View File

@ -219,17 +219,14 @@ def ProfileUpdateView(request, pk):
prof_user = User.objects.get(profile__pk=pk)
if request.method == 'POST':
profileform_form = UsersAddProfileForm(request.POST, instance=prof_user.profile)
profileform_form = UsersAddProfileForm(request.POST, request.FILES, instance=prof_user.profile)
#profileform_parents = UsersAddProfileFormParents(request.POST, instance=request.user)
if profileform_form.is_valid():
print(profileform_form)
profileform_form.save()
#prename = request.user.first_name
#name = request.user.last_name
#messages.success(request, f'Daten für {prename} {name} aktualisiert!')
prename = request.user.first_name
name = request.user.last_name
messages.success(request, f'Daten für {prename} {name} aktualisiert!')
# Daten neu laden und nicht die "Mächten sie die Daten speichern...?"
return redirect('users-management')