Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
U
Učebnice
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
TO
Učebnice
Commits
055f8892
Commit
055f8892
authored
1 year ago
by
Tomáš Valenta
Browse files
Options
Downloads
Patches
Plain Diff
finish material queryset
parent
aa61bd5e
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Pipeline
#14049
passed
1 year ago
Stage: build
Stage: test_deploy
Changes
4
Pipelines
2
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
lectures/admin.py
+17
-0
17 additions, 0 deletions
lectures/admin.py
lectures/forms.py
+24
-0
24 additions, 0 deletions
lectures/forms.py
lectures/models.py
+4
-1
4 additions, 1 deletion
lectures/models.py
lectures/views.py
+12
-12
12 additions, 12 deletions
lectures/views.py
with
57 additions
and
13 deletions
lectures/admin.py
+
17
−
0
View file @
055f8892
...
@@ -2,6 +2,7 @@ from django.contrib import admin
...
@@ -2,6 +2,7 @@ from django.contrib import admin
from
shared.admin
import
MarkdownxGuardedModelAdmin
from
shared.admin
import
MarkdownxGuardedModelAdmin
from
.forms
import
LectureGroupTypeFormset
from
.models
import
(
from
.models
import
(
Lecture
,
Lecture
,
LectureGroup
,
LectureGroup
,
...
@@ -39,6 +40,7 @@ class LectureMaterialInline(admin.StackedInline):
...
@@ -39,6 +40,7 @@ class LectureMaterialInline(admin.StackedInline):
class
LectureGroupTypeInline
(
admin
.
StackedInline
):
class
LectureGroupTypeInline
(
admin
.
StackedInline
):
model
=
LectureGroupType
model
=
LectureGroupType
autocomplete_fields
=
(
"
group
"
,)
autocomplete_fields
=
(
"
group
"
,)
formset
=
LectureGroupTypeFormset
extra
=
1
extra
=
1
...
@@ -56,8 +58,23 @@ class LectureAdmin(MarkdownxGuardedModelAdmin):
...
@@ -56,8 +58,23 @@ class LectureAdmin(MarkdownxGuardedModelAdmin):
list_display
=
(
list_display
=
(
"
name
"
,
"
name
"
,
"
timestamp
"
,
"
timestamp
"
,
"
display_lecture_group_types
"
,
)
)
@admin.display
(
description
=
"
Výukové skupiny
"
)
def
display_lecture_group_types
(
self
,
obj
)
->
str
:
group_names
=
[]
for
lecture_group_type
in
obj
.
lecture_group_types
.
all
():
group_names
.
append
(
str
(
lecture_group_type
.
group
))
display_string
=
"
,
"
.
join
(
group_names
)
if
len
(
display_string
)
>
64
:
display_string
=
display_string
[:
64
]
+
"
...
"
return
display_string
class
LectureLectorAdmin
(
MarkdownxGuardedModelAdmin
):
class
LectureLectorAdmin
(
MarkdownxGuardedModelAdmin
):
search_fields
=
(
"
name
"
,
"
username
"
)
search_fields
=
(
"
name
"
,
"
username
"
)
...
...
This diff is collapsed.
Click to expand it.
lectures/forms.py
0 → 100644
+
24
−
0
View file @
055f8892
from
django
import
forms
class
LectureGroupTypeFormset
(
forms
.
models
.
BaseInlineFormSet
):
# https://stackoverflow.com/a/877920
def
clean
(
self
):
groups
=
[]
for
form
in
self
.
forms
:
try
:
if
form
.
cleaned_data
:
if
form
.
cleaned_data
[
"
group
"
]
in
groups
and
not
form
.
cleaned_data
.
get
(
"
DELETE
"
,
False
):
raise
forms
.
ValidationError
(
"
Školení nemůžeš přiřadit jednotlivé skupině více než jednou.
"
)
groups
.
append
(
form
.
cleaned_data
[
"
group
"
])
except
AttributeError
as
exception
:
# annoyingly, if a subform is invalid Django explicity raises
# an AttributeError for cleaned_data
pass
This diff is collapsed.
Click to expand it.
lectures/models.py
+
4
−
1
View file @
055f8892
...
@@ -106,6 +106,9 @@ class LectureGroupType(models.Model):
...
@@ -106,6 +106,9 @@ class LectureGroupType(models.Model):
verbose_name
=
"
Požadovanost
"
,
verbose_name
=
"
Požadovanost
"
,
)
)
def
__str__
(
self
)
->
str
:
return
f
"
{
self
.
group
}
-
{
self
.
lecture
}
"
class
Meta
:
class
Meta
:
verbose_name
=
"
Úroveň požadovanosti pro skupinu
"
verbose_name
=
"
Úroveň požadovanosti pro skupinu
"
verbose_name_plural
=
"
Úroveň požadovanosti pro skupiny
"
verbose_name_plural
=
"
Úroveň požadovanosti pro skupiny
"
...
@@ -261,7 +264,7 @@ class LectureRecording(NameStrMixin, models.Model):
...
@@ -261,7 +264,7 @@ class LectureRecording(NameStrMixin, models.Model):
def
get_lecture_material_file_location
(
instance
,
filename
):
def
get_lecture_material_file_location
(
instance
,
filename
):
return
get_file_location
(
instane
,
filename
,
path_prefix
=
"
_private
"
)
return
get_file_location
(
instan
c
e
,
filename
,
path_prefix
=
"
_private
"
)
class
LectureMaterialFileProxy
(
FieldFile
):
class
LectureMaterialFileProxy
(
FieldFile
):
...
...
This diff is collapsed.
Click to expand it.
lectures/views.py
+
12
−
12
View file @
055f8892
...
@@ -25,23 +25,23 @@ class LectureMaterialFileDownloadView(ObjectDownloadView):
...
@@ -25,23 +25,23 @@ class LectureMaterialFileDownloadView(ObjectDownloadView):
attachment
=
False
attachment
=
False
def
get_queryset
(
self
,
*
args
,
**
kwargs
):
def
get_queryset
(
self
,
*
args
,
**
kwargs
):
queryset
=
(
queryset
=
super
().
get_queryset
(
*
args
,
**
kwargs
)
super
()
material
=
queryset
.
first
()
.
get_queryset
(
*
args
,
**
kwargs
)
.
filter
(
if
material
is
None
:
lecture__groups__in
=
(
raise
HTTPExceptions
.
NOT_FOUND
get_objects_for_user
(
self
.
current_user
,
"
lectures.view_lecturegroup
"
success
,
auth_redirect
=
get_lectures
(
).
filter
(
models
.
Q
(
user_groups__in
=
self
.
current_user
.
groups
.
all
()))
self
.
request
,
filter
=
models
.
Q
(
id
=
material
.
lecture_id
),
get_exceptions
=
True
)
)
)
)
if
not
success
:
raise
HTTPExceptions
.
NOT_FOUND
return
queryset
return
queryset
def
get
(
self
,
request
,
*
args
,
**
kwargs
):
def
get
(
self
,
request
,
*
args
,
**
kwargs
):
self
.
current_user
=
request
.
user
self
.
request
=
request
return
super
().
get
(
request
,
*
args
,
**
kwargs
)
return
super
().
get
(
request
,
*
args
,
**
kwargs
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment