diff --git a/bbssite/settings.py b/bbssite/settings.py index 829796a..7cd1dff 100755 --- a/bbssite/settings.py +++ b/bbssite/settings.py @@ -1,5 +1,4 @@ # Django settings for bbs project. - import os BASE_DIR = os.path.dirname(os.path.dirname(__file__)) @@ -8,7 +7,6 @@ DEBUG = True ADMINS = ( # ('Your Name', 'your_email@example.com'), ) - MANAGERS = ADMINS DATABASES = { @@ -18,68 +16,28 @@ DATABASES = { }, } -# Local time zone for this installation. Choices can be found here: -# http://en.wikipedia.org/wiki/List_of_tz_zones_by_name -# although not all choices may be available on all operating systems. -# On Unix systems, a value of None will cause Django to use the same -# timezone as the operating system. -# If running in a Windows environment this must be set to the same as your -# system time zone. TIME_ZONE = 'Europe/Oslo' - -# Language code for this installation. All choices can be found here: -# http://www.i18nguy.com/unicode/language-identifiers.html LANGUAGE_CODE = 'nb' +USE_I18N = True +USE_L10N = True SITE_ID = 1 -# If you set this to False, Django will make some optimizations so as not -# to load the internationalization machinery. -USE_I18N = True - -# If you set this to False, Django will not format dates, numbers and -# calendars according to the current locale -USE_L10N = True - -# Absolute filesystem path to the directory that will hold user-uploaded files. -# Example: "/home/media/media.lawrence.com/media/" +# Media and uploads MEDIA_ROOT = os.path.join(BASE_DIR, 'media') - -# URL that handles the media served from MEDIA_ROOT. Make sure to use a -# trailing slash. -# Examples: "http://media.lawrence.com/media/", "http://example.com/media/" MEDIA_URL = '/media/' -# Absolute path to the directory static files should be collected to. -# Don't put anything in this directory yourself; store your static files -# in apps' "static/" subdirectories and in STATICFILES_DIRS. -# Example: "/home/media/media.lawrence.com/static/" +# Static files STATIC_ROOT = '' - -# URL prefix for static files. -# Example: "http://media.lawrence.com/static/" STATIC_URL = '/static/' - -# URL prefix for admin static files -- CSS, JavaScript and images. -# Make sure to use a trailing slash. -# Examples: "http://foo.com/static/admin/", "/static/admin/". -ADMIN_MEDIA_PREFIX = '/static/admin/' - -# Additional locations of static files STATICFILES_DIRS = ( - # Put strings here, like "/home/html/static" or "C:/www/django/static". - # Always use forward slashes, even on Windows. - # Don't forget to use absolute paths, not relative paths. os.path.join(BASE_DIR, 'static'), ) -# List of finder classes that know how to find static files in -# various locations. STATICFILES_FINDERS = ( 'django.contrib.staticfiles.finders.FileSystemFinder', 'django.contrib.staticfiles.finders.AppDirectoriesFinder', 'compressor.finders.CompressorFinder', -# 'django.contrib.staticfiles.finders.DefaultStorageFinder', ) # Make this unique, and don't share it with anybody. @@ -124,6 +82,7 @@ INSTALLED_APPS = ( 'django.contrib.messages', 'django.contrib.staticfiles', 'django.contrib.admin', + 'widget_tweaks', 'bootstrapform', 'compressor', @@ -134,32 +93,6 @@ LOCAL_APPS = ( ) INSTALLED_APPS += LOCAL_APPS -# A sample logging configuration. The only tangible logging -# performed by this configuration is to send an email to -# the site admins on every HTTP 500 error. -# See http://docs.djangoproject.com/en/dev/topics/logging for -# more details on how to customize your logging configuration. -LOGGING = { - 'version': 1, - 'disable_existing_loggers': False, - 'handlers': { - 'mail_admins': { - 'level': 'ERROR', - 'class': 'django.utils.log.AdminEmailHandler' - } - }, - 'loggers': { - 'django.request': { - 'handlers': ['mail_admins'], - 'level': 'ERROR', - 'propagate': True, - }, - } -} - -# User profile -AUTH_PROFILE_MODULE = 'main.UserProfile' - LOGIN_REDIRECT_URL = '/' SESSION_COOKIE_AGE = 1209600 # 15 minutes @@ -172,6 +105,6 @@ if not DEBUG: COMPRESS_ENABLED = True try: - from local_settings import * + from .local_settings import * except ImportError: pass diff --git a/bbssite/urls.py b/bbssite/urls.py index 0d82bab..78cf691 100755 --- a/bbssite/urls.py +++ b/bbssite/urls.py @@ -15,9 +15,9 @@ urlpatterns = [ url(r'^admin/', include(admin.site.urls)), ] +urlpatterns += staticfiles_urlpatterns() if settings.DEBUG: - urlpatterns += staticfiles_urlpatterns() urlpatterns += [ url(r'^media/(?P.*)$', 'django.views.static.serve', { 'document_root': settings.MEDIA_ROOT, diff --git a/main/migrations/0001_initial.py b/main/migrations/0001_initial.py index 71bd271..88aa8da 100644 --- a/main/migrations/0001_initial.py +++ b/main/migrations/0001_initial.py @@ -26,7 +26,7 @@ class Migration(migrations.Migration): name='Order', fields=[ ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)), - ('order_sum', models.FloatField(db_column=b'sum')), + ('order_sum', models.FloatField(db_column='sum')), ('created', models.DateTimeField(auto_now_add=True)), ('customer', models.ForeignKey(related_name='orders', blank=True, to=settings.AUTH_USER_MODEL, null=True)), ], @@ -50,7 +50,7 @@ class Migration(migrations.Migration): ('description', models.CharField(max_length=256, blank=True)), ('volume_liter', models.FloatField(null=True)), ('alcohol_percent', models.FloatField(null=True)), - ('image', models.ImageField(upload_to=b'products', blank=True)), + ('image', models.ImageField(upload_to='products', blank=True)), ('customer_support', models.CharField(max_length=32, blank=True)), ('inventory_amount', models.FloatField(default=0)), ('active', models.BooleanField(default=True)), diff --git a/main/models.py b/main/models.py index f40d684..9ccd0d7 100755 --- a/main/models.py +++ b/main/models.py @@ -125,17 +125,18 @@ class UserProfile(models.Model): def last_purchase(self): if len(self.user.orders.all()) == 0: return None - return self.user.orders.order_by('created').reverse()[0] + + return self.user.orders.order_by('-created')[0] def last_purchase_date(self): last = self.last_purchase() - if last: - return last.created - else: - return datetime.min + last_p = last.created if last else datetime.min + print(self.user, last_p) + return last_p def profile_image_url(self): from django.templatetags.static import static + if not self.image: return static('dist/images/unknown_person.png') diff --git a/main/views/general.py b/main/views/general.py index 959aed8..bf29061 100644 --- a/main/views/general.py +++ b/main/views/general.py @@ -3,7 +3,7 @@ from __future__ import unicode_literals from datetime import datetime, timedelta -import settings +from django.conf import settings from django.contrib import messages from django.contrib.auth.models import User from django.core.urlresolvers import reverse @@ -18,7 +18,8 @@ from main.utils import users_format_js, users_with_perm def register(request): products = Product.objects.filter(active=True) - cheapest_product_price = products.aggregate(Min('sale_price_int')).values()[0] or 0 + cheapest_product_price = list(products.aggregate(Min('sale_price_int')).values())[0] or 0 + half_a_year_ago = datetime.now() - timedelta(days=180) users = User.objects.filter(profile__balance__gte=cheapest_product_price) # sort users after user's last purchase time @@ -109,11 +110,7 @@ def deposit(request): allowed_users = users_with_perm('add_transaction') error_message_template = '{0} {1} kan ikke sette inn {2} kr, det overskrider maks saldo ({3} kr) med {4} kr' - # FIXME: dont need this - try: - limit_deposists = settings.BBS_LIMIT_DEPOSITS - except: - pass + limit_deposists = settings.BBS_LIMIT_DEPOSITS if request.method == "POST": form = DepositForm(request.POST) diff --git a/main/views/stats.py b/main/views/stats.py index e138292..30a56ab 100644 --- a/main/views/stats.py +++ b/main/views/stats.py @@ -122,7 +122,7 @@ def stats_orders_hourly(request): response = { 'start': str(orders[0].created), - 'hourly': [[k, v] for k, v in f_hourly.iteritems()], + 'hourly': [[k, v] for k, v in f_hourly.items()], 'total': sum(f_hourly.values()), } return JsonResponse(response) @@ -143,7 +143,7 @@ def stats_products_realtime(request): products[order_line.product].append([order_time_in_milliseconds, prev_entry[1] + order_line.amount]) serialized_products = {} - for product, value in products.iteritems(): + for product, value in products.items(): serialized_products[product.name] = value response = { @@ -168,9 +168,9 @@ def stats_products_per_user(request, user_id=None): products[order_line.product].append([order_time_in_milliseconds, prev_entry[1] + order_line.amount]) serialized_products = [] - for product, value in products.iteritems(): + for product, value in products.items(): serialized_products.append({ 'name': product.name, 'data': value }) - return JsonResponse(serialized_products) + return JsonResponse(serialized_products, safe=False) diff --git a/templates/deposit.html b/templates/deposit.html index baeb2a7..e954358 100644 --- a/templates/deposit.html +++ b/templates/deposit.html @@ -49,8 +49,8 @@ {% for user in users %}
  • {% spaceless %} Profile picture
    - {{ user.first_name }} {{ user.last_name|slice:":1"}}
    - {{ user.profile.balanceĀ }} + {{ user.first_name }} {{ user.last_name|slice:":1" }}
    + {{ user.profile.balance }} {% endspaceless %}
  • {% endfor %} diff --git a/templates/register.html b/templates/register.html index 89e7608..8bd9d2f 100644 --- a/templates/register.html +++ b/templates/register.html @@ -45,7 +45,7 @@ Ekstern
      {% endspaceless %} - {% for user in users %}
  • {% spaceless %} + {% for user in users %}
  • {% spaceless %} Profile picture
    {{ user.first_name }} {{ user.last_name|slice:":1"}}
    {{ user.profile.balanceĀ }}