def detail(request, poll_id):
    p = get_object_or_404(Poll.published.all(), pk=poll_id)
    debug(p)

    if request.method == 'POST':
        form = PollForm(request.POST, instance=p)

        if form.is_valid():
            form.save()
            return HttpResponseRedirect(reverse('polls_results', kwargs={'poll_id': p.id}))
    else:
        form = PollForm(instance=p)

    return render_to_response('polls/detail.html', {
        'poll': p,
        'form': form,
    }, context_instance=RequestContext(request))
Example #2
0
    def post(self, request, username, format=None):

        consumer = User.objects.get(
            id=request.DATA['user']
            [:])  # the user who this transaction is meant for
        vendor = self.get_object(
            username=username)  # The user that is logged in

        if consumer != vendor:

            if request.DATA['debit_credit'] == "DEBIT":

                amount = int(request.DATA['amount'][:])

                if amount <= consumer.acct_balance:

                    # Amount is subtracted (debited) from consumer
                    new_balance = consumer.acct_balance - amount
                    consumer.acct_balance = new_balance

                    # Amount is added (credited) to vendor
                    new_balance = vendor.acct_balance + amount
                    vendor.acct_balance = new_balance

                    # Make an entry of the debit transaction
                    serializer = TransactionsSerializer(data=request.DATA)
                    debug(serializer.data)
                    if serializer.is_valid():
                        consumer.save()
                        vendor.save()
                        serializer.save()
                        return Response(serializer.data,
                                        status=status.HTTP_201_CREATED)
                    else:
                        return Response(serializer.errors,
                                        status=status.HTTP_206_PARTIAL_CONTENT)

                else:
                    return Response(status=status.HTTP_400_BAD_REQUEST)
        else:
            return Response(status=status.HTTP_400_BAD_REQUEST)
Example #3
0
	def post(self, request, username, format=None):
		
		consumer = User.objects.get(id=request.DATA['user'][:]) # the user who this transaction is meant for
		vendor = self.get_object(username=username) # The user that is logged in
		
		if consumer != vendor:
		
			if request.DATA['debit_credit'] == "DEBIT":
			
				amount = int(request.DATA['amount'][:])
			
				if amount <= consumer.acct_balance:
				
					# Amount is subtracted (debited) from consumer
					new_balance = consumer.acct_balance - amount
					consumer.acct_balance = new_balance
					
					
					# Amount is added (credited) to vendor
					new_balance = vendor.acct_balance + amount
					vendor.acct_balance = new_balance
					
					# Make an entry of the debit transaction
					serializer = TransactionsSerializer(data=request.DATA)
					debug(serializer.data)
					if serializer.is_valid():
						consumer.save()
						vendor.save()
						serializer.save()
						return Response(serializer.data, status=status.HTTP_201_CREATED)
					else:
						return Response(serializer.errors, status=status.HTTP_206_PARTIAL_CONTENT)
					
				else:
					return Response(status=status.HTTP_400_BAD_REQUEST)
		else:
				return Response(status=status.HTTP_400_BAD_REQUEST)
def index(request):
    latest_poll_list = Poll.published.all().order_by('-pub_date')[:5]
    debug(latest_poll_list, console=True)
    return render_to_response('polls/index.html', {'latest_poll_list': latest_poll_list})
Example #5
0
	def get_ip(self):
		debug(self.request)
		return self.request.META['REMOTE_ADDR']