Esempio n. 1
0
def view_form_history(word=None):
    page = flask.g.database.get_page(get_url(word))
    access_edit = False
    if page is not None:
        # Проверка на права пользователя вносить правки в статью
        if current_user.is_authenticated():
            access_edit = access_f(page['access'], current_user)
    if current_user.is_authenticated():
        if current_user.is_admin():
             access_edit = True

    if current_user.is_authenticated() is False or access_edit is False:
        return render_template('page.html',
                               page=None,
                               message=u"Вы не имеете прав на просмотр истории изменения страницы",
                               navigation=True,
                               word=get_url(word),
                               history = True
                               )

    pages = flask.g.database.get_pages_history(get_url(word))
#    if pages is None:
#        return 'error!'
#    else:
    return render_template('history.html', pages=pages, word=get_url(word), navigation=True, history = True)
Esempio n. 2
0
def view_pages_latedit(num=None):
    data = g.database.get_latedit_page()
    pages = []
    key = False
    if current_user.is_authenticated():
        if current_user.is_admin():
            pages = data
            key = True
    if key is False:
        for d in data:
            access = access_f(d['access'], current_user)
            if access is True:
                pages.append(d)

    return render_template('latedit.html', pages = pages)
Esempio n. 3
0
def get_form_edit(word):
    page = flask.g.database.get_page(get_url(word))

#    word = get_url(word)

    access_edit = True
    if page is not None:
        # Проверка на права пользователя вносить правки в статью
        access_edit = access_f(page['access'], current_user)

    if current_user.is_authenticated() is False or access_edit is False:
        return render_template('page.html',
                               page=page,
                               message=u"Вы не имеете прав на редaкатирование страницы",
                               navigation=True,
                               word=get_url(word)
                               )
    if page is None:
        # вывожу форму создания статьи
        form = CreateDataForm()
        form.title.data = get_word(word)
        form.access.data = u'All'
        return render_template('form_create.html', form=form, word=get_url(word))
    else:
#        return str(access_edit)
#
#        if access_edit is True:
#            return 'good'
#        else:
#            return 'false'
#        return str(list_access)

        # Вывожу форму редактирования статьи
        form = EditDataForm(request.form)
        form.title.data = page['title']
        form.text.data = page['text']
        form.tags.data = ", ".join(page['tags'])
        form.url.data = page['url']
        form.access.data = page['access']
#        form.tags.data  = page['tags']
        return render_template('form_edit.html', form=form, navigation=True, word=get_url(word))
Esempio n. 4
0
def save_history(word):
    page_id = request.form['history']

    page = flask.g.database.get_page(get_url(word))
    if page is None:
        return None
    access_edit = True
        # Проверка на права пользователя вносить правки в статью
    access_edit = access_f(page['access'], current_user)
    if current_user.is_admin():
        access_edit = True

    if current_user.is_authenticated() is False or access_edit is False:
        return render_template('page.html',
                                page=page,
                                message=u"Вы не имеете прав на просмотр истории изменения страницы",
                                navigation=True,
                                word=get_url(word),
                                history = True
                            )

    flask.g.database.set_activity_history(word, page_id)
    return redirect(url_for('.view', word=word))
Esempio n. 5
0
def view_form_edit(word):
    page = flask.g.database.get_page(get_url(word))
    access_edit = True
    if page is not None:
        # Проверка на права пользователя вносить правки в статью
        access_edit = access_f(page['access'], current_user)
        if current_user.is_authenticated():
            if current_user.is_admin():
                access_edit = True

    if current_user.is_authenticated() is False or access_edit is False:
        return render_template('page.html',
                               page=None,
                               message=u"Вы не имеете прав на редaкатирование страницы",
                               navigation=True,
                               edit = True,
                               word=get_url(word)
                               )
    if current_user.is_admin() is False and (word == u"Служебная:Заглавная_страница" or word == u'Служебная:Левое_меню'):
        return render_template('page.html',
                               page=None,
                               message=u"Вы не имеете прав на редaкатирование страницы",
                               navigation=True,
                               edit = True,
                               word=get_url(word)
                            )
    if word == u"Служебная:Заглавная_страница":
        form = ServiceGeneralForm(request.form)
        action = u' создание '
        navigation = False
        if page is not None:
            form.title.data = page['title']
            form.text.data = page['text']
            navigation = True
            action = u" редактирование "
        return render_template('service_general_page.html',
                                form = form,
                                navigation=navigation,
                                edit = True,
                                word=get_url(word),
                                action_page = action
                              )

    if word == u"Служебная:Левое_меню":
        form = ServiceLeftMenuForm(request.form)
        action = u' создание '
        navigation = False
        if page is not None:
            form.text.data = page['text']
            action = u" редактирование "
            navigation = True
        return render_template('service_left_menu_page.html',
                                form = form,
                                navigation=navigation,
                                edit = True,
                                word=get_url(word),
                                action_page = action
                              )
    if word.find(' ') != -1:
        return redirect( url_for('.view_form_edit', word = get_url(word)) )

    if page is None:
        # вывожу форму создания статьи
        form = CreateDataForm()
        form.title.data = get_word(word)
        form.access.data = current_user.login
        form.access_show.data = u'all'
        return render_template('form_create.html', form=form, word=get_url(word))
    else:
        # Вывожу форму редактирования статьи
        form = EditDataForm(request.form)
