Fakultas Ilmu Komputer UI

Commit b5126bfc authored by Arief Pratama's avatar Arief Pratama
Browse files

Merge branch '2006560831-70' into 'master'

[70] Update Halaman Sunting Profil Kontributor/Admin

See merge request !7
parents 2a653b40 3e27c003
Pipeline #57106 passed with stages
in 7 minutes and 48 seconds
......@@ -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
......@@ -16,7 +16,11 @@
<div class="col-md-6">
<div class="fieldWrapper">
{{ field.label_tag }} {{ field }}
{{ field.errors }}
{% if field.errors %}
<span class="text-danger">
{{ field.errors }}
</span>
{% endif %}
{% if field.help_text %}
<p class="help">{{ field.help_text|safe }}</p>
{% endif %}
......
......@@ -16,7 +16,9 @@
<div class="col-md-6">
<div class="fieldWrapper">
{{ field.label_tag }} {{ field }}
{{ field.errors }}
<span class="text-danger">
{{ field.errors }}
</span>
{% if field.help_text %}
<p class="help">{{ field.help_text|safe }}</p>
{% endif %}
......
......@@ -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()
......
......@@ -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)
......
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