コード例 #1
0
ファイル: views.py プロジェクト: WildfootTW/Django_Demo
def comment (request, id):
    if id:
        r = Restaurant.objects.get(id=id)
    else:
        return HttpResponseRedirect("/restaurants_list/")
    #error = False
    #errors = []
    if request.POST:
        f = CommentForm(request.POST)
        if f.is_valid():
            visitor = f.cleaned_data['visitor']
            content = f.cleaned_data['content']
            email = f.cleaned_data['email']
            date_time = timezone.localtime(timezone.now())
            c = Comment.objects.create( 
                    visitor=visitor,
                    email=email,
                    content=content,
                    date_time=date_time,
                    restaurant=r )
            f = CommentForm(initial={'content':'無意見'})
        #error = any(not request.POST[k] for k in request.POST)
    else:
        f = CommentForm(initial={'content':'無意見'})
    return render(request, 'comments.html', locals())
コード例 #2
0
ファイル: views.py プロジェクト: JackieWSC/Onepiece
    def post(self, request, **kwargs):
        r = Restaurant.objects.get(id=kwargs['id'])


        if 'ok' in request.POST:
            form = CommentForm(request.POST)

            if form.is_valid():
                user = form.cleaned_data['user']
                content = form.cleaned_data['content']
                email = form.cleaned_data['email']
                date_time = datetime.datetime.now()

                c = Comment.objects.create(
                        user=user, email=email, content=content, date_time=date_time, restaurant=r)
                c.save()
                form = CommentForm(initial={'content':'No comments'})
        else:
            form = CommentForm(initial={'content':'No comments'})

        context = {
            'r' : r,
            'form' : form,
        }

        return render(request, 'comments.html', context)
コード例 #3
0
ファイル: views.py プロジェクト: yuchaz/djRestaurant
def comment(request, idx):
    if idx:
        rs = Restaurant.objects.get(id=idx)
        # get the selected restaurants! by the index of idx!
    else:
        return HttpResponseRedirect("/restaurants_list/")
    if "ok" in request.POST:  # if sb submit the data.
        fm = CommentForm(request.POST)
        if fm.is_valid():
            user = request.POST["user"]
            email = request.POST["email"]
            content = request.POST["content"]
            Comment.objects.create(content=content, user=user, email=email, date_time=datetime.now(), restaurant=rs)
            # 填寫完畢之後要清除CommentForm
            fm = CommentForm(initial={"content": "我沒意見"})
    else:
        # 若沒有填寫,要清空CommentForm
        fm = CommentForm(initial={"content": "我沒意見"})
        # if not user or not content or not email:
        # 	errors.append('請填寫所有空格')
        # if '@' not in email:
        # 	errors.append('請輸入email')
        # if not errors:
        # 	Comment.objects.create(content=content, user=user, email=email, date_time=datetime.now(), restaurant=rs)
        # 	user=''
        # 	email=''
        # 	content=''
    return render(request, "comment.html", locals())
コード例 #4
0
ファイル: views.py プロジェクト: gn00533502/restaurant
def comment(request, restaurant_id):
    if restaurant_id:
        r = Restaurant.objects.get(id=restaurant_id)
    else:
        return HttpResponseRedirect("/restaurants_list/")
    errors = [] #用於作欄位正確性判斷
    if request.POST:
        f = CommentForm(request.POST)
        if f.is_valid():
            visitor = f.cleaned_data['visitor']
            content = f.cleaned_data['content']
            email = f.cleaned_data['email']
            date_time = timezone.localtime(timezone.now())
            c = Comment.objects.create(
                visitor=visitor, email=email,
                content=content,
                date_time=date_time,
                restaurant=r
            )
            #產生一個非綁定表單,將生成html碼
            #設定初始值
            f = CommentForm(initial={'content':'我沒意見'})
    else:
        f = CommentForm(initial={'content':'我沒意見'})
    return render_to_response('comments.html', RequestContext(request,locals()))
コード例 #5
0
def comment(request, id):	
	if id:
		r = Restaurant.objects.get(id=id)
	else:
		return HttpResponseRedirect("/restaurants_list/")
	# error = True
	# errors = []
	if request.POST:
		f = CommentForm(request.POST)
		if f.is_valid():
			visitor = f.cleaned_data['visitor']
			content = f.cleaned_data['content']
			email = f.cleaned_data['email']
			date_time = timezone.localtime(timezone.now())
			c = Comment.objects.create(
				visitor=visitor,
				email=email,
				content=content,
				date_time=date_time,
				restaurant=r
			)
			f = CommentForm()
	else:
		f = CommentForm();
	return render_to_response('comments.html', RequestContext(request, locals()))	
コード例 #6
0
def foodcomment(request, id):	
	if id:
		f = Food.objects.get(id=id)
	else:
		return HttpResponseRedirect("/menu/")
	# error = True
	# errors = []
	if request.POST:
		cf = CommentForm(request.POST)
		if cf.is_valid():
			visitor = cf.cleaned_data['visitor']
			content = cf.cleaned_data['content']
			email = cf.cleaned_data['email']
			date_time = timezone.localtime(timezone.now())
			c = FoodComment.objects.create(
				visitor=visitor,
				email=email,
				content=content,
				date_time=date_time,
				food=f
			)
			cf = CommentForm()
	else:
		cf = CommentForm();
	return render_to_response('foodcomments.html', RequestContext(request, locals()))	
コード例 #7
0
ファイル: views.py プロジェクト: ZhipengJia/djcode
def comment1(request, id):
    if id:
        r = Restaurant.objects.get(id=id)
    else:
        return HttpResponseRedireced("/res/list/")

    errors = []
    if request.POST:
        visitor = request.POST['visitor']
        email = request.POST['email']
        content = request.POST['content']
        date_time = timezone.localtime(timezone.now())
        f = CommentForm(request.POST)
        if f.is_valid():
            visitor = f.cleaned_data['visitor']
            email = f.cleaned_data['email']
            content = f.cleaned_data['content']
            ### 权限验证
            #user = User.objects.get(username=request.user)
            #perm = Permission.objects.get(codename='can_comment')
            #if user.has_perm('restaurants.can_comment'):
            Comment.objects.create(visitor=visitor,
                                   email=email,
                                   content=content,
                                   date_time=date_time,
                                   restaurant=r)
            visitor, email, content = ('', '', '')
            #else:
            #	warm = "您没有权限!"
    else:
        f = CommentForm()
    return render_to_response('comments.html',
                              RequestContext(request, locals()))
コード例 #8
0
ファイル: views.py プロジェクト: ZhipengJia/djcode
def comment1(request, id):
    if id:
        r = Restaurant.objects.get(id=id)
    else:
        return HttpResponseRedireced("/res/list/")

    errors = []
    if request.POST:
        visitor = request.POST["visitor"]
        email = request.POST["email"]
        content = request.POST["content"]
        date_time = timezone.localtime(timezone.now())
        f = CommentForm(request.POST)
        if f.is_valid():
            visitor = f.cleaned_data["visitor"]
            email = f.cleaned_data["email"]
            content = f.cleaned_data["content"]
            ### 权限验证
            # user = User.objects.get(username=request.user)
            # perm = Permission.objects.get(codename='can_comment')
            # if user.has_perm('restaurants.can_comment'):
            Comment.objects.create(visitor=visitor, email=email, content=content, date_time=date_time, restaurant=r)
            visitor, email, content = ("", "", "")
            # else:
            # 	warm = "您没有权限!"
    else:
        f = CommentForm()
    return render_to_response("comments.html", RequestContext(request, locals()))
