Ejemplo n.º 1
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
Ejemplo n.º 2
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
Ejemplo n.º 3
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
Ejemplo n.º 4
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
Ejemplo n.º 5
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
Ejemplo n.º 6
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
Ejemplo n.º 7
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
Ejemplo n.º 8
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
Ejemplo n.º 9
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