コード例 #1
0
def replyCreate_view(request):
    if request.method == "POST":
        parent_obj = None
        try:
            account = Account.objects.get(user=request.user)
            parent_id = int(request.POST.get('parent_id'))
            content = request.POST.get('reply')
            post = Post.objects.get(slug=request.POST.get('post_slug'))
        except:
            parent_id = None

        if parent_id:
            parent_obj = Comment.objects.get(id=parent_id)
            if parent_obj:
                reply_comment = Comment()
                reply_comment.account = account
                reply_comment.post = post
                reply_comment.content = content
                reply_comment.parent = parent_obj
                reply_comment.save()
                post.comments += 1
                post.save()
                # notify to the comment owner
                if parent_obj.account != reply_comment.account:
                    content = reply_comment.account.user.first_name + ' ' + reply_comment.account.user.last_name + ' replied to your comment "' + reply_comment.content[:
                                                                                                                                                                        20] + '"'
                    notf = Notification()
                    notf.account = parent_obj.account
                    notf.post = post
                    notf.content = content
                    notf.save()

                # notify others who also replied to the comment avoiding repeatation...
                marked = []
                replies = parent_obj.replies.all()
                for replied in replies:
                    if replied.account.user.email not in marked:
                        if reply_comment.account != replied.account and parent_obj.account != replied.account:  # don't notify the replier him/her-self
                            content = reply_comment.account.user.first_name + ' ' + reply_comment.account.user.last_name + ' also replied on ' + parent_obj.account.user.first_name + "'s comment " + '"' + reply_comment.content[:
                                                                                                                                                                                                                                  20] + '"'
                            notf = Notification()
                            notf.account = replied.account
                            notf.post = post
                            notf.content = content
                            notf.save()
                            marked.append(replied.account.user.email)
        return HttpResponseRedirect(post.get_absolute_url)
    return HttpResponseRedirect('/posts/')
コード例 #2
0
ファイル: views.py プロジェクト: babu12f/restaurants
def updateStatus_view(request, order_id):
	if not request.user.is_staff or not request.user.is_superuser or request.method != "POST":
		return HttpResponseRedirect('/404notfound/')
	try:
		order = Order.objects.get(order_id=order_id)
		if order.status == True:
			order.status = False
			notf = "Order #" + str(order.order_no) + " is pending."
		elif order.status == False:
			order.status = True
			notf = "Order #" + str(order.order_no) + " is accepted."
		order.save()
	except:
		messages.success(request, "Couldn't change status.")
		pass

	# SEND NOTIFICATION
	if order.account != None:
		notification 		 = Notification()
		notification.account = order.account
		notification.content = notf
		notification.link    = '/orders/' + order.order_id + '/'
		notification.save()
	
	return HttpResponseRedirect('/orders/management/')
コード例 #3
0
def newOrder_view(request):
    template_name = 'orders/confirmed-page.html'
    if request.method == "POST":
        cartKey = request.POST['cart']
        phone = request.POST['cell']
        order_type = request.POST['orderType']
        account = None
        if request.user.is_authenticated:
            account = Account.objects.get(user=request.user)
        else:
            qs = Account.objects.filter(phone=phone).exists()
            if qs:
                account = Account.objects.get(phone=phone)
        order = Order()
        order.account = account
        try:
            cart = Cart.objects.get(key=cartKey)
            cart.is_active = True
            cart.save()
            order.cart = cart
        except:
            messages.warning(request,
                             "Order request failed! Please try again.")
            return HttpResponseRedirect('/restaurants/' +
                                        cart.restaurant.slug + '/')
        _discount = 0.00
        try:
            dObj = Discount.objects.get(key=request.POST['promoCode'])
            if dObj.used == False:
                _discount = int(
                    float(cart.subtotal * dObj.percentage) / 100.00)
                dObj.used = True
                dObj.save()
        except:
            pass
        order.name = request.POST['name']
        order.phone = phone
        order.shipping_address = request.POST['location']
        order.order_type = order_type
        order.payment_method = request.POST['paymentMethod']
        order.expected_time = request.POST['time']

        if order_type == 'home':
            order.cost = cart.total - _discount + 30.00  # Shipping cost
        else:
            order.cost = cart.total - _discount
        order.discount = _discount
        order.save()
        # SEND NOTIFICATION
        if account != None:
            notification = Notification()
            notification.account = account
            notification.content = "You order <span class='font-weight-bold'>#" + str(
                order.order_no
            ) + "</span> has been added. We will confirm it in minutes."
            notification.link = '/orders/' + order.order_id + '/'
            notification.save()
        return HttpResponseRedirect('/orders/' + order.order_id + '/')
    messages.warning(request, "Something went wrong. Please try again.")
    return HttpResponseRedirect('/restaurants/' + cart.restaurant.slug + '/')
コード例 #4
0
ファイル: views.py プロジェクト: rk4bir/friends
def like_view(request, slug):
    if request.method == "POST":
        post = Post.objects.get(slug=slug)
        account = Account.objects.get(user=request.user)
        qs = Like.objects.filter(post=post).filter(account=account)
        if not qs.exists():
            like = Like()
            like.account = account
            like.post = post
            like.save()
            post.likes += 1
            post.save()
            if like.account != post.account:
                notf = Notification()
                notf.account = post.account
                notf.post = post
                content = like.account.user.first_name + ' ' + like.account.user.last_name + ' liked  your post.'
                notf.content = content
                notf.save()
        else:
            like = Like.objects.get(post=post, account=account)
            like.delete()
            post.likes -= 1
            post.save()
        return HttpResponseRedirect(post.get_absolute_url)
    return HttpResponseRedirect('/posts/')
コード例 #5
0
ファイル: models.py プロジェクト: wangjiaji/heartbeat
def update_comment_list(sender, instance, created, **kwargs):
    if created:
        if instance.beat.creator.notify_comment:
            note = Notification()
            note.sender = instance.creator
            note.recipient = instance.beat.creator
            note.note_type = 1
            note.content = instance.text[:20]
            note.subject_id = instance.beat_id
            note.save()
        redis_push_list('Beat', instance.beat_id, 'comments', instance.id)
コード例 #6
0
def create_view(request):
    if request.method == "POST":
        try:
            post = Post.objects.get(slug=request.POST.get('slug'))
            account = Account.objects.get(user=request.user)
            content = request.POST.get('comment')
        except:
            return HttpResponseRedirect('/posts/')
        comment = Comment()
        comment.account = account
        comment.post = post
        comment.content = content
        comment.save()
        post.comments += 1
        post.save()

        # notify the owner of the post
        if post.account != comment.account:
            notf = Notification()
            notf.account = post.account
            notf.post = post
            content = comment.account.user.first_name + ' ' + comment.account.user.last_name + ' commented on your post "' + comment.content[:
                                                                                                                                             20] + '"'
            notf.content = content
            notf.save()
        commented_all = Comment.objects.all().filter(post=post)
        marked = []
        # notify others who also commented
        for commented in commented_all:
            if commented.account.user.email not in marked:
                if comment.account != post.account and comment.account != commented.account and commented.account != post.account:
                    notf = Notification()
                    notf.account = commented.account
                    notf.post = post
                    content = comment.account.user.first_name + ' ' + comment.account.user.last_name + ' also commented ' + post.account.user.first_name + "'s post " + '"' + comment.content[:
                                                                                                                                                                                              20] + '"'
                    notf.content = content
                    notf.save()
                    marked.append(commented.account.user.email)
        return HttpResponseRedirect(post.get_absolute_url)
    return HttpResponseRedirect('/posts/')
コード例 #7
0
ファイル: views.py プロジェクト: babu12f/restaurants
def DeleteOrder_view(request, order_id):
	if not request.user.is_staff or not request.user.is_superuser or request.method != "POST":
		return HttpResponseRedirect('/404notfound/')
	try:
		order = Order.objects.get(order_id=order_id)
		# SEND NOTIFICATION
		if order.account != None:
			notification 		 = Notification()
			notification.account = order.account
			notification.content = "Order #" + str(order.order_no) + " has been deleted."
			notification.link    = '/orders/' + order.order_id + '/'
			notification.save()
		order.delete()
	except:
		messages.success(request, "Couldn't change status.")
		pass

	return HttpResponseRedirect('/orders/management/')