Fakultas Ilmu Komputer UI

Commit bb3877af authored by Gregorius Aprisunnea's avatar Gregorius Aprisunnea
Browse files

add implementation of removing ExifMetadata in app/views.py on suntingProfile...

add implementation of removing ExifMetadata in app/views.py on suntingProfile for both admin and kontributor
parent ad56e56a
Pipeline #57748 passed with stages
in 19 minutes and 21 seconds
...@@ -19,6 +19,7 @@ from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger ...@@ -19,6 +19,7 @@ from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger
from administration.models import VerificationReport from administration.models import VerificationReport
from app.forms import SuntingProfilForm, UploadMateriForm from app.forms import SuntingProfilForm, UploadMateriForm
from app.models import Category, Comment, Materi, Like, ViewStatistics, DownloadStatistics, ReqMaterial from app.models import Category, Comment, Materi, Like, ViewStatistics, DownloadStatistics, ReqMaterial
from app.utils.fileManagementUtil import get_random_filename, remove_image_exifdata
from authentication.models import User from authentication.models import User
import django import django
...@@ -340,11 +341,26 @@ class SuntingProfilView(TemplateView): ...@@ -340,11 +341,26 @@ class SuntingProfilView(TemplateView):
raise PermissionDenied(request) raise PermissionDenied(request)
current_user = self.request.user current_user = self.request.user
form = SuntingProfilForm( form = SuntingProfilForm(
request.POST, request.FILES, instance=current_user) request.POST, request.FILES, instance=current_user)
if form.is_valid(): if form.is_valid():
current_user.default_profile_picture = True current_user.default_profile_picture = True
form.save()
# Removing exifdata from profile picture on upload
if request.FILES:
f_name = request.FILES['profile_picture'].name
f_name = get_random_filename(f_name)
f_path = settings.MEDIA_ROOT + "/" + f_name
request.FILES['profile_picture'].name = f_name
form = SuntingProfilForm(
request.POST, request.FILES, instance=current_user)
form.save()
remove_image_exifdata(f_path)
else:
form.save()
return HttpResponseRedirect("/profil/") return HttpResponseRedirect("/profil/")
else: else:
context = self.get_context_data(**kwargs) context = self.get_context_data(**kwargs)
...@@ -379,11 +395,26 @@ class SuntingProfilAdminView(TemplateView): ...@@ -379,11 +395,26 @@ class SuntingProfilAdminView(TemplateView):
raise PermissionDenied(request) raise PermissionDenied(request)
current_user = self.request.user current_user = self.request.user
form = SuntingProfilForm( form = SuntingProfilForm(
request.POST, request.FILES, instance=current_user) request.POST, request.FILES, instance=current_user)
if form.is_valid(): if form.is_valid():
current_user.default_profile_picture = True current_user.default_profile_picture = True
form.save()
# Removing exifdata from profile picture on upload
if request.FILES:
f_name = request.FILES['profile_picture'].name
f_name = get_random_filename(f_name)
f_path = settings.MEDIA_ROOT + "/" + f_name
request.FILES['profile_picture'].name = f_name
form = SuntingProfilForm(
request.POST, request.FILES, instance=current_user)
form.save()
remove_image_exifdata(f_path)
else:
form.save()
return HttpResponseRedirect("/profil-admin/") return HttpResponseRedirect("/profil-admin/")
else: else:
context = self.get_context_data(**kwargs) context = self.get_context_data(**kwargs)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment