예제 #1
0
파일: cms.py 프로젝트: whythawk/hrd
def update_translations(page):
    trans = Cms.query.filter_by(page_id=page.page_id)
    trans = trans.filter(db.not_(Cms.id == page.id))
    trans = trans.filter(db.or_(Cms.status == 'publish', Cms.current == True))

    for tran in trans:
        tran.active = page.active
        tran.private = page.private
        tran.url = page.url
        tran.image = page.image
        db.session.add(tran)
    db.session.commit()
예제 #2
0
파일: cms.py 프로젝트: rrymrrsn/hrd
def update_translations(page):
    trans = Cms.query.filter_by(page_id=page.page_id)
    trans = trans.filter(db.not_(Cms.id == page.id))
    trans = trans.filter(db.or_(
        Cms.status == 'publish', Cms.current == True
    ))

    for tran in trans:
        tran.active = page.active
        tran.private = page.private
        tran.url = page.url
        tran.image = page.image
        db.session.add(tran)
    db.session.commit()
예제 #3
0
def update_translations(org):
    trans = Organisation.query.filter_by(org_id=org.org_id)
    trans = trans.filter(db.not_(Organisation.id == org.id))
    trans = trans.filter(
        db.or_(Organisation.status == 'publish', Organisation.current == True))

    for tran in trans:
        tran.address = org.address
        tran.contact = org.contact
        tran.phone = org.phone
        tran.email = org.email
        tran.pgp_key = org.pgp_key
        tran.website = org.website
        tran.active = org.active
        tran.private = org.private
        tran.image = org.image
        db.session.add(tran)
    db.session.commit()
예제 #4
0
def update_translations(org):
    trans = Organisation.query.filter_by(org_id=org.org_id)
    trans = trans.filter(db.not_(Organisation.id == org.id))
    trans = trans.filter(
        db.or_(
            Organisation.status == 'publish', Organisation.current == True
        )
    )

    for tran in trans:
        tran.address = org.address
        tran.contact = org.contact
        tran.phone = org.phone
        tran.email = org.email
        tran.pgp_key = org.pgp_key
        tran.website = org.website
        tran.active = org.active
        tran.private = org.private
        tran.image = org.image
        db.session.add(tran)
    db.session.commit()
예제 #5
0
파일: cms.py 프로젝트: whythawk/hrd
def cms_edit(id):
    set_menu()
    lang = get_admin_lang()
    permission_content(lang)
    errors = []
    page = Cms.query.filter_by(page_id=id, lang=lang, current=True)
    page = page.first()
    if not page and lang != 'en':
        page = Cms.query.filter_by(page_id=id, lang='en', current=True)
        page = page.first()
        if not page:
            abort(404)
    if not page:
        abort(404)
    if request.method == 'POST' and 'title' in request.form:
        if page.lang != lang:
            # no translation
            page = page_reedit(page)

        if (page.title != get_str('title')
                or page.content != get_str('content')):
            if page.status == 'publish':
                page = page_reedit(page)

            page.title = get_str('title')
            page.content = get_str('content')
            page.status = 'edit'
            trans_need_update(page)
        if lang == 'en':
            page.active = get_bool('active')
            page.private = get_bool('private')

            url = get_str('url')
            if url:
                check = Cms.query.filter(Cms.page_id != id, Cms.url == url)
                check = check.filter(
                    db.or_(Cms.status == 'publish', Cms.current == True))
                if check.count():
                    errors.append(
                        'The url is already used by another page choose ' + \
                        'a new url or change the url of the existing page ' + \
                        'first. The url has been reset in this form.'
                    )
                elif url in config.DISALLOWED_URLS:
                    errors.append(
                        'The url provided is not allowed please choose ' + \
                        'a new one. The url has been reset in this form.'
                    )
                else:
                    page.url = url

            if get_bool('logo_remove'):
                page.image = None

            logo = request.files['logo']
            if logo:
                extension = os.path.splitext(logo.filename)[1]
                if extension and extension.lower(
                ) in config.ALLOWED_IMAGE_TYPES:
                    filename = unicode(uuid.uuid4())
                    filename += extension
                    logo.save(
                        os.path.join(app.config['UPLOAD_FOLDER'], filename))
                    page.image = filename
                else:
                    errors.append(
                        'The image uploaded is not of an allowed type')

        db.session.add(page)
        db.session.commit()
        if lang == 'en':
            update_translations(page)
        if not errors:
            return redirect(url_for_admin('cms_preview', id=id))
    if lang != 'en':
        trans = Cms.query.filter_by(page_id=id, lang='en',
                                    current=True).first()
    else:
        trans = {}
    if lang != page.lang:
        page = {}
    translations = get_trans(id)
    return render_template('admin/cms_edit.html',
                           page=page,
                           trans=trans,
                           translations=translations,
                           errors=errors)
예제 #6
0
파일: cms.py 프로젝트: rrymrrsn/hrd
def cms_edit(id):
    set_menu()
    lang = get_admin_lang()
    permission_content(lang)
    errors = []
    page = Cms.query.filter_by(page_id=id, lang=lang, current=True)
    page = page.first()
    if not page and lang != 'en':
        page = Cms.query.filter_by(page_id=id, lang='en', current=True)
        page = page.first()
        if not page:
            abort(404)
    if not page:
        abort(404)
    if request.method == 'POST' and 'title' in request.form:
        if page.lang != lang:
            # no translation
            page = page_reedit(page)

        if (page.title != get_str('title')
                or page.content != get_str('content')):
            if page.status == 'publish':
                page = page_reedit(page)

            page.title = get_str('title')
            page.content = get_str('content')
            page.status = 'edit'
            trans_need_update(page)
        if lang == 'en':
            page.active = get_bool('active')
            page.private = get_bool('private')

            url = get_str('url')
            if url:
                check = Cms.query.filter(Cms.page_id != id, Cms.url == url)
                check = check.filter(db.or_(
                    Cms.status == 'publish', Cms.current == True
                ))
                if check.count():
                    errors.append(
                        'The url is already used by another page choose ' + \
                        'a new url or change the url of the existing page ' + \
                        'first. The url has been reset in this form.'
                    )
                elif url in config.DISALLOWED_URLS:
                    errors.append(
                        'The url provided is not allowed please choose ' + \
                        'a new one. The url has been reset in this form.'
                    )
                else:
                    page.url = url

            if get_bool('logo_remove'):
                page.image = None

            logo = request.files['logo']
            if logo:
                extension = os.path.splitext(logo.filename)[1]
                if extension and extension.lower() in config.ALLOWED_IMAGE_TYPES:
                    filename = unicode(uuid.uuid4())
                    filename += extension
                    logo.save(
                        os.path.join(app.config['UPLOAD_FOLDER'], filename)
                    )
                    page.image = filename
                else:
                    errors.append(
                        'The image uploaded is not of an allowed type'
                    )

        db.session.add(page)
        db.session.commit()
        if lang == 'en':
            update_translations(page)
        if not errors:
            return redirect(url_for_admin('cms_preview', id=id))
    if lang != 'en':
        trans = Cms.query.filter_by(page_id=id, lang='en',
                                    current=True).first()
    else:
        trans = {}
    if lang != page.lang:
        page = {}
    translations = get_trans(id)
    return render_template('admin/cms_edit.html', page=page, trans=trans,
                           translations=translations, errors=errors)