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)
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']})
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'] })
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'] })
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']})
def list_filter_tag(request, tag=None): articles = ArticleService.searchArticleByTag(tag) return JsonResponse({'articles': articles['data']})
def list_filter_cat(request, cat=None): articles = ArticleService.searchArticleByCat(cat) return JsonResponse({'articles': articles['data']})
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']})
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']})
async def delete_article(article_id:int, db:Session = Depends(get_db)): return ArticleService.delete_article(article_id=article_id, db=db)
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)
async def create_article(article:ArticleCreate, db: Session = Depends(get_db)): return ArticleService.create_new_article(db=db, article=article)
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
async def get_articles(db: Session = Depends(get_db)): articels = ArticleService.get_articles(db=db) return articels
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'] })