예제 #1
0
def tag_add(request):
    if request.method == 'POST':
        f = TagForm(request.POST)
        if f.is_valid():
            if request.POST.get('author') == '' and request.user.is_superuser:
                new_tag = f.save(commit=False)
                new_tag.author = Author.objects.get(user__username='******')
                new_tag.save()
                f.save_m2m()

            elif request.POST.get('author') and request.user.is_superuser:
                new_tag = f.save()

            else:
                new_tag = f.save(commit=False)
                new_tag.author = Author.objects.get(
                    user__username=request.user.username)
                new_tag.save()
                f.save_m2m()

            messages.add_message(request, messages.INFO, 'Tag added')
            return redirect('tag_add')

        else:
            print(f.errors)

    else:
        f = TagForm()

    return render(request, 'cadmin/tag_add.html', {'form': f})
예제 #2
0
def tag_add(request):
    # If request is POST, create a bound form(form with data)
    if request.method == "POST":
        f = TagForm(request.POST)
        if f.is_valid():
            # new_category = f.save()
            # new_category = f.save(commit=False)
            # new_category.author = get_user(request)
            # new_category.save()
            if request.POST.get('author') == "" and request.user.is_superuser:
                # if author is not supplied and user is superuser
                new_tag = f.save(commit=False)
                author = Author.objects.get(user__username='******')
                new_tag.author = author
                new_tag.save()
            elif request.POST.get('author') and request.user.is_superuser:
                # if author is supplied and user is superuser
                new_tag = f.save()
            else:
                # if author not a superuser
                new_tag = f.save(commit=False)
                new_tag.author = Author.objects.get(
                    user__username=request.user.username)
                new_tag.save()

            messages.add_message(request, messages.INFO, 'Tag added')
            return redirect('tag_add')
    # if request is GET the show unbound form to the user
    else:
        f = TagForm()
    return render(request, 'cadmin/tag_add.html', {'form': f})
예제 #3
0
def tag_update(request, pk):
    tag = get_object_or_404(Tag, pk=pk)
    if request.method == 'POST':
        f = TagForm(request.POST, instance=tag)
        if f.is_valid():
            if request.POST.get('author') == '' and request.user.is_superuser:
                updated_tag = f.save(commit=False)
                updated_tag.author = Author.objects.get(user__username='******')
                updated_tag.save()
                f.save_m2m()

            elif request.POST.get('author') and request.user.is_superuser:
                updated_tag = f.save()

            else:
                updated_tag = f.save(commit=False)
                updated_tag.author = Author.objects.get(
                    user__username=request.user.username)
                updated_tag.save()
                f.save_m2m()

            messages.add_message(request, messages.INFO, 'Tag updated')
            return redirect('tag_update', pk=pk)

        else:
            print(f.errors)

    else:
        f = TagForm(instance=tag)

    return render(request, 'cadmin/tag_update.html', {'form': f})
예제 #4
0
def tag_update(request, pk):
    tag = get_object_or_404(Tag, pk=pk)
    # If request is POST, create a bound form(form with data)
    if request.method == "POST":  # If request is POST, create a bound form
        f = TagForm(request.POST, instance=tag)
        if f.is_valid():
            # updated_tag = f.save()
            if request.POST.get('author') == "" and request.user.is_superuser:
                # if author is not supplied and user is superuser
                updated_tag = f.save(commit=False)
                author = Author.objects.get(user__username='******')
                updated_tag.author = author
                updated_tag.save()
            elif request.POST.get('author') and request.user.is_superuser:
                # if author is supplied and user is superuser
                updated_tag = f.save()
            else:
                # if author not a superuser
                updated_tag = f.save(commit=False)
                updated_tag.author = Author.objects.get(
                    user__username=request.user.username)
                updated_tag.save()

            messages.add_message(request, messages.INFO, 'Tag updated')
            return redirect(reverse('tag_update', args=[tag.id]))
    # if request is GET the show unbound form to the user
    else:
        f = TagForm(instance=tag)
    return render(request, 'cadmin/tag_update.html', {'form': f, 'tag': tag})
예제 #5
0
def TagCreate(request):
    tag = Tag.objects.all()
    form = TagForm
    if request.method == 'POST':
        form = TagForm(request.POST)

        if form.is_valid():
            form.save()

            return HttpResponseRedirect(reverse("blog:tag_add"))

    return render(request, 'blog/tag_create_form.html', {
        'tag': tag,
        'form': form
    })
