Exemplo n.º 1
0
def article_update_view(request, pk):
    article = get_object_or_404(Article, pk=pk)
    if request.method == "GET":
        form = ArticleForm(
            initial={
                'description': article.description,
                'maxdescription': article.maxdescription,
                'status': article.status,
                'date_completion': article.date_completion
            })
        return render(request,
                      'article_update.html',
                      context={
                          'form': form,
                          'article': article
                      })
    elif request.method == 'POST':
        form = ArticleForm(data=request.POST)
        if form.is_valid():
            # Article.objects.filter(pk=pk).update(**form.cleaned_data)
            article.description = form.cleaned_data['description']
            article.maxdescription = form.cleaned_data['maxdescription']
            article.status = form.cleaned_data['status']
            article.date_completion = form.cleaned_data['date_completion']
            article.save()
            return redirect('article_create', pk=article.pk)
        else:
            return render(request,
                          'article_update.html',
                          context={
                              'article': article,
                              'form': form
                          })
    else:
        return HttpResponseNotAllowed(permitted_methods=['GET', 'POST'])
Exemplo n.º 2
0
def article_update_view(request, pk):
    article = get_object_or_404(Article, pk=pk)
    if request.method == 'GET':
        form = ArticleForm(
            data={
                'title': article.title,
                'created_at': article.created_at,
                'text': article.text,
                'category': article.category
            })
        return render(request,
                      'update.html',
                      context={
                          'form': form,
                          'article': article
                      })
    elif request.method == 'POST':
        form = ArticleForm(data=request.POST)
        if form.is_valid():
            article.title = form.cleaned_data['title']
            article.text = form.cleaned_data['text']
            article.created_at = form.cleaned_data['created_at']
            article.category = form.cleaned_data['category']
            article.save()
            return redirect('article_view', pk=article.pk)
        else:
            return render(request,
                          'update.html',
                          context={
                              'form': form,
                              'article': article
                          })
Exemplo n.º 3
0
def task_update_view(request, pk):
    task = get_object_or_404(Article, pk=pk)
    if request.method == 'GET':
        form = ArticleForm(
            data={
                'description': task.description,
                'total_description': task.total_description,
                'status': task.status,
                'date': task.date
            })
        return render(request,
                      'update.html',
                      context={
                          'form': form,
                          'task': task
                      })
    elif request.method == 'POST':
        form = ArticleForm(data=request.POST)
        if form.is_valid():
            task.description = form.cleaned_data['description']
            task.total_description = form.cleaned_data['total_description']
            task.status = form.cleaned_data['status']
            task.date = form.cleaned_data['date']
            task.save()
            return redirect('task_view', pk=task.pk)
        else:
            return render(request,
                          'update.html',
                          context={
                              'form': form,
                              'article': task
                          })
Exemplo n.º 4
0
def edit_view(request, pk):
    try:
        articles = get_object_or_404(Article, pk=pk)
        if request.method == 'GET':
            form = ArticleForm(
                data={
                    'description': articles.description,
                    'status': articles.status,
                    'text': articles.text,
                    'created_at': articles.created_at
                })
            return render(request,
                          'edit.html',
                          context={
                              'articles': articles,
                              'form': form
                          })
        elif request.method == "POST":
            form = ArticleForm(data=request.POST)
            if form.is_valid():
                articles.description = form.cleaned_data['description']
                articles.status = form.cleaned_data['status']
                articles.text = form.cleaned_data['text']
                articles.created_at = form.cleaned_data['created_at']
                articles.save()
                return redirect('article', pk=articles.pk)
            else:
                return render(request,
                              'edit.html',
                              context={
                                  'form': form,
                                  'articles': articles
                              })
    except Article.DoesNotExist:
        return HttpResponseNotFound("<h2>Article not found</h2>")
Exemplo n.º 5
0
 def post(self, request, *args, **kwargs):
     form = ArticleForm(data=request.POST)
     if form.is_valid():
         article = Article.objects.create(
             title=form.cleaned_data['title'],
             author=form.cleaned_data['author'],
             text=form.cleaned_data['text'])
         return redirect('article_view', pk=article.pk)
     else:
         return render(request, 'create.html', context={'form': form})
Exemplo n.º 6
0
 def post(self, request, *args, **kwargs):
     article = get_object_or_404(Article, pk=kwargs.get('pk'))
     form = ArticleForm(data=request.POST)
     if form.is_valid():
         article.title = form.cleaned_data['title']
         article.author = form.cleaned_data['author']
         article.text = form.cleaned_data['text']
         article.category = form.cleaned_data['category']
         article.save()
         return redirect('article_view', pk=article.pk)
     else:
         return render(request, 'update.html', context={'form': form, 'article': article})
Exemplo n.º 7
0
def edit(request, pk):
    choice = STATUS_CHOICE
    article = get_object_or_404(Article, pk=pk)
    if request.method == 'GET':
        if article.create_at is None:
            create_at = ''
        else:
            create_at = article.create_at.strftime("%Y-%m-%d")
        form = ArticleForm(
            initial={
                "name": article.name,
                "description": article.description,
                "status": article.status,
                "create_at": create_at
            })
        return render(request,
                      'edit.html',
                      context={
                          'form': form,
                          'article': article,
                          'create_at': create_at,
                          'choice': choice
                      })
    elif request.method == 'POST':
        form = ArticleForm(data=request.POST)
        if form.is_valid():
            article.name = form.cleaned_data['name']
            article.description = form.cleaned_data['description']
            article.status = form.cleaned_data['status']
            create_at = form.cleaned_data['create_at']
            if create_at == '':
                create_at = None
            article.create_at = create_at
            article.save()
            return redirect('find', pk=article.pk)
        else:
            if article.create_at is None:
                create_at = ''
            else:
                create_at = article.create_at.strftime("%Y-%m-%d")
            return render(request,
                          'edit.html',
                          context={
                              'article': article,
                              'form': form,
                              'create_at': create_at,
                              'choice': choice
                          })
    else:
        return HttpResponseNotAllowed(permitted_methods=['GET', 'POST'])
