From 94833b4ab499d45698a8cf4d671dd5e14e74f643 Mon Sep 17 00:00:00 2001 From: kaezon Date: Sun, 17 Apr 2016 01:00:53 -0400 Subject: [PATCH] Reorganization Because the app should have more independence from the project. --- rapid_sales_tool/migrations/0001_initial.py | 41 ++++++++++++++++ rapid_sales_tool/migrations/__init__.py | 0 .../static/rapid_sales_tool/js/orders.js | 27 +++++++++++ .../static/rapid_sales_tool/js/stock.js | 47 +++++++++++++++++++ .../templates/rapid_sales_tool}/orders.html | 0 .../templates/rapid_sales_tool}/stock.html | 0 rapid_sales_tool/views.py | 4 +- 7 files changed, 117 insertions(+), 2 deletions(-) create mode 100644 rapid_sales_tool/migrations/0001_initial.py create mode 100644 rapid_sales_tool/migrations/__init__.py create mode 100644 rapid_sales_tool/static/rapid_sales_tool/js/orders.js create mode 100644 rapid_sales_tool/static/rapid_sales_tool/js/stock.js rename {templates/public => rapid_sales_tool/templates/rapid_sales_tool}/orders.html (100%) rename {templates/public => rapid_sales_tool/templates/rapid_sales_tool}/stock.html (100%) diff --git a/rapid_sales_tool/migrations/0001_initial.py b/rapid_sales_tool/migrations/0001_initial.py new file mode 100644 index 0000000..c883b5f --- /dev/null +++ b/rapid_sales_tool/migrations/0001_initial.py @@ -0,0 +1,41 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.9.3 on 2016-04-17 02:31 +from __future__ import unicode_literals + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + ] + + operations = [ + migrations.CreateModel( + name='Order', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('customer_name', models.CharField(max_length=64)), + ('item_quantity', models.PositiveIntegerField()), + ('order_price', models.DecimalField(decimal_places=2, max_digits=17)), + ('is_paid', models.BooleanField()), + ], + ), + migrations.CreateModel( + name='StockItem', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('item_name', models.CharField(max_length=255)), + ('item_count', models.PositiveIntegerField()), + ('unit_cost', models.DecimalField(decimal_places=2, max_digits=17)), + ], + ), + migrations.AddField( + model_name='order', + name='item', + field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='rapid_sales_tool.StockItem'), + ), + ] diff --git a/rapid_sales_tool/migrations/__init__.py b/rapid_sales_tool/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/rapid_sales_tool/static/rapid_sales_tool/js/orders.js b/rapid_sales_tool/static/rapid_sales_tool/js/orders.js new file mode 100644 index 0000000..f2f55fa --- /dev/null +++ b/rapid_sales_tool/static/rapid_sales_tool/js/orders.js @@ -0,0 +1,27 @@ +var orderModal = $('#newOrderModal') +var orderForm = $('#orderForm'); +$( document ).ready( + orderForm.submit(function() { + orderModal.find(".modalResponse").first().empty().attr('class','modalResponse'); + $.ajax({ + type: orderForm.attr('method'), + url: orderForm.attr('action'), + data: orderForm.serialize(), + success: function(data) { + orderModal.modal('hide'); + location.reload(); + }, + error: function(data) { + orderModal.find(".modalResponse").first().empty().append('×'); + orderModal.find(".modalResponse").first().append(data.responseText); + orderModal.find(".modalResponse").first().addClass("alert alert-danger fade in"); + } + }); + return false; + }), + $(".modal").each( function() { + $(this).on('hidden.bs.modal', function () { + $(this).find(".modalResponse").first().empty().attr('class','modalResponse'); + }) + }) +); \ No newline at end of file diff --git a/rapid_sales_tool/static/rapid_sales_tool/js/stock.js b/rapid_sales_tool/static/rapid_sales_tool/js/stock.js new file mode 100644 index 0000000..ea609e2 --- /dev/null +++ b/rapid_sales_tool/static/rapid_sales_tool/js/stock.js @@ -0,0 +1,47 @@ +var addItemModal = $('#newItemModal'); +var addStockModal = $('#addStockModal') +var itemForm = $('#addItemForm'); +var stockForm = $('#addStockForm'); +$( document ).ready( + addItemModal.submit(function() { + addItemModal.find(".modalResponse").first().empty().attr('class','modalResponse'); + $.ajax({ + type: itemForm.attr('method'), + url: itemForm.attr('action'), + data: itemForm.serialize(), + success: function(data) { + addItemModal.modal('hide'); + location.reload(); + }, + error: function(data) { + addItemModal.find(".modalResponse").first().empty().append('×'); + addItemModal.find(".modalResponse").first().append(data.responseText); + addItemModal.find(".modalResponse").first().addClass("alert alert-danger fade in"); + } + }); + return false; + }), + stockForm.submit(function() { + addStockModal.find(".modalResponse").first().empty().attr('class','modalResponse'); + $.ajax({ + type: stockForm.attr('method'), + url: stockForm.attr('action'), + data: stockForm.serialize(), + success: function(data) { + addStockModal.modal('hide'); + location.reload(); + }, + error: function(data) { + addStockModal.find(".modalResponse").first().empty().append('×'); + addStockModal.find(".modalResponse").first().append(data.responseText); + addStockModal.find(".modalResponse").first().addClass("alert alert-danger fade in"); + } + }); + return false; + }), + $(".modal").each( function() { + $(this).on('hidden.bs.modal', function () { + $(this).find(".modalResponse").first().empty().attr('class','modalResponse'); + }) + }) +); \ No newline at end of file diff --git a/templates/public/orders.html b/rapid_sales_tool/templates/rapid_sales_tool/orders.html similarity index 100% rename from templates/public/orders.html rename to rapid_sales_tool/templates/rapid_sales_tool/orders.html diff --git a/templates/public/stock.html b/rapid_sales_tool/templates/rapid_sales_tool/stock.html similarity index 100% rename from templates/public/stock.html rename to rapid_sales_tool/templates/rapid_sales_tool/stock.html diff --git a/rapid_sales_tool/views.py b/rapid_sales_tool/views.py index df75281..0e53e16 100644 --- a/rapid_sales_tool/views.py +++ b/rapid_sales_tool/views.py @@ -30,7 +30,7 @@ def order(request): return HttpResponseRedirect(reverse(order)) else: addOrderForm = AddOrderForm() - return render(request, 'public/orders.html', {'addOrderForm': addOrderForm, 'orders': orders, 'service_name': settings.SERVICE_NAME}, context_instance=RequestContext(request)) + return render(request, 'rapid_sales_tool/orders.html', {'addOrderForm': addOrderForm, 'orders': orders, 'service_name': settings.SERVICE_NAME}, context_instance=RequestContext(request)) def cancelOrder(request): if request.method == 'POST': @@ -68,7 +68,7 @@ def stock(request): else: addItemForm = AddItemForm() addStockForm = AddStockForm() - return render(request, 'public/stock.html', {'addItemForm': addItemForm, 'addStockForm': addStockForm, 'items': items, 'service_name': settings.SERVICE_NAME}, context_instance=RequestContext(request)) + return render(request, 'rapid_sales_tool/stock.html', {'addItemForm': addItemForm, 'addStockForm': addStockForm, 'items': items, 'service_name': settings.SERVICE_NAME}, context_instance=RequestContext(request)) def editStock(request, stock_id): stock_item = get_object_or_404(StockItem, pk=stock_id)