예제 #6
0
    def test_tag_form(self):
        """Test adding and editing tag form"""
        form = TagForm(data={})
        self.assertFalse(form.is_valid())

        form = TagForm(data={'name': 'foo'})
        self.assertTrue(form.is_valid())
        form.save()
        tag = Tag.objects.get()
        self.assertEqual(tag.name, 'foo')

        form = TagForm(instance=tag, data={'name': 'bar'})
        self.assertTrue(form.is_valid())
        form.save()
        tag = Tag.objects.get()
        self.assertEqual(tag.name, 'bar')
예제 #7
0
    def test_tag_form(self):
        """Test adding and editing tag form"""
        form = TagForm(data={})
        self.assertFalse(form.is_valid())

        form = TagForm(data={"name": "foo"})
        self.assertTrue(form.is_valid())
        form.save()
        tag = Tag.objects.get()
        self.assertEqual(tag.name, "foo")

        form = TagForm(instance=tag, data={"name": "bar"})
        self.assertTrue(form.is_valid())
        form.save()
        tag = Tag.objects.get()
        self.assertEqual(tag.name, "bar")
예제 #8
0
    def test_tag_form(self):
        """Test adding and editing tag form"""
        form = TagForm(data={})
        self.assertFalse(form.is_valid())

        form = TagForm(data={'name': 'foo'})
        self.assertTrue(form.is_valid())
        form.save()
        tag = Tag.objects.get()
        self.assertEqual(tag.name, 'foo')

        form = TagForm(instance=tag, data={'name': 'bar'})
        self.assertTrue(form.is_valid())
        form.save()
        tag = Tag.objects.get()
        self.assertEqual(tag.name, 'bar')
예제 #9
0
파일: views.py 프로젝트: venommile/main
    def post(self, request):
        bound_form = TagForm(request.POST)

        if bound_form.is_valid():
            new_tag = bound_form.save()
            return redirect('tags_list')
        return render(request, 'blog/tag_create.html', {'form': bound_form})
예제 #10
0
파일: views.py 프로젝트: venommile/main
    def post(self, request, slug):
        tag = Tag.objects.get(slug__iexact=slug)
        bound_form = TagForm(request.POST, instance=tag)

        if bound_form.is_valid():
            new_tag = bound_form.save()
            return redirect('tags_list')
        return render(request, 'blog/tag_update.html', {
            'form': bound_form,
            'tag': tag
        })
예제 #11
0
파일: views.py 프로젝트: Ununtuplicate/TGDB
def tag_add(request):

    # if request is POST, create bound form
    if request.method == "POST":
        f = TagForm(request.POST)

        # check whether form is valid
        # if valid, save data to database
        # redirect user to add post form

        # if form is invalid, show with errors
        if f.is_valid():
            # new_category = f.save()
            # new_category = f.save(commit=False)
            # new_category.author = get_user(request)
            # new_category.save()

            if request.POST.get('author') == "" and request.user.is_superuser:
                # if author is not supplied and user is superuser
                new_tag = f.save(commit=False)
                author = Author.objects.get(user__username='******')
                new_tag.author = author
                new_tag.save()
            elif request.POST.get('author') and request.user.is_superuser:
                # if author is supplied and user is superuser
                new_tag = f.save()
            else:
                # if author is not a superuser
                new_tag = f.save(commit=False)
                new_tag.author = Author.objects.get(
                    user__username=request.user.username)
                new_tag.save()

            messages.add_message(request, messages.INFO, 'Tag Added')
            return redirect('tag_add')

    # if request is GET show unbound form
    else:
        f = TagForm()

    return render(request, 'cadmin/tag_add.html', {'form': f})
예제 #12
0
def tag_add(request):

    # if request is POST, create a bound form(form with data
    if request.method == "POST":
        f = TagForm(request.POST)

        # check whether form is valid or not
        # if the form is valid, save the data to the database
        # and redirect the user back to the add post form

        # if form is invalid show form with errors again
        if f.is_valid():
            # new_tag = f.save()
            # new_tag = f.save(commit=False)
            # new_tag.author = get_user(request)
            # new_tag.save()

            if request.POST.get('author') == "" and request.user.is_superuser:
                # if author is not supplied and user is superuser
                new_tag = f.save(commit=False)
                author = Author.objects.get(user__username='******')
                new_tag.author = author
                new_tag.save()
            elif request.POST.get('author') and request.user.is_superuser:
                # if author is supplied and user is superuser
                new_tag = f.save()
            else:
                # if author not a superuser
                new_tag = f.save(commit=False)
                new_tag.author = Author.objects.get(
                    user__username=request.user.username)
                new_tag.save()

            messages.add_message(request, messages.INFO, _('Tag added'))
            return redirect('tag_add')

    # if request is GET the show unbound form to the user
    else:
        f = TagForm()

    return render(request, 'cadmin/tag_add.html', {'form': f})
