diff options
author | shivam kohli <kohlishivam5522@gmail.com> | 2018-07-05 04:43:22 +0530 |
---|---|---|
committer | shivam kohli <kohlishivam5522@gmail.com> | 2018-07-05 04:43:22 +0530 |
commit | 1cfc3be3bc7d089f2e01f6e4546476efd455f601 (patch) | |
tree | 5785e9ad96ccecfcc6a38983dee511ed6b791578 /inventory | |
parent | cd3fdd5d00fe2ce4b49a5cf3577fc7886e2fbf31 (diff) | |
download | codeless-1cfc3be3bc7d089f2e01f6e4546476efd455f601.tar.gz codeless-1cfc3be3bc7d089f2e01f6e4546476efd455f601.tar.bz2 codeless-1cfc3be3bc7d089f2e01f6e4546476efd455f601.zip |
added licence header and digital inventory
Diffstat (limited to 'inventory')
-rw-r--r-- | inventory/forms.py | 27 | ||||
-rw-r--r-- | inventory/migrations/0001_initial.py | 62 | ||||
-rw-r--r-- | inventory/migrations/0002_auto_20180607_1714.py | 29 | ||||
-rw-r--r-- | inventory/models.py | 20 | ||||
-rw-r--r-- | inventory/views.py | 45 |
5 files changed, 123 insertions, 60 deletions
diff --git a/inventory/forms.py b/inventory/forms.py index 2d32f5a..dd77769 100644 --- a/inventory/forms.py +++ b/inventory/forms.py @@ -1,10 +1,29 @@ #!/usr/bin/env python3 # -*- coding: utf-8 -*- +# 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/>. +# +# @author Shivam Kohli + + from django import forms from django.contrib.auth.forms import UserCreationForm from django.contrib.auth.models import User -from inventory.models import Merchant +from inventory.models import Merchant, Product class SignUpForm(UserCreationForm): @@ -37,3 +56,9 @@ class LoginForm(forms.ModelForm): "username", "password" ) + + +class DocumentForm(forms.ModelForm): + class Meta: + model = Product + fields = ('name', 'price', 'description', 'document', ) diff --git a/inventory/migrations/0001_initial.py b/inventory/migrations/0001_initial.py index 88a7471..c09fa98 100644 --- a/inventory/migrations/0001_initial.py +++ b/inventory/migrations/0001_initial.py @@ -15,64 +15,70 @@ class Migration(migrations.Migration): migrations.CreateModel( name='Merchant', fields=[ - ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)), + ('id', models.AutoField(verbose_name='ID', primary_key=True, serialize=False, auto_created=True)), ('address', models.TextField()), - ('pay_url', models.URLField(default=b'NULL', max_length=250)), + ('pay_url', models.URLField(max_length=250, default='NULL')), ('user', models.OneToOneField(to=settings.AUTH_USER_MODEL)), ], ), migrations.CreateModel( name='Order', fields=[ - ('order_id', models.AutoField(serialize=False, primary_key=True)), - ('description', models.CharField(max_length=300, null=True, blank=True)), + ('order_id', models.AutoField(primary_key=True, serialize=False)), + ('description', models.CharField(max_length=300, blank=True, null=True)), ('order_date', models.DateTimeField(auto_now=True)), - ('address', models.CharField(max_length=250, null=True, blank=True)), - ('fulfillment_url', models.URLField(default=b'NULL')), + ('address', models.CharField(max_length=250, blank=True, null=True)), + ('fulfillment_url', models.URLField(default='NULL')), ], ), migrations.CreateModel( name='PaymentButton', fields=[ - ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)), - ('text', models.CharField(max_length=100, null=True, blank=True)), - ('font_size', models.CharField(max_length=50, null=True, blank=True)), - ('color', models.CharField(max_length=50, null=True, blank=True)), - ('background_color', models.CharField(max_length=50, null=True, blank=True)), - ('border_radius', models.CharField(max_length=50, null=True, blank=True)), + ('id', models.AutoField(verbose_name='ID', primary_key=True, serialize=False, auto_created=True)), + ('text', models.CharField(max_length=100, blank=True, null=True)), + ('font_size', models.CharField(max_length=50, blank=True, null=True)), + ('color', models.CharField(max_length=50, blank=True, null=True)), + ('background_color', models.CharField(max_length=50, blank=True, null=True)), + ('border_radius', models.CharField(max_length=50, blank=True, null=True)), ], ), migrations.CreateModel( name='Product', fields=[ - ('product_id', models.AutoField(serialize=False, primary_key=True)), - ('name', models.CharField(max_length=50, null=True, blank=True)), - ('description', models.CharField(max_length=300, null=True, blank=True)), - ('price', models.CharField(max_length=50, null=True, blank=True)), + ('product_id', models.AutoField(primary_key=True, serialize=False)), + ('name', models.CharField(max_length=50, blank=True, null=True)), + ('description', models.CharField(max_length=300, blank=True, null=True)), + ('price', models.CharField(max_length=50, blank=True, null=True)), ('delivery_date', models.DateTimeField(auto_now=True)), - ('starting_inventory', models.IntegerField(null=True, blank=True)), - ('minimum_required', models.IntegerField(null=True, blank=True)), - ('inventory_on_hand', models.IntegerField(null=True, blank=True)), - ('inventory_recieved', models.IntegerField(null=True, blank=True)), - ('inventory_shipped', models.IntegerField(null=True, blank=True)), - ('user', models.ForeignKey(to=settings.AUTH_USER_MODEL, null=True)), + ('starting_inventory', models.IntegerField(blank=True, null=True)), + ('minimum_required', models.IntegerField(blank=True, null=True)), + ('inventory_on_hand', models.IntegerField(blank=True, null=True)), + ('inventory_recieved', models.IntegerField(blank=True, null=True)), + ('inventory_shipped', models.IntegerField(blank=True, null=True)), + ('document', models.FileField(upload_to='document/')), + ('user', models.ForeignKey(null=True, to=settings.AUTH_USER_MODEL)), ], ), migrations.CreateModel( name='Purchase', fields=[ - ('purchase_id', models.AutoField(serialize=False, primary_key=True)), - ('description', models.CharField(max_length=300, null=True, blank=True)), + ('purchase_id', models.AutoField(primary_key=True, serialize=False)), + ('description', models.CharField(max_length=300, blank=True, null=True)), ('purchase_date', models.DateTimeField(auto_now=True)), - ('product_recieved', models.IntegerField(null=True, blank=True)), - ('supplier', models.CharField(max_length=50, null=True, blank=True)), - ('product_id', models.ManyToManyField(to='inventory.Product', null=True)), + ('product_recieved', models.IntegerField(blank=True, null=True)), + ('supplier', models.CharField(max_length=50, blank=True, null=True)), + ('product_id', models.ManyToManyField(null=True, to='inventory.Product')), ], ), migrations.AddField( + model_name='paymentbutton', + name='product', + field=models.ForeignKey(null=True, to='inventory.Product'), + ), + migrations.AddField( model_name='order', name='product_id', - field=models.ManyToManyField(to='inventory.Product', null=True), + field=models.ManyToManyField(null=True, to='inventory.Product'), ), migrations.AddField( model_name='order', diff --git a/inventory/migrations/0002_auto_20180607_1714.py b/inventory/migrations/0002_auto_20180607_1714.py deleted file mode 100644 index 600d07c..0000000 --- a/inventory/migrations/0002_auto_20180607_1714.py +++ /dev/null @@ -1,29 +0,0 @@ -# -*- coding: utf-8 -*- -from __future__ import unicode_literals - -from django.db import models, migrations - - -class Migration(migrations.Migration): - - dependencies = [ - ('inventory', '0001_initial'), - ] - - operations = [ - migrations.AddField( - model_name='paymentbutton', - name='product', - field=models.ForeignKey(null=True, to='inventory.Product'), - ), - migrations.AlterField( - model_name='merchant', - name='pay_url', - field=models.URLField(max_length=250, default='NULL'), - ), - migrations.AlterField( - model_name='order', - name='fulfillment_url', - field=models.URLField(default='NULL'), - ), - ] diff --git a/inventory/models.py b/inventory/models.py index aa8b848..6319f10 100644 --- a/inventory/models.py +++ b/inventory/models.py @@ -1,6 +1,25 @@ #!/usr/bin/env python3 # -*- coding: utf-8 -*- +# 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/>. +# +# @author Shivam Kohli + + from django.db import models from django.contrib.auth.models import User from django.db.models.signals import post_save @@ -35,6 +54,7 @@ class Product(models.Model): inventory_recieved = models.IntegerField(blank=True, null=True) inventory_shipped = models.IntegerField(blank=True, null=True) user = models.ForeignKey(User, on_delete=models.CASCADE, null=True) + document = models.FileField(upload_to='document/') def __str__(self): return self.name diff --git a/inventory/views.py b/inventory/views.py index a5919fc..93e7cd8 100644 --- a/inventory/views.py +++ b/inventory/views.py @@ -1,7 +1,27 @@ #!/usr/bin/env python3 # -*- coding: utf-8 -*- -from inventory.forms import SignUpForm, MerchantDetailForm, LoginForm + +# 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/>. +# +# @author Shivam Kohli + + +from inventory.forms import SignUpForm, MerchantDetailForm, LoginForm, DocumentForm from inventory.models import Merchant, Product from django.contrib.auth.models import User from django.contrib.auth import authenticate @@ -210,7 +230,28 @@ def customize_payment_button(request): @login_required def new_product(request): - return render(request, 'inventory/new_product.html') + if request.method == 'POST': + form = DocumentForm(request.POST, request.FILES) + if form.is_valid(): + user_instance = User.objects.get(username=request.user.username) + Product.objects.create( + name=form.cleaned_data['name'], + description=form.cleaned_data['description'], + price=form.cleaned_data['price'], + starting_inventory=0, + minimum_required=0, + inventory_on_hand=0, + inventory_recieved=0, + inventory_shipped=0, + user=user_instance, + document=form.cleaned_data['document'] + ) + return redirect('home') + else: + form = DocumentForm() + return render(request, 'inventory/new_product.html', { + 'form': form + }) def signup(request): |