Fakultas Ilmu Komputer UI
Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
PMPL
Class Project
DIGIPUS
Commits
3e27c003
Commit
3e27c003
authored
Oct 01, 2020
by
Arief Pratama
Browse files
[70] Update Halaman Sunting Profil Kontributor/Admin
parent
2a653b40
Changes
5
Hide whitespace changes
Inline
Side-by-side
app/forms.py
View file @
3e27c003
...
...
@@ -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
app/templates/sunting.html
View file @
3e27c003
...
...
@@ -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 %}
...
...
app/templates/sunting_admin.html
View file @
3e27c003
...
...
@@ -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 %}
...
...
app/tests.py
View file @
3e27c003
...
...
@@ -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
()
...
...
app/views.py
View file @
3e27c003
...
...
@@ -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
)
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment