Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Maják
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
Container registry
Model registry
Operate
Environments
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
Maják
Commits
5de6ddfd
Verified
Commit
5de6ddfd
authored
1 year ago
by
jindra12
Browse files
Options
Downloads
Patches
Plain Diff
Stop duplicates
#210
parent
4ef59983
No related branches found
No related tags found
2 merge requests
!816
Release
,
!801
Prepare basic shared tags
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
district/models.py
+23
-12
23 additions, 12 deletions
district/models.py
main/models.py
+13
-0
13 additions, 0 deletions
main/models.py
shared/models.py
+63
-27
63 additions, 27 deletions
shared/models.py
uniweb/models.py
+29
-7
29 additions, 7 deletions
uniweb/models.py
with
128 additions
and
46 deletions
district/models.py
+
23
−
12
View file @
5de6ddfd
...
@@ -458,7 +458,14 @@ class DistrictArticlePage(
...
@@ -458,7 +458,14 @@ class DistrictArticlePage(
@property
@property
def
get_tags
(
self
):
def
get_tags
(
self
):
if
self
.
shared_from
is
not
None
:
if
self
.
shared_from
is
not
None
:
return
self
.
articles_page
.
search_tags_by_article_id
([
self
.
pk
])
return
self
.
articles_page
.
search_tags_by_unioned_id_query
(
[
{
"
union_page_ptr_id
"
:
self
.
pk
,
"
union_page_kind
"
:
"
district
"
,
}
]
)
return
self
.
tags
.
all
return
self
.
tags
.
all
def
get_context
(
self
,
request
):
def
get_context
(
self
,
request
):
...
@@ -565,19 +572,23 @@ class DistrictArticlesPage(
...
@@ -565,19 +572,23 @@ class DistrictArticlesPage(
# (tags__slug)
# (tags__slug)
context
=
super
().
get_context
(
request
)
context
=
super
().
get_context
(
request
)
site_
article_ids
=
self
.
append_all_shared_articles_ids
(
article_ids
_with_type
=
self
.
append_all_shared_articles_ids
_with_type
(
DistrictArticlePage
.
objects
.
child_of
(
self
)
DistrictArticlePage
.
objects
.
child_of
(
self
)
)
)
page_ids
=
list
(
map
(
lambda
unioned
:
unioned
[
"
union_page_ptr_id
"
],
article_ids_with_type
)
)
# Naplním "tag" a "article_page_list" parametry
# Naplním "tag" a "article_page_list" parametry
context
.
update
(
**
self
.
get_tag_and_articles
(
request
,
site_articl
e_ids
))
context
.
update
(
**
self
.
get_tag_and_articles
(
request
,
pag
e_ids
))
context
[
"
tag_list
"
]
=
self
.
get_tag_qs
(
site_
article_ids
)
context
[
"
tag_list
"
]
=
self
.
get_tag_qs
(
article_ids
_with_type
)
# Pro obecnou paginaci posílám "extra_query", abych si podržel tag pro další GET
# Pro obecnou paginaci posílám "extra_query", abych si podržel tag pro další GET
context
[
"
extra_query
"
]
=
"
&tag={}
"
.
format
(
request
.
GET
.
get
(
"
tag
"
,
""
))
context
[
"
extra_query
"
]
=
"
&tag={}
"
.
format
(
request
.
GET
.
get
(
"
tag
"
,
""
))
return
context
return
context
def
get_tag_and_articles
(
self
,
request
,
site_articl
e_ids
:
list
)
->
dict
:
def
get_tag_and_articles
(
self
,
request
,
pag
e_ids
:
list
)
->
dict
:
"""
"""
Vrátí vyfiltrované články podle tagu a page query pro z daného
"
výběru
"
Vrátí vyfiltrované články podle tagu a page query pro z daného
"
výběru
"
pro danou stránku (site_article_ids). Lepší by bylo články a tag řešit
pro danou stránku (site_article_ids). Lepší by bylo články a tag řešit
...
@@ -591,17 +602,17 @@ class DistrictArticlesPage(
...
@@ -591,17 +602,17 @@ class DistrictArticlesPage(
tag
=
Tag
.
objects
.
filter
(
slug
=
request
.
GET
[
"
tag
"
])[
0
]
tag
=
Tag
.
objects
.
filter
(
slug
=
request
.
GET
[
"
tag
"
])[
0
]
article_page_qs
=
self
.
append_all_shared_articles
(
article_page_qs
=
self
.
append_all_shared_articles
(
DistrictArticlePage
.
objects
.
filter
(
DistrictArticlePage
.
objects
.
filter
(
id__in
=
site_articl
e_ids
,
tags__slug
=
tag
.
slug
page_ptr_id__in
=
pag
e_ids
,
tags__slug
=
tag
.
slug
),
),
filter
=
lambda
shared
:
shared
.
filter
(
filter
=
lambda
shared
:
shared
.
filter
(
id__in
=
site_articl
e_ids
,
tags__slug
=
tag
.
slug
page_ptr_id__in
=
pag
e_ids
,
tags__slug
=
tag
.
slug
),
),
)
)
except
(
KeyError
,
IndexError
):
except
(
KeyError
,
IndexError
):
tag
=
None
tag
=
None
article_page_qs
=
self
.
append_all_shared_articles
(
article_page_qs
=
self
.
append_all_shared_articles
(
DistrictArticlePage
.
objects
.
filter
(
id__in
=
site_articl
e_ids
),
DistrictArticlePage
.
objects
.
filter
(
page_ptr_id__in
=
pag
e_ids
),
filter
=
lambda
shared
:
shared
.
filter
(
id__in
=
site_articl
e_ids
),
filter
=
lambda
shared
:
shared
.
filter
(
page_ptr_id__in
=
pag
e_ids
),
)
)
return
{
return
{
...
@@ -612,13 +623,13 @@ class DistrictArticlesPage(
...
@@ -612,13 +623,13 @@ class DistrictArticlesPage(
"
tag
"
:
tag
,
"
tag
"
:
tag
,
}
}
def
get_tag_qs
(
self
,
site_
article_ids
:
list
)
->
models
.
QuerySet
:
def
get_tag_qs
(
self
,
article_ids
_with_type
:
list
)
->
models
.
QuerySet
:
"""
"""
Getuje Tagy pouze pro DistrictArticlePage omezeno IDčky getnutých přes
Getuje Tagy pouze pro DistrictArticlePage omezeno IDčky getnutých přes
root_page. Počítá, kolik článků je s daným tagem.
root_page. Počítá, kolik článků je s daným tagem.
"""
"""
return
self
.
search_tags_by_
article_id
(
return
self
.
search_tags_by_
unioned_id_query
(
site_
article_ids
,
article_ids
_with_type
,
tags_model_query
=
lambda
query
:
query
.
annotate
(
count
=
models
.
Count
(
"
slug
"
))
tags_model_query
=
lambda
query
:
query
.
annotate
(
count
=
models
.
Count
(
"
slug
"
))
.
order_by
(
"
slug
"
)
.
order_by
(
"
slug
"
)
.
values
(
"
name
"
,
"
slug
"
,
"
count
"
),
.
values
(
"
name
"
,
"
slug
"
,
"
count
"
),
...
...
This diff is collapsed.
Click to expand it.
main/models.py
+
13
−
0
View file @
5de6ddfd
...
@@ -666,6 +666,19 @@ class MainArticlePage(
...
@@ -666,6 +666,19 @@ class MainArticlePage(
class
Meta
:
class
Meta
:
verbose_name
=
"
Aktualita
"
verbose_name
=
"
Aktualita
"
@property
def
get_tags
(
self
):
if
self
.
shared_from
is
not
None
:
return
self
.
articles_page
.
search_tags_by_unioned_id_query
(
[
{
"
union_page_ptr_id
"
:
self
.
pk
,
"
union_page_kind
"
:
"
uniweb
"
,
}
]
)
return
self
.
tags
.
all
# def get_context(self, request): chceme/nechceme?
# def get_context(self, request): chceme/nechceme?
# context = super().get_context(request)
# context = super().get_context(request)
# context["related_articles"] = (
# context["related_articles"] = (
...
...
This diff is collapsed.
Click to expand it.
shared/models.py
+
63
−
27
View file @
5de6ddfd
...
@@ -282,8 +282,8 @@ class SharedTaggedMainArticle(ItemBase):
...
@@ -282,8 +282,8 @@ class SharedTaggedMainArticle(ItemBase):
class
SharedArticlesPageType
(
Enum
):
class
SharedArticlesPageType
(
Enum
):
DISTRICT
=
(
"
district
"
,)
DISTRICT
=
"
district
"
UNIWEB
=
(
"
uniweb
"
,)
UNIWEB
=
"
uniweb
"
MAIN
=
"
main
"
MAIN
=
"
main
"
...
@@ -305,6 +305,15 @@ class ArticlesMixin(models.Model):
...
@@ -305,6 +305,15 @@ class ArticlesMixin(models.Model):
elif
self
.
_meta
.
app_label
==
"
main
"
:
elif
self
.
_meta
.
app_label
==
"
main
"
:
return
SharedArticlesPageType
.
MAIN
return
SharedArticlesPageType
.
MAIN
def
unique_page_query_materialized
(
self
,
results
):
return
list
(
reduce
(
lambda
unique
,
item
:
unique
|
{
f
"
{
item
[
'
union_page_ptr_id
'
]
}
"
:
item
},
list
(
results
),
{},
).
values
()
)
def
append_all_shared_articles_query
(
def
append_all_shared_articles_query
(
self
,
previous_query
:
models
.
QuerySet
|
None
=
None
,
filter
=
None
self
,
previous_query
:
models
.
QuerySet
|
None
=
None
,
filter
=
None
):
):
...
@@ -340,6 +349,9 @@ class ArticlesMixin(models.Model):
...
@@ -340,6 +349,9 @@ class ArticlesMixin(models.Model):
main_fields
=
reduce
(
fields_reducer
,
main_meta_fields
,
{})
|
{
main_fields
=
reduce
(
fields_reducer
,
main_meta_fields
,
{})
|
{
"
union_thumb_image_id
"
:
F
(
"
search_image_id
"
),
"
union_thumb_image_id
"
:
F
(
"
search_image_id
"
),
"
union_page_kind
"
:
Value
(
SharedArticlesPageType
.
MAIN
.
value
,
output_field
=
models
.
CharField
()
),
}
}
district_fields
=
setup_fields_order
(
district_fields
=
setup_fields_order
(
...
@@ -348,6 +360,10 @@ class ArticlesMixin(models.Model):
...
@@ -348,6 +360,10 @@ class ArticlesMixin(models.Model):
|
{
|
{
"
union_region
"
:
Value
(
""
,
models
.
CharField
()),
"
union_region
"
:
Value
(
""
,
models
.
CharField
()),
"
union_article_type
"
:
Value
(
0
,
models
.
PositiveSmallIntegerField
()),
"
union_article_type
"
:
Value
(
0
,
models
.
PositiveSmallIntegerField
()),
"
union_page_kind
"
:
Value
(
SharedArticlesPageType
.
DISTRICT
.
value
,
output_field
=
models
.
CharField
(),
),
},
},
)
)
...
@@ -365,6 +381,9 @@ class ArticlesMixin(models.Model):
...
@@ -365,6 +381,9 @@ class ArticlesMixin(models.Model):
"
union_article_type
"
:
Value
(
0
,
models
.
PositiveSmallIntegerField
()),
"
union_article_type
"
:
Value
(
0
,
models
.
PositiveSmallIntegerField
()),
"
union_is_black
"
:
Value
(
False
,
models
.
BooleanField
()),
"
union_is_black
"
:
Value
(
False
,
models
.
BooleanField
()),
"
union_thumb_image_id
"
:
F
(
"
search_image_id
"
),
"
union_thumb_image_id
"
:
F
(
"
search_image_id
"
),
"
union_page_kind
"
:
Value
(
SharedArticlesPageType
.
UNIWEB
.
value
,
output_field
=
models
.
CharField
()
),
},
},
)
)
...
@@ -407,24 +426,20 @@ class ArticlesMixin(models.Model):
...
@@ -407,24 +426,20 @@ class ArticlesMixin(models.Model):
),
),
)
)
results
=
(
main_by_values
=
main_by_slug
.
values
(
main_by_slug
.
values
(
**
main_fields
,
**
main_fields
,
union_shared_from_id
=
shared_field
,
union_shared_from_id
=
shared_field
,
)
)
.
union
(
uniweb_by_values
=
uniweb_by_slug
.
values
(
uniweb_by_slug
.
values
(
**
uniweb_fields
,
**
uniweb_fields
,
union_shared_from_id
=
shared_field
,
union_shared_from_id
=
shared_field
,
)
)
)
district_by_values
=
district_by_slug
.
values
(
.
union
(
district_by_slug
.
values
(
**
district_fields
,
**
district_fields
,
union_shared_from_id
=
shared_field
,
union_shared_from_id
=
shared_field
,
)
)
)
)
results
=
main_by_values
.
union
(
uniweb_by_values
).
union
(
district_by_values
)
empty_shared_field
=
Value
(
empty_shared_field
=
Value
(
None
,
None
,
...
@@ -456,11 +471,13 @@ class ArticlesMixin(models.Model):
...
@@ -456,11 +471,13 @@ class ArticlesMixin(models.Model):
return
results
.
order_by
(
"
union_date
"
)
return
results
.
order_by
(
"
union_date
"
)
def
append_all_shared_articles_ids
(
def
append_all_shared_articles_ids
_with_type
(
self
,
previous_query
:
models
.
QuerySet
|
None
=
None
,
filter
=
None
self
,
previous_query
:
models
.
QuerySet
|
None
=
None
,
filter
=
None
):
):
results
=
self
.
append_all_shared_articles_query
(
previous_query
,
filter
)
results
=
self
.
append_all_shared_articles_query
(
previous_query
,
filter
)
return
results
.
values_list
(
"
id
"
,
flat
=
True
)
return
self
.
unique_page_query_materialized
(
results
.
values
(
"
union_page_ptr_id
"
,
"
union_page_kind
"
)
)
def
append_all_shared_articles
(
def
append_all_shared_articles
(
self
,
previous_query
:
models
.
QuerySet
|
None
=
None
,
filter
=
None
self
,
previous_query
:
models
.
QuerySet
|
None
=
None
,
filter
=
None
...
@@ -480,7 +497,7 @@ class ArticlesMixin(models.Model):
...
@@ -480,7 +497,7 @@ class ArticlesMixin(models.Model):
results
=
self
.
append_all_shared_articles_query
(
previous_query
,
filter
)
results
=
self
.
append_all_shared_articles_query
(
previous_query
,
filter
)
evaluated
=
list
(
evaluated
=
self
.
unique_page_query_materialized
(
results
results
)
# We MUST eval here since we can't turn values() into concrete class instances in QuerySet after union
)
# We MUST eval here since we can't turn values() into concrete class instances in QuerySet after union
...
@@ -528,21 +545,40 @@ class ArticlesMixin(models.Model):
...
@@ -528,21 +545,40 @@ class ArticlesMixin(models.Model):
slug
=
request
.
GET
.
get
(
"
sdilene
"
,
""
)
slug
=
request
.
GET
.
get
(
"
sdilene
"
,
""
)
return
self
.
get_article_page_by_slug
(
slug
).
serve
(
request
)
return
self
.
get_article_page_by_slug
(
slug
).
serve
(
request
)
def
search_tags_by_article_id
(
def
search_tags_by_unioned_id_query
(
self
,
site_article_ids
:
list
,
additional_query
=
None
,
tags_model_query
=
None
self
,
site_article_id_page_list
:
list
,
additional_query
=
None
,
tags_model_query
=
None
,
):
):
DistrictArticleTag
=
apps
.
get_model
(
app_label
=
"
district.DistrictArticleTag
"
)
DistrictArticleTag
=
apps
.
get_model
(
app_label
=
"
district.DistrictArticleTag
"
)
UniwebArticleTag
=
apps
.
get_model
(
app_label
=
"
uniweb.UniwebArticleTag
"
)
UniwebArticleTag
=
apps
.
get_model
(
app_label
=
"
uniweb.UniwebArticleTag
"
)
MainArticleTag
=
apps
.
get_model
(
app_label
=
"
main.MainArticleTag
"
)
MainArticleTag
=
apps
.
get_model
(
app_label
=
"
main.MainArticleTag
"
)
get_ids_by_page_type
=
lambda
page_type
:
list
(
map
(
lambda
unioned
:
unioned
[
"
union_page_ptr_id
"
],
filter
(
lambda
unioned
:
unioned
[
"
union_page_kind
"
]
==
page_type
,
site_article_id_page_list
,
),
)
)
district_tags
=
DistrictArticleTag
.
objects
.
filter
(
district_tags
=
DistrictArticleTag
.
objects
.
filter
(
content_object_id__in
=
site_article_ids
content_object_id__in
=
get_ids_by_page_type
(
SharedArticlesPageType
.
DISTRICT
.
value
)
)
)
uniweb_tags
=
UniwebArticleTag
.
objects
.
filter
(
uniweb_tags
=
UniwebArticleTag
.
objects
.
filter
(
content_object_id__in
=
site_article_ids
content_object_id__in
=
get_ids_by_page_type
(
SharedArticlesPageType
.
UNIWEB
.
value
)
)
)
main_tags
=
MainArticleTag
.
objects
.
filter
(
main_tags
=
MainArticleTag
.
objects
.
filter
(
content_object_id__in
=
site_article_ids
content_object_id__in
=
get_ids_by_page_type
(
SharedArticlesPageType
.
MAIN
.
value
)
)
)
if
additional_query
is
not
None
:
if
additional_query
is
not
None
:
...
...
This diff is collapsed.
Click to expand it.
uniweb/models.py
+
29
−
7
View file @
5de6ddfd
...
@@ -536,13 +536,13 @@ class UniwebArticlesIndexPage(
...
@@ -536,13 +536,13 @@ class UniwebArticlesIndexPage(
### OTHERS
### OTHERS
class
Meta
:
verbose_name
=
"
Sekce článků
"
@route
(
r
"
^sdilene/$
"
,
name
=
"
shared
"
)
@route
(
r
"
^sdilene/$
"
,
name
=
"
shared
"
)
def
shared
(
self
,
request
):
def
shared
(
self
,
request
):
return
self
.
setup_article_page_context
(
request
)
return
self
.
setup_article_page_context
(
request
)
class
Meta
:
verbose_name
=
"
Sekce článků
"
def
get_context
(
self
,
request
):
def
get_context
(
self
,
request
):
context
=
super
().
get_context
(
request
)
context
=
super
().
get_context
(
request
)
num
=
request
.
GET
.
get
(
"
page
"
)
num
=
request
.
GET
.
get
(
"
page
"
)
...
@@ -550,15 +550,24 @@ class UniwebArticlesIndexPage(
...
@@ -550,15 +550,24 @@ class UniwebArticlesIndexPage(
tag_params
=
self
.
search_tags_by_tag_name
(
tag
)
tag_params
=
self
.
search_tags_by_tag_name
(
tag
)
own_children
=
UniwebArticlePage
.
objects
.
child_of
(
self
)
articles
=
self
.
append_all_shared_articles
(
articles
=
self
.
append_all_shared_articles
(
UniwebArticlePage
.
objects
.
child_of
(
self
),
own_children
,
filter
=
lambda
articles
:
articles
.
filter
(
**
tag_params
),
filter
=
lambda
articles
:
articles
.
filter
(
**
tag_params
)
if
tag
is
not
None
else
articles
,
)
)
articles_ids
=
list
(
map
(
lambda
article
:
article
.
pk
,
articles
))
articles_ids
=
self
.
append_all_shared_articles_ids_with_type
(
own_children
,
filter
=
lambda
articles
:
articles
.
filter
(
**
tag_params
)
if
tag
is
not
None
else
articles
,
)
context
[
"
articles
"
]
=
Paginator
(
articles
,
ARTICLES_PER_PAGE
).
get_page
(
num
)
context
[
"
articles
"
]
=
Paginator
(
articles
,
ARTICLES_PER_PAGE
).
get_page
(
num
)
context
[
"
tags
"
]
=
self
.
search_tags_by_
article_id
(
articles_ids
)
context
[
"
tags
"
]
=
self
.
search_tags_by_
unioned_id_query
(
articles_ids
)
context
[
"
active_tag
"
]
=
tag
context
[
"
active_tag
"
]
=
tag
return
context
return
context
...
@@ -597,6 +606,19 @@ class UniwebArticlePage(
...
@@ -597,6 +606,19 @@ class UniwebArticlePage(
class
Meta
:
class
Meta
:
verbose_name
=
"
Článek
"
verbose_name
=
"
Článek
"
@property
def
get_tags
(
self
):
if
self
.
shared_from
is
not
None
:
return
self
.
articles_page
.
search_tags_by_unioned_id_query
(
[
{
"
union_page_ptr_id
"
:
self
.
pk
,
"
union_page_kind
"
:
"
uniweb
"
,
}
]
)
return
self
.
tags
.
all
def
get_context
(
self
,
request
):
def
get_context
(
self
,
request
):
context
=
super
().
get_context
(
request
)
context
=
super
().
get_context
(
request
)
context
[
"
related_articles
"
]
=
(
context
[
"
related_articles
"
]
=
(
...
...
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