Exemplo n.º 8
0
def article_create_view(request, *args, **kwargs):
    if request.method == 'GET':
        form = ArticleForm()
        return render(request, 'create.html', context={'form': form})
    elif request.method == 'POST':
        form = ArticleForm(data=request.POST)
        if form.is_valid():
            article = Article.objects.create(
                title=form.cleaned_data['title'],
                author=form.cleaned_data['author'],
                text=form.cleaned_data['text'],
                category=form.cleaned_data['category'])
            return redirect('article_view', pk=article.pk)
        else:
            return render(request, 'create.html', context={'form': form})
Exemplo n.º 9
0
def task_create_view(request, *args, **kwargs):
    if request.method == 'GET':
        form = ArticleForm()
        return render(request, 'task_create.html', context={'form': form})
    elif request.method == 'POST':
        form = ArticleForm(data=request.POST)
        if form.is_valid():
            article = Article.objects.create(
                description=form.cleaned_data['description'],
                total_description=form.cleaned_data['total_description'],
                status=form.cleaned_data['status'],
                date=form.cleaned_data['date'])
            return redirect('task_view', pk=article.pk)
        else:
            return render(request, 'task_create.html', context={'form': form})
Exemplo n.º 10
0
def article_view(request):
    if request.method == "GET":
        return render(request,
                      'article_view.html',
                      context={'form': ArticleForm()})
    elif request.method == 'POST':
        form = ArticleForm(data=request.POST)
        if form.is_valid():
            article = Article.objects.create(
                description=form.cleaned_data['description'],
                maxdescription=form.cleaned_data['maxdescription'],
                status=form.cleaned_data['status'],
                date_completion=form.cleaned_data['date_completion'])
            return redirect('article_create', pk=article.pk)
        else:
            return render(request, 'article_view.html', context={'form': form})
    else:
        return HttpResponseNotAllowed(permitted_methods=['GET', 'POST'])
Exemplo n.º 11
0
def article_create_view(request, *args, **kwargs):
    if request.method == 'GET':
        form = ArticleForm()
        return render(request,
                      'create_view.html',
                      context={
                          'form': form,
                          'category_choices': status_choices
                      })
    elif request.method == 'POST':
        form = ArticleForm(data=request.POST)
        if form.is_valid():
            article = Article.objects.create(
                description=form.cleaned_data['description'],
                status=form.cleaned_data['status'],
                text=form.cleaned_data['text'],
                created_at=form.cleaned_data['created_at'])
            return redirect('article', pk=article.pk)
        else:
            return render(request, 'create_view.html', context={'form': form})
Exemplo n.º 12
0
def article_update_view(request, pk):
    article = get_object_or_404(Article, pk=pk)
    if request.method == "GET":
        form = ArticleForm(initial={
            'title': article.title,
            'text': article.text,
            'author': article.author,
            'status': article.status,
            # форматирование перед выводом для DateTime.
            'publish_at': make_naive(article.publish_at)\
                .strftime(BROWSER_DATETIME_FORMAT)
            # для дат выглядит просто как:
            # 'publish_at': article.publish_at
        })
        return render(request,
                      'article_update.html',
                      context={
                          'form': form,
                          'article': article
                      })
    elif request.method == 'POST':
        form = ArticleForm(data=request.POST)
        if form.is_valid():
            # Article.objects.filter(pk=pk).update(**form.cleaned_data)
            article.title = form.cleaned_data['title']
            article.text = form.cleaned_data['text']
            article.author = form.cleaned_data['author']
            article.status = form.cleaned_data['status']
            article.publish_at = form.cleaned_data['publish_at']
            article.save()
            return redirect('article_view', pk=article.pk)
        else:
            return render(request,
                          'article_update.html',
                          context={
                              'article': article,
                              'form': form
                          })
    else:
        return HttpResponseNotAllowed(permitted_methods=['GET', 'POST'])
Exemplo n.º 13
0
def article_create_view(request):
    if request.method == "GET":
        return render(request,
                      'article_create.html',
                      context={'form': ArticleForm()})
    elif request.method == 'POST':
        form = ArticleForm(data=request.POST)
        if form.is_valid():
            # article = Article.objects.create(**form.cleaned_data)
            article = Article.objects.create(
                title=form.cleaned_data['title'],
                text=form.cleaned_data['text'],
                author=form.cleaned_data['author'],
                status=form.cleaned_data['status'],
                publish_at=form.cleaned_data['publish_at'])
            return redirect('article_view', pk=article.pk)
        else:
            return render(request,
                          'article_create.html',
                          context={'form': form})
    else:
        return HttpResponseNotAllowed(permitted_methods=['GET', 'POST'])
Exemplo n.º 14
0
def add_new(request):
    choice = STATUS_CHOICE
    if request.method == 'POST':
        form = ArticleForm(data=request.POST)
        if form.is_valid():
            article = Article.objects.create(
                name=form.cleaned_data['name'],
                description=form.cleaned_data['description'],
                status=form.cleaned_data['status'],
                create_at=form.cleaned_data['create_at'])
            return redirect('find', pk=article.pk)
        else:
            return render(request,
                          'add_new.html',
                          context={
                              'form': form,
                              'choice': choice
                          })
    return render(request,
                  'add_new.html',
                  context={
                      'choice': choice,
                      'form': ArticleForm()
                  })