Skip to content

Commit

Permalink
Add delete on over
Browse files Browse the repository at this point in the history
  • Loading branch information
pta2002 committed May 21, 2017
1 parent 379985b commit 801d6a3
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 30 deletions.
8 changes: 4 additions & 4 deletions shop/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'))})
Expand Down Expand Up @@ -104,4 +104,4 @@ class ReviewAdmin(admin.ModelAdmin):
inlines = [ReviewVoteInline]

admin.site.register(UserShop)
admin.site.register(ShippingUpdate)
admin.site.register(ShippingUpdate)
25 changes: 25 additions & 0 deletions shop/migrations/0003_auto_20170521_1334.py
Original file line number Diff line number Diff line change
@@ -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),
),
]
6 changes: 5 additions & 1 deletion shop/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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', ''),
Expand All @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion shop/static/shop/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -262,5 +262,5 @@ html {
}

body {
margin-bottom: 60px;
margin-bottom: 100px;
}
7 changes: 6 additions & 1 deletion shop/templates/shop/newproduct.html
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ <h4>General info</h4>
<label for="stock" class="control-label">Stock</label>
<input type="number" placeholder="Stock" name="stock" id="stock" v-model="stock" class="form-control">
</div>
<div class="checkbox">
<label>
<input type="checkbox" name="delete-on-over" v-model="deleteover"> Delete when stock is over
</label>
</div>
</div>
</div>
</div>
Expand Down Expand Up @@ -127,4 +132,4 @@ <h4>Images</h4>
{% load static %}
<script src="{% static 'shop/vue.js' %}"></script>
<script src="{% static 'shop/newproduct.js' %}"></script>
{% endblock %}
{% endblock %}
40 changes: 22 additions & 18 deletions shop/templates/shop/product.html
Original file line number Diff line number Diff line change
Expand Up @@ -60,24 +60,28 @@ <h1>{{ product.product_name }}</h1>
<td><a href="{% url 'shop:shop' product.seller.username %}">{{product.seller}}</a></td>
</tr>
</table>
{% if can_buy %}
{% if not product.in_stock %}
<a href="#" disabled class="btn btn-primary btn-disabled btn-block">OUT OF STOCK</a>
{% else %}
{% if not incart %}
<a href="{% url 'shop:addtocart' product.id %}" class="btn {% if not user.is_authenticated %}btn-default{% else %}btn-primary{% endif %} btn-block">
{% if not user.is_authenticated %}LOGIN TO {% endif %}ADD TO CART</a>
{% else %}
<a href="#" disabled class="btn btn-primary btn-disabled btn-block">ALREADY IN CART</a>
{% endif %}
{% endif %}
{% else %}
{% if user.is_authenticated %}
<a href="#" disabled class="btn btn-primary btn-disabled btn-block">ALREADY OWNED</a>
{% else %}
<a href="{% url 'shop:login' %}?next={{ request.path }}" class="btn btn-default btn-block">LOG IN TO BUY</a>
{% endif %}
{% endif %}
{% if product.removed %}
<a href="#" disabled class="btn btn-danger btn-disabled btn-block">PRODUCT REMOVED</a>
{% else %}
{% if can_buy %}
{% if not product.in_stock %}
<a href="#" disabled class="btn btn-primary btn-disabled btn-block">OUT OF STOCK</a>
{% else %}
{% if not incart %}
<a href="{% url 'shop:addtocart' product.id %}" class="btn {% if not user.is_authenticated %}btn-default{% else %}btn-primary{% endif %} btn-block">
{% if not user.is_authenticated %}LOGIN TO {% endif %}ADD TO CART</a>
{% else %}
<a href="#" disabled class="btn btn-primary btn-disabled btn-block">ALREADY IN CART</a>
{% endif %}
{% endif %}
{% else %}
{% if user.is_authenticated %}
<a href="#" disabled class="btn btn-primary btn-disabled btn-block">ALREADY OWNED</a>
{% else %}
<a href="{% url 'shop:login' %}?next={{ request.path }}" class="btn btn-default btn-block">LOG IN TO BUY</a>
{% endif %}
{% endif %}
{% endif %}
{% if product.seller == user %}
<a href="{% url 'shop:editproduct' product.id %}" class="btn btn-default btn-block">Edit product</a>
{% endif %}
Expand Down
11 changes: 6 additions & 5 deletions shop/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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':
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 801d6a3

Please sign in to comment.