Ejemplo n.º 1
0
def edit_blog(request, *, blog_id):
    if not check_admin(request):
        return 'redirect:/login'
    else:
        return dict(__template__='edit_blog.html',
                    id=blog_id,
                    action='/api/edit_blog')
Ejemplo n.º 2
0
Archivo: apis.py Proyecto: LRG00/Weppy
def api_add_blog(request, *, title, title_en, summary, content, created_at,
                 categery_id):
    if not check_admin(request):
        return dict(message='no permition')
    if not title or not title.strip():
        raise APIValueError('title', 'title cannot be empty.')
    if not title_en or not title_en.strip():
        raise APIValueError('title_en', 'title_en cannot be empty.')
    if not summary or not summary.strip():
        raise APIValueError('summary', 'summary cannot be empty.')
    if not content or not content.strip():
        raise APIValueError('content', 'content cannot be empty.')
    if not created_at or not created_at.strip():
        raise APIValueError('created_at', 'content cannot be empty.')
    if not categery_id or not categery_id.strip():
        raise APIValueError('created_at', 'content cannot be empty.')
    blog = Blog(title=title.strip(),
                title_en=title_en.strip(),
                content=content.strip(),
                summary=summary.strip(),
                created_at=created_at.strip(),
                categery_id=int(categery_id.strip()))

    yield from blog.save()

    return blog
Ejemplo n.º 3
0
Archivo: apis.py Proyecto: LRG00/Weppy
def api_edit_blog(request, *, id, title, title_en, summary, content,
                  created_at, categery_id):
    if not check_admin(request):
        return dict(message='no permition')
    if not title or not title.strip():
        raise APIValueError('title', 'title cannot be empty.')
    if not title_en or not title_en.strip():
        raise APIValueError('title_en', 'title_en cannot be empty.')
    if not summary or not summary.strip():
        raise APIValueError('summary', 'summary cannot be empty.')
    if not content or not content.strip():
        raise APIValueError('content', 'content cannot be empty.')
    if not created_at or not created_at.strip():
        raise APIValueError('created_at', 'content cannot be empty.')

    blog = yield from Blog.find(id.strip())
    blog.title = title.strip()
    blog.summary = summary.strip()
    blog.content = content.strip()
    blog.created_at = created_at.strip(),
    blog.categery_id = categery_id.strip()
    blog.title_en = title_en.strip()

    yield from blog.update()

    return blog
Ejemplo n.º 4
0
Archivo: apis.py Proyecto: LRG00/Weppy
def api_add_categery(request, *, name):
    if not check_admin(request):
        return dict(message='no permition')
    if not name or not name.strip():
        raise APIValueError('name', 'name cannot be empty.')
    categery = Categery(name=name.strip())
    yield from categery.save()
    return categery
Ejemplo n.º 5
0
Archivo: apis.py Proyecto: LRG00/Weppy
def api_delete_blog(request, *, id):
    if not check_admin(request):
        return dict(message='no permition')
    if not id:
        raise APIValueError('ID', 'ID is Invalid')
    print(id)
    blog = yield from Blog.find(id)
    yield from blog.remove()
    return dict(id=id)
Ejemplo n.º 6
0
def add_blog(request):
    if not check_admin(request):
        return 'redirect:/login'
    else:
        all_categeries = yield from Categery.find_all()
        return dict(__template__='edit_blog.html',
                    id='',
                    all_categeries=all_categeries,
                    action='/api/add_blog')
Ejemplo n.º 7
0
Archivo: apis.py Proyecto: LRG00/Weppy
def api_edit_categery(request, *, id, name):
    if not check_admin(request):
        return dict(message='no permition')
    if not name or not name.strip():
        raise APIValueError('name', 'name cannot be empty.')
    if not id or not id.strip():
        raise APIValueError('categery_id', 'categery_id cannot be empty.')
    categery = yield from Categery.find(int(id.strip()))
    categery.name = name
    yield from categery.update()
    return categery
Ejemplo n.º 8
0
def manage_blogs(request, *, page='1'):
    if not check_admin(request):
        return 'redirect:/login'
    else:
        page_index = get_page_index(page)
        num = yield from Blog.get_count('id')
        page = Page(num, page_index)
        if num == 0:
            return dict(page=page, blogs=())
        print(page)
        return dict(__template__='manage_blogs.html', page=page)
Ejemplo n.º 9
0
def edit_categery(request, *, categery_id):
    if not check_admin(request):
        return 'redirect:/login'
    else:
        categery = None
        if categery_id:
            categery = yield from Categery.find(categery_id)
        return dict(__template__='edit_categery.html',
                    id=categery_id,
                    categery=categery,
                    action='/api/edit_categery')
Ejemplo n.º 10
0
def manage_categeries(request):
    if not check_admin(request):
        return 'redirect:/login'
    else:
        return dict(__template__='manage_categeries.html', )
Ejemplo n.º 11
0
def add_categery(request):
    if not check_admin(request):
        return 'redirect:/login'
    else:
        return dict(__template__='edit_categery.html',
                    action='/api/add_categery')