Python 3 fixes
This commit is contained in:
1 parent
b69f917d57
commit
ec638d51f9
8 files changed
+61
-47
No files matched your search
+1
-1
@@ -11,7 +11,7 @@ admin.autodiscover()
|
|||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
url(r'', include(main_urls)),
|
url(r'', include(main_urls)),
|
||||||
url(r'^accounts/login/$', 'django.contrib.auth.views.login', name='login'),
|
url(r'^accounts/login/$', 'django.contrib.auth.views.login', name='login'),
|
||||||
url(r'^accounts/logout/$', 'main.views.users.logout', name='logout'),
|
url(r'^accounts/logout/$', 'django.contrib.auth.views.logout', name='logout'),
|
||||||
|
|
||||||
url(r'^admin/', include(admin.site.urls)),
|
url(r'^admin/', include(admin.site.urls)),
|
||||||
]
|
]
|
||||||
|
|||||||
+3
-3
@@ -1,6 +1,6 @@
|
|||||||
import os
|
import os
|
||||||
import django.core.handlers.wsgi
|
|
||||||
|
|
||||||
os.environ['DJANGO_SETTINGS_MODULE'] = 'bbssite.settings'
|
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'bbssite.settings')
|
||||||
|
|
||||||
application = django.core.handlers.wsgi.WSGIHandler()
|
from django.core.wsgi import get_wsgi_application
|
||||||
|
application = get_wsgi_application()
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
from django.apps import AppConfig
|
||||||
|
|
||||||
|
|
||||||
|
class BBSAppConfig(AppConfig):
|
||||||
|
name = 'bbs'
|
||||||
|
verbose_name = 'Biceps Bar System'
|
||||||
|
|
||||||
|
def ready(self):
|
||||||
|
# all models are loaded, now attach signals
|
||||||
|
import main.signals
|
||||||
+30
-33
@@ -1,16 +1,14 @@
|
|||||||
from django.contrib.auth.models import User
|
from __future__ import unicode_literals
|
||||||
from django.db import models
|
|
||||||
from django.db.models.signals import post_save
|
|
||||||
from django.dispatch import receiver
|
|
||||||
from django.utils.translation import ugettext_lazy as _
|
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
|
from django.conf import settings
|
||||||
|
from django.db import models
|
||||||
|
from django.utils.encoding import python_2_unicode_compatible
|
||||||
|
from django.utils.translation import ugettext_lazy as _
|
||||||
|
|
||||||
|
|
||||||
|
@python_2_unicode_compatible
|
||||||
class Product(models.Model):
|
class Product(models.Model):
|
||||||
|
|
||||||
def __unicode__(self):
|
|
||||||
return self.name
|
|
||||||
|
|
||||||
name = models.CharField(max_length=64)
|
name = models.CharField(max_length=64)
|
||||||
sale_price_int = models.FloatField()
|
sale_price_int = models.FloatField()
|
||||||
sale_price_ext = models.FloatField()
|
sale_price_ext = models.FloatField()
|
||||||
@@ -48,12 +46,16 @@ class Product(models.Model):
|
|||||||
def wholesale_value(self):
|
def wholesale_value(self):
|
||||||
return self.wholesale_unit_price * self.inventory_amount
|
return self.wholesale_unit_price * self.inventory_amount
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return self.name
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
ordering = ['name']
|
ordering = ['name']
|
||||||
|
|
||||||
|
|
||||||
|
@python_2_unicode_compatible
|
||||||
class Order(models.Model):
|
class Order(models.Model):
|
||||||
customer = models.ForeignKey(User, null=True, blank=True, related_name='orders')
|
customer = models.ForeignKey(settings.AUTH_USER_MODEL, null=True, blank=True, related_name='orders')
|
||||||
order_sum = models.FloatField(db_column='sum')
|
order_sum = models.FloatField(db_column='sum')
|
||||||
created = models.DateTimeField(auto_now_add=True)
|
created = models.DateTimeField(auto_now_add=True)
|
||||||
|
|
||||||
@@ -61,12 +63,13 @@ class Order(models.Model):
|
|||||||
return self.customer is None
|
return self.customer is None
|
||||||
|
|
||||||
def reciept(self):
|
def reciept(self):
|
||||||
return u"{0}".format(u", ".join([str(ol) for ol in self.orderlines.all()]))
|
return "{}".format(", ".join([str(ol) for ol in self.orderlines.all()]))
|
||||||
|
|
||||||
def __unicode__(self):
|
def __str__(self):
|
||||||
return u"{0}: {1} kr".format(self.customer or u"Ekstern", self.order_sum)
|
return "{}: {} kr".format(self.customer or "Ekstern", self.order_sum)
|
||||||
|
|
||||||
|
|
||||||
|
@python_2_unicode_compatible
|
||||||
class OrderLine(models.Model):
|
class OrderLine(models.Model):
|
||||||
order = models.ForeignKey('main.Order', related_name='orderlines')
|
order = models.ForeignKey('main.Order', related_name='orderlines')
|
||||||
product = models.ForeignKey('main.Product', related_name='orderlines')
|
product = models.ForeignKey('main.Product', related_name='orderlines')
|
||||||
@@ -77,26 +80,28 @@ class OrderLine(models.Model):
|
|||||||
def price(self):
|
def price(self):
|
||||||
return self.amount * self.unit_price
|
return self.amount * self.unit_price
|
||||||
|
|
||||||
def __unicode__(self):
|
def __str__(self):
|
||||||
return u"{0} {1} ({2} kr per)".format(self.amount, self.product, self.unit_price)
|
return "{} {} ({} kr per)".format(self.amount, self.product, self.unit_price)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
unique_together = ('order', 'product')
|
unique_together = ('order', 'product')
|
||||||
|
|
||||||
|
|
||||||
|
@python_2_unicode_compatible
|
||||||
class Transaction(models.Model):
|
class Transaction(models.Model):
|
||||||
""" Money """
|
""" Money """
|
||||||
user = models.ForeignKey(User, related_name='transactions')
|
user = models.ForeignKey(settings.AUTH_USER_MODEL, related_name='transactions')
|
||||||
amount = models.FloatField()
|
amount = models.FloatField()
|
||||||
created = models.DateTimeField(auto_now_add=True)
|
created = models.DateTimeField(auto_now_add=True)
|
||||||
|
|
||||||
def __unicode__(self):
|
def __str__(self):
|
||||||
return u"{0}: {1}: {2}".format(self.id, self.user, self.amount)
|
return "{}: {}: {}".format(self.id, self.user, self.amount)
|
||||||
|
|
||||||
|
|
||||||
|
@python_2_unicode_compatible
|
||||||
class InventoryTransaction(models.Model):
|
class InventoryTransaction(models.Model):
|
||||||
""" Goods """
|
""" Goods """
|
||||||
user = models.ForeignKey(User, related_name='inventory_transactions')
|
user = models.ForeignKey(settings.AUTH_USER_MODEL, related_name='inventory_transactions')
|
||||||
product = models.ForeignKey('main.Product', related_name='transactions', verbose_name=_('Produkt'))
|
product = models.ForeignKey('main.Product', related_name='transactions', verbose_name=_('Produkt'))
|
||||||
amount = models.FloatField(verbose_name=_('Antall'))
|
amount = models.FloatField(verbose_name=_('Antall'))
|
||||||
unit_price = models.FloatField(verbose_name=_('Enhetspris'))
|
unit_price = models.FloatField(verbose_name=_('Enhetspris'))
|
||||||
@@ -107,8 +112,8 @@ class InventoryTransaction(models.Model):
|
|||||||
def price(self):
|
def price(self):
|
||||||
return self.amount * self.unit_price
|
return self.amount * self.unit_price
|
||||||
|
|
||||||
def __unicode__(self):
|
def __str__(self):
|
||||||
return u"{0}: {1}: {2} ({3} kr per)".format(
|
return "{}: {}: {} ({} kr per)".format(
|
||||||
self.id,
|
self.id,
|
||||||
self.user,
|
self.user,
|
||||||
self.product,
|
self.product,
|
||||||
@@ -116,10 +121,10 @@ class InventoryTransaction(models.Model):
|
|||||||
self.unit_price)
|
self.unit_price)
|
||||||
|
|
||||||
|
|
||||||
|
@python_2_unicode_compatible
|
||||||
class UserProfile(models.Model):
|
class UserProfile(models.Model):
|
||||||
user = models.OneToOneField(User, related_name='profile')
|
user = models.OneToOneField(settings.AUTH_USER_MODEL, related_name='profile')
|
||||||
balance = models.FloatField(default=0.0)
|
balance = models.FloatField(default=0.0)
|
||||||
#image = models.ImageField(upload_to='users', blank=True)
|
|
||||||
image = models.URLField(blank=True)
|
image = models.URLField(blank=True)
|
||||||
|
|
||||||
def last_purchase(self):
|
def last_purchase(self):
|
||||||
@@ -131,7 +136,6 @@ class UserProfile(models.Model):
|
|||||||
def last_purchase_date(self):
|
def last_purchase_date(self):
|
||||||
last = self.last_purchase()
|
last = self.last_purchase()
|
||||||
last_p = last.created if last else datetime.min
|
last_p = last.created if last else datetime.min
|
||||||
print(self.user, last_p)
|
|
||||||
return last_p
|
return last_p
|
||||||
|
|
||||||
def profile_image_url(self):
|
def profile_image_url(self):
|
||||||
@@ -142,12 +146,5 @@ class UserProfile(models.Model):
|
|||||||
|
|
||||||
return self.image
|
return self.image
|
||||||
|
|
||||||
def __unicode__(self):
|
def __str__(self):
|
||||||
return u"{0}".format(self.user)
|
return "{}".format(self.user)
|
||||||
|
|
||||||
|
|
||||||
# Create a new UserProfile object when we create a new User.
|
|
||||||
@receiver(post_save, sender=User, dispatch_uid='randomz')
|
|
||||||
def create_user_profile(sender, instance, created, **kwargs):
|
|
||||||
if created:
|
|
||||||
UserProfile.objects.create(user=instance)
|
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
from django.contrib.auth.models import User
|
||||||
|
from django.db.models.signals import post_save
|
||||||
|
from django.dispatch import receiver
|
||||||
|
from main.models import UserProfile
|
||||||
|
|
||||||
|
|
||||||
|
@receiver(post_save, sender=User, dispatch_uid='randomz')
|
||||||
|
def create_user_profile(sender, instance, created, **kwargs):
|
||||||
|
# Create a new UserProfile object when we create a new User.
|
||||||
|
if created:
|
||||||
|
UserProfile.objects.create(user=instance)
|
||||||
+1
-1
@@ -21,5 +21,5 @@ def users_format_js(users):
|
|||||||
users_js = []
|
users_js = []
|
||||||
for user in users:
|
for user in users:
|
||||||
users_js.append('"' + user.first_name + ' ' + user.last_name[:1] + '"')
|
users_js.append('"' + user.first_name + ' ' + user.last_name[:1] + '"')
|
||||||
users_js = "[{0}]".format(u",".join(users_js))
|
users_js = "[{}]".format(u",".join(users_js))
|
||||||
return users_js
|
return users_js
|
||||||
+4
-2
@@ -1,10 +1,12 @@
|
|||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
from datetime import datetime, timedelta, time
|
import time
|
||||||
|
from datetime import datetime, timedelta
|
||||||
from django.db.models import Sum, Count
|
from django.db.models import Sum, Count
|
||||||
from django.http import JsonResponse
|
from django.http import JsonResponse
|
||||||
from django.shortcuts import render, get_object_or_404
|
from django.shortcuts import render, get_object_or_404
|
||||||
from itertools import groupby
|
from itertools import groupby
|
||||||
|
|
||||||
|
from django.utils import six
|
||||||
from main.models import Product, OrderLine, Order
|
from main.models import Product, OrderLine, Order
|
||||||
|
|
||||||
|
|
||||||
@@ -61,7 +63,7 @@ def stats_product(product):
|
|||||||
f_per_user.append([who, num])
|
f_per_user.append([who, num])
|
||||||
|
|
||||||
response = {
|
response = {
|
||||||
'product': serialize_product(Product.objects.get(pk=product)) if type(product) is unicode else serialize_product(product),
|
'product': serialize_product(Product.objects.get(pk=product)) if type(product) in six.string_types else serialize_product(product),
|
||||||
'counts': f_per_user,
|
'counts': f_per_user,
|
||||||
'total_counts': sum([row['num'] for row in per_user]),
|
'total_counts': sum([row['num'] for row in per_user]),
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-7
@@ -6,23 +6,17 @@ from django.contrib.auth.decorators import login_required
|
|||||||
from django.db import connection
|
from django.db import connection
|
||||||
from django.db.models import Sum, Count
|
from django.db.models import Sum, Count
|
||||||
from django.shortcuts import render, redirect
|
from django.shortcuts import render, redirect
|
||||||
from django.contrib.auth import logout as auth_logout
|
|
||||||
from main.forms import SimpleCreateUserForm
|
from main.forms import SimpleCreateUserForm
|
||||||
from main.models import Order
|
from main.models import Order
|
||||||
from main.models import Transaction
|
from main.models import Transaction
|
||||||
|
|
||||||
|
|
||||||
def logout(request):
|
|
||||||
auth_logout(request)
|
|
||||||
return render(request, 'registration/logout.html')
|
|
||||||
|
|
||||||
|
|
||||||
def create_user(request):
|
def create_user(request):
|
||||||
if request.method == "POST":
|
if request.method == "POST":
|
||||||
form = SimpleCreateUserForm(data=request.POST)
|
form = SimpleCreateUserForm(data=request.POST)
|
||||||
if form.is_valid():
|
if form.is_valid():
|
||||||
user = form.save()
|
user = form.save()
|
||||||
messages.success(request, "Hurra! {0} {1} er lagt til".format(user.first_name, user.last_name))
|
messages.success(request, "Hurra! {} {} er lagt til".format(user.first_name, user.last_name))
|
||||||
return redirect('create-user')
|
return redirect('create-user')
|
||||||
|
|
||||||
else:
|
else:
|
||||||
|
|||||||
Reference in new issue
Block a user