annotate libervia/pages/events/new/page_meta.py @ 1361:626b7bbb7f90

server: mechanism to exit Libervia with an exit code: the new `SysExit` exception can now be used to quit Libervia with a given shell exit code.
author Goffi <goffi@goffi.org>
date Sat, 14 Nov 2020 22:24:58 +0100
parents f511f8fbbf8a
children 106bae41f5c8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1216
b2d067339de3 python 3 port:
Goffi <goffi@goffi.org>
parents: 1145
diff changeset
1 #!/usr/bin/env python3
1239
f511f8fbbf8a fixed shebangs
Goffi <goffi@goffi.org>
parents: 1216
diff changeset
2
1111
4d1c4bd4931a pages (events): added root, admin, new, rsvp and view pages
Goffi <goffi@goffi.org>
parents:
diff changeset
3
4d1c4bd4931a pages (events): added root, admin, new, rsvp and view pages
Goffi <goffi@goffi.org>
parents:
diff changeset
4 from libervia.server.constants import Const as C
4d1c4bd4931a pages (events): added root, admin, new, rsvp and view pages
Goffi <goffi@goffi.org>
parents:
diff changeset
5 from twisted.internet import defer
4d1c4bd4931a pages (events): added root, admin, new, rsvp and view pages
Goffi <goffi@goffi.org>
parents:
diff changeset
6 from sat.core.log import getLogger
4d1c4bd4931a pages (events): added root, admin, new, rsvp and view pages
Goffi <goffi@goffi.org>
parents:
diff changeset
7 from sat.tools.common import date_utils
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1111
diff changeset
8
1111
4d1c4bd4931a pages (events): added root, admin, new, rsvp and view pages
Goffi <goffi@goffi.org>
parents:
diff changeset
9 """creation of new events"""
4d1c4bd4931a pages (events): added root, admin, new, rsvp and view pages
Goffi <goffi@goffi.org>
parents:
diff changeset
10
1216
b2d067339de3 python 3 port:
Goffi <goffi@goffi.org>
parents: 1145
diff changeset
11 name = "event_new"
1111
4d1c4bd4931a pages (events): added root, admin, new, rsvp and view pages
Goffi <goffi@goffi.org>
parents:
diff changeset
12 access = C.PAGES_ACCESS_PROFILE
1216
b2d067339de3 python 3 port:
Goffi <goffi@goffi.org>
parents: 1145
diff changeset
13 template = "event/create.html"
1145
29eb15062416 pages: set __name__ for imported pages
Goffi <goffi@goffi.org>
parents: 1124
diff changeset
14 log = getLogger(__name__)
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1111
diff changeset
15
1111
4d1c4bd4931a pages (events): added root, admin, new, rsvp and view pages
Goffi <goffi@goffi.org>
parents:
diff changeset
16
4d1c4bd4931a pages (events): added root, admin, new, rsvp and view pages
Goffi <goffi@goffi.org>
parents:
diff changeset
17 @defer.inlineCallbacks
4d1c4bd4931a pages (events): added root, admin, new, rsvp and view pages
Goffi <goffi@goffi.org>
parents:
diff changeset
18 def on_data_post(self, request):
4d1c4bd4931a pages (events): added root, admin, new, rsvp and view pages
Goffi <goffi@goffi.org>
parents:
diff changeset
19 request_data = self.getRData(request)
4d1c4bd4931a pages (events): added root, admin, new, rsvp and view pages
Goffi <goffi@goffi.org>
parents:
diff changeset
20 profile = self.getProfile(request)
4d1c4bd4931a pages (events): added root, admin, new, rsvp and view pages
Goffi <goffi@goffi.org>
parents:
diff changeset
21 title, location, body, date, main_img, bg_img = self.getPostedData(
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1111
diff changeset
22 request, ("name", "location", "body", "date", "main_image", "bg_image")
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1111
diff changeset
23 )
1111
4d1c4bd4931a pages (events): added root, admin, new, rsvp and view pages
Goffi <goffi@goffi.org>
parents:
diff changeset
24 timestamp = date_utils.date_parse(date)
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1111
diff changeset
25 data = {"name": title, "description": body, "location": location}
1111
4d1c4bd4931a pages (events): added root, admin, new, rsvp and view pages
Goffi <goffi@goffi.org>
parents:
diff changeset
26
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1111
diff changeset
27 for value, var in ((main_img, "image"), (bg_img, "background-image")):
1111
4d1c4bd4931a pages (events): added root, admin, new, rsvp and view pages
Goffi <goffi@goffi.org>
parents:
diff changeset
28 value = value.strip()
4d1c4bd4931a pages (events): added root, admin, new, rsvp and view pages
Goffi <goffi@goffi.org>
parents:
diff changeset
29 if not value:
4d1c4bd4931a pages (events): added root, admin, new, rsvp and view pages
Goffi <goffi@goffi.org>
parents:
diff changeset
30 continue
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1111
diff changeset
31 if not value.startswith("http"):
1111
4d1c4bd4931a pages (events): added root, admin, new, rsvp and view pages
Goffi <goffi@goffi.org>
parents:
diff changeset
32 self.pageError(request, C.HTTP_BAD_REQUEST)
4d1c4bd4931a pages (events): added root, admin, new, rsvp and view pages
Goffi <goffi@goffi.org>
parents:
diff changeset
33 data[var] = value
1216
b2d067339de3 python 3 port:
Goffi <goffi@goffi.org>
parents: 1145
diff changeset
34 data["register"] = C.BOOL_TRUE
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1111
diff changeset
35 node = yield self.host.bridgeCall("eventCreate", timestamp, data, "", "", "", profile)
1216
b2d067339de3 python 3 port:
Goffi <goffi@goffi.org>
parents: 1145
diff changeset
36 log.info("Event node created at {node}".format(node=node))
1111
4d1c4bd4931a pages (events): added root, admin, new, rsvp and view pages
Goffi <goffi@goffi.org>
parents:
diff changeset
37
1216
b2d067339de3 python 3 port:
Goffi <goffi@goffi.org>
parents: 1145
diff changeset
38 request_data["post_redirect_page"] = (self.getPageByName("event_admin"), "@", node)
1111
4d1c4bd4931a pages (events): added root, admin, new, rsvp and view pages
Goffi <goffi@goffi.org>
parents:
diff changeset
39 defer.returnValue(C.POST_NO_CONFIRM)