Fakultas Ilmu Komputer UI

Commit 970abaeb authored by Mika dabelza abi's avatar Mika dabelza abi
Browse files

Merge branch 'Coldfix-Staging-StatusFilter' into 'staging'

Coldfix staging status filter

See merge request ppl-fasilkom-ui/2020/ppl-c/diskominfo-depok-digipus/marjinal-digipus!32
parents 055ead5d ed6dc085
# Generated by Django 3.0.3 on 2020-04-27 01:57
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('app', '0001_initial'),
]
operations = [
migrations.AlterField(
model_name='comment',
name='profile',
field=models.CharField(default='9bb0d6', max_length=100),
),
migrations.AlterField(
model_name='comment',
name='user',
field=models.CharField(default='b38c137f9b6a4cd0b61fc72840358bbe', max_length=100),
),
]
# Generated by Django 3.0.3 on 2020-04-27 15:10
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('app', '0002_auto_20200427_0857'),
]
operations = [
migrations.AlterField(
model_name='comment',
name='profile',
field=models.CharField(default='77e693', max_length=100),
),
migrations.AlterField(
model_name='comment',
name='user',
field=models.CharField(default='bcf5ec5adb434db0b85a00dfa1058930', max_length=100),
),
]
# Generated by Django 3.0.3 on 2020-04-30 06:16
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('app', '0003_auto_20200427_2210'),
('app', '0003_auto_20200430_1122'),
]
operations = [
]
......@@ -43,10 +43,12 @@ class Comment(models.Model):
class Materi(models.Model):
# 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")
author = models.CharField(max_length=30, default="author")
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)
publisher = models.CharField(max_length=30, default="publiser")
descriptions = models.TextField(default="descriptions")
......
......@@ -4,8 +4,10 @@ from django.core import serializers
from django.test import Client, TestCase, RequestFactory
from django.urls import resolve
from .models import Category, Comment, Materi
from .views import DaftarKatalog, DetailMateri, DashboardKontributorView
from .models import Materi, Category, Comment
from django.core import serializers
import json
from app.views import UploadMateriHTML, UploadMateriView
from authentication.models import User
......@@ -83,7 +85,7 @@ 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)
......
......@@ -10,7 +10,9 @@ from django.http import (Http404, HttpResponse, HttpResponseRedirect,
from django.shortcuts import get_object_or_404, redirect, render
from django.template import loader
from django.views.generic import TemplateView
from django.core import serializers
from .models import Materi,Category
from django.db.models import Q
from .forms import UploadMateriForm
from .models import Category, Materi
......@@ -24,43 +26,48 @@ 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()
try:
context["materi_list"] = Materi.objects.all().filter(status = "(\"APPROVE\", \"Diterima\")")
except:
context["materi_list"] = None
getSearch = request.GET.get("search")
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
list = Materi.objects.filter(
Q(title__icontains=getSearch) |
Q(author__icontains=getSearch) |
Q(uploader__name__icontains=getSearch) |
Q(descriptions__icontains=getSearch) |
Q(publisher__icontains=getSearch)
).distinct()
# list = Materi.objects.filter(
# Q(title__icontains=getSearch) |
# Q(descriptions__icontains=getSearch) |
# Q(author__icontains=getSearch) |
# Q(uploader__icontains=getSearch) |
# Q(publisher__icontains=getSearch)
# )
context["materi_list"] = list.filter(status = "(\"APPROVE\", \"Diterima\")")
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
kategori = Category.objects.get(pk = pkGet)
list = Materi.objects.filter(categories = kategori.pk)
context["materi_list"] = list.filter(status = "(\"APPROVE\", \"Diterima\")")
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")
if getSort:
list = Materi.objects.all().filter(status = "(\"APPROVE\", \"Diterima\")")
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"
......
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