#        form.title.data = page['title']
        form.text.data = page['text']
        form.tags.data = ", ".join(page['tags'])
#        form.tags.data = page['tags']
        form.url.data = page['url']
        form.access.data = page['access']
        form.access_show.data = page['access_show']
        form.active.data = True
#        form.tags.data  = page['tags']
        return render_template('form_edit.html', form=form, navigation=True, edit = True, word=get_url(word))
Esempio n. 6
0
def save_edit(word=None):
    # Получаю статьью из БД
    page = flask.g.database.get_page(get_url(word))

    access_edit = True
    if page is not None:
        # Проверка на права пользователя вносить правки в статью
        access_edit = access_f(page['access'], current_user)
    if current_user.is_authenticated() is False or access_edit is False:
        return render_template('page.html',
                               page=page,
                               message=u"Вы не имеете прав на редaкатирование страницы",
                               navigation=True,
                               word=word
                               )

    if page is None:
        form = CreateDataForm(request.form)
         # Создаю новую статью
        if form.validate():
            # Получаю данные из формы
            url = get_url(form.title.data)
            title = form.title.data.strip()
            text = form.text.data.strip()
            tags = form.tags.data.strip()
            comment = form.comment.data.strip()
            access = form.access.data.strip()
            # Сохраняю данные в БД
            flask.g.database.insert_page(url=url,
                                         title=title,
                                         text=text,
                                         user=current_user.login,
                                         comment=comment,
                                         tags=tags,
                                         access=access
                                         )
            # Редирект на созданную страницу
            return redirect(url_for('.view', word=get_url(title)))
        else:
            return render_template('form_create.html', form=form, navigation=True)
    else:
        form = EditDataForm(request.form)
        if form.validate():
            # Получение данных из формы
            url = get_url(form.title.data)
            title = form.title.data.strip()
            text = form.text.data.strip()
            tags = form.tags.data.strip()
            comment = form.comment.data.strip()
            access = form.access.data.strip()
            # URL имеющейся страницы
            url_page = form.url.data.strip()
            flask.g.database.update_page(url=url,
                                         url_page=url_page,
                                         title=title,
                                         text=text,
                                         user=current_user.login,
                                         comment=comment,
                                         tags=tags,
                                         access=access
                                         )
            return redirect(url_for('.view', word=url))
        else:
            return render_template('form_edit.html', form=form, navigation=True)
