Fakultas Ilmu Komputer UI

Commit 0c47aa5c authored by I Gusti Putu Agastya Indrayana's avatar I Gusti Putu Agastya Indrayana
Browse files

Merge branch 'Coldfix-Staging-PBI-6-Halaman-Katalog' into 'staging'

Coldfix staging pbi 6 halaman katalog

See merge request ppl-fasilkom-ui/2020/ppl-c/diskominfo-depok-digipus/marjinal-digipus!22
parents e7e2dae8 17bd2abd
# Generated by Django 3.0.3 on 2020-04-22 14:44
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('app', '0007_auto_20200421_2151'),
]
operations = [
migrations.AlterField(
model_name='comment',
name='profile',
field=models.CharField(default='51e685', max_length=100),
),
migrations.AlterField(
model_name='comment',
name='user',
field=models.CharField(default='9a89fd18ef5d4351a884acf98b36b71d', max_length=100),
),
]
# Generated by Django 3.0.3 on 2020-04-22 16:11
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('app', '0008_auto_20200422_2144'),
]
operations = [
migrations.AlterField(
model_name='comment',
name='profile',
field=models.CharField(default='ca5be3', max_length=100),
),
migrations.AlterField(
model_name='comment',
name='user',
field=models.CharField(default='f88e20b6dcfc43daba68479578ecc003', max_length=100),
),
]
# Generated by Django 3.0.3 on 2020-04-23 05:21
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('app', '0012_auto_20200423_1006'),
('app', '0009_auto_20200422_2311'),
]
operations = [
]
......@@ -11,14 +11,18 @@ VERIFICATION_STATUS = [
]
# Create your models here.
def getRandomColor():
color = "%06x" % random.randint(0, 0xFFFFFF)
return color
return color
def getRandomUserId():
userId = uuid.uuid4().hex
return userId
class Category(models.Model):
name = models.CharField(max_length=20)
description = models.CharField(max_length=20)
......@@ -28,18 +32,19 @@ class Category(models.Model):
class Comment(models.Model):
user = models.CharField(max_length = 100, default= getRandomUserId())
profile = models.CharField(max_length = 100, default= getRandomColor())
comment = models.CharField(max_length = 150, default= 'comments')
user = models.CharField(max_length=100, default=getRandomUserId())
profile = models.CharField(max_length=100, default=getRandomColor())
comment = models.CharField(max_length=150, default='comments')
def __str__(self):
return self.user
class Materi(models.Model):
#TODO: file fields, cover ubah jadi image fields, uploader jadi one to one kontributor
# TODO: file fields, cover ubah jadi image fields, uploader jadi one to one kontributor
cover = models.ImageField()
content = models.FileField()
title = models.CharField(max_length=50, default='title')
title = models.CharField(max_length=50, default='title')
author = models.CharField(max_length=30, default='author')
# ubah jadi one to one ke kontributor
uploader = models.ForeignKey(User, on_delete=models.SET_NULL, null=True)
......@@ -51,5 +56,3 @@ class Materi(models.Model):
comments = models.ManyToManyField(Comment)
feedback = models.TextField(blank=True, default='')
......@@ -130,4 +130,4 @@ Materi
</div> -->
</div>
</div>
{% endblock content %}
\ No newline at end of file
{% endblock content %}
......@@ -10,9 +10,9 @@
<div class="col">
<h2 class="pageTitle">Temukan Materi Yang Kamu Mau!</h2>
<p class="description">Cari dengan judul buku, penerbit, atau penulis</p>
<form class="searchBar">
<form class="searchBar" action=''>
<div class="col-6 form-group">
<input type="email" class="form-control" placeholder="Tulis di sini">
<input type="text" name='search' class="form-control" placeholder="Tulis di sini" value='{{request.GET.search}}'>
</div>
<button type="submit" class="btn btn-cari">Cari</button>
</form>
......@@ -40,9 +40,11 @@
aria-labelledby="headingOne"
data-parent="#accordionExample">
<div class="card-body">
<p>Kategory test1</p>
<p>Kategory test1</p>
<p>Kategory test1</p>
{% for itemKategori in kategori_list %}
<li>
<a href="?kategori={{itemKategori.pk}}">{{itemKategori.name}}</a>
</li>
{% endfor %}
</div>
</div>
</div>
......@@ -56,9 +58,15 @@
</div>
<div id="collapseTwo" class="collapse" aria-labelledby="headingTwo" data-parent="#accordionExample">
<div class="card-body">
<p>Sort test1</p>
<p>Sort test1</p>
<p>Sort test1</p>
<li>
<a href="?sort=judul">judul</a>
</li>
<li>
<a href="?sort=penulis">penulis</a>
</li>
<li>
<a href="?sort=pengunggah">pengunggah</a>
</li>
</div>
</div>
</div>
......
from django.test import TestCase, Client
from django.urls import resolve
from .views import DaftarKatalog, DetailMateri
from .models import Materi, Category, Comment
from django.core import serializers
......@@ -16,6 +17,34 @@ class DaftarKatalogTest(TestCase):
response = Client().get('/')
self.assertTemplateUsed(response, 'app/katalog_materi.html')
def test_daftar_kategori(self):
kategori = Category()
kategori.name = "baru"
kategori.description = "kategori baru saya"
kategori.save()
kategori2 = Category()
kategori2.name = "baru2"
kategori2.save()
materi1 = Materi()
materi1.title = "baru lah"
materi1.save()
materi1.categories.add(kategori.id)
materi1.save()
materi2 = Materi()
materi2.save()
materi2.categories.add(kategori2)
materi2.save()
cl = Client()
res = cl.get('/?kategori='+str(kategori.pk))
self.assertIn(materi1, res.context['materi_list'])
self.assertNotIn(materi2,res.context['materi_list'])
def test_daftar_katalog_using_daftar_katalog_func(self):
found = resolve('/')
self.assertEqual(found.func.__name__, DaftarKatalog.as_view().__name__)
......@@ -96,5 +125,5 @@ class TemplateLoaderTest(TestCase):
url = "/test.html"
expected_template_name = "error-404.html"
response = Client().get(url)
self.assertEqual(response.status_code, 200)
self.assertEqual(response.status_code,200)
self.assertTemplateUsed(response, expected_template_name)
......@@ -3,7 +3,8 @@ from django.template import loader
from django.http import HttpResponse, JsonResponse, HttpResponseRedirect
from django.views.generic import TemplateView
from django.core import serializers
from .models import Materi
from .models import Materi,Category
from django.db.models import Q
from .forms import UploadMateriForm
from django.core.exceptions import PermissionDenied
......@@ -16,10 +17,39 @@ class DaftarKatalog(TemplateView):
def get(self, request, *args, **kwargs):
context = self.get_context_data(**kwargs)
context["kategori_list"] = Category.objects.all()
context["materi_list"] = Materi.objects.all()
getSearch = request.GET.get('search')
if getSearch:
list = Materi.objects.all().filter(
Q(title__icontains = getSearch) |
Q(descriptions__icontains = getSearch) |
Q(author__icontains=getSearch) |
Q(uploader__icontains=getSearch) |
Q(publisher__icontains=getSearch)
).distinct
context["materi_list"] = list
getKategori = request.GET.get("kategori")
if getKategori:
pkGet = request.GET.get("kategori")
kategori = Category.objects.get(pk = pkGet)
list = Materi.objects.filter(categories = kategori.pk)
context["materi_list"] = list
getSort = request.GET.get("sort")
if getSort:
list = Materi.objects.all()
if(getSort == "judul"):
context["materi_list"] = list.order_by('title')
elif(getSort == "penulis"):
context["materi_list"] = list.order_by('author')
elif(getSort == "pengunggah"):
context["materi_list"] = list.order_by('uploader')
return self.render_to_response(context=context)
class DetailMateri(TemplateView):
template_name = "app/detail_materi.html"
......@@ -35,6 +65,9 @@ class DetailMateri(TemplateView):
return self.render_to_response(context=context)
# class DetailMateri(TemplateView):
# template_name = "app/detail_materi.html"
......
/*//////////////////////////////////////////////////////////////////
[ FONT ]*/
@font-face {
font-family: Poppins-Regular;
src: url('../fonts/poppins/Poppins-Regular.ttf');
}
@font-face {
font-family: Poppins-Medium;
src: url('../fonts/poppins/Poppins-Medium.ttf');
}
@font-face {
font-family: Poppins-Bold;
src: url('../fonts/poppins/Poppins-Bold.ttf');
}
@font-face {
font-family: Poppins-SemiBold;
src: url('../fonts/poppins/Poppins-SemiBold.ttf');
}
@font-face {
font-family: Montserrat-Bold;
src: url('../fonts/montserrat/Montserrat-Bold.ttf');
}
@font-face {
font-family: Montserrat-SemiBold;
src: url('../fonts/montserrat/Montserrat-SemiBold.ttf');
}
@font-face {
font-family: Montserrat-Regular;
src: url('../fonts/montserrat/Montserrat-Regular.ttf');
}
/*//////////////////////////////////////////////////////////////////
[ RESTYLE TAG ]*/
* {
margin: 0px;
padding: 0px;
box-sizing: border-box;
}
body, html {
height: 100%;
font-family: Poppins-Regular, sans-serif;
}
/*---------------------------------------------*/
a {
font-family: Poppins-Regular;
font-size: 14px;
line-height: 1.7;
color: #666666;
margin: 0px;
transition: all 0.4s;
-webkit-transition: all 0.4s;
-o-transition: all 0.4s;
-moz-transition: all 0.4s;
}
a:focus {
outline: none !important;
}
a:hover {
text-decoration: none;
color: #6675df;
}
/*---------------------------------------------*/
h1,h2,h3,h4,h5,h6 {
margin: 0px;
}
p {
font-family: Poppins-Regular;
font-size: 14px;
line-height: 1.7;
color: #666666;
margin: 0px;
}
ul, li {
margin: 0px;
list-style-type: none;
}
/*---------------------------------------------*/
input {
outline: none;
border: none;
}
textarea {
outline: none;
border: none;
}
textarea:focus, input:focus {
border-color: transparent !important;
}
input:focus::-webkit-input-placeholder { color:transparent; }
input:focus:-moz-placeholder { color:transparent; }
input:focus::-moz-placeholder { color:transparent; }
input:focus:-ms-input-placeholder { color:transparent; }
textarea:focus::-webkit-input-placeholder { color:transparent; }
textarea:focus:-moz-placeholder { color:transparent; }
textarea:focus::-moz-placeholder { color:transparent; }
textarea:focus:-ms-input-placeholder { color:transparent; }
input::-webkit-input-placeholder { color: #999999;}
input:-moz-placeholder { color: #999999;}
input::-moz-placeholder { color: #999999;}
input:-ms-input-placeholder { color: #999999;}
textarea::-webkit-input-placeholder { color: #999999;}
textarea:-moz-placeholder { color: #999999;}
textarea::-moz-placeholder { color: #999999;}
textarea:-ms-input-placeholder { color: #999999;}
label {
display: block;
margin: 0;
}
/*---------------------------------------------*/
button {
outline: none !important;
border: none;
background: transparent;
}
button:hover {
cursor: pointer;
}
iframe {
border: none !important;
}
/*//////////////////////////////////////////////////////////////////
[ utility ]*/
/*==================================================================
[ Text ]*/
.txt1 {
font-family: Montserrat-Regular;
font-size: 13px;
line-height: 1.4;
color: #555555;
}
.txt2 {
font-family: Montserrat-Regular;
font-size: 13px;
line-height: 1.4;
color: #999999;
}
/*==================================================================
[ Size ]*/
.size1 {
width: 355px;
max-width: 100%;
}
.size2 {
width: calc(100% - 43px);
}
/*==================================================================
[ Background ]*/
.bg1 {background: #3b5998;}
.bg2 {background: #1da1f2;}
.bg3 {background: #cd201f;}
/*//////////////////////////////////////////////////////////////////
[ login ]*/
.limiter {
width: 100%;
margin: 0 auto;
}
.container-login100 {
width: 100%;
min-height: 100vh;
display: -webkit-box;
display: -webkit-flex;
display: -moz-box;
display: -ms-flexbox;
display: flex;
flex-wrap: wrap;
justify-content: center;
align-items: center;
background: #f2f2f2;
}
.wrap-login100 {
width: 100%;
background: #fff;
overflow: hidden;
display: -webkit-box;
display: -webkit-flex;
display: -moz-box;
display: -ms-flexbox;
display: flex;
flex-wrap: wrap;
align-items: stretch;
flex-direction: row-reverse;
}
/*==================================================================
[ login more ]*/
.login100-more {
width: calc(100% - 560px);
background-repeat: no-repeat;
background-size: cover;
background-position: center;
position: relative;
z-index: 1;
}
.login100-more::before {
content: "";
display: block;
position: absolute;
z-index: -1;
width: 100%;
height: 100%;
top: 0;
left: 0;
background: rgba(0,0,0,0.1);
}
/*==================================================================
[ Form ]*/
.login100-form {
width: 560px;
min-height: 100vh;
display: block;
background-color: #f7f7f7;
padding: 173px 55px 55px 55px;
}
.login100-form-title {
width: 100%;
display: block;
font-family: Poppins-Regular;
font-size: 30px;
color: #333333;
line-height: 1.2;
text-align: center;
}
/*------------------------------------------------------------------
[ Input ]*/
.wrap-input100 {
display: -webkit-box;
display: -webkit-flex;
display: -moz-box;
display: -ms-flexbox;
display: flex;
flex-wrap: wrap;
align-items: flex-end;
width: 100%;
height: 80px;
position: relative;
border: 1px solid #e6e6e6;
border-radius: 10px;
margin-bottom: 10px;
}
.label-input100 {
font-family: Montserrat-Regular;
font-size: 18px;
color: #999999;
line-height: 1.2;
display: block;
position: absolute;
pointer-events: none;
width: 100%;
padding-left: 24px;
left: 0;
top: 30px;
-webkit-transition: all 0.4s;
-o-transition: all 0.4s;
-moz-transition: all 0.4s;
transition: all 0.4s;
}
.input100 {
display: block;
width: 100%;
background: transparent;
font-family: Montserrat-Regular;
font-size: 18px;
color: #555555;
line-height: 1.2;
padding: 0 26px;
}
input.input100 {
height: 100%;
-webkit-transition: all 0.4s;
-o-transition: all 0.4s;
-moz-transition: all 0.4s;
transition: all 0.4s;
}
/*---------------------------------------------*/
.focus-input100 {
position: absolute;
display: block;
width: calc(100% + 2px);
height: calc(100% + 2px);
top: -1px;
left: -1px;