def new(self, event_id): event_node = self._get_row(model.Event, event_id) self._check_access(event_node) fs = AlbumForm('album-new') if request.POST and fs.fields.cancel.id in request.POST: return redirect_to(event_node.url()) if request.POST and fs.is_valid(request.POST): node = model.Album() node.settings = picasa.photos( fs.fields.user.value, fs.fields.albumid.value, limit=30 ) node.node_user_id = current_user().id meta.Session.add(node) event_node.albums.append(node) meta.Session.commit() flash(u'Альбом успешно добавлен') if self.back_page(): return redirect_to(**self.back_page()) return redirect_to(event_node.url()) c.form = fs c.fs = fs.fields if is_ajax(): result = render('/album/new_partial.html') else: result = render('/album/new.html') if request.POST: result = fs.htmlfill(result) return result
def reload(self, id): node = self._get_row(model.Album, id) event_node = node.event self._check_access(event_node) album = gdata.GDataFeedFromString(node.settings) node.settings = urlopen(album.GetSelfLink().href).read() meta.Session.commit() flash(u'Альбом успешно обновлен') if self.back_page(): return redirect_to(**self.back_page()) return redirect_to(event_node.url())
def publish(self, id, published): node = self._get_row(model.Article, id) if published == "1": node.published = datetime.now() message = u"Статья успешно опубликована" else: node.published = None message = u"Статья успешно сохранена как черновик" meta.Session.commit() flash(message) if self.back_page(): return redirect_to(**self.back_page()) return redirect_to(node.url())
def edit(self, id): node = self._get_row(model.Article, id) fs = ArticleForm("article-edit", node.path) if request.POST and fs.fields.cancel.id in request.POST: if self.back_page(): return redirect_to(**self.back_page()) return redirect_to(node.url()) if request.POST and fs.is_valid(request.POST): node.title = fs.fields.title.value node.content = fs.fields.content.value is_valid = True if not fs.fields.path.value: fs.fields.path.value = translit.slugify(node.title) is_valid = fs.is_valid(fs.get_values(use_ids=True)) if is_valid: node.path = fs.fields.path.value meta.Session.commit() flash(u"Статья успешно сохранена") if fs.fields.save_view.id in request.POST: return redirect_to(node.url()) elif fs.fields.save_view_list.id in request.POST: if node.label is not None: return redirect_to(node.label) return redirect_to("articles") if not request.POST: fs.set_values({"title": node.title, "path": node.path, "content": node.content}) c.form = fs c.fs = fs.fields c.node = node if is_ajax(): result = render("/article/edit_partial.html") else: result = render("/article/edit.html") return fs.htmlfill(result)
def remove(self, id): node = self._get_row(model.Article, id) fs = form.DeleteAcceptForm("article-remove") if request.POST: if fs.fields.save.id in request.POST: meta.Session.delete(node) meta.Session.commit() flash(u"Статья успешно удалена") if self.back_page() is not None: return redirect_to(**self.back_page()) return redirect_to("articles") else: c.form = fs if is_ajax(): result = render("/util/delete_accept_partial.html") else: result = render("/util/delete_accept.html") return result
def edit(self, id): node = self._get_row(model.Person, id) event_node = node.event self._check_access(event_node) fs = PersonForm('person-edit') if request.POST and fs.fields.cancel.id in request.POST: return self._redirect_to_default(event_node.id) if request.POST and fs.is_valid(request.POST): node.fullname = fs.fields.fullname.value if fs.fields.avatar.value is not None: node.avatar = avatar_prepare(fs.fields.avatar.value.file) meta.Session.add(node) event_node.persons.append(node) meta.Session.commit() flash(u'Учасник успешно сохранен') if self.back_page(): return redirect_to(**self.back_page()) return redirect_to(event_node.url()) if not request.POST: fs.set_values({ 'fullname': node.fullname, 'avatar': node.avatar }) c.node = node c.form = fs c.fs = fs.fields if is_ajax(): result = render('/person/edit_partial.html') else: result = render('/person/edit.html') return fs.htmlfill(result)
def remove(self, id): node = self._get_row(model.Album, id) event_node = node.event self._check_access(event_node) fs = form.DeleteAcceptForm('album-remove') if request.POST: if fs.fields.save.id in request.POST: meta.Session.delete(node) meta.Session.commit() flash(u'Альбом успешно удален') if self.back_page(): return redirect_to(**self.back_page()) return redirect_to(event_node.url()) else: c.form = fs if is_ajax(): result = render('/util/delete_accept_partial.html') else: result = render('/util/delete_accept.html') return result
def edit(self, id): node = self._get_row(model.Report, id) event_node = node.event self._check_access(event_node) fs = ReportForm('report-edit') if request.POST and fs.fields.cancel.id in request.POST: if self.back_page(): return redirect_to(**self.back_page()) return redirect_to(node.url()) if request.POST and fs.is_valid(request.POST): node.title = fs.fields.title.value node.content = fs.fields.content.value meta.Session.commit() flash(u'Отчет успешно сохранен') if fs.fields.save_view.id in request.POST: return redirect_to(node.url()) elif fs.fields.save_view_event.id in request.POST: return redirect_to(event_node.url()) if not request.POST: fs.set_values({ 'title': node.title, 'content': node.content }) c.form = fs c.fs = fs.fields c.node = node if is_ajax(): result = render('/report/edit_partial.html') else: result = render('/report/edit.html') return fs.htmlfill(result)
def new(self, event_id): event_node = self._get_row(model.Event, event_id) self._check_access(event_node) fs = ReportForm('report-new') if request.POST and fs.fields.cancel.id in request.POST: return redirect_to(event_node.url()) if request.POST and fs.is_valid(request.POST): node = model.Report() node.title = fs.fields.title.value node.content = fs.fields.content.value node.event = event_node node.node_user_id = current_user().id meta.Session.add(node) meta.Session.commit() flash(u'Отчет успешно добавлен') if fs.fields.save_view.id in request.POST: return redirect_to(node.url()) elif fs.fields.save_view_event.id in request.POST: return redirect_to(event_node.url()) else: return redirect_to(node.url_edit()) c.form = fs c.fs = fs.fields if is_ajax(): result = render('/report/new_partial.html') else: result = render('/report/new.html') if request.POST: result = fs.htmlfill(result) return result
def new(self, event_id): event_node = self._get_row(model.Event, event_id) self._check_access(event_node) fs = PersonForm('person-new') if request.POST and fs.fields.cancel.id in request.POST: return self._redirect_to_default(event_node.id) if request.POST and fs.is_valid(request.POST): node = model.Person() node.fullname = fs.fields.fullname.value node.event = event_node if fs.fields.avatar.value is not None: node.avatar = avatar_prepare(fs.fields.avatar.value.file) node.node_user_id = current_user().id meta.Session.add(node) meta.Session.commit() flash(u'Участник успешно добавлен') if self.back_page(): return redirect_to(**self.back_page()) return redirect_to(event_node.url()) c.form = fs c.fs = fs.fields if is_ajax(): result = render('/person/new_partial.html') else: result = render('/person/new.html') if request.POST: result = fs.htmlfill(result) return result
def edit(self, id): node = self._get_row(model.Report, id) event_node = node.event self._check_access(event_node) fs = ReportForm('report-edit') if request.POST and fs.fields.cancel.id in request.POST: if self.back_page(): return redirect_to(**self.back_page()) return redirect_to(node.url()) if request.POST and fs.is_valid(request.POST): node.title = fs.fields.title.value node.content = fs.fields.content.value meta.Session.commit() flash(u'Отчет успешно сохранен') if fs.fields.save_view.id in request.POST: return redirect_to(node.url()) elif fs.fields.save_view_event.id in request.POST: return redirect_to(event_node.url()) if not request.POST: fs.set_values({'title': node.title, 'content': node.content}) c.form = fs c.fs = fs.fields c.node = node if is_ajax(): result = render('/report/edit_partial.html') else: result = render('/report/edit.html') return fs.htmlfill(result)
def demo_up(self): event = meta.Session.query(model.Event).filter( model.Event.id == 1 ).one() user = meta.Session.query(model.User).filter( model.User.nickname == 'demo' ).one() for node in event.persons: meta.Session.delete(node) for node in event.reports: meta.Session.delete(node) for node in event.albums: meta.Session.delete(node) meta.Session.commit() dir = config['demo_dir'] info_file = os.path.join(dir, 'info.yml') info = codecs.open(info_file, 'r', 'utf-8') info = yaml.load(info) event.title = info['title'] if 'summary' in info: event.summary = info['summary'] if 'start' in info: event.start = info['start'] if 'finish' in info: event.finish = info['finish'] event.node_user = user event.created = datetime.now() if 'albums' in info: for album in info['albums']: node = model.Album() node.settings = picasa.photos(album['user'], album['albumid'], 15) node.node_user = user node.event = event meta.Session.add(node) persons_dir = os.path.join(dir, u'persons') for file in os.listdir(persons_dir): path = os.path.join(persons_dir, file) if os.path.isfile(path): node = model.Person() node.fullname = file.split('.')[0] node.avatar = avatar_prepare(open(path, 'r')) node.node_user = user node.event = event meta.Session.add(node) reports_dir = os.path.join(dir, u'reports') for file in os.listdir(reports_dir): path = os.path.join(reports_dir, file) if os.path.isfile(path): text = codecs.open(path, 'r', 'utf-8').read() node = model.Report() node.title = file.split('.')[0] node.content = text node.node_user = user node.event = event meta.Session.add(node) meta.Session.commit() flash(u'Демонстрация обновлена') return redirect_to('demo')