diff --git a/shop/admin.py b/shop/admin.py index 290d6ef..d39d098 100644 --- a/shop/admin.py +++ b/shop/admin.py @@ -29,10 +29,10 @@ class KeySetAdmin(admin.ModelAdmin): @admin.register(Product) class ProductAdmin(admin.ModelAdmin): - list_display = ('product_name', 'seller', 'get_rating', 'price', 'stock', 'physical', 'approved') - list_filter = ('approved', 'physical','worldwide_shipping','free_shipping') + list_display = ('product_name', 'seller', 'get_rating', 'price', 'stock', 'physical', 'approved', 'removed') + list_filter = ('approved', 'physical','worldwide_shipping','free_shipping', 'removed') fieldsets = ( - ('Product info', {'fields': ('product_name', 'product_description', ('price', 'price_currency', 'cached_rate'), 'seller')}), + ('Product info', {'fields': ('product_name', 'product_description', ('price', 'price_currency', 'cached_rate'), 'seller', ('removed', 'delete_on_over'))}), ('Moderation', {'fields': ('approved',)}), ('Shipping/Delivery', {'fields': (('stock', 'physical'), ('ships_from', 'worldwide_shipping'), ('local_price', 'outside_price', 'free_shipping'))}), ('Digital', {'fields': ('redeeming_instructions',('unlimited_stock','can_purchase_multiple'))}) @@ -104,4 +104,4 @@ class ReviewAdmin(admin.ModelAdmin): inlines = [ReviewVoteInline] admin.site.register(UserShop) -admin.site.register(ShippingUpdate) \ No newline at end of file +admin.site.register(ShippingUpdate) diff --git a/shop/migrations/0003_auto_20170521_1334.py b/shop/migrations/0003_auto_20170521_1334.py new file mode 100644 index 0000000..0f85713 --- /dev/null +++ b/shop/migrations/0003_auto_20170521_1334.py @@ -0,0 +1,25 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.10.5 on 2017-05-21 13:34 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('shop', '0002_auto_20170520_1307'), + ] + + operations = [ + migrations.AddField( + model_name='product', + name='delete_on_over', + field=models.BooleanField(default=False), + ), + migrations.AddField( + model_name='product', + name='removed', + field=models.BooleanField(default=False), + ), + ] diff --git a/shop/models.py b/shop/models.py index 3a9e8be..e95ab10 100644 --- a/shop/models.py +++ b/shop/models.py @@ -73,6 +73,8 @@ class Product(models.Model): unlimited_stock = models.BooleanField(default=False) can_purchase_multiple = models.BooleanField(default=True) + delete_on_over = models.BooleanField(default=False) + removed = models.BooleanField(default=False) def __str__(self): return self.product_name @@ -128,7 +130,7 @@ def buy(self, address, wallet, ammount, gift=False): us = UserShop(user=self.seller, pay_to_address=a) us.save() if (self.stock >= ammount or self.unlimited_stock) and \ - self.ships_to(address): + self.ships_to(address) and not self.removed: if getattr(settings, 'FEE_ADDRESS', '') != '': wallet.send_to( getattr(settings, 'FEE_ADDRESS', ''), @@ -147,6 +149,8 @@ def buy(self, address, wallet, ammount, gift=False): fee = 1 if not self.unlimited_stock: self.stock -= ammount + if self.delete_on_over and self.stock == 0: + self.removed = True self.save() send_mail("Someone bought one of your items!", """Hello %s, diff --git a/shop/static/shop/main.css b/shop/static/shop/main.css index f4010ad..9c355a8 100644 --- a/shop/static/shop/main.css +++ b/shop/static/shop/main.css @@ -262,5 +262,5 @@ html { } body { - margin-bottom: 60px; + margin-bottom: 100px; } diff --git a/shop/templates/shop/newproduct.html b/shop/templates/shop/newproduct.html index 9a56463..ac8a4b1 100644 --- a/shop/templates/shop/newproduct.html +++ b/shop/templates/shop/newproduct.html @@ -38,6 +38,11 @@

General info

+
+ +
@@ -127,4 +132,4 @@

Images

{% load static %} -{% endblock %} \ No newline at end of file +{% endblock %} diff --git a/shop/templates/shop/product.html b/shop/templates/shop/product.html index 60d65ef..d6c3ffa 100644 --- a/shop/templates/shop/product.html +++ b/shop/templates/shop/product.html @@ -60,24 +60,28 @@

{{ product.product_name }}

{{product.seller}} - {% if can_buy %} - {% if not product.in_stock %} - OUT OF STOCK - {% else %} - {% if not incart %} - - {% if not user.is_authenticated %}LOGIN TO {% endif %}ADD TO CART - {% else %} - ALREADY IN CART - {% endif %} - {% endif %} - {% else %} - {% if user.is_authenticated %} - ALREADY OWNED - {% else %} - LOG IN TO BUY - {% endif %} - {% endif %} + {% if product.removed %} + PRODUCT REMOVED + {% else %} + {% if can_buy %} + {% if not product.in_stock %} + OUT OF STOCK + {% else %} + {% if not incart %} + + {% if not user.is_authenticated %}LOGIN TO {% endif %}ADD TO CART + {% else %} + ALREADY IN CART + {% endif %} + {% endif %} + {% else %} + {% if user.is_authenticated %} + ALREADY OWNED + {% else %} + LOG IN TO BUY + {% endif %} + {% endif %} + {% endif %} {% if product.seller == user %} Edit product {% endif %} diff --git a/shop/views.py b/shop/views.py index a2e2028..927d6d3 100644 --- a/shop/views.py +++ b/shop/views.py @@ -27,7 +27,7 @@ # Create your views here. def view_product(request, id): - product = get_object_or_404(Product, id=id) + product = get_object_or_404(Product, id=id, approved=True) if request.method == 'POST': @@ -124,7 +124,7 @@ def view_cart(request): @login_required def add_to_cart(request, id): cart = request.user.cart - product = get_object_or_404(Product, id=id) + product = get_object_or_404(Product, id=id, approved=True, removed=False) if request.user.userextra.can_purchase_item(product): if product.in_stock(): if cart.in_cart(product): @@ -610,7 +610,7 @@ def items(self, number=6): def homepage(request): sections = [] - new_section = HomeSection(lambda: Product.objects.all().order_by('-date'), + new_section = HomeSection(lambda: Product.objects.filter(removed=False, approved=True).order_by('-date'), 'Recently added') sections.append(new_section) @@ -814,7 +814,7 @@ def sell_new_product(request): if request.POST.get('product-name', '').strip() == '': errors.append("Product name can't be empty!") - if 'unlimited' in request.POST: + if 'unlimited' not in request.POST: try: stock = int(request.POST.get('stock', 0)) if stock < 0: @@ -879,7 +879,8 @@ def sell_new_product(request): stock=int(request.POST.get('stock', 0)), seller=request.user, free_shipping='free-shipping' in request.POST, - unlimited_stock='unlimited' in request.POST + unlimited_stock='unlimited' in request.POST, + delete_on_over = 'delete-on-over' in request.POST ) p.save() for i in imgs: