gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] [taler-codeless] branch master updated: added comments and


From: gnunet
Subject: [GNUnet-SVN] [taler-codeless] branch master updated: added comments and pep8 coding style
Date: Mon, 16 Jul 2018 16:01:39 +0200

This is an automated email from the git hooks/post-receive script.

shivam-kohli pushed a commit to branch master
in repository codeless.

The following commit(s) were added to refs/heads/master by this push:
     new 6445ed8  added comments and pep8 coding style
6445ed8 is described below

commit 6445ed8e1ceaf170315187635cf7df86e179b179
Author: shivam kohli <address@hidden>
AuthorDate: Mon Jul 16 19:30:29 2018 +0530

    added comments and pep8 coding style
---
 inventory/views.py | 75 +++++++++++++++++++++++++++++++++++++++++-------------
 1 file changed, 57 insertions(+), 18 deletions(-)

diff --git a/inventory/views.py b/inventory/views.py
index 88f7199..1896f4c 100644
--- a/inventory/views.py
+++ b/inventory/views.py
@@ -4,17 +4,17 @@
 
 # This file is part of the Taler Codeless Merchant.
 # (C) 2018 GNUnet e.V.
-# 
+#
 # The Taler Codeless Merchant is free software: you can redistribute it and/or
 # modify it under the terms of the GNU Affero General Public License as 
published
 # by the Free Software Foundation, either version 3 of the License, or (at your
 # option) any later version.
-# 
+#
 # The Taler Codeless Merchant is distributed in the hope that it will be 
useful,
 # but WITHOUT ANY WARRANTY; without even the implied warranty of 
MERCHANTABILITY
 # or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public 
License
 # for more details.
-# 
+#
 # You should have received a copy of the GNU Affero General Public License 
along
 # with the Taler Codeless Merchant.  If not, see 
<https://www.gnu.org/licenses/>.
 #
@@ -39,7 +39,15 @@ import json
 from django.http import JsonResponse
 
 
+BACKEND_URL = "https://backend.demo.taler.net/";
+
+
 def fulfillment(request):
+    """ This function is responsible for redirecting to a
+    page after successfully payment is done.
+    For digital Inventory is displays the required document
+    on payment completion.
+    """
     order_id = request.GET.get('order_id')
     if order_id is None:
         return HttpResponse("Error while loading the page")
@@ -48,7 +56,8 @@ def fulfillment(request):
     for item in range(len(product)):
         if product[item].document:
             filename = product[item].document.file.name.split('/')[-1]
-            response = HttpResponse(product[item].document.file, 
content_type='application/pdf')
+            file = product[item].document.file
+            response = HttpResponse(file, content_type='application/pdf')
             response['Content-Disposition'] = 'inline; filename=%s' % filename
             return response
         else:
@@ -56,6 +65,8 @@ def fulfillment(request):
 
 
 def shipment(request):
+    """ Function to redirect to the shipment detail form
+    """
     context_dict = {}
     name = request.GET.get('name')
     price = request.GET.get('price')
@@ -68,6 +79,9 @@ def shipment(request):
 
 @login_required
 def order(request):
+    """ To display all the purchases made by the merchant this function
+    is invoked.
+    """
     user_instance = User.objects.get(username=request.user.username)
     order = Order.objects.filter(merchant=user_instance)
     context_dict = {}
@@ -92,6 +106,12 @@ def order(request):
 
 @csrf_exempt
 def pay(request):
+    """ The function is invoked by the wallet. In this function
+    the csrf token in exemted.
+    For proper inventory tracking this function is responsible
+    to update the inventory only after the successfull payment
+    completion.
+    """
     if request.method == 'POST':
         body_unicode = request.body.decode('utf-8')
         json_data = json.loads(body_unicode)
@@ -103,27 +123,36 @@ def pay(request):
         if r.status_code != 200:
             return HttpResponse(r.status_code)
         contract_terms = r.json()["contract_terms"]
+        merchant = contract_terms["merchant"]["name"]
         order_instance = Order.objects.create(
             order_id=contract_terms["order_id"],
             summary=contract_terms["summary"],
-            
merchant=User.objects.get(username=contract_terms["merchant"]["name"])
+            merchant=User.objects.get(username=merchant)
             )
         order_instance.save()
         for i in contract_terms['products']:
             product_instance = Product.objects.get(name=i["description"])
             order_instance.product_id.add(product_instance)
             order_instance.save()
-            update_inventory(i["description"],i["quantity"])
+            update_inventory(i["description"], i["quantity"])
         return JsonResponse(r.json())
 
 
 def payment(request):
+    """ This function is called when the user has submitted
+    the shipment details. The order for the required product
+    is made and a post request is send for creation of the
+    order. On the basis of this a required order_id is returned
+    which is used to send a get request and check the status of
+    the order. On the basis of this the user is redirected to the
+    payment page.
+    """
     session_id = request.session.session_key
     name = request.GET.get('name')
     price = request.GET.get('price')
     merchant = request.GET.get('merchant')
-    name_user = request.GET.get('name_user')
-    address_user = request.GET.get('address_user')
+    # name_user = request.GET.get('name_user')
+    # address_user = request.GET.get('address_user')
     summary = name+' purchased from '+merchant
     user = User.objects.get(username=merchant)
     primary_key = user.pk
@@ -175,7 +204,7 @@ def payment(request):
 def backend_get(endpoint, params):
     headers = {"Authorization": "ApiKey sandbox"}
     try:
-        resp = requests.get(urljoin("https://backend.demo.taler.net/";, 
endpoint),
+        resp = requests.get(urljoin(BACKEND_URL, endpoint),
             params=params,
             headers=headers)
     except requests.ConnectionError:
@@ -190,7 +219,7 @@ def backend_get(endpoint, params):
 def backend_post(endpoint, json):
     headers = {"Authorization": "ApiKey sandbox"}
     try:
-        resp_url = urljoin("https://backend.demo.taler.net/";, endpoint)
+        resp_url = urljoin(BACKEND_URL, endpoint)
         resp = requests.post(resp_url,
             json=json,
             headers=headers)
@@ -212,6 +241,9 @@ def update_inventory(name, quantity):
 
 @login_required
 def home(request):
+    """ Home page for the merchant where he can add
+    and view all his inventory.
+    """
     user_instance = User.objects.get(username=request.user.username)
     product = Product.objects.filter(user=user_instance)
     context_dict = {}
@@ -246,6 +278,9 @@ def update_stock(request, uid):
 
 @login_required
 def add_product(request):
+    """ When a merchant is required to add a new product in his
+    inventory this function is invoked.
+    """
     name = request.POST.get('name')
     product_instance = Product.objects.get_or_create(name=name)[0]
     description = request.POST.get('description')
@@ -257,7 +292,8 @@ def add_product(request):
     product_instance.inventory_on_hand = starting_inventory
     minimum_required = request.POST.get('minimum_required')
     product_instance.minimum_required = minimum_required
-    user_instance = User.objects.get(username=request.user.username)
+    current_merchant = request.user.username
+    user_instance = User.objects.get(username=current_merchant)
     product_instance.user = user_instance
     product_instance.save()
     product = Product.objects.filter(user=user_instance)
@@ -277,17 +313,20 @@ def add_product(request):
 
 @login_required
 def product(request, uid):
-    product = Product.objects.get_or_create(product_id=uid)[0]
+    """ The product display page for the Mercheant.
+    The required product details are included in this page.
+    """
+    item = Product.objects.get_or_create(product_id=uid)[0]
     context_dict = {}
-    context_dict['name'] = product.name
-    context_dict['description'] = product.description
-    context_dict['price'] = product.price
-    context_dict['inventory_on_hand'] = product.inventory_on_hand
-    url_update_inventory = str('/update_stock/') + product.name
+    context_dict['name'] = item.name
+    context_dict['description'] = item.description
+    context_dict['price'] = item.price
+    context_dict['inventory_on_hand'] = item.inventory_on_hand
+    url_update_inventory = str('/update_stock/') + item.name
     context_dict['url_update_inventory'] = url_update_inventory
     base_url = request.build_absolute_uri().rsplit('/', 3)[0]
     merchant = request.user.username
-    parameters = 
"name="+product.name+'&price='+product.price+'&merchant='+merchant
+    parameters = "name="+item.name+'&price='+item.price+'&merchant='+merchant
     context_dict['href'] = base_url+"/shipment?"+parameters
     return render(request, 'inventory/product.html', context_dict)
 

-- 
To stop receiving notification emails like this one, please contact
address@hidden



reply via email to

[Prev in Thread] Current Thread [Next in Thread]