Fakultas Ilmu Komputer UI

Commit b8088dc9 authored by insan ramadhan's avatar insan ramadhan
Browse files

Merge branch '1906457480-105' into 'master'

1906457480-105

See merge request !8
parents b5126bfc b43ebe3e
Pipeline #57113 passed with stages
in 10 minutes and 15 seconds
# 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)),
],
),
]
......@@ -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(
......
......@@ -62,6 +62,7 @@
</div>
<button type="submit" class="btn btn-cari">Cari</button>
</form>
<p class="pageTitle">Tidak menemukan materi yang kamu cari ? ajukan permintaan materi kami <a href="/req-materi">disini</a></p>
</div>
</div>
</div>
......
{% 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>
{% if user %}
<p class="description">Tuliskan judul materi yang kamu mau</p>
{% else %}
<p class="description">Tuliskan judul materi yang kamu mau, anda harus login terlebih dahulu untuk melakukan permintaan</p>
{% endif %}
<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
......@@ -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"),
]
......@@ -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
import django
......@@ -390,6 +390,58 @@ 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 request.user.is_authenticated == False:
return HttpResponseRedirect("/login/")
#raise PermissionDenied(request)
# else 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"
......
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