Fakultas Ilmu Komputer UI

Commit 51c653e6 authored by Salsabila Hava Qabita's avatar Salsabila Hava Qabita
Browse files

Merge branch '1706979461-62' into 'master'

[#62] Material: Add Release Year Field on Material Upload

See merge request !46
parents 46cff8ea fa7bb0bc
Pipeline #58200 failed with stages
in 22 minutes and 24 seconds
...@@ -2,16 +2,20 @@ from django import forms ...@@ -2,16 +2,20 @@ from django import forms
from app.models import Materi, Category, RatingContributor from app.models import Materi, Category, RatingContributor
from authentication.models import User from authentication.models import User
import datetime
def year_choices():
return[(r,r) for r in range(2000, datetime.date.today().year+1)]
class UploadMateriForm(forms.ModelForm): class UploadMateriForm(forms.ModelForm):
categories = forms.ModelMultipleChoiceField(queryset=Category.objects.all(),widget=forms.CheckboxSelectMultiple(attrs={'style' : 'column-count:2'}),required=True) categories = forms.ModelMultipleChoiceField(queryset=Category.objects.all(),widget=forms.CheckboxSelectMultiple(attrs={'style' : 'column-count:2'}),required=True)
#categories.widget.attrs["style"] = "column-count:2" #categories.widget.attrs["style"] = "column-count:2"
release_year = forms.TypedChoiceField(coerce=int, choices=year_choices, initial=datetime.date.today().year)
class Meta: class Meta:
model = Materi model = Materi
fields = ["title", "author", "publisher", fields = ["title", "author", "publisher", "release_year",
"categories", "descriptions", "cover", "content"] "categories", "descriptions", "cover", "content"]
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
......
# Generated by Django 3.1 on 2020-10-09 16:13
import app.models
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('app', '0020_merge_20201009_2039'),
]
operations = [
migrations.AddField(
model_name='materi',
name='release_year',
field=models.IntegerField(default=app.models.current_year),
),
]
import random import random
import datetime
from django.contrib.postgres import search from django.contrib.postgres import search
from django.core.exceptions import ValidationError from django.core.exceptions import ValidationError
...@@ -24,6 +25,8 @@ def getRandomColor(): ...@@ -24,6 +25,8 @@ def getRandomColor():
color = "%06x" % random.randint(0, 0xFFFFFF) color = "%06x" % random.randint(0, 0xFFFFFF)
return color return color
def current_year():
return datetime.date.today().year
class Category(models.Model): class Category(models.Model):
name = models.CharField(max_length=20) name = models.CharField(max_length=20)
...@@ -56,6 +59,7 @@ class Materi(models.Model): ...@@ -56,6 +59,7 @@ class Materi(models.Model):
author = models.CharField(max_length=30, default="Penyusun") author = models.CharField(max_length=30, default="Penyusun")
uploader = models.ForeignKey(User, on_delete=models.SET_NULL, null=True) uploader = models.ForeignKey(User, on_delete=models.SET_NULL, null=True)
publisher = models.CharField(max_length=30, default="Penerbit") publisher = models.CharField(max_length=30, default="Penerbit")
release_year = models.IntegerField(default=current_year)
pages = models.IntegerField(default=0) pages = models.IntegerField(default=0)
descriptions = models.TextField(default="Deskripsi") descriptions = models.TextField(default="Deskripsi")
status = models.CharField(max_length=30, choices=VERIFICATION_STATUS, default=VERIFICATION_STATUS[0][0]) status = models.CharField(max_length=30, choices=VERIFICATION_STATUS, default=VERIFICATION_STATUS[0][0])
......
...@@ -127,6 +127,14 @@ ...@@ -127,6 +127,14 @@
<p class="info-content">{{materi_data.publisher}}</p> <p class="info-content">{{materi_data.publisher}}</p>
</dd> </dd>
</div> </div>
<div class="info" id="1">
<dl class="col col-4">
<dt class="info-name">Tahun Terbit</dt>
</dl>
<dd>
<p class="info-content">{{materi_data.release_year}}</p>
</dd>
</div>
<div class="info" id="1"> <div class="info" id="1">
<dl class="col col-4"> <dl class="col col-4">
<dt class="info-name">Kontributor</dt> <dt class="info-name">Kontributor</dt>
......
...@@ -19,6 +19,7 @@ from django.db.utils import IntegrityError ...@@ -19,6 +19,7 @@ from django.db.utils import IntegrityError
from django.test import Client, RequestFactory, TestCase, TransactionTestCase from django.test import Client, RequestFactory, TestCase, TransactionTestCase
from pytz import timezone from pytz import timezone
from time import sleep from time import sleep
import datetime as dt
from administration.models import VerificationSetting, VerificationReport from administration.models import VerificationSetting, VerificationReport
from administration.utils import id_generator from administration.utils import id_generator
...@@ -56,7 +57,7 @@ from .views import ( ...@@ -56,7 +57,7 @@ from .views import (
UploadMateriView, UploadMateriView,
UploadMateriExcelView, UploadMateriExcelView,
) )
from app.forms import SuntingProfilForm from app.forms import SuntingProfilForm, year_choices
from app.utils.fileManagementUtil import get_random_filename, remove_image_exifdata from app.utils.fileManagementUtil import get_random_filename, remove_image_exifdata
ERROR_403_MESSAGE = "Kamu harus login untuk mengakses halaman ini" ERROR_403_MESSAGE = "Kamu harus login untuk mengakses halaman ini"
...@@ -2272,3 +2273,17 @@ class MateriModelTest(TestCase): ...@@ -2272,3 +2273,17 @@ class MateriModelTest(TestCase):
Like.objects.create(timestamp=datetime.now(), materi=self.materi, session_id="dummysessionid2") Like.objects.create(timestamp=datetime.now(), materi=self.materi, session_id="dummysessionid2")
self.assertEqual(2, self.materi.like_count) self.assertEqual(2, self.materi.like_count)
class YearChoicesTest(TestCase):
def test_release_year_contains_the_right_current_year(self):
now = dt.date.today().year
choices = year_choices()
self.assertEqual((now, now), choices[-1])
def test_min_release_year_is_2000(self):
choices = year_choices()
self.assertEqual((2000, 2000), choices[0])
\ No newline at end of file
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