Fakultas Ilmu Komputer UI
Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
PMPL
Class Project
DIGIPUS
Commits
1b4abf28
Commit
1b4abf28
authored
Oct 01, 2020
by
insan ramadhan
Browse files
update req material
parent
8da3db42
Pipeline
#57063
passed with stages
in 7 minutes and 8 seconds
Changes
5
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
app/migrations/0015_reqmaterial.py
0 → 100644
View file @
1b4abf28
# Generated by Django 3.0.3 on 2020-10-01 04:23
from
django.db
import
migrations
,
models
import
django.utils.timezone
class
Migration
(
migrations
.
Migration
):
dependencies
=
[
(
'app'
,
'0014_rating'
),
]
operations
=
[
migrations
.
CreateModel
(
name
=
'ReqMaterial'
,
fields
=
[
(
'id'
,
models
.
AutoField
(
auto_created
=
True
,
primary_key
=
True
,
serialize
=
False
,
verbose_name
=
'ID'
)),
(
'title'
,
models
.
CharField
(
max_length
=
100
)),
(
'timestamp'
,
models
.
DateTimeField
(
default
=
django
.
utils
.
timezone
.
now
)),
],
),
]
app/models.py
View file @
1b4abf28
...
...
@@ -83,6 +83,10 @@ class Like(models.Model):
timestamp
=
models
.
DateTimeField
(
default
=
timezone
.
now
)
session_id
=
models
.
CharField
(
max_length
=
32
,
blank
=
False
)
class
ReqMaterial
(
models
.
Model
):
title
=
models
.
CharField
(
max_length
=
100
)
timestamp
=
models
.
DateTimeField
(
default
=
timezone
.
now
)
class
ViewStatistics
(
models
.
Model
):
materi
=
models
.
ForeignKey
(
...
...
app/templates/req_materi.html
0 → 100644
View file @
1b4abf28
{% extends "base.html" %}
{% load static %}
{% block title %}Digipus Home{% endblock %}
{% block header %}
<!DOCTYPE html>
<html
lang=
"en"
>
<head>
<title>
Digipus Home
</title>
<meta
charset=
"UTF-8"
>
<meta
name=
"viewport"
content=
"width=device-width, initial-scale=1"
>
<link
rel=
"stylesheet"
type=
"text/css"
href=
"{% static 'app/css/katalog_materi.css' %}"
>
<!-- Bootstrap core CSS -->
<link
href=
"../../static/app/vendor/bootstrap/css/bootstrap.min.css"
rel=
"stylesheet"
>
<!-- Custom styles for this template -->
<link
href=
"../../static/app/css/heroic-features.css"
rel=
"stylesheet"
>
<!--===============================================================================================-->
<link
rel=
"icon"
type=
"image/png"
href=
"{% static 'images/icons/logo.ico' %}"
/>
<!--===============================================================================================-->
<!--===============================================================================================-->
<link
rel=
"stylesheet"
type=
"text/css"
href=
"{% static 'fonts/font-awesome-4.7.0/css/font-awesome.min.css' %}"
>
<!--===============================================================================================-->
<!--===============================================================================================-->
<link
rel=
"stylesheet"
type=
"text/css"
href=
"{% static 'vendor/animate/animate.css' %}"
>
<!--===============================================================================================-->
<link
rel=
"stylesheet"
type=
"text/css"
href=
"{% static 'vendor/css-hamburgers/hamburgers.min.css' %}"
>
<!--===============================================================================================-->
<link
rel=
"stylesheet"
type=
"text/css"
href=
"{% static 'vendor/animsition/css/animsition.min.css' %}"
>
<!--===============================================================================================-->
<link
rel=
"stylesheet"
type=
"text/css"
href=
"{% static 'vendor/select2/select2.min.css' %}"
>
<!--===============================================================================================-->
<link
rel=
"stylesheet"
type=
"text/css"
href=
"{% static 'vendor/daterangepicker/daterangepicker.css' %}"
>
<!--===============================================================================================-->
<link
rel=
"stylesheet"
type=
"text/css"
href=
"{% static 'css/styles.css' %}"
>
<link
rel=
"stylesheet"
type=
"text/css"
href=
"{% static 'css/util.css' %}"
>
<link
rel=
"stylesheet"
type=
"text/css"
href=
"{% static 'css/main.css' %}"
>
<!--===============================================================================================-->
{% endblock header %}
{% block content %}
</head>
<body
style=
"background-color: #f8f8f8;"
>
<!-- Page Content -->
<div
class=
"container"
>
<header
class=
"jumbotron my-4"
>
<div
class=
"container"
>
<div
class=
"row header"
>
<div
class=
"col"
>
<h2
class=
"pageTitle"
>
Permintaan materi!
</h2>
<p
class=
"description"
>
Tuliskan judul materi yang kamu mau
</p>
<form
class=
"searchBar"
>
{% csrf_token %}
<div
class=
"col-6 form-group"
>
<input
type=
"text"
name=
'search'
class=
"form-control"
placeholder=
"Tulis di sini"
id=
"title"
value=
""
required
>
</div>
<button
id=
"btn_req_submit"
style=
"width: auto;padding-left: 10px;padding-right: 10px;"
class=
"btn btn-cari"
>
Kirim Permintaan
</button>
</form>
<p
id=
"msg"
style=
"display: none;margin: 5px"
>
Permintaan berhasil dikirim
</p>
</div>
</div>
</div>
</header>
</div>
<!-- /.container -->
</body>
</html>
<script
src=
"https://kit.fontawesome.com/bc2cedd6b2.js"
crossorigin=
"anonymous"
></script>
<script
src=
"//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"
></script>
<script
src=
"https://unpkg.com/sweetalert/dist/sweetalert.min.js"
></script>
<script
type=
"text/javascript"
>
var
csrftoken
=
jQuery
(
"
[name=csrfmiddlewaretoken]
"
).
val
();
</script>
<script>
function
csrfSafeMethod
(
method
)
{
return
(
/^
(
GET|HEAD|OPTIONS|TRACE
)
$/
.
test
(
method
));
}
</script>
<script
type=
"text/javascript"
>
$
(
'
#btn_req_submit
'
).
click
(
function
()
{
var
title
=
document
.
getElementById
(
'
title
'
);
var
msg
=
document
.
getElementById
(
'
msg
'
);
if
(
title
.
value
==
''
){
return
;
}
$
.
ajaxSetup
({
beforeSend
:
function
(
xhr
,
settings
)
{
if
(
!
csrfSafeMethod
(
settings
.
type
)
&&
!
this
.
crossDomain
)
{
xhr
.
setRequestHeader
(
"
X-CSRFToken
"
,
csrftoken
);
}
}
});
$
.
ajax
({
type
:
'
POST
'
,
url
:
"
{% url 'post-req-materi' %}
"
,
data
:
{
'
title
'
:
title
.
value
,
},
success
:
function
(
Json
)
{
/* clear the error message first */
if
(
Json
.
success
){
swal
(
"
Informasi!
"
,
Json
.
msg
,
"
success
"
);
msg
.
style
.
display
=
'
block
'
;
title
.
value
=
""
;
setTimeout
(
function
(){
$
(
"
#msg
"
).
fadeOut
(
"
slow
"
);
},
3000
);
}
else
{
swal
(
"
Informasi!
"
,
Json
.
msg
,
"
error
"
);
msg
.
style
.
display
=
'
block
'
;
setTimeout
(
function
(){
$
(
"
#msg
"
).
fadeOut
(
"
slow
"
);
},
3000
);
}
},
error
:
function
(
xhr
,
status
,
errorThrown
)
{
xhr
.
status
;
swal
(
"
Error!
"
,
xhr
.
responseText
,
"
error
"
);
xhr
.
responseText
;
}
});
return
false
;
});
</script>
{% endblock %}
\ No newline at end of file
app/urls.py
View file @
1b4abf28
...
...
@@ -4,7 +4,7 @@ from app import views
from
app.views
import
(
DashboardKontributorView
,
ProfilKontributorView
,
SuksesLoginAdminView
,
SuksesLoginKontributorView
,
SuntingProfilView
,
UploadMateriHTML
,
UploadMateriView
,
ProfilAdminView
,
CommentsView
,
SuntingProfilAdminView
)
ProfilAdminView
,
CommentsView
,
SuntingProfilAdminView
,
ReqMateriView
)
urlpatterns
=
[
path
(
""
,
views
.
DaftarKatalog
.
as_view
(),
name
=
"daftar_katalog"
),
...
...
@@ -26,4 +26,6 @@ urlpatterns = [
path
(
"profil-admin/"
,
ProfilAdminView
.
as_view
(),
name
=
"profil-admin"
),
path
(
'kontributor/<int:pk_user>/comments/'
,
CommentsView
.
as_view
(),
name
=
'comments'
),
path
(
"sunting-admin/"
,
SuntingProfilAdminView
.
as_view
(),
name
=
"sunting-admin"
),
path
(
"req-materi/"
,
ReqMateriView
.
as_view
(),
name
=
"req-materi"
),
path
(
"post-req-materi/"
,
views
.
post_req_materi
,
name
=
"post-req-materi"
),
]
app/views.py
View file @
1b4abf28
...
...
@@ -18,7 +18,7 @@ from .models import Category, Comment, Materi
from
django.core.paginator
import
Paginator
,
EmptyPage
,
PageNotAnInteger
from
administration.models
import
VerificationReport
from
app.forms
import
SuntingProfilForm
,
UploadMateriForm
from
app.models
import
Category
,
Comment
,
Materi
,
Like
,
ViewStatistics
,
DownloadStatistics
from
app.models
import
Category
,
Comment
,
Materi
,
Like
,
ViewStatistics
,
DownloadStatistics
,
ReqMaterial
from
authentication.models
import
User
...
...
@@ -389,6 +389,55 @@ class SuntingProfilAdminView(TemplateView):
context
[
"form"
]
=
form
return
self
.
render_to_response
(
context
)
class
ReqMateriView
(
TemplateView
):
template_name
=
"req_materi.html"
def
dispatch
(
self
,
request
,
*
args
,
**
kwargs
):
if
not
request
.
user
.
is_admin
:
raise
PermissionDenied
(
request
)
return
super
(
ReqMateriView
,
self
).
dispatch
(
request
,
*
args
,
**
kwargs
)
def
get_context_data
(
self
,
**
kwargs
):
context
=
super
(
ReqMateriView
,
self
).
get_context_data
(
**
kwargs
)
return
context
def
get
(
self
,
request
,
*
args
,
**
kwargs
):
context
=
self
.
get_context_data
(
**
kwargs
)
current_user
=
self
.
request
.
user
context
[
"user"
]
=
current_user
context
[
"form"
]
=
SuntingProfilForm
(
instance
=
current_user
)
return
self
.
render_to_response
(
context
)
def
post
(
self
,
request
,
*
args
,
**
kwargs
):
if
request
.
user
.
is_authenticated
==
False
:
raise
PermissionDenied
(
request
)
current_user
=
self
.
request
.
user
form
=
SuntingProfilForm
(
request
.
POST
,
request
.
FILES
,
instance
=
current_user
)
if
form
.
is_valid
():
current_user
.
default_profile_picture
=
True
form
.
save
()
return
HttpResponseRedirect
(
"/profil-admin/"
)
else
:
context
=
self
.
get_context_data
(
**
kwargs
)
context
[
"form"
]
=
form
return
self
.
render_to_response
(
context
)
def
post_req_materi
(
request
):
if
request
.
method
==
'POST'
:
#return JsonResponse({"success": True, "msg": "Permintaan materi berhasil dikirimkan"})
title
=
request
.
POST
.
get
(
'title'
,
None
)
if
title
is
None
:
return
JsonResponse
({
"success"
:
False
,
"msg"
:
"Missing parameter"
})
ReqMaterial
(
title
=
title
).
save
()
return
JsonResponse
({
"success"
:
True
,
"msg"
:
"Permintaan materi berhasil dikirimkan"
})
else
:
return
JsonResponse
({
"success"
:
False
,
"msg"
:
"Unsuported method"
})
class
SuksesLoginKontributorView
(
TemplateView
):
template_name
=
"sukses_kontri.html"
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a 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