예제 #13
0
파일: views.py 프로젝트: Ununtuplicate/TGDB
def tag_update(request, pk):
    tag = get_object_or_404(Tag, pk=pk)

    # if request is POST, created bound form
    if request.method == "POST":
        f = TagForm(request.POST, instance=tag)

        # check whether form is valid
        # if valid, save to database
        # redirect to tag update form

        # if form is invalid, show with errors
        if f.is_valid():
            # updated_tag = f.save()

            if reuqest.POST.get('author') == "" and request.user.is_superuser:
                # is author is not supplied and user is superuser
                updated_tag = f.save(commit=False)
                author = Author.objects.get(user__username='******')
                udated_tag.author = author
                updated_tag.save()
            elif request.POST.get('author') and request.user.is_superuser:
                # author is supplied and user is superuser
                updated_category = f.save()
            else:
                # author is not a superuser
                updated_tag = f.save(commit=False)
                updated_tag.author = Author.objects.get(
                    user__username=request.user.username)
                updated_tag.save()

            messages.add_message(request, messages.INFO, 'Tag Updated')
            return redirect(reverse('tag_update', args=[tag.id]))

    #if request is GET show unbound form
    else:
        f = TagForm(instance=tag)

    return render(request, 'cadmin/tag_update.html', {'form': f, 'tag': tag})
예제 #14
0
파일: views.py 프로젝트: kydkang/TGDB2
def tag_update(request, pk):
    tag = get_object_or_404(Tag, pk=pk)
    if request.method == "POST":
        f = TagForm(request.POST, instance=tag)
        if f.is_valid():
            if request.POST.get('author') == "" and request.user.is_superuser:
                updated_tag = f.save(commit=False)
                author = Author.objects.get(user__username='******')
                updated_tag.author = author
                updated_tag.save()
            elif request.POST.get('author') and request.user.is_superuser:
                updated_tag = f.save()
            else:
                updated_tag = f.save(commit=False)
                updated_tag.author = Author.objects.get(
                    user__username=request.user.username)
                updated_tag.save()

            messages.add_message(request, messages.INFO, 'Tag updated')
            return redirect(reverse('tag_update', args=[tag.id]))
    else:
        f = TagForm(instance=tag)
    return render(request, 'cadmin/tag_update.html', {'form': f, 'tag': tag})
예제 #15
0
def admin_add_tag(request):

    if users.is_current_user_admin():
        if request.method == 'GET':
            form = TagForm()
            
        elif request.method == 'POST':
            form = TagForm(request.POST)
            if form.is_valid():
                tag = form.save(commit=False)
                tag.title = string.lower(tag.title)
                tag.put()
            return HttpResponseRedirect('/admin')
        return render_to_response('admin/edit.html',
                                      dictionary={ 'form':form,
                                                    'type': 'Add Tag',
                                                     },
                                      context_instance=RequestContext(request)
                                    )
    else:
        return HttpResponseRedirect('/')
예제 #16
0
def admin_add_tag(request):

    if users.is_current_user_admin():
        if request.method == 'GET':
            form = TagForm()

        elif request.method == 'POST':
            form = TagForm(request.POST)
            if form.is_valid():
                tag = form.save(commit=False)
                tag.title = string.lower(tag.title)
                tag.put()
            return HttpResponseRedirect('/admin')
        return render_to_response('admin/edit.html',
                                  dictionary={
                                      'form': form,
                                      'type': 'Add Tag',
                                  },
                                  context_instance=RequestContext(request))
    else:
        return HttpResponseRedirect('/')
예제 #17
0
 def post(self, request):
     form = TagForm(request.POST)
     if form.is_valid():
         form.save()
         return redirect('create_post')
     return render(request, 'blog/create_tag.html', context={'form': form})