Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
AlekSIS-Core
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Terraform modules
Monitor
Service Desk
Analyze
Contributor 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-Core
Commits
cd57d3c9
Commit
cd57d3c9
authored
5 years ago
by
Jonathan Weth
Browse files
Options
Downloads
Patches
Plain Diff
Refactoring at dashboard background functions for articles and events
parent
f1b6ced2
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!86
Merge school-apps
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
requirements.txt
+1
-0
1 addition, 0 deletions
requirements.txt
schoolapps/dashboard/views.py
+1
-1
1 addition, 1 deletion
schoolapps/dashboard/views.py
schoolapps/helper.py
+69
-31
69 additions, 31 deletions
schoolapps/helper.py
with
71 additions
and
32 deletions
requirements.txt
+
1
−
0
View file @
cd57d3c9
requests
mysqlclient
django
django-auth-ldap
...
...
This diff is collapsed.
Click to expand it.
schoolapps/dashboard/views.py
+
1
−
1
View file @
cd57d3c9
...
...
@@ -39,7 +39,7 @@ def api_information(request):
unread_notifications
=
request
.
user
.
notifications
.
all
().
filter
(
user
=
request
.
user
,
read
=
False
).
order_by
(
'
-created_at
'
)
# user_type = UserInformation.user_type(request.user)
newest_articles
=
get_newest_articles
(
"
https://katharineum-zu-luebeck.de
"
,
1
,
[
22
]
)
newest_articles
=
get_newest_articles
(
limit
=
1
)
if
len
(
newest_articles
)
>=
0
:
newest_article
=
newest_articles
[
0
]
else
:
...
...
This diff is collapsed.
Click to expand it.
schoolapps/helper.py
+
69
−
31
View file @
cd57d3c9
...
...
@@ -6,6 +6,7 @@ from datetime import datetime
from
django.utils
import
timezone
,
formats
from
ics
import
Calendar
import
requests
def
path_and_rename
(
instance
,
filename
):
...
...
@@ -26,36 +27,60 @@ def msg_box(msg, status="success", icon="info"):
return
{
"
msg
"
:
msg
,
"
status
"
:
status
,
"
icon
"
:
icon
}
import
requests
WP_DOMAIN
:
str
=
"
https://katharineum-zu-luebeck.de
"
def
get_newest_articles
(
domain
,
limit
=
0
,
author_blacklist
=
None
):
def
get_newest_articles
(
domain
:
str
=
WP_DOMAIN
,
limit
:
int
=
5
,
author_whitelist
:
list
=
None
,
author_blacklist
:
list
=
None
,
category_whitelist
:
list
=
None
,
category_blacklist
:
list
=
None
):
"""
This function returns the newest articles/posts of a
w
ord
p
ress
-
site.
This function returns the newest articles/posts of a
W
ord
P
ress
site.
:param domain: The domain to get the newest posts from (for example https://wordpress.com). Don
'
t put a slash (/) at the end!
:param limit: if 0: all posts will be shown, else nly the certain number
:param author_blacklist: if the authors id (an integer) is in this list, the article won
'
t be displayed
:param author_whitelist: If this list is filled, only articles which are written by one of this authors will be shown
:param author_blacklist: If the author
'
s id (an integer) is in this list, the article won
'
t be shown
:param category_whitelist: If this list is filled, only articles which are in one of this categories will be shown
:param category_blacklist: If the category
'
s id (an integer) is in this list, the article won
'
t be shown
:return: a list of the newest posts/articles
"""
# Make mutable default arguments unmutable
if
category_whitelist
is
None
:
category_whitelist
=
[]
if
category_blacklist
is
None
:
category_blacklist
=
[]
if
author_whitelist
is
None
:
author_whitelist
=
[]
if
author_blacklist
is
None
:
author_blacklist
=
[]
suffix
=
"
/wp-json/wp/v2/posts
"
suffix
:
str
=
"
/wp-json/wp/v2/posts
"
url
:
str
=
domain
+
suffix
url
=
domain
+
suffix
site
:
requests
.
request
=
requests
.
get
(
url
)
data
:
dict
=
site
.
json
()
site
=
requests
.
get
(
url
)
data
=
site
.
json
()
posts
:
list
=
[]
posts
=
[]
print
(
data
)
for
post
in
data
:
if
post
[
"
author
"
]
not
in
author_blacklist
:
# Now get the link to the image
if
post
[
"
_links
"
].
get
(
"
wp:featuredmedia
"
,
False
):
media_site
=
requests
.
get
(
post
[
"
_links
"
][
"
wp:featuredmedia
"
][
0
][
"
href
"
]).
json
()
image_url
=
media_site
[
"
guid
"
][
"
rendered
"
]
if
len
(
author_whitelist
)
>
0
and
post
[
"
author
"
]
not
in
author_whitelist
:
continue
if
post
[
"
categories
"
][
0
]
not
in
category_blacklist
:
if
len
(
category_whitelist
)
>
0
and
post
[
"
categories
"
][
0
]
not
in
category_whitelist
:
continue
# Now get the link to the image
if
post
[
"
_links
"
].
get
(
"
wp:featuredmedia
"
,
False
):
media_site
:
requests
.
request
=
requests
.
get
(
post
[
"
_links
"
][
"
wp:featuredmedia
"
][
0
][
"
href
"
]).
json
()
image_url
:
str
=
media_site
[
"
guid
"
][
"
rendered
"
]
else
:
image_url
:
str
=
""
posts
.
append
(
{
...
...
@@ -71,46 +96,59 @@ def get_newest_articles(domain, limit=0, author_blacklist=None):
return
posts
CALENDAR_URL
=
"
https://nimbus.katharineum.de/remote.php/dav/public-calendars/owit7yysLB2CYNTq?export
"
# Set calendar here
CALENDAR_URL
:
str
=
"
https://nimbus.katharineum.de/remote.php/dav/public-calendars/owit7yysLB2CYNTq?export
"
CALENDAR
:
Calendar
=
Calendar
(
requests
.
get
(
CALENDAR_URL
).
text
)
def
get_current_events
():
c
=
Calendar
(
requests
.
get
(
CALENDAR_URL
).
text
)
print
(
c
.
events
)
e
=
list
(
c
.
timeline
)[
0
]
print
(
c
.
timeline
.
today
())
i
=
0
events
=
[]
for
event
in
c
.
timeline
.
start_after
(
timezone
.
now
()):
if
i
>=
5
:
def
get_current_events
(
calendar
:
Calendar
=
CALENDAR
,
limit
:
int
=
5
)
->
list
:
"""
Get upcoming events from calendar
:param calendar: The calendar object
:param limit: Count of events
:return: List of upcoming events
"""
i
:
int
=
0
events
:
list
=
[]
for
event
in
calendar
.
timeline
.
start_after
(
timezone
.
now
()):
# Check for limit
if
i
>=
limit
:
break
i
+=
1
# Create formatted dates and times for begin and end
begin_date_formatted
=
formats
.
date_format
(
event
.
begin
)
end_date_formatted
=
formats
.
date_format
(
event
.
end
)
begin_time_formatted
=
formats
.
time_format
(
event
.
begin
.
time
())
end_time_formatted
=
formats
.
time_format
(
event
.
end
.
time
())
if
event
.
begin
.
date
()
==
event
.
end
.
date
():
# Event is only on one day
formatted
=
begin_date_formatted
if
not
event
.
all_day
:
# No all day event
formatted
+=
"
"
+
begin_time_formatted
if
event
.
begin
.
time
!=
event
.
end
.
time
():
# Event has an end time
formatted
+=
"
–
"
+
end_time_formatted
else
:
# Event is on multiple days
if
event
.
all_day
:
# Event is all day
formatted
=
"
{} – {}
"
.
format
(
begin_date_formatted
,
end_date_formatted
)
else
:
# Event has begin and end times
formatted
=
"
{} {} – {} {}
"
.
format
(
begin_date_formatted
,
begin_time_formatted
,
end_date_formatted
,
end_time_formatted
)
print
(
formatted
)
print
(
formats
.
date_format
(
event
.
begin
))
events
.
append
({
"
name
"
:
event
.
name
,
#
"begin": event.begin,
#
"end": event.end,
"
begin
_timestamp
"
:
event
.
begin
.
timestamp
,
"
end
_timestamp
"
:
event
.
end
.
timestamp
,
"
formatted
"
:
formatted
})
# print(event)
print
(
events
)
print
(
"
Event
'
{}
'
started {}
"
.
format
(
e
.
name
,
e
.
begin
.
humanize
()))
return
events
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