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
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
TO
Maják
Commits
955855d7
You need to sign in or sign up before continuing.
Commit
955855d7
authored
2 years ago
by
Tomáš Valenta
Browse files
Options
Downloads
Patches
Plain Diff
iCal parsing
parent
38209cc3
No related branches found
No related tags found
2 merge requests
!787
Release
,
!749
Add personal calendars, move from requests-cache to Django cache
Pipeline
#12324
passed
2 years ago
Stage: build
Changes
3
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
main/migrations/0055_remove_mainpersonpage_nextcloud_calendar_url_and_more.py
+22
-0
22 additions, 0 deletions
..._remove_mainpersonpage_nextcloud_calendar_url_and_more.py
main/models.py
+30
-34
30 additions, 34 deletions
main/models.py
shared/blocks.py
+10
-2
10 additions, 2 deletions
shared/blocks.py
with
62 additions
and
36 deletions
main/migrations/0055_remove_mainpersonpage_nextcloud_calendar_url_and_more.py
0 → 100644
+
22
−
0
View file @
955855d7
# Generated by Django 4.1.8 on 2023-04-12 22:53
from
django.db
import
migrations
,
models
class
Migration
(
migrations
.
Migration
):
dependencies
=
[
(
'
main
'
,
'
0054_mainpersonpage_ical_calendar_url_and_more
'
),
]
operations
=
[
migrations
.
RemoveField
(
model_name
=
'
mainpersonpage
'
,
name
=
'
nextcloud_calendar_url
'
,
),
migrations
.
AlterField
(
model_name
=
'
mainpersonpage
'
,
name
=
'
ical_calendar_url
'
,
field
=
models
.
URLField
(
blank
=
True
,
help_text
=
'
Podporuje Mrak, Google Kalendář a další. Návod na synchronizaci najdeš na pi2.cz/kalendare
'
,
max_length
=
256
,
null
=
True
,
verbose_name
=
'
iCal adresa kalendáře
'
),
),
]
This diff is collapsed.
Click to expand it.
main/models.py
+
30
−
34
View file @
955855d7
from
functools
import
cached_property
import
requests
from
dateutil.relativedelta
import
relativedelta
from
datetime
import
date
,
timedelta
from
django.conf
import
settings
from
django.contrib
import
messages
from
django.core.cache
import
cache
from
django.core.paginator
import
Paginator
from
django.core.validators
import
RegexValidator
from
django.db
import
models
from
django.forms
import
ValidationError
from
django.http
import
HttpResponseRedirect
,
JsonResponse
from
django.shortcuts
import
render
from
django.utils
import
timezone
from
icalevnt
import
icalevents
from
modelcluster.contrib.taggit
import
ClusterTaggableManager
from
modelcluster.fields
import
ParentalKey
from
taggit.models
import
TaggedItemBase
...
...
@@ -795,17 +801,10 @@ class MainPersonPage(ExtendedMetadataPageMixin, SubpageMixin, MetadataPageMixin,
max_length
=
256
,
blank
=
True
,
null
=
True
,
help_text
=
"
Musí být ve formátu iCal. V Google kalendáři lze exportovat v nastavení (TODO).
"
,
)
nextcloud_calendar_url
=
models
.
URLField
(
"
Adresa kalendáře v Mraku
"
,
max_length
=
256
,
blank
=
True
,
null
=
True
,
help_text
=
(
'
V nastavení kalendáře klikni na ikonu
"
+
"
vedle
"
odkaz na sdílení
"
'
"
a
vlož zkopírovaný odkaz.
"
)
"
Podporuje Mrak, Google Kalendář a další. Návod na synchronizaci najdeš
"
"
n
a
pi2.cz/kalendare
"
)
,
)
settings_panels
=
[]
...
...
@@ -827,13 +826,7 @@ class MainPersonPage(ExtendedMetadataPageMixin, SubpageMixin, MetadataPageMixin,
FieldPanel
(
"
text
"
),
FieldPanel
(
"
email
"
),
FieldPanel
(
"
phone
"
),
MultiFieldPanel
(
[
FieldPanel
(
"
ical_calendar_url
"
),
FieldPanel
(
"
nextcloud_calendar_url
"
),
],
"
Kalendář
"
,
),
FieldPanel
(
"
social_links
"
),
FieldPanel
(
"
people
"
),
]
...
...
@@ -855,31 +848,34 @@ class MainPersonPage(ExtendedMetadataPageMixin, SubpageMixin, MetadataPageMixin,
order_by
(
"
-timestamp
"
)
)[:
20
]
if
self
.
ical_calendar_url
:
context
[
"
calendar_data
"
]
=
self
.
get_ical_data
()
print
(
context
[
"
calendar_data
"
])
return
context
### OTHERS
def
clean
(
self
)
->
None
:
cleaned_data
=
super
().
clean
(
)
def
get_ical_data
(
self
)
->
list
:
ical_response
=
cache
.
get
(
f
"
calendar_
{
self
.
ical_calendar_url
}
"
)
BOTH_CALENDARS_DEFINED_ERROR_MESSAGE
=
(
"
Nemůžeš definovat kalendář z Mraku a v iCal formátu najednou.
"
)
if
ical_response
is
None
:
ical_response
=
requests
.
get
(
self
.
ical_calendar_url
)
ical_response
.
raise_for_status
()
ical_response
=
ical_response
.
text
if
(
cleaned_data
.
get
(
"
ical_calendar_url
"
)
and
cleaned_data
.
get
(
"
nextcloud_calendar_url
"
)
):
self
.
add_error
(
"
ical_calendar_url
"
,
BOTH_CALENDARS_DEFINED_ERROR_MESSAGE
)
self
.
add_error
(
"
nextcloud_calendar_url
"
,
BOTH_CALENDARS_DEFINED_ERROR_MESSAGE
cache
.
set
(
f
"
calendar_
{
self
.
ical_calendar_url
}
"
,
ical_response
,
timeout
=
3600
,
# 1 hour
)
return
cleaned_data
return
icalevents
.
parse_events
(
ical_response
,
start
=
date
.
today
()
-
timedelta
(
days
=
30
),
end
=
date
.
today
()
+
timedelta
(
days
=
60
),
)
class
Meta
:
verbose_name
=
"
Detail osoby
"
...
...
This diff is collapsed.
Click to expand it.
shared/blocks.py
+
10
−
2
View file @
955855d7
...
...
@@ -777,7 +777,11 @@ class ChartRedmineIssueDataset(blocks.StructBlock):
issues_response
.
raise_for_status
()
issues_response
=
issues_response
.
json
()
cache
.
set
(
f
"
redmine_
{
issues_url
}
"
,
issues_response
)
cache
.
set
(
f
"
redmine_
{
issues_url
}
"
,
issues_response
,
timeout
=
604800
,
# 1 week
)
only_grow
=
value
.
get
(
"
only_grow
"
,
False
)
...
...
@@ -795,7 +799,11 @@ class ChartRedmineIssueDataset(blocks.StructBlock):
issues_response
.
raise_for_status
()
issues_response
=
issues_response
.
json
()
cache
.
set
(
f
"
redmine_
{
url_with_offset
}
"
,
issues_response
)
cache
.
set
(
f
"
redmine_
{
url_with_offset
}
"
,
issues_response
,
timeout
=
604800
,
# 1 week
)
collected_issues
+=
issues_response
[
"
issues
"
]
...
...
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