Exemplo n.º 1
0
def book_details(request, book_id):
    book = get_object_or_404(Book, id=book_id)  # Book.obgects.get(pk=book_id)
    context = {'book': book}
    if request.user.id is not None:
        if request.method == 'POST':
            form = ReviewForm(request.POST)
            if form.is_valid():
                new_review = Review.objects.create(
                    user=request.user,
                    book=context['book'],
                    text=form.cleaned_data.get('text'))
                new_review.save()
        else:
            if Review.objects.filter(user=request.user,
                                     book=context['book']).count() == 0:
                form = ReviewForm()
                context['form'] = form
    context['reviews'] = book.review_set.all()
    ip_s = request.META.get('REMOTE_ADDR')
    geo_info = ''
    if ip_s != '127.0.0.1':
        geo_info = GeoIP2().city(ip_s)
    if not geo_info:
        geo_info = GeoIP2().city('93.178.204.228')
    context['geo_info'] = geo_info
    print(geo_info)

    return render(request, 'store/detail.html', context=context)
Exemplo n.º 2
0
def post_coment(request, pk):
    post = get_object_or_404(Post, pk=pk)
    if request.method == "POST":
        form = ComentForm(request.POST)
        if form.is_valid():
            comentario = form.save(commit=False)
            comentario.post = post
            #post.published_date = timezone.now()
            comentario.save()
            return redirect('post_detail', pk=post.pk)
    else:
        form = ComentForm()
    return render(request, 'blog/coment_edit.html', {'form': form})


# def coment_detail(request, pk):
#     post = get_object_or_404(Post, pk=pk)
#     return render(request, "blog/coment_list.html", {'form': form})






#teste
#def home(request):
 #   now = database.datatime.now()
  #  return render(request, 'blog/home.html')
Exemplo n.º 3
0
def applyuser(request):
    if request.method == 'POST':
        form = Userinformation(request.POST, request.FILES)
        if form.is_valid():
            # file is saved
            form.save()
            return HttpResponseRedirect('success')
    else:
        form = Userinformation()
    return render(request, 'registration.html', {'form': form})
Exemplo n.º 4
0
 def save(self, commit=True):
     data = {}
     form = super()
     try:
         if form.is_valid():
             form.save()
         else:
             data['error'] = form.errors
     except Exception as e:
         data['error'] = str(e)
     return data
Exemplo n.º 5
0
def usar_update(request):
    user = request.user
    form = usaeupdate(instance=user)
    if request.method == 'POST':
        form = usaeupdate(request.POST, instance=user)
        if form.is_valid():
            form = form.save(commit=False)
            form.user = request.user
            form.save()
            return redirect('asas:asas')
    return render(request, 'user_update.html', {'form': form})
Exemplo n.º 6
0
def post_new(request):
    if request.method == "POST":
        form = PostForm(request.POST)
        if form.is_valid():
            post = form.save(commit=False)
            post.author = request.user
            post.published_date = timezone.now()
            post.save()
            return redirect('post_detail', pk=post.pk)
    else:
        form = PostForm()
    return render(request, 'blog/post_edit.html', {'form': form})
Exemplo n.º 7
0
def products_page(request):
    hookahs = Hookah.objects.all()
    bowls = Bowl.objects.all()
    tabacco = Tabacco.objects.all()
    coals = Coals.objects.all()
    form = ComplectForm()
    if request.method == 'POST':
        form = ComplectForm(request.POST)
        if form.is_valid():
            form.save()
        return redirect('complect')
    context = {'hookahs':hookahs,'bowls':bowls,'tabacco':tabacco,'coals':coals,'form':form}
    return render(request,'online_delivery/product.html',context)