From d9d7302b8d45d2f15a146a85cf5ddccf6ff175fb Mon Sep 17 00:00:00 2001 From: Arief Pratama Date: Thu, 1 Oct 2020 20:38:37 +0700 Subject: [PATCH 1/5] Update sunting profile forms --- app/forms.py | 5 ++++- app/views.py | 3 ++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/app/forms.py b/app/forms.py index e303249..7122615 100644 --- a/app/forms.py +++ b/app/forms.py @@ -27,10 +27,13 @@ class UploadMateriForm(forms.ModelForm): class SuntingProfilForm(forms.ModelForm): class Meta: model = User - fields = ["profile_picture", "linkedin", + fields = ["email","name","instansi", "nik", "alamat", "nomor_telpon", + "profile_picture", "linkedin", "facebook", "twitter", "instagram", "biography"] def __init__(self, *args, **kwargs): super(SuntingProfilForm, self).__init__(*args, **kwargs) for field_name, field in self.fields.items(): field.widget.attrs["class"] = "form-control" + + self.fields["email"].widget.attrs["readonly"] = True diff --git a/app/views.py b/app/views.py index a505a3e..ddfa07c 100644 --- a/app/views.py +++ b/app/views.py @@ -20,6 +20,7 @@ from administration.models import VerificationReport from app.forms import SuntingProfilForm, UploadMateriForm from app.models import Category, Comment, Materi, Like, ViewStatistics, DownloadStatistics from authentication.models import User +import django class DaftarKatalog(TemplateView): @@ -317,7 +318,7 @@ class SuntingProfilView(TemplateView): template_name = "sunting.html" def dispatch(self, request, *args, **kwargs): - if not request.user.is_contributor: + if isinstance(request.user, django.contrib.auth.models.AnonymousUser): raise PermissionDenied(request) return super(SuntingProfilView, self).dispatch(request, *args, **kwargs) -- GitLab From 77d66c71fe02f5942e414e976860925067ece015 Mon Sep 17 00:00:00 2001 From: Arief Pratama Date: Thu, 1 Oct 2020 20:58:00 +0700 Subject: [PATCH 2/5] Test Anonymous Access --- app/tests.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/app/tests.py b/app/tests.py index f8fff26..b91c0de 100644 --- a/app/tests.py +++ b/app/tests.py @@ -507,6 +507,13 @@ class SuntingProfilTest(TestCase): # Logout self.client.logout() + def test_sunting_profile_access_anonymous(self): + # Test + response = self.client.get(self.url) + self.assertEqual(response.status_code, 403) + + + class SuntingProfilAdminTest(TestCase): def setUp(self): self.client = Client() -- GitLab From 36678e277903c390325523f2df95b0f7eea9556e Mon Sep 17 00:00:00 2001 From: Arief Pratama Date: Thu, 1 Oct 2020 22:16:25 +0700 Subject: [PATCH 3/5] Red message error, autofocus --- app/forms.py | 8 +++++++- app/templates/sunting.html | 6 +++++- app/tests.py | 17 +++++++++++++++++ 3 files changed, 29 insertions(+), 2 deletions(-) diff --git a/app/forms.py b/app/forms.py index 7122615..64a096e 100644 --- a/app/forms.py +++ b/app/forms.py @@ -33,7 +33,13 @@ class SuntingProfilForm(forms.ModelForm): def __init__(self, *args, **kwargs): super(SuntingProfilForm, self).__init__(*args, **kwargs) + for field_name, field in self.fields.items(): field.widget.attrs["class"] = "form-control" - + + if any(self.errors): + key = list(self.errors)[0] + self.fields[key].widget.attrs["autofocus"] = "" + + self.fields["email"].widget.attrs["readonly"] = True diff --git a/app/templates/sunting.html b/app/templates/sunting.html index 7da9441..ce7e4d5 100644 --- a/app/templates/sunting.html +++ b/app/templates/sunting.html @@ -16,7 +16,11 @@
{{ field.label_tag }} {{ field }} - {{ field.errors }} + {% if field.errors %} + + {{ field.errors }} + + {% endif %} {% if field.help_text %}

{{ field.help_text|safe }}

{% endif %} diff --git a/app/tests.py b/app/tests.py index b91c0de..eef0f2e 100644 --- a/app/tests.py +++ b/app/tests.py @@ -15,6 +15,7 @@ from .views import (DaftarKatalog, DashboardKontributorView, DetailMateri, ProfilKontributorView, SuksesLoginAdminView, SuksesLoginKontributorView, SuntingProfilView, ProfilAdminView, CommentsView, SuntingProfilAdminView, RevisiMateriView) +from app.forms import SuntingProfilForm class DaftarKatalogTest(TestCase): @@ -512,6 +513,22 @@ class SuntingProfilTest(TestCase): response = self.client.get(self.url) self.assertEqual(response.status_code, 403) + def test_sunting_profile_autofocus(self): + form_data = { + "email": "kontributor@gov.id", + "name": "kontributor", + "instansi": "instansi", + "nik": "nik", + "alamat": "alamat", + "nomor_telpon": "123456789", + "twitter": "Twit", + "instagram": "https://instagram.com/test_ig" + } + form = SuntingProfilForm(data=form_data) + + # Test + self.assertEqual(form.fields["twitter"].widget.attrs.get("autofocus"), "") + self.assertEqual(form.fields["instagram"].widget.attrs.get("autofocus"), None) class SuntingProfilAdminTest(TestCase): -- GitLab From c882d8dff41ff4406558a407b2bc60f61eeb8f33 Mon Sep 17 00:00:00 2001 From: Arief Pratama Date: Thu, 1 Oct 2020 22:38:54 +0700 Subject: [PATCH 4/5] Fix dispatch logic --- app/views.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views.py b/app/views.py index ddfa07c..489710e 100644 --- a/app/views.py +++ b/app/views.py @@ -318,7 +318,7 @@ class SuntingProfilView(TemplateView): template_name = "sunting.html" def dispatch(self, request, *args, **kwargs): - if isinstance(request.user, django.contrib.auth.models.AnonymousUser): + if not request.user.is_authenticated or not request.user.is_contributor: raise PermissionDenied(request) return super(SuntingProfilView, self).dispatch(request, *args, **kwargs) -- GitLab From 3204c3ea55f84b82cb481cbeaa2565b5db173079 Mon Sep 17 00:00:00 2001 From: Arief Pratama Date: Thu, 1 Oct 2020 23:10:03 +0700 Subject: [PATCH 5/5] Add Style sunting admin --- app/templates/sunting_admin.html | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/templates/sunting_admin.html b/app/templates/sunting_admin.html index 5e38894..2903a8b 100644 --- a/app/templates/sunting_admin.html +++ b/app/templates/sunting_admin.html @@ -16,7 +16,9 @@
{{ field.label_tag }} {{ field }} - {{ field.errors }} + + {{ field.errors }} + {% if field.help_text %}

{{ field.help_text|safe }}

{% endif %} -- GitLab