Fakultas Ilmu Komputer UI
Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
PMPL
Class Project
DIGIPUS
Commits
fa7bb0bc
Commit
fa7bb0bc
authored
Oct 10, 2020
by
Salsabila Hava Qabita
Browse files
[
#62
] Material: Add Release Year Field on Material Upload
parent
68ae0470
Changes
6
Hide whitespace changes
Inline
Side-by-side
app/forms.py
View file @
fa7bb0bc
...
...
@@ -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
):
...
...
app/migrations/0021_materi_release_year.py
0 → 100644
View file @
fa7bb0bc
# 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
),
),
]
app/models.py
View file @
fa7bb0bc
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
])
...
...
app/templates/app/detail_materi.html
View file @
fa7bb0bc
...
...
@@ -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>
...
...
app/tests.py
View file @
fa7bb0bc
...
...
@@ -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
digipus/__pycache__/settings.cpython-36.pyc
View file @
fa7bb0bc
No preview for this file type
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment