示例#1
0
def admin_list_pagination(request):
    if 'lek_id' in request.GET and request.GET['lek_id']:
        lek = {
            'id': {
                'S': request.GET['lek_id']
            },
            'title': {
                'S': request.GET['lek_title']
            }
        }
    else:
        lek = None

    articles = ArticleService.list(model_name='ArticleModel',
                                   last_evaluated_key=lek,
                                   limit=5)
    next_lek = articles['lek']

    if next_lek == None:
        resp_lek = {'id': '', 'title': ''}
    else:
        resp_lek = {'id': next_lek['id']['S'], 'title': next_lek['title']['S']}

    data = {
        'articles': articles['data'],
        'lek': resp_lek,
    }

    return JsonResponse(data)
示例#2
0
def list_filter_keyword(request):
    keyword = request.POST['keyword']
    if not keyword:
        return redirect('/mysite/list/')

    articles = ArticleService.searchArticleByKeyword(keyword)
    cats = CategoryService.list(model_name='CategoryModel', limit=None)
    tags = TagService.list(model_name='TagModel', limit=60)
    return render(request, 'mysite/list.html', {'articles': articles['data'], 'lek': articles['lek'], 'cats': cats['data'], 'tags': tags['data']})
示例#3
0
def admin_search_keyword(request):
    keyword = request.POST['keyword']
    if not keyword:
        return redirect('/admin/mysite/list/')

    articles = ArticleService.searchArticleByKeyword(keyword)
    return render(request, 'admin/list.html', {
        'articles': articles['data'],
        'lek': articles['lek']
    })
示例#4
0
def admin_page(request, id=None):
    tags = TagService.list(limit=None)
    cats = CategoryService.list(model_name='CategoryModel', limit=None)
    article = {}
    if id:
        article = ArticleService.getByHashKey('ArticleModel', id)

    return render(request, 'admin/page.html', {
        'article': article,
        'cats': cats['data'],
        'tags': tags['data']
    })
示例#5
0
def list_tag(request, tag=None):
    articles = ArticleService.searchArticleByTag(tag)
    cats = CategoryService.list(model_name='CategoryModel', limit=None)
    tags = TagService.list(model_name='TagModel', limit=None)
    return render(request, 'mysite/list.html', {'articles': articles['data'], 'lek': articles['lek'], 'cats': cats['data'], 'tags': tags['data']})
示例#6
0
def list_filter_tag(request, tag=None):
    articles = ArticleService.searchArticleByTag(tag)
    return JsonResponse({'articles': articles['data']})
示例#7
0
def list_filter_cat(request, cat=None):
    articles = ArticleService.searchArticleByCat(cat)
    return JsonResponse({'articles': articles['data']})
示例#8
0
def page(request, id=0):
    article = ArticleService.getByHashKey('ArticleModel', id)
    cats = CategoryService.list(model_name='CategoryModel', limit=None)
    tags = TagService.list(model_name='TagModel', limit=None)
    return render(request, 'mysite/page.html', {'article' : article, 'cats': cats['data'], 'tags': tags['data']})
示例#9
0
def list(request, last_evaluated_key=None):
    articles = ArticleService.list(model_name='ArticleModel')
    cats = CategoryService.listCategoryWithCount()
    tags = TagService.list(model_name='TagModel', limit=60)
    return render(request, 'mysite/list.html', {'articles': articles['data'], 'lek': articles['lek'], 'cats': cats['data'], 'tags': tags['data']})
示例#10
0
async def delete_article(article_id:int, db:Session = Depends(get_db)):
    return ArticleService.delete_article(article_id=article_id, db=db)
示例#11
0
async def update_article(article:ArticleCreate, article_id:int, db:Session = Depends(get_db)):
    return ArticleService.update_article(article_id=article_id,article=article,db=db)
示例#12
0
async def create_article(article:ArticleCreate, db: Session = Depends(get_db)):
    return ArticleService.create_new_article(db=db, article=article)
示例#13
0
async def get_article(article_id:int, db:Session = Depends(get_db)):
    the_article = ArticleService.get_article(db=db, article_id=article_id)
    if the_article is None:
        raise HTTPException(status_code=404, detail="The article does not exist")
    return the_article
示例#14
0
async def get_articles(db: Session = Depends(get_db)):
    articels = ArticleService.get_articles(db=db)
    return articels
示例#15
0
def admin_list(request, last_evaluated_key=None):
    articles = ArticleService.list(model_name='ArticleModel', limit=5)
    return render(request, 'admin/list.html', {
        'articles': articles['data'],
        'lek': articles['lek']
    })