annotate libervia/pages/events/new/page_meta.py @ 1124:28e3eb3bb217

files reorganisation and installation rework: - files have been reorganised to follow other SàT projects and usual Python organisation (no more "/src" directory) - VERSION file is now used, as for other SàT projects - replace the overcomplicated setup.py be a more sane one. Pyjamas part is not compiled anymore by setup.py, it must be done separatly - removed check for data_dir if it's empty - installation tested working in virtual env - libervia launching script is now in bin/libervia
author Goffi <goffi@goffi.org>
date Sat, 25 Aug 2018 17:59:48 +0200
parents src/pages/events/new/page_meta.py@cdd389ef97bc
children 29eb15062416
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1111
4d1c4bd4931a pages (events): added root, admin, new, rsvp and view pages
Goffi <goffi@goffi.org>
parents:
diff changeset
1 #!/usr/bin/env python2.7
4d1c4bd4931a pages (events): added root, admin, new, rsvp and view pages
Goffi <goffi@goffi.org>
parents:
diff changeset
2 # -*- coding: utf-8 -*-
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
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1111
diff changeset
11 name = u"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
4d1c4bd4931a pages (events): added root, admin, new, rsvp and view pages
Goffi <goffi@goffi.org>
parents:
diff changeset
13 template = u"event/create.html"
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1111
diff changeset
14 log = getLogger(u"pages/" + name)
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
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1111
diff changeset
34 data[u"register"] = C.BOOL_TRUE
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)
1111
4d1c4bd4931a pages (events): added root, admin, new, rsvp and view pages
Goffi <goffi@goffi.org>
parents:
diff changeset
36 log.info(u"Event node created at {node}".format(node=node))
4d1c4bd4931a pages (events): added root, admin, new, rsvp and view pages
Goffi <goffi@goffi.org>
parents:
diff changeset
37
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1111
diff changeset
38 request_data["post_redirect_page"] = (self.getPageByName(u"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)