Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
N
Nuovo sito
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
16
Issues
16
List
Boards
Labels
Milestones
Merge Requests
2
Merge Requests
2
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Gruppo Web
Nuovo sito
Commits
4e500606
Commit
4e500606
authored
Dec 02, 2023
by
shadMod
💬
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
split news.py in views.py and utils.py
parent
14d6bf2e
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
111 additions
and
62 deletions
+111
-62
uitwww/src/news/utils.py
uitwww/src/news/utils.py
+58
-62
uitwww/src/news/views.py
uitwww/src/news/views.py
+53
-0
No files found.
uitwww/src/news/
new
s.py
→
uitwww/src/news/
util
s.py
View file @
4e500606
# Source code of the Ubuntu-it website
# Source code of the Ubuntu-it website
# Copyright (C) 2023 shadMod
# Copyright (C) 2023 shadMod
<m.allegro@shadmod.com>
#
#
# This program is free software: you can redistribute it and/or modify
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published
# it under the terms of the GNU Affero General Public License as published
...
@@ -14,22 +14,17 @@
...
@@ -14,22 +14,17 @@
# You should have received a copy of the GNU Affero General Public License
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import
os
import
os
import
flask
import
locale
import
locale
import
markdown
import
markdown
from
datetime
import
datetime
from
datetime
import
datetime
from
...
import
cache
CACHE_FILE
=
"news-cache.json"
class
News
:
class
Get
News
:
"""
"""
:base_path: path
:param base_path: path
:return: [
:return: [
{
{
"title": "Lorem Ipsum",
"title": "Lorem Ipsum",
...
@@ -51,50 +46,8 @@ class News:
...
@@ -51,50 +46,8 @@ class News:
- Aliquam tincidunt mauris.
- Aliquam tincidunt mauris.
"""
"""
def
__init__
(
self
):
def
__init__
(
self
,
base_path
):
self
.
base_path
=
None
self
.
base_path
=
base_path
def
prepare_blueprint
(
self
,
app
):
"""
Prepare a blueprint with the news pages
"""
bp
=
flask
.
Blueprint
(
"news"
,
__name__
)
# populate base_path
self
.
base_path
=
os
.
path
.
join
(
app
.
instance_path
,
"news"
)
@
bp
.
route
(
"/"
)
@
bp
.
route
(
"/<year>"
)
@
cache
.
enable
def
index
(
year
:
int
=
None
):
news
=
[]
if
year
is
None
:
data
=
{}
for
subdir
in
sorted
(
os
.
listdir
(
self
.
base_path
),
reverse
=
True
):
data
[
subdir
]
=
os
.
listdir
(
os
.
path
.
join
(
self
.
base_path
,
subdir
))
for
year
,
file_list
in
data
.
items
():
for
file
in
file_list
:
news
.
append
(
self
.
get_data
(
file
,
int
(
year
)))
else
:
dir_path
=
os
.
path
.
join
(
self
.
base_path
,
str
(
year
))
if
os
.
path
.
exists
(
dir_path
):
file_list
=
os
.
listdir
(
dir_path
)
for
file
in
file_list
:
news
.
append
(
self
.
get_data
(
file
,
year
))
return
flask
.
render_template
(
"news/index.html"
,
news
=
news
,
)
@
bp
.
route
(
"/<year>/<filename>"
)
def
detail
(
year
:
int
,
filename
:
str
):
return
flask
.
render_template
(
"news/detail.html"
,
news
=
self
.
get_data
(
f"
{
filename
}
.md"
,
year
)
)
return
bp
def
get_data
(
self
,
filename
:
str
,
year
:
int
=
None
):
def
get_data
(
self
,
filename
:
str
,
year
:
int
=
None
):
"""
"""
...
@@ -143,3 +96,46 @@ class News:
...
@@ -143,3 +96,46 @@ class News:
# what's left I put in html
# what's left I put in html
data
[
"html"
]
=
""
.
join
(
html_tmp
)
data
[
"html"
]
=
""
.
join
(
html_tmp
)
return
data
return
data
@
property
def
list_files
(
self
)
->
list
:
data
=
[]
for
list_files
in
self
.
get_all_files
.
values
():
data
.
extend
(
list_files
)
return
data
@
property
def
get_all_files
(
self
)
->
dict
:
data
=
{}
for
subdir
in
sorted
(
os
.
listdir
(
self
.
base_path
),
reverse
=
True
):
data
[
subdir
]
=
os
.
listdir
(
os
.
path
.
join
(
self
.
base_path
,
subdir
))
return
data
def
get_all_files_counter
(
self
,
counter
:
int
)
->
dict
:
i
=
0
data
=
{}
for
year
,
list_news
in
self
.
get_all_files
.
items
():
if
year
not
in
data
:
data
[
year
]
=
[]
for
filename
in
list_news
:
data
[
year
].
append
(
filename
)
i
+=
1
if
i
==
counter
:
break
if
i
==
counter
:
break
return
data
def
list_news
(
self
,
year
=
None
):
news
=
[]
if
year
is
None
:
for
year
,
file_list
in
self
.
get_all_files
.
items
():
for
file
in
file_list
:
news
.
append
(
self
.
get_data
(
file
,
int
(
year
)))
else
:
dir_path
=
os
.
path
.
join
(
self
.
base_path
,
str
(
year
))
if
os
.
path
.
exists
(
dir_path
):
file_list
=
os
.
listdir
(
dir_path
)
for
file
in
file_list
:
news
.
append
(
self
.
get_data
(
file
,
year
))
return
news
uitwww/src/news/views.py
0 → 100644
View file @
4e500606
# Source code of the Ubuntu-it website
# Copyright (C) 2023 shadMod <m.allegro@shadmod.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import
os
import
flask
from
...
import
cache
from
.utils
import
GetNews
CACHE_FILE
=
"news-cache.json"
class
News
:
@
staticmethod
def
prepare_blueprint
(
app
):
"""
Prepare a blueprint with the news pages
"""
bp
=
flask
.
Blueprint
(
"news"
,
__name__
)
nw_cl
=
GetNews
(
os
.
path
.
join
(
app
.
instance_path
,
"news"
))
@
bp
.
route
(
"/"
)
@
bp
.
route
(
"/<year>"
)
@
cache
.
enable
def
index
(
year
:
int
=
None
):
return
flask
.
render_template
(
"news/index.html"
,
news
=
nw_cl
.
list_news
(
year
),
)
@
bp
.
route
(
"/<year>/<filename>"
)
def
detail
(
year
:
int
,
filename
:
str
):
return
flask
.
render_template
(
"news/detail.html"
,
news
=
nw_cl
.
get_data
(
f"
{
filename
}
.md"
,
year
)
)
return
bp
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment