diff --git a/app/forms.py b/app/forms.py index e3032496727d46e129cd23af793be5b956b7df07..64a096e421bf1aacaa9b648b8d869f1c0adfb4e3 100644 --- a/app/forms.py +++ b/app/forms.py @@ -27,10 +27,19 @@ 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" + + 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 7da9441aaee181eea156ec6ea028d4ef4ae098b7..ce7e4d5058805e0872313b316cf420899ab60203 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/templates/sunting_admin.html b/app/templates/sunting_admin.html index 5e388943e57ab433733484437f85f2ea4c5963a7..2903a8bbd8671dcc30e00acc29dcf2d901876d09 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 %} diff --git a/app/tests.py b/app/tests.py index 9a6e595baaad2f4ac0a3b64914143396636661a7..e4c39151060cbece3aefc99dc0fd52fda2e82d4e 100644 --- a/app/tests.py +++ b/app/tests.py @@ -18,6 +18,7 @@ from .views import (DaftarKatalog, DashboardKontributorView, DetailMateri, ProfilKontributorView, SuksesLoginAdminView, SuksesLoginKontributorView, SuntingProfilView, ProfilAdminView, CommentsView, SuntingProfilAdminView, RevisiMateriView) +from app.forms import SuntingProfilForm class DaftarKatalogTest(TestCase): @@ -510,6 +511,29 @@ 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) + + 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): def setUp(self): self.client = Client() diff --git a/app/views.py b/app/views.py index a505a3e437b826cca65915cb85146b763be1547d..489710ecd52fc4d4335f4ffc3637775223494edf 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 not request.user.is_authenticated or not request.user.is_contributor: raise PermissionDenied(request) return super(SuntingProfilView, self).dispatch(request, *args, **kwargs)