From fa7bb0bc0d8db3ae2ea507a9ecd926171365f12c Mon Sep 17 00:00:00 2001 From: Salsabila Hava Qabita <salsabila.hava@ui.ac.id> Date: Sat, 10 Oct 2020 12:54:46 +0700 Subject: [PATCH] [#62] Material: Add Release Year Field on Material Upload --- app/forms.py | 6 +++++- app/migrations/0021_materi_release_year.py | 19 +++++++++++++++++++ app/models.py | 4 ++++ app/templates/app/detail_materi.html | 8 ++++++++ app/tests.py | 17 ++++++++++++++++- digipus/__pycache__/settings.cpython-36.pyc | Bin 3523 -> 3557 bytes 6 files changed, 52 insertions(+), 2 deletions(-) create mode 100644 app/migrations/0021_materi_release_year.py diff --git a/app/forms.py b/app/forms.py index 84facd1..5435842 100644 --- a/app/forms.py +++ b/app/forms.py @@ -2,16 +2,20 @@ from django import forms from app.models import Materi, Category, RatingContributor 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): categories = forms.ModelMultipleChoiceField(queryset=Category.objects.all(),widget=forms.CheckboxSelectMultiple(attrs={'style' : 'column-count:2'}),required=True) #categories.widget.attrs["style"] = "column-count:2" + release_year = forms.TypedChoiceField(coerce=int, choices=year_choices, initial=datetime.date.today().year) class Meta: model = Materi - fields = ["title", "author", "publisher", + fields = ["title", "author", "publisher", "release_year", "categories", "descriptions", "cover", "content"] def __init__(self, *args, **kwargs): diff --git a/app/migrations/0021_materi_release_year.py b/app/migrations/0021_materi_release_year.py new file mode 100644 index 0000000..8294e44 --- /dev/null +++ b/app/migrations/0021_materi_release_year.py @@ -0,0 +1,19 @@ +# 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), + ), + ] diff --git a/app/models.py b/app/models.py index aa54208..227eabd 100644 --- a/app/models.py +++ b/app/models.py @@ -1,4 +1,5 @@ import random +import datetime from django.contrib.postgres import search from django.core.exceptions import ValidationError @@ -24,6 +25,8 @@ def getRandomColor(): color = "%06x" % random.randint(0, 0xFFFFFF) return color +def current_year(): + return datetime.date.today().year class Category(models.Model): name = models.CharField(max_length=20) @@ -56,6 +59,7 @@ class Materi(models.Model): author = models.CharField(max_length=30, default="Penyusun") uploader = models.ForeignKey(User, on_delete=models.SET_NULL, null=True) publisher = models.CharField(max_length=30, default="Penerbit") + release_year = models.IntegerField(default=current_year) pages = models.IntegerField(default=0) descriptions = models.TextField(default="Deskripsi") status = models.CharField(max_length=30, choices=VERIFICATION_STATUS, default=VERIFICATION_STATUS[0][0]) diff --git a/app/templates/app/detail_materi.html b/app/templates/app/detail_materi.html index e15f5f9..d614e18 100644 --- a/app/templates/app/detail_materi.html +++ b/app/templates/app/detail_materi.html @@ -127,6 +127,14 @@ <p class="info-content">{{materi_data.publisher}}</p> </dd> </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"> <dl class="col col-4"> <dt class="info-name">Kontributor</dt> diff --git a/app/tests.py b/app/tests.py index cd74464..f274765 100644 --- a/app/tests.py +++ b/app/tests.py @@ -18,6 +18,7 @@ from django.db.utils import IntegrityError from django.test import Client, RequestFactory, TestCase, TransactionTestCase from pytz import timezone from time import sleep +import datetime as dt from administration.models import VerificationSetting, VerificationReport from administration.utils import id_generator @@ -53,7 +54,7 @@ from .views import ( UploadMateriView, UploadMateriExcelView, ) -from app.forms import SuntingProfilForm +from app.forms import SuntingProfilForm, year_choices from app.utils.fileManagementUtil import get_random_filename, remove_image_exifdata ERROR_403_MESSAGE = "Kamu harus login untuk mengakses halaman ini" @@ -2173,3 +2174,17 @@ class MateriModelTest(TestCase): Like.objects.create(timestamp=datetime.now(), materi=self.materi, session_id="dummysessionid2") 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 diff --git a/digipus/__pycache__/settings.cpython-36.pyc b/digipus/__pycache__/settings.cpython-36.pyc index a2dfadd532b5c69b61e9c0a2768ccc1ee6376edf..0857014007c24fe96681cc07b645936f81fe7ea1 100644 GIT binary patch delta 586 zcmX>s{Zv}nn3tDpyJtgur!WJ<V+JI^&%nUoz`(#zEHY8Kus%g3MKnb$oj-~%MLb0! zMKVPyMLI<$MK(n)MIxOuia$j@N+3lcN-#w+l`)GoODL5yMX8x7oiRl|ML9(!MKwh& zMLnG*lQBhO4of;?lyHh>lt?N|idHIjigt=lFLRV=DoctkoF|sblA;IaiKo_!PGBrj zNYPI*NM%VeY-UVlNihPG#$eI}Oq!;cH8Z7{&tc1CjFQO9Nfn#GSmcq(5G9eym?fEF z(aabnmCBSQohp@LnPSz;lq!*;Z^Mx1k}5udv8V*BjwQt+RR-!H6t(qG#S$s{Db{cw z+B7qz*v?@BSqB%hYi3GgjFL^UkCIDqNO8<$OmRqY0+Y^Q(j}8Ioh3>>#WhMH#VtxP zMLtR?MLtS7MLtReZiag^Q<Q3oN0b^|MB5z{m{IB}o>3ZbL9b?}D9se_D6JHqDD4#A zD4i6hU<OUU&1OuCnG8hoQp=0=5(^57_54!Hi=FfH(lXPdgi4AM)6z1N<BLlYOEQZ~ zGLws=Skv;0N^>{gV7bVy>gj3~6P%ixT3nJ^q+lKs;2Yo*6Ht_2nVPNOotl$atYBnd ZWH9+9j|t<7$#T4!lkIugCcE?2005L-o)iE8 delta 554 zcmaDVeOOxAn3tF9n?hE+voHh0V+JI^!@$7cz`(#z%r{ZFus)q9iZ4YZMKnb$MLb0! zMKVPyMLI<^oimC*MJ7rhMK($>MJ|;wi#1Cql`}=YnJJwyMJ7cdMKMJwML9(!oh6eo zMRg8K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