コード例 #9
0
def comment(request, id):
    if id:
        r = Restaurant.objects.get(id=id)
    else:
        return HttpResponseRedirect("/restaurants_list/")
    errors = []
    if request.POST:
        visitor = request.POST['visitor']
        content = request.POST['content']
        email = request.POST['email']
        date_time = timezone.localtime(timezone.now())  #目前時間
        if any(not request.POST[k] for k in request.POST):
            errors.append('*有空白欄位,請不要留空白')
        if '@' not in email:
            errors.append('* email格式不正確,請重新輸入')
        if not errors:
            Comment.objects.create(visitor=visitor,
                                   email=email,
                                   content=content,
                                   date_time=date_time,
                                   restaurant=r)
            visitor, email, content = ('', '', '')
    f = CommentForm()
    return render_to_response('comments.html',
                              RequestContext(request, locals()))
コード例 #10
0
ファイル: views4.py プロジェクト: ZhipengJia/djcode
def comment1(request,id):
	if id:
		r = Restaurant.objects.get(id=id)
	else:
		return HttpResponseRedireced("/list/")

	errors = []
	if request.POST:
		visitor=request.POST['visitor']
		email=request.POST['email']
		content=request.POST['content']
		date_time=timezone.localtime(timezone.now())
		if any(not request.POST[k] for k in request.POST):
			errors.append('*表单输入不完整,请重新输入。')

		if not '@' in email:
			errors.append('*邮箱格式不正确,请重新输入。')
		if not errors:
			Comment.objects.create(visitor=visitor,
						email=email,
						content=content,
						date_time=date_time,
						restaurant=r	
)
	f = CommentForm()
	return render_to_response('comments.html',RequestContext(request,locals()))
コード例 #11
0
ファイル: views.py プロジェクト: ekils/Uniformity_algorithm
def comment(request,idd):
    if idd:
        r = Restaurant.objects.get(id=idd)
    else:
        return HttpResponseRedirect("/restaurants_list/")

    # errors= []
    print(request.POST)
    if 'ok' in request.POST:
        print('okokok')
        f = CommentForm(request.POST)

        if f.is_valid():
            user = request.POST['user']
            content = request.POST['content']
            email = request.POST['email']
            date_time = datetime.datetime.now()     # 擷取現在時間

            c = Comment.objects.create(user=user, email=email, content=content, date_time=date_time, restaurant=r)
            c.save()
            f = CommentForm()
    else:
        print('not ok , not ok , not ok  ')
        f = CommentForm()
    return render_to_response('comments.html',locals())
コード例 #12
0
def comment(request, idx):
    if idx:
        rs = Restaurant.objects.get(id=idx)
        # get the selected restaurants! by the index of idx!
    else:
        return HttpResponseRedirect('/restaurants_list/')
    if 'ok' in request.POST:  # if sb submit the data.
        fm = CommentForm(request.POST)
        if fm.is_valid():
            user = request.POST['user']
            email = request.POST['email']
            content = request.POST['content']
            Comment.objects.create(content=content,
                                   user=user,
                                   email=email,
                                   date_time=datetime.now(),
                                   restaurant=rs)
            # 填寫完畢之後要清除CommentForm
            fm = CommentForm(initial={'content': '我沒意見'})
    else:
        #若沒有填寫,要清空CommentForm
        fm = CommentForm(initial={'content': '我沒意見'})
        # if not user or not content or not email:
        # 	errors.append('請填寫所有空格')
        # if '@' not in email:
        # 	errors.append('請輸入email')
        # if not errors:
        # 	Comment.objects.create(content=content, user=user, email=email, date_time=datetime.now(), restaurant=rs)
        # 	user=''
        # 	email=''
        # 	content=''
    return render(request, 'comment.html', locals())
コード例 #13
0
def restaurant_detail_view(request, pk):
    if request.method == "POST":
        form = CommentForm(request.POST)
        restaurant = get_object_or_404(Restaurant, pk=pk)
        if form.is_valid():
            comment = form.save(commit=False)
            comment.author = request.user
            comment.restaurant = restaurant
            comment.save()
            return redirect('restaurants:detail:restaurant-detail', pk=pk)
    if request.method == "GET":
        restaurant = get_object_or_404(Restaurant, pk=pk)
        comment_list = Comment.objects.filter(restaurant=restaurant)
        form = CommentForm
        ctx = {
            "restaurant": restaurant,
            "comment_list": comment_list,
            "form": form,
        }
        return render(request, 'restaurant/detail.html', ctx)
    else:
        raise Http404
