]>
git.ipfire.org Git - pbs.git/blob - src/web/handlers_mirrors.py
7 from .handlers_base
import BaseHandler
9 class MirrorListHandler(BaseHandler
):
11 mirrors
= self
.pakfire
.mirrors
12 mirrors_nearby
= self
.pakfire
.mirrors
.get_for_location(self
.current_address
)
14 mirrors_worldwide
= []
15 for mirror
in mirrors
:
16 if mirror
in mirrors_nearby
:
19 mirrors_worldwide
.append(mirror
)
23 "mirrors_nearby" : mirrors_nearby
,
24 "mirrors_worldwide" : mirrors_worldwide
,
27 # Get recent log messages.
28 kwargs
["log"] = self
.pakfire
.mirrors
.get_history(limit
=5)
30 self
.render("mirrors/list.html", **kwargs
)
33 class MirrorDetailHandler(BaseHandler
):
34 def get(self
, hostname
):
35 mirror
= self
.pakfire
.mirrors
.get_by_hostname(hostname
)
37 raise tornado
.web
.HTTPError(404, "Could not find mirror: %s" % hostname
)
39 log
= self
.pakfire
.mirrors
.get_history(mirror
=mirror
, limit
=10)
41 self
.render("mirrors/detail.html", mirror
=mirror
, log
=log
)
44 class MirrorActionHandler(BaseHandler
):
46 A handler that makes sure if the user has got sufficent rights to
50 # Check if the user has sufficient rights to create a new mirror.
51 if not self
.current_user
.has_perm("manage_mirrors"):
52 raise tornado
.web
.HTTPError(403)
55 class MirrorNewHandler(MirrorActionHandler
):
56 @tornado.web
.authenticated
57 def get(self
, hostname
="", path
="", hostname_missing
=False, path_invalid
=False):
58 self
.render("mirrors/new.html", _hostname
=hostname
, path
=path
,
59 hostname_missing
=hostname_missing
, path_invalid
=path_invalid
)
61 @tornado.web
.authenticated
65 hostname
= self
.get_argument("name", None)
67 errors
["hostname_missing"] = True
69 path
= self
.get_argument("path", "")
71 errors
["path_invalid"] = True
75 "hostname" : hostname
,
78 return self
.get(**errors
)
80 mirror
= mirrors
.Mirror
.create(self
.pakfire
, hostname
, path
,
81 user
=self
.current_user
)
84 self
.redirect("/mirror/%s" % mirror
.hostname
)
87 class MirrorEditHandler(MirrorActionHandler
):
88 @tornado.web
.authenticated
89 def get(self
, hostname
):
90 mirror
= self
.pakfire
.mirrors
.get_by_hostname(hostname
)
92 raise tornado
.web
.HTTPError(404, "Could not find mirror: %s" % hostname
)
94 self
.render("mirrors/edit.html", mirror
=mirror
)
96 @tornado.web
.authenticated
97 def post(self
, hostname
):
98 mirror
= self
.pakfire
.mirrors
.get_by_hostname(hostname
)
100 raise tornado
.web
.HTTPError(404, "Could not find mirror: %s" % hostname
)
102 with self
.db
.transaction():
103 mirror
.hostname
= self
.get_argument("name")
104 mirror
.path
= self
.get_argument("path", "")
105 mirror
.owner
= self
.get_argument("owner", None)
106 mirror
.contact
= self
.get_argument("contact", None)
107 mirror
.supports_https
= self
.get_argument("supports_https", False)
109 self
.redirect("/mirror/%s" % mirror
.hostname
)
112 class MirrorDeleteHandler(MirrorActionHandler
):
113 @tornado.web
.authenticated
114 def get(self
, hostname
):
115 mirror
= self
.pakfire
.mirrors
.get_by_hostname(hostname
)
117 raise tornado
.web
.HTTPError(404, "Could not find mirror: %s" % hostname
)
119 confirmed
= self
.get_argument("confirmed", None)
121 mirror
.set_status("deleted", user
=self
.current_user
)
123 self
.redirect("/mirrors")
126 self
.render("mirrors/delete.html", mirror
=mirror
)