示例#1
0
    def list(self, user=None):
        self.is_page_back = True
        query = meta.Session.query(model.Event)
        if user is None:
            query = query.select_from(
                join(model.Event, model.User,
                     model.Event.node_user_id == model.User.id)).filter(
                         and_(model.Event.published != None,
                              model.User.nickname != 'demo'))
        else:
            user_query = meta.Session.query(model.User)
            try:
                user_node = user_query.filter(
                    model.User.nickname == user).one()
            except NoResultFound:
                abort(404)

            query = query.filter(model.Event.node_user_id == user_node.id)

            if user_node.nickname != current_user().nickname:
                query = query.filter(model.Event.published != None)

        query = query.order_by(model.Event.start.desc())

        c.user = user
        c.nodes = pager_or_404(query)
        if is_ajax():
            result = self.taconite(render('/event/list_partial.html'))
        else:
            result = render('/event/list.html')
        return result
示例#2
0
    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
示例#3
0
    def remove(self, id):
        node = self._get_row(model.Event, id)
        if 1 == node.id:
            abort(403)
        self._check_access(node)

        fs = form.DeleteAcceptForm('event-remove')

        if request.POST:
            if fs.fields.save.id in request.POST:
                meta.Session.delete(node)
                meta.Session.commit()
                flash(u'Событие успешно удалено')
                c.is_full_redirect = True
                return self._redirect_to(controller='event',
                                         action='list',
                                         user=current_user().nickname)
            return redirect_to(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
示例#4
0
    def new(self):
        fs = EventForm('event-new')

        if request.POST and fs.fields.cancel.id in request.POST:
            return redirect_to(current_user().url())

        if request.POST and fs.is_valid(request.POST):
            node = model.Event()
            node.title = fs.fields.title.value
            node.summary = fs.fields.summary.value
            node.start = fs.fields.start.value
            node.finish = fs.fields.finish.value
            node.node_user_id = current_user().id

            meta.Session.add(node)
            meta.Session.commit()
            flash(u'Событие успешно добавлено')
            return redirect_to(node.url())

        c.form = fs
        c.fs = fs.fields

        if is_ajax():
            result = render('/event/new_partial.html')
        else:
            result = render('/event/new.html')
        if request.POST:
            result = fs.htmlfill(result)
        return result
示例#5
0
    def show(self, id):
        self.is_page_back = True

        c.node = self._get_row(model.Event, id)

        if is_ajax():
            result = self.taconite(render('/event/show_partial.html'))
        else:
            result = render('/event/show.html')
        return result
示例#6
0
    def show(self, id):
        self.is_page_back = True

        node = self._get_row(model.Report, id)
        event_node = node.event

        c.node = node
        if is_ajax():
            result = self.taconite(render('/report/show_partial.html'))
        else:
            result = render('/report/show.html')
        return result
示例#7
0
文件: report.py 项目: naskoro/horosh
    def show(self, id):
        self.is_page_back = True

        node = self._get_row(model.Report, id)
        event_node = node.event

        c.node = node
        if is_ajax():
            result = self.taconite(render('/report/show_partial.html'))
        else:
            result = render('/report/show.html')
        return result
示例#8
0
    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)
示例#9
0
    def new(self, label=None):

        fs = ArticleForm('article-new')

        if request.POST and fs.fields.cancel.id in request.POST:
            if label is not None:
                return redirect_to(label)
            return redirect_to('articles')

        if request.POST and fs.is_valid(request.POST):
            node = model.Article()
            node.title = fs.fields.title.value
            node.content = fs.fields.content.value
            node.label = label
            node.node_user_id = current_user().id

            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.add(node)
                meta.Session.commit()

                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')
                else:
                    return redirect_to(node.url_edit())

        c.form = fs
        c.fs = fs.fields

        if is_ajax():
            result = render('/article/new_partial.html')
        else:
            result = render('/article/new.html')
        if request.POST:
            result = fs.htmlfill(result)
        return result
示例#10
0
文件: article.py 项目: naskoro/horosh
    def new(self, label=None):

        fs = ArticleForm("article-new")

        if request.POST and fs.fields.cancel.id in request.POST:
            if label is not None:
                return redirect_to(label)
            return redirect_to("articles")

        if request.POST and fs.is_valid(request.POST):
            node = model.Article()
            node.title = fs.fields.title.value
            node.content = fs.fields.content.value
            node.label = label
            node.node_user_id = current_user().id

            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.add(node)
                meta.Session.commit()

                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")
                else:
                    return redirect_to(node.url_edit())

        c.form = fs
        c.fs = fs.fields

        if is_ajax():
            result = render("/article/new_partial.html")
        else:
            result = render("/article/new.html")
        if request.POST:
            result = fs.htmlfill(result)
        return result
示例#11
0
文件: article.py 项目: naskoro/horosh
    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)
示例#12
0
文件: article.py 项目: naskoro/horosh
    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
示例#13
0
    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
示例#14
0
    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)
示例#15
0
    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
示例#16
0
文件: report.py 项目: naskoro/horosh
    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)
示例#17
0
    def edit(self, id):
        node = self._get_row(model.Event, id)
        self._check_access(node)

        fs = EventForm('event-edit')

        if request.POST and fs.fields.cancel.id in request.POST:
            return redirect_to(node.url())

        if request.POST and fs.is_valid(request.POST):
            node.title = fs.fields.title.value
            node.summary = fs.fields.summary.value
            node.start = fs.fields.start.value
            node.finish = fs.fields.finish.value

            meta.Session.commit()
            flash(u'Информация о событии успешно сохранена')
            if self.back_page():
                return redirect_to(**self.back_page())
            return redirect_to(node.url())

        if not request.POST:
            fs.set_values({
                'title': node.title,
                'start': node.start.strftime(DATE_FORMAT),
                'finish': node.finish.strftime(DATE_FORMAT),
                'summary': node.summary
            })

        c.node = node
        c.form = fs
        c.fs = fs.fields

        if is_ajax():
            result = render('/event/edit_partial.html')
        else:
            result = render('/event/edit.html')
        return fs.htmlfill(result)
示例#18
0
文件: report.py 项目: naskoro/horosh
    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
示例#19
0
    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
示例#20
0
    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
示例#21
0
    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)