Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
AlekSIS-App-DashboardFeeds
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
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
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
AlekSIS®
Official
AlekSIS-App-DashboardFeeds
Commits
b1ea9ce0
Commit
b1ea9ce0
authored
3 years ago
by
Julian
Committed by
Hangzhi Yu
3 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Move exception catching to icalwidget model code
parent
e9188376
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!55
Resolve "Cache iCal data"
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
aleksis/apps/dashboardfeeds/models.py
+12
-2
12 additions, 2 deletions
aleksis/apps/dashboardfeeds/models.py
aleksis/apps/dashboardfeeds/util/event_feed.py
+4
-25
4 additions, 25 deletions
aleksis/apps/dashboardfeeds/util/event_feed.py
with
16 additions
and
27 deletions
aleksis/apps/dashboardfeeds/models.py
+
12
−
2
View file @
b1ea9ce0
import
datetime
import
logging
from
django.contrib
import
messages
from
django.db
import
models
from
django.db.models.signals
import
post_delete
from
django.dispatch
import
receiver
...
...
@@ -11,6 +13,8 @@ from aleksis.core.models import DashboardWidget
from
.util.event_feed
import
get_current_events_with_cal
logger
=
logging
.
getLogger
(
__name__
)
class
RSSFeedWidget
(
DashboardWidget
):
template
=
"
dashboardfeeds/rss.html
"
...
...
@@ -82,10 +86,16 @@ class ICalFeedWidget(DashboardWidget):
events_count
=
models
.
IntegerField
(
verbose_name
=
_
(
"
Number of displayed events
"
),
default
=
5
)
def
get_context
(
self
,
request
):
events
,
errors
=
get_current_events_with_cal
(
self
.
url
,
self
.
events_count
,
request
)
if
errors
:
try
:
events
=
get_current_events_with_cal
(
self
.
url
,
self
.
events_count
)
except
Exception
as
e
:
events
=
[]
logger
.
error
(
str
(
e
))
self
.
broken
=
True
self
.
save
()
if
request
:
messages
.
error
(
request
,
_
(
"
There was an error getting your calendar.
"
))
feed
=
{
"
base_url
"
:
self
.
base_url
,
"
feed_events
"
:
events
,
...
...
This diff is collapsed.
Click to expand it.
aleksis/apps/dashboardfeeds/util/event_feed.py
+
4
−
25
View file @
b1ea9ce0
import
logging
from
datetime
import
timedelta
from
typing
import
Optional
,
Tuple
from
django.contrib
import
messages
from
django.http
import
HttpRequest
from
django.utils
import
formats
,
timezone
from
django.utils.translation
import
gettext_lazy
as
_
import
requests
from
cache_memoize
import
cache_memoize
from
ics
import
Calendar
logger
=
logging
.
getLogger
(
__name__
)
def
get_current_events
(
calendar
:
Calendar
,
limit
:
int
=
5
)
->
list
:
"""
Get upcoming events from a calendar (ICS) object.
...
...
@@ -76,26 +69,12 @@ def get_current_events(calendar: Calendar, limit: int = 5) -> list:
@cache_memoize
(
300
)
def
get_current_events_with_cal
(
calendar_url
:
str
,
limit
:
int
=
5
,
request
:
Optional
[
HttpRequest
]
=
None
)
->
Tuple
[
list
,
list
]:
def
get_current_events_with_cal
(
calendar_url
:
str
,
limit
:
int
=
5
)
->
list
:
"""
Get current events.
Download an iCalendar file from an URL, parse using the ICS library
and return a limited number of events.
"""
try
:
content
=
requests
.
get
(
calendar_url
,
timeout
=
3
)
except
requests
.
RequestException
as
e
:
logger
.
error
(
str
(
e
))
return
[],
[
str
(
e
)]
try
:
calendar
:
Calendar
=
Calendar
(
content
.
text
)
except
Exception
as
e
:
logger
.
error
(
str
(
e
))
if
request
:
messages
.
error
(
request
,
_
(
"
There was an error getting your calendar
"
))
return
[],
[
str
(
e
)]
return
get_current_events
(
calendar
,
limit
),
[]
content
=
requests
.
get
(
calendar_url
,
timeout
=
3
)
calendar
:
Calendar
=
Calendar
(
content
.
text
)
return
get_current_events
(
calendar
,
limit
)
This diff is collapsed.
Click to expand it.
Julian
@ZugBahnHof
mentioned in commit
a9a999c5
·
3 years ago
mentioned in commit
a9a999c5
mentioned in commit a9a999c5110fa06cf534bd34e6720837d1803550
Toggle commit list
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