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
7fb11b74
Commit
7fb11b74
authored
Sep 10, 2018
by
Pietro Albini
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
aggiungi il supporto ai redirect
parent
ff3db682
Pipeline
#132
passed with stage
in 0 seconds
Changes
4
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
74 additions
and
1 deletion
+74
-1
uitwww/__init__.py
uitwww/__init__.py
+2
-1
uitwww/__main__.py
uitwww/__main__.py
+2
-0
uitwww/data/redirects.yml
uitwww/data/redirects.yml
+23
-0
uitwww/redirects.py
uitwww/redirects.py
+47
-0
No files found.
uitwww/__init__.py
View file @
7fb11b74
...
...
@@ -25,7 +25,7 @@ from . import db
from
.
import
download
from
.
import
navbar
from
.
import
pages
from
.
import
util
s
from
.
import
redirect
s
from
.
import
utils
...
...
@@ -57,6 +57,7 @@ def create_app(data_path):
app
.
download
=
download
.
Downloads
(
data_path
)
app
.
register_blueprint
(
redirects
.
prepare_blueprint
(
app
))
app
.
register_blueprint
(
app
.
download
.
prepare_blueprint
(
app
),
url_prefix
=
"/download"
)
app
.
register_blueprint
(
actions
.
prepare_blueprint
(
app
),
url_prefix
=
"/+actions"
)
app
.
register_blueprint
(
auth
.
prepare_blueprint
(
app
),
url_prefix
=
"/+auth"
)
...
...
uitwww/__main__.py
View file @
7fb11b74
...
...
@@ -53,6 +53,8 @@ def run(data, gunicorn_config, port, public, workers, debug):
extra_files
=
[
os
.
path
.
join
(
src_directory
,
"data/navbar.yml"
),
os
.
path
.
join
(
src_directory
,
"data/permissions.yml"
),
os
.
path
.
join
(
src_directory
,
"data/redirects.yml"
),
os
.
path
.
join
(
src_directory
,
"data/downloads.toml"
),
]
app
.
run
(
debug
=
True
,
port
=
port
,
host
=
host
,
extra_files
=
extra_files
)
...
...
uitwww/data/redirects.yml
0 → 100644
View file @
7fb11b74
# La sezione "internal" contiene i redirect che puntano ad altre pagine sempre
# all'interno del sito di Ubuntu-it. La chiave è l'indirizzo originale, mentre
# il valore deve contenere l'endpoint, ed opzionalmente gli argomenti
# dell'endpoint dentro alla chiave args. Per esempio:
#
# "/old-download/desktop":
# endpoint: download.landing
# args:
# distro: desktop
internal
:
"
/download/derivate"
:
endpoint
:
download.index
"
/comunita/orientamento"
:
endpoint
:
pages.contribuire_index
# La sezione "external" contiene i redirect che puntano a pagine esterne al
# sito di Ubuntu-it. La chiave è l'indirizzo interno, il valore è l'URL a cui
# gli utenti devono essere reindirizzati
external
:
"
/scopri-ubuntu/richiedi-cd"
:
"
https://wiki.ubuntu-it.org/GruppoPromozione/ProgettoCDUbuntu"
uitwww/redirects.py
0 → 100644
View file @
7fb11b74
# Source code of the Ubuntu-it website
# Copyright (C) 2018 Pietro Albini <pietroalbini@ubuntu.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; witout 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
flask
import
pkg_resources
import
yaml
import
hashlib
def
prepare_blueprint
(
app
):
"""Prepare a blueprint containing all the redirects"""
raw
=
pkg_resources
.
resource_string
(
"uitwww"
,
"data/redirects.yml"
)
config
=
yaml
.
load
(
raw
.
decode
(
"utf-8"
))
bp
=
flask
.
Blueprint
(
"redirects"
,
__name__
)
for
origin
,
dest
in
config
[
"external"
].
items
():
endpoint
=
"ext_"
+
hashlib
.
sha1
(
origin
.
encode
(
"utf-8"
)).
hexdigest
()[:
10
]
@
bp
.
route
(
origin
,
endpoint
=
endpoint
)
def
_
(
_dest
=
dest
):
return
flask
.
redirect
(
_dest
)
for
origin
,
dest
in
config
[
"internal"
].
items
():
endpoint
=
"int_"
+
hashlib
.
sha1
(
origin
.
encode
(
"utf-8"
)).
hexdigest
()[:
10
]
@
bp
.
route
(
origin
,
endpoint
=
endpoint
)
def
_
(
_dest
=
dest
):
_dest
.
setdefault
(
"args"
,
{})
return
flask
.
redirect
(
flask
.
url_for
(
_dest
[
"endpoint"
],
**
_dest
[
"args"
])
)
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