コード例 #14
0
ファイル: views.py プロジェクト: dwatow/mysite
def comment(request,id):
    if id:
        r = Restaurant.objects.get(id=id)
    else:
        return HttpResponseRedirect("/restaurants_list/")

    if request.user.is_authenticated and request.user.has_perm('restaurants.can_comment'):
        errors = []
        if 'ok' in request.POST:
            f = CommentForm(request.POST)
            if f.is_valid():
                user = request.POST['user']
                content = request.POST['content']
                email = request.POST['email']
                date_time = datetime.datetime.now()
                c = Comment(user=user, email=email, content=content, date_time=date_time, restaurant=r)
                c.save()
                f = CommentForm()
        else:
            f = CommentForm()
    else:
        return HttpReponseRedirect('/restaurants_list/')
        
    return render_to_response('comments.html',locals())
コード例 #15
0
def comment(request, request_id):

    if request_id:
        r = Restaurant.objects.get(id=request_id)
    else:
        return HttpResponseRedirect('/restaurants_list/')
    if request.POST:
        visitor = request.POST['visitor']
        content = request.POST['content']
        email = request.POST['email']
        date_time = timezone.localtime(timezone.now())
        Comment.objects.create(visitor=visitor, content=content, email=email, date_time=date_time, restaurant=r)
        visitor, email, content = ('','','')
        form = CommentForm()
    return render(request, 'comments.html', locals())
コード例 #16
0
ファイル: views.py プロジェクト: Yapoyang/itri_cloud
def comment(request, id):
    if id:
        r = Restaurant.objects.get(id=id)
    else:
        return HttpResponseRedirect("/restaurants_list/")
    if request.POST:
        f = CommentForm(request.POST)
        if f.is_valid():
            visitor = f.cleaned_data['visitor']
            content = f.cleaned_data['content']
            email = f.cleaned_data['email']
            date_time = timezone.localtime(timezone.now())
            c = Comment.objects.create(visitor=visitor,
                                       email=email,
                                       content=content,
                                       date_time=date_time,
                                       restaurant=r)
            f = CommentForm(initial={'content': 'No comment'})
    else:
        f = CommentForm(initial={'content': 'No comment'})
    return render_to_response('comments.html', locals())
コード例 #17
0
def foodcomment(request, id):
    if id:
        f = Food.objects.get(id=id)
    else:
        return HttpResponseRedirect("/menu/")
    # error = True
    # errors = []
    if request.POST:
        cf = CommentForm(request.POST)
        if cf.is_valid():
            visitor = cf.cleaned_data['visitor']
            content = cf.cleaned_data['content']
            email = cf.cleaned_data['email']
            date_time = timezone.localtime(timezone.now())
            c = FoodComment.objects.create(visitor=visitor,
                                           email=email,
                                           content=content,
                                           date_time=date_time,
                                           food=f)
            cf = CommentForm()
    else:
        cf = CommentForm()
    return render_to_response('foodcomments.html',
                              RequestContext(request, locals()))
コード例 #18
0
ファイル: views.py プロジェクト: WinSon-XiaoYin/django-learn
def comment(request, id):
    if id:
        r = Restaurant.objects.get(id=id)
        user = request.user
    else:
        return HttpResponseRedirect('/restaurants_list')
    if request.POST:
        f = CommentForm(request.POST)
        if f.is_valid():
            visitor = request.POST['visitor']
            content = request.POST['content']
            email = request.POST['email']
            date_time = timezone.localtime(timezone.now())

            c = Comment.objects.create(visitor=visitor,
                                       email=email,
                                       content=content,
                                       date_time=date_time,
                                       restaurant=r)
            f = CommentForm(initial={'content': '我没意见'})
    else:
        f = CommentForm(initial={'content': '我没意见'})
    return render_to_response('comments.html',
                              RequestContext(request, locals()))