Esempio n. 7
0
def save_edit(word=None):
    # Получаю статьью из БД
    page = flask.g.database.get_page(get_url(word))
    url = get_url(word)
    access_edit = True
    access_show = True
    if word == u"Служебная:Заглавная_страница" or word == u"Служебная:Левое_меню":
        if current_user.is_authenticated() is False:
            return render_template('page.html',
                                    page=page,
                                    message=u"Вы не имеете прав на редaкатирование страницы",
                                    navigation=True,
                                    word=word,
                                    edit = True
                                  )
        elif current_user.is_admin() is False:
            return render_template('page.html',
                                    page=page,
                                    message=u"Вы не имеете прав на редaкатирование страницы",
                                    navigation=True,
                                    word=word,
                                    edit = True
                                )
    if page is not None:
        # Проверка на права пользователя вносить правки в статью
        access_edit = access_f(page['access'], current_user)
    if current_user.is_admin():
        access_edit = True

    if current_user.is_authenticated() is False or access_edit is False:
        return render_template('page.html',
                               page=page,
                               message=u"Вы не имеете прав на редaкатирование страницы",
                               navigation=True,
                               word=word,
                               edit = True
                              )

    if word == u'Служебная:Заглавная_страница':
        if current_user.is_admin() is False:
            return render_template('page.html',
                                    page=page,
                                    message=u"Вы не имеете прав на редaкатирование страницы",
                                    navigation=True,
                                    word=word,
                                    edit = True
                                )
        else:
            form = ServiceGeneralForm(request.form)
            if form.validate():
                text = form.text.data.strip()
                title = form.title.data.strip()
                if page is None:
                    flask.g.database.insert_page(url=word,
                                                title=title,
                                                text=text,
                                                user=current_user.login,
                                                comment='',
                                                tags='',
                                                access='',
                                                access_show = ''
                                                )
                else:
                    flask.g.database.update_page(url=url,
                                            url_page=word,
                                            title=title,
                                            text=text,
                                            user=current_user.login,
                                            comment='',
                                            tags='',
                                            access='',
                                            access_show = '',
                                            active = True,
                                            update_title = True
                                        )
                return redirect(url_for('.view', word=get_url(word)))
            else:
                action = u' создание '
                if page is not None:
#                    form.title.data = page['title']
#                    form.text.data = page['text']
                    action = u" редактирование "
                return render_template('service_general_page.html',
                                        form = form,
                                        navigation=True,
                                        edit = True,
                                        word=get_url(word),
                                        action_page = action
                                    )

    if word == u'Служебная:Левое_меню':
        if current_user.is_admin() is False:
            return render_template('page.html',
                                    page=page,
                                    message=u"Вы не имеете прав на редaкатирование страницы",
                                    navigation=True,
                                    word=word,
                                    edit = True
                                )
        else:
            form = ServiceLeftMenuForm(request.form)
            if form.validate():
                text = form.text.data.strip()
                if page is None:
                    flask.g.database.insert_page(url=word,
                                                title='',
                                                text=text,
                                                user=current_user.login,
                                                comment='',
                                                tags='',
                                                access='',
                                                access_show = ''
                                                )
                else:
                    flask.g.database.update_page(url=url,
                                            url_page=word,
                                            title='',
                                            text=text,
                                            user=current_user.login,
                                            comment='',
                                            tags='',
                                            access='',
                                            access_show = '',
                                            active = True,
                                            update_title = True
                                        )
                return redirect(url_for('.view', word=get_url(word)))

    if page is None:
        form = CreateDataForm(request.form)
#        return "access = " + form.access.data.strip()
         # Создаю новую статью
        if form.validate():
            # Получаю данные из формы
            url = get_url(form.title.data)
            title = form.title.data.strip()
            text = form.text.data.strip()

            tags = form.tags.data.strip()
#            tags.x

            comment = form.comment.data.strip()
            access = form.access.data.strip()

#            return access
            access_show = form.access_show.data.strip()
            # Сохраняю данные в БД
            flask.g.database.insert_page(url=url,
                                         title=title,
                                         text=text,
                                         user=current_user.login,
                                         comment=comment,
                                         tags=tags,
                                         access=access,
                                         access_show = access_show
                                         )
            # Редирект на созданную страницу
            return redirect(url_for('.view', word=get_url(title)))
        else:
            return render_template(
                                    'form_create.html',
                                    form=form,
                                    navigation=True,
                                    edit = True,
                                    word=get_url(word)
                                )
    else:
        form = EditDataForm(request.form)
#        return form.text.data
        if form.validate():
#            return word
            # Получение данных из формы
#            url = get_url(form.title.data)
#            title = form.title.data.strip()
            text = form.text.data.strip()
            tags = form.tags.data.strip()
            comment = form.comment.data.strip()
            access = form.access.data.strip()
            access_show = form.access_show.data.strip()
            active = form.active.data
#            return str(active)
            # URL имеющейся страницы
            url_page = form.url.data.strip()
            flask.g.database.update_page(url=url,
                                         url_page=url_page,
                                         title=None,
                                         text=text,
                                         user=current_user.login,
                                         comment=comment,
                                         tags=tags,
                                         access=access,
                                         access_show = access_show,
                                         active = active
                                         )
            return redirect(url_for('.view', word=url))
        else:
            return render_template('form_edit.html',
                                    form=form,
                                    navigation=True,
                                    edit = True,
                                    word=get_url(word)
                                  )