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
66d2c716
Commit
66d2c716
authored
2 years ago
by
OndraRehounek
Committed by
jan.bednarik
2 years ago
Browse files
Options
Downloads
Patches
Plain Diff
main: handle empty first month in timeline
parent
063db107
Branches
Branches containing commit
No related tags found
2 merge requests
!614
Release
,
!613
main: handle empty first month in timeline
Pipeline
#9709
passed
2 years ago
Stage: build
Changes
2
Pipelines
3
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
.isort.cfg
+1
-1
1 addition, 1 deletion
.isort.cfg
main/models.py
+21
-9
21 additions, 9 deletions
main/models.py
with
22 additions
and
10 deletions
.isort.cfg
+
1
−
1
View file @
66d2c716
...
@@ -3,4 +3,4 @@
...
@@ -3,4 +3,4 @@
line_length
=
88
line_length
=
88
multi_line_output
=
3
multi_line_output
=
3
include_trailing_comma
=
true
include_trailing_comma
=
true
known_third_party
=
PyPDF2,arrow,bleach,bs4,captcha,celery,django,environ,faker,fastjsonschema,icalevnt,markdown,modelcluster,pirates,pytest,pytz,requests,sentry_sdk,taggit,tweepy,wagtail,wagtailmetadata,weasyprint,yaml
known_third_party
=
PyPDF2,arrow,bleach,bs4,captcha,celery,
dateutil,
django,environ,faker,fastjsonschema,icalevnt,markdown,modelcluster,pirates,pytest,pytz,requests,sentry_sdk,taggit,tweepy,wagtail,wagtailmetadata,weasyprint,yaml
This diff is collapsed.
Click to expand it.
main/models.py
+
21
−
9
View file @
66d2c716
from
datetime
import
timedelta
from
datetime
import
timedelta
from
functools
import
cached_property
from
functools
import
cached_property
from
dateutil.relativedelta
import
relativedelta
from
django.conf
import
settings
from
django.conf
import
settings
from
django.core.paginator
import
Paginator
from
django.core.paginator
import
Paginator
from
django.db
import
models
from
django.db
import
models
...
@@ -333,15 +334,21 @@ class MainArticlesPage(
...
@@ -333,15 +334,21 @@ class MainArticlesPage(
class
Meta
:
class
Meta
:
verbose_name
=
"
Rozcestník článků
"
verbose_name
=
"
Rozcestník článků
"
def
get_article_data_list
(
self
,
month_back
):
def
get_article_data_list
(
self
,
months_back
:
int
=
1
):
first_day_of_last_month
=
None
target_date_list
=
(
last_month
=
timezone
.
now
().
today
()
MainArticlePage
.
objects
.
filter
(
article_type
=
ARTICLE_TYPES
.
WORK_TIMELINE
)
for
x
in
range
(
month_back
):
.
order_by
(
"
-date
"
)
last_month
=
last_month
.
replace
(
day
=
1
)
-
timedelta
(
days
=
1
)
.
values_list
(
"
date
"
,
flat
=
True
)
first_day_of_last_month
=
last_month
.
replace
(
day
=
1
)
)
if
not
target_date_list
:
return
[
self
.
get_empty_month_data
(
timezone
.
now
().
date
())]
target_date
=
target_date_list
[
0
]
-
relativedelta
(
months
=
months_back
)
first_day_of_target_month
=
target_date
.
replace
(
day
=
1
)
sorted_article_qs
=
MainArticlePage
.
objects
.
filter
(
sorted_article_qs
=
MainArticlePage
.
objects
.
filter
(
date__gt
=
first_day_of_
las
t_month
,
article_type
=
ARTICLE_TYPES
.
WORK_TIMELINE
date__gt
=
first_day_of_
targe
t_month
,
article_type
=
ARTICLE_TYPES
.
WORK_TIMELINE
).
order_by
(
"
-date
"
)
).
order_by
(
"
-date
"
)
article_data_list
=
[]
article_data_list
=
[]
...
@@ -365,16 +372,21 @@ class MainArticlesPage(
...
@@ -365,16 +372,21 @@ class MainArticlesPage(
def
get_context
(
self
,
request
,
*
args
,
**
kwargs
):
def
get_context
(
self
,
request
,
*
args
,
**
kwargs
):
ctx
=
super
().
get_context
(
request
,
args
,
kwargs
)
ctx
=
super
().
get_context
(
request
,
args
,
kwargs
)
article_timeline_list
=
self
.
get_article_data_list
(
1
)
article_timeline_list
=
self
.
get_article_data_list
(
1
)
ctx
[
"
article_timeline_list
"
]
=
article_timeline_list
ctx
[
"
article_timeline_list
"
]
=
article_timeline_list
ctx
[
"
show_next_timeline_articles
"
]
=
MainArticlePage
.
objects
.
filter
(
ctx
[
"
show_next_timeline_articles
"
]
=
MainArticlePage
.
objects
.
filter
(
article_type
=
ARTICLE_TYPES
.
WORK_TIMELINE
article_type
=
ARTICLE_TYPES
.
WORK_TIMELINE
).
count
()
>
len
(
article_timeline_list
)
).
count
()
>
len
(
article_timeline_list
)
article_list
=
MainArticlePage
.
objects
.
filter
(
article_list
=
MainArticlePage
.
objects
.
filter
(
article_type
=
ARTICLE_TYPES
.
PRESS_RELEASE
article_type
=
ARTICLE_TYPES
.
PRESS_RELEASE
).
order_by
(
"
-date
"
)
).
order_by
(
"
-date
"
)[
:
11
]
# dám LIMIT +1, abych věděl, jestli má cenu show_next
ctx
[
"
article_article_list
"
]
=
article_list
[:
10
]
ctx
[
"
article_article_list
"
]
=
article_list
[:
10
]
ctx
[
"
show_next_article
"
]
=
len
(
article_list
)
>
4
ctx
[
"
show_next_article
"
]
=
len
(
article_list
)
>
10
return
ctx
return
ctx
def
get_timeline_articles_response
(
self
,
request
):
def
get_timeline_articles_response
(
self
,
request
):
...
...
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