From ce976101a1da82982434605ce342aa8d6f7100c2 Mon Sep 17 00:00:00 2001 From: Nikolai R Kristiansen Date: Tue, 22 Mar 2016 16:17:34 +0100 Subject: [PATCH] python3! Major work inside --- bestilling/admin.py | 6 +- bestilling/baseviews.py | 4 +- bestilling/migrations/0001_initial.py | 36 ++--- .../migrations/0002_auto__add_uploadedfile.py | 47 ------- bestilling/models.py | 10 +- bestilling/serializers.py | 2 +- bestilling/settings.py | 124 +++++------------- bestilling/urls.py | 21 +-- bestilling/utils.py | 3 +- bestilling/views.py | 18 +-- bestilling/wsgi.py | 40 +----- design/migrations/0001_initial.py | 36 +++++ design/migrations/0002_auto_20160322_1520.py | 19 +++ design/migrations/__init__.py | 0 design/models.py | 1 + design/tests.py | 15 --- design/urls.py | 12 +- design/views.py | 45 +++---- prm/migrations/0001_initial.py | 33 +++++ prm/migrations/0002_auto_20160322_1520.py | 19 +++ prm/migrations/__init__.py | 0 prm/tests.py | 15 --- prm/urls.py | 11 +- prm/views.py | 2 +- requirements.txt | 13 +- static/js/attachments.js | 2 +- tekst/migrations/0001_initial.py | 37 ++++++ tekst/migrations/0002_auto_20160322_1520.py | 19 +++ tekst/migrations/__init__.py | 0 tekst/urls.py | 11 +- tekst/views.py | 2 +- templates/form_base.html | 2 +- templates/form_success.html | 2 +- templates/order_base.html | 2 +- 34 files changed, 305 insertions(+), 304 deletions(-) delete mode 100644 bestilling/migrations/0002_auto__add_uploadedfile.py create mode 100644 design/migrations/0001_initial.py create mode 100644 design/migrations/0002_auto_20160322_1520.py create mode 100644 design/migrations/__init__.py create mode 100644 prm/migrations/0001_initial.py create mode 100644 prm/migrations/0002_auto_20160322_1520.py create mode 100644 prm/migrations/__init__.py create mode 100644 tekst/migrations/0001_initial.py create mode 100644 tekst/migrations/0002_auto_20160322_1520.py create mode 100644 tekst/migrations/__init__.py diff --git a/bestilling/admin.py b/bestilling/admin.py index 7c1af12..a0a4a22 100644 --- a/bestilling/admin.py +++ b/bestilling/admin.py @@ -1,5 +1,5 @@ from django.contrib import admin -from django.contrib.contenttypes import generic +from django.contrib.contenttypes.admin import GenericTabularInline from bestilling.models import Attachment from prm.models import PrmOrder @@ -7,7 +7,7 @@ from tekst.models import TekstOrder from design.models import DesignOrder -class UploadedFileline(generic.GenericTabularInline): +class UploadedFileline(GenericTabularInline): model = Attachment extra = 1 @@ -20,4 +20,4 @@ class OrderAdmin(admin.ModelAdmin): admin.site.register(PrmOrder, OrderAdmin) admin.site.register(TekstOrder, OrderAdmin) admin.site.register(DesignOrder, OrderAdmin) -admin.site.register(Attachment) \ No newline at end of file +admin.site.register(Attachment) diff --git a/bestilling/baseviews.py b/bestilling/baseviews.py index 6d45ac2..09a9909 100644 --- a/bestilling/baseviews.py +++ b/bestilling/baseviews.py @@ -12,9 +12,9 @@ from django.conf import settings import trello from bestilling import utils - from bestilling.models import Attachment + class BaseFormView(TemplateView): mail_template_name = "confirmation_mail.txt" mail_from = 'no-reply@studentersamfundet.no' @@ -79,7 +79,7 @@ class BaseFormView(TemplateView): board = client.get_board(self.trello_board_id) all_lists = board.all_lists() - order_list = filter(lambda x: x.name == list_name and (x.fetch() or x.closed == False), all_lists) + order_list = list(filter(lambda x: x.name.decode('utf-8') == list_name and (x.fetch() or x.closed is False), all_lists)) if len(order_list) == 0: order_list.append(board.add_list(list_name)) diff --git a/bestilling/migrations/0001_initial.py b/bestilling/migrations/0001_initial.py index c999def..9f86db6 100644 --- a/bestilling/migrations/0001_initial.py +++ b/bestilling/migrations/0001_initial.py @@ -1,20 +1,26 @@ # -*- coding: utf-8 -*- -from south.utils import datetime_utils as datetime -from south.db import db -from south.v2 import SchemaMigration -from django.db import models +from __future__ import unicode_literals + +from django.db import migrations, models +import bestilling.utils -class Migration(SchemaMigration): +class Migration(migrations.Migration): - def forwards(self, orm): - pass + dependencies = [ + ('contenttypes', '0002_remove_content_type_name'), + ] - def backwards(self, orm): - pass - - models = { - - } - - complete_apps = ['bestilling'] \ No newline at end of file + operations = [ + migrations.CreateModel( + name='Attachment', + fields=[ + ('id', models.AutoField(verbose_name='ID', auto_created=True, serialize=False, primary_key=True)), + ('uploaded_file', models.FileField(validators=[bestilling.utils.validate_file_extension], upload_to='uploads')), + ('trello_id', models.CharField(null=True, max_length=40, blank=True)), + ('created', models.DateTimeField(auto_now_add=True)), + ('object_id', models.PositiveIntegerField()), + ('content_type', models.ForeignKey(to='contenttypes.ContentType')), + ], + ), + ] diff --git a/bestilling/migrations/0002_auto__add_uploadedfile.py b/bestilling/migrations/0002_auto__add_uploadedfile.py deleted file mode 100644 index 10ed1fd..0000000 --- a/bestilling/migrations/0002_auto__add_uploadedfile.py +++ /dev/null @@ -1,47 +0,0 @@ -# -*- coding: utf-8 -*- -from south.utils import datetime_utils as datetime -from south.db import db -from south.v2 import SchemaMigration -from django.db import models - - -class Migration(SchemaMigration): - - def forwards(self, orm): - # Adding model 'Attachment' - db.create_table(u'bestilling_attachment', ( - (u'id', self.gf('django.db.models.fields.AutoField')(primary_key=True)), - ('uploaded_file', self.gf('django.db.models.fields.files.FileField')(max_length=100)), - ('trello_id', self.gf('django.db.models.fields.CharField')(max_length=40, null=True, blank=True)), - ('created', self.gf('django.db.models.fields.DateTimeField')(auto_now_add=True, blank=True)), - ('content_type', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['contenttypes.ContentType'])), - ('object_id', self.gf('django.db.models.fields.PositiveIntegerField')()), - )) - db.send_create_signal(u'bestilling', ['Attachment']) - - - def backwards(self, orm): - # Deleting model 'Attachment' - db.delete_table(u'bestilling_attachment') - - - models = { - u'bestilling.attachment': { - 'Meta': {'object_name': 'Attachment'}, - 'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['contenttypes.ContentType']"}), - 'created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}), - u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), - 'object_id': ('django.db.models.fields.PositiveIntegerField', [], {}), - 'trello_id': ('django.db.models.fields.CharField', [], {'max_length': '40', 'null': 'True', 'blank': 'True'}), - 'uploaded_file': ('django.db.models.fields.files.FileField', [], {'max_length': '100'}) - }, - u'contenttypes.contenttype': { - 'Meta': {'ordering': "('name',)", 'unique_together': "(('app_label', 'model'),)", 'object_name': 'ContentType', 'db_table': "'django_content_type'"}, - 'app_label': ('django.db.models.fields.CharField', [], {'max_length': '100'}), - u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), - 'model': ('django.db.models.fields.CharField', [], {'max_length': '100'}), - 'name': ('django.db.models.fields.CharField', [], {'max_length': '100'}) - } - } - - complete_apps = ['bestilling'] \ No newline at end of file diff --git a/bestilling/models.py b/bestilling/models.py index a0de841..d689533 100644 --- a/bestilling/models.py +++ b/bestilling/models.py @@ -1,6 +1,7 @@ +import uuid + +from django.contrib.contenttypes.fields import GenericForeignKey from django.db import models -from django_extensions.db.fields import UUIDField -from django.contrib.contenttypes import generic from django.contrib.contenttypes.models import ContentType from bestilling.utils import validate_file_extension @@ -18,11 +19,12 @@ class Attachment(models.Model): content_type = models.ForeignKey(ContentType, limit_choices_to=_limit_order_choices) object_id = models.PositiveIntegerField() - order_object = generic.GenericForeignKey('content_type', 'object_id') + order_object = GenericForeignKey('content_type', 'object_id') class Order(models.Model): - uuid = UUIDField(unique=True, auto=True, version=1) # version 1 guarantees no collisions + # uuid = UUIDField(unique=True, auto=True, version=1) # version 1 guarantees no collisions + uuid = models.UUIDField(unique=True, default=uuid.uuid4) # auto=True, version=1 client = models.CharField(max_length=50) deadline = models.DateField() contact_name = models.CharField(max_length=50) diff --git a/bestilling/serializers.py b/bestilling/serializers.py index 1a107eb..19f9c26 100644 --- a/bestilling/serializers.py +++ b/bestilling/serializers.py @@ -7,4 +7,4 @@ class AttachmentSerializer(ModelSerializer): class Meta: model = Attachment fields = ('id', 'uploaded_file', 'trello_id', 'object_id', 'content_type') - read_only_fields = ('id',) \ No newline at end of file + read_only_fields = ('id',) diff --git a/bestilling/settings.py b/bestilling/settings.py index e83f6b0..477a063 100644 --- a/bestilling/settings.py +++ b/bestilling/settings.py @@ -1,8 +1,6 @@ -# Copy and change variables marked with TODO to local_settings.py to make it work. import os DEBUG = True -TEMPLATE_DEBUG = DEBUG # Path of our project: BASE_DIR = os.path.realpath(os.path.join(os.path.dirname(__file__), os.pardir)) @@ -10,74 +8,29 @@ BASE_DIR = os.path.realpath(os.path.join(os.path.dirname(__file__), os.pardir)) ADMINS = ( # ('Your Name', 'your_email@example.com'), ) - MANAGERS = ADMINS DATABASES = { 'default': { 'ENGINE': 'django.db.backends.sqlite3', - 'NAME': 'db.sqlite3', + 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), } } - -# Trello keys, tokens and board ids -TRELLO_API_KEY = "" # TODO -TRELLO_TOKEN = "" # TODO -TRELLO_DESIGN_BOARD_ID = "" # TODO -TRELLO_TEKST_BOARD_ID = "" # TODO -TRELLO_PRM_BOARD_ID = "" # TODO - -# Hosts/domain names that are valid for this site; required if DEBUG is False -# See https://docs.djangoproject.com/en/1.5/ref/settings/#allowed-hosts ALLOWED_HOSTS = [] -# 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. -# In a Windows environment this must be set to 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' - -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 - -# If you set this to False, Django will not use timezone-aware datetimes. USE_TZ = True -# Absolute filesystem path to the directory that will hold user-uploaded files. -# Example: "/var/www/example.com/media/" 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://example.com/media/", "http://media.example.com/" 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: "/var/www/example.com/static/" STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles') - -# URL prefix for static files. -# Example: "http://example.com/static/", "http://static.example.com/" STATIC_URL = '/static/' - # 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'), ) @@ -91,17 +44,30 @@ STATICFILES_FINDERS = ( # Make this unique, and don't share it with anybody. SECRET_KEY = 'asdf123' -# List of callables that know how to import templates from various sources. -TEMPLATE_LOADERS = ( - 'django.template.loaders.filesystem.Loader', - 'django.template.loaders.app_directories.Loader', -) +TEMPLATES = [ + { + 'BACKEND': 'django.template.backends.django.DjangoTemplates', + 'DIRS': [ + os.path.join(BASE_DIR, 'templates') + ], + 'APP_DIRS': True, + 'OPTIONS': { + 'context_processors': [ + 'django.template.context_processors.debug', + 'django.template.context_processors.request', + 'django.contrib.auth.context_processors.auth', + 'django.contrib.messages.context_processors.messages', + ], + }, + }, +] MIDDLEWARE_CLASSES = ( 'django.middleware.common.CommonMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', + 'django.contrib.auth.middleware.SessionAuthenticationMiddleware', 'django.contrib.messages.middleware.MessageMiddleware', ) @@ -110,13 +76,6 @@ ROOT_URLCONF = 'bestilling.urls' # Python dotted path to the WSGI application used by Django's runserver. WSGI_APPLICATION = 'bestilling.wsgi.application' -TEMPLATE_DIRS = ( - # Put strings here, like "/home/html/django_templates" or "C:/www/django/templates". - # Always use forward slashes, even on Windows. - # Don't forget to use absolute paths, not relative paths. - os.path.join(BASE_DIR, 'templates'), -) - INSTALLED_APPS = ( 'django.contrib.auth', 'django.contrib.contenttypes', @@ -127,41 +86,22 @@ INSTALLED_APPS = ( 'django.contrib.admin', 'django.contrib.admindocs', 'rest_framework', - 'south', +) +INSTALLED_APPS += ( 'design', 'tekst', 'prm', 'bestilling' ) -# 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 when DEBUG=False. -# 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, - 'filters': { - 'require_debug_false': { - '()': 'django.utils.log.RequireDebugFalse' - } - }, - 'handlers': { - 'mail_admins': { - 'level': 'ERROR', - 'filters': ['require_debug_false'], - 'class': 'django.utils.log.AdminEmailHandler' - } - }, - 'loggers': { - 'django.request': { - 'handlers': ['mail_admins'], - 'level': 'ERROR', - 'propagate': True, - }, - } -} +SITE_ID = 1 + +# Trello keys, tokens and board ids +TRELLO_API_KEY = "" +TRELLO_TOKEN = "" +TRELLO_DESIGN_BOARD_ID = "" +TRELLO_TEKST_BOARD_ID = "" +TRELLO_PRM_BOARD_ID = "" MAIL_KAK_DESIGN = 'kak-design@studentersamfundet.no' MAIL_KAK_TEKST = 'kak-tekst@studentersamfundet.no' @@ -169,9 +109,9 @@ MAIL_KAK_PRM = 'kak-prm@studentersamfundet.no' UPLOAD_FILENAME_EXTENSIONS_ALLOWED = [ 'png', 'ai', 'eps', 'jpeg', 'jpg', 'tif', 'tiff', 'indd', 'webp' - 'pdf', 'doc', 'docx', 'xls', 'xlsx', 'txt', 'zip'] + 'pdf', 'doc', 'docx', 'xls', 'xlsx', 'txt', 'zip', '.gif'] try: - from local_settings import * + from .local_settings import * except ImportError: - pass \ No newline at end of file + pass diff --git a/bestilling/urls.py b/bestilling/urls.py index 132ac70..e236277 100644 --- a/bestilling/urls.py +++ b/bestilling/urls.py @@ -1,24 +1,25 @@ -from django.conf.urls import patterns, include, url +from django.conf.urls import url, include from django.contrib import admin from django.conf import settings from bestilling.views import IndexView, AttachmentView +from design import urls as design_urls +from tekst import urls as tekst_urls +from prm import urls as prm_urls admin.autodiscover() -urlpatterns = patterns( - '', - url(r'^design/', include('design.urls')), - url(r'^tekst/', include('tekst.urls')), - url(r'^prm/', include('prm.urls')), +urlpatterns = [ + url(r'^design/', include(design_urls)), + url(r'^tekst/', include(tekst_urls)), + url(r'^prm/', include(prm_urls)), url(r'^$', IndexView.as_view()), url(r'^attachments/$', AttachmentView.as_view(), name='attachments'), url(r'^admin/', include(admin.site.urls)), -) +] if settings.DEBUG: - urlpatterns += patterns( - '', + urlpatterns += [ url(r'^media/(?P.*)$', 'django.views.static.serve', { 'document_root': settings.MEDIA_ROOT, }), - ) \ No newline at end of file + ] diff --git a/bestilling/utils.py b/bestilling/utils.py index 3b89b80..38c9756 100644 --- a/bestilling/utils.py +++ b/bestilling/utils.py @@ -1,3 +1,4 @@ +from __future__ import unicode_literals import re from django.core.exceptions import ValidationError from django.conf import settings @@ -19,4 +20,4 @@ def validate_file_extension(value): for ext in settings.UPLOAD_FILENAME_EXTENSIONS_ALLOWED: if value.name.lower().endswith(ext): return # bail out - raise ValidationError(u'Ikke tillatt filendelse i "{0}"'.format(value)) \ No newline at end of file + raise ValidationError('Ikke tillatt filendelse i "{0}"'.format(value)) diff --git a/bestilling/views.py b/bestilling/views.py index cc04676..319eaeb 100644 --- a/bestilling/views.py +++ b/bestilling/views.py @@ -1,7 +1,4 @@ from django.conf import settings -from django.http import HttpResponse -from django.template import Context -from django.template.loader import get_template from django.views.generic import TemplateView from rest_framework import generics @@ -12,20 +9,15 @@ from bestilling.serializers import AttachmentSerializer class IndexView(TemplateView): - def get(self, request): - template = get_template('index.html') - context_data = {} - - response = template.render(Context(context_data)) - return HttpResponse(response) - + template_name = 'index.html' + class AttachmentView(generics.ListCreateAPIView): queryset = Attachment.objects.all() serializer_class = AttachmentSerializer - def post_save(self, obj, created=False): - + def perform_create(self, serializer): + obj = serializer.save() if obj.order_object is not None: client = trello.TrelloClient(api_key=settings.TRELLO_API_KEY, token=settings.TRELLO_TOKEN) attachment = client.fetch_json( @@ -35,4 +27,4 @@ class AttachmentView(generics.ListCreateAPIView): ) # Persist trello attachment id obj.trello_id = attachment['id'] - obj.save() \ No newline at end of file + obj.save() diff --git a/bestilling/wsgi.py b/bestilling/wsgi.py index 01b7d5d..a7233a1 100644 --- a/bestilling/wsgi.py +++ b/bestilling/wsgi.py @@ -1,41 +1,15 @@ """ WSGI config for bestilling project. -This module contains the WSGI application used by Django's development server -and any production WSGI deployments. It should expose a module-level variable -named ``application``. Django's ``runserver`` and ``runfcgi`` commands discover -this application via the ``WSGI_APPLICATION`` setting. - -Usually you will have the standard Django WSGI application here, but it also -might make sense to replace the whole Django WSGI application with a custom one -that later delegates to the Django one. For example, you could introduce WSGI -middleware here, or combine a Django application with an application of another -framework. +It exposes the WSGI callable as a module-level variable named ``application``. +For more information on this file, see +https://docs.djangoproject.com/en/1.8/howto/deployment/wsgi/ """ -import os, sys -from os.path import dirname, join - -def map_path(target_name=''): - return join(dirname(__file__), target_name).replace('\\', '/') - -path = map_path("..") -if path not in sys.path: - sys.path.append(path) - -# We defer to a DJANGO_SETTINGS_MODULE already in the environment. This breaks -# if running multiple sites in the same mod_wsgi process. To fix this, use -# mod_wsgi daemon mode with each site in its own daemon process, or use -# os.environ["DJANGO_SETTINGS_MODULE"] = "bestilling.settings" -os.environ.setdefault("DJANGO_SETTINGS_MODULE", "bestilling.settings") - -# This application object is used by any WSGI server configured to use this -# file. This includes Django's development server, if the WSGI_APPLICATION -# setting points here. +import os from django.core.wsgi import get_wsgi_application -application = get_wsgi_application() -# Apply WSGI middleware here. -# from helloworld.wsgi import HelloWorldApplication -# application = HelloWorldApplication(application) + +os.environ.setdefault("DJANGO_SETTINGS_MODULE", "bestilling.settings") +application = get_wsgi_application() diff --git a/design/migrations/0001_initial.py b/design/migrations/0001_initial.py new file mode 100644 index 0000000..813aae0 --- /dev/null +++ b/design/migrations/0001_initial.py @@ -0,0 +1,36 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import migrations, models +import django_extensions.db.fields + + +class Migration(migrations.Migration): + + dependencies = [ + ] + + operations = [ + migrations.CreateModel( + name='DesignOrder', + fields=[ + ('id', models.AutoField(verbose_name='ID', auto_created=True, serialize=False, primary_key=True)), + ('uuid', django_extensions.db.fields.UUIDField(editable=False, version=1, blank=True, unique=True)), + ('client', models.CharField(max_length=50)), + ('deadline', models.DateField()), + ('contact_name', models.CharField(max_length=50)), + ('contact_email', models.CharField(max_length=50)), + ('contact_number', models.CharField(null=True, max_length=20, blank=True)), + ('created', models.DateTimeField(auto_now_add=True)), + ('trello_card_id', models.CharField(max_length=40)), + ('format_type', models.CharField(choices=[('Trykk - Flyer', 'Trykk - Flyer'), ('Trykk - Plakat', 'Trykk - Plakat'), ('Trykk - Banner', 'Trykk - Banner'), ('Web - Annonse', 'Web - Annonse'), ('Web - Banner', 'Web - Banner'), ('Web - Bilde', 'Web - Bilde')], max_length=50)), + ('paper_size', models.CharField(choices=[('A1', 'A1 (594 x 841 mm)'), ('A2', 'A2 (420 x 594 mm)'), ('B3', 'B3 (353 x 500 mm)'), ('A3', 'A3 (297 x 420 mm)'), ('A4', 'A4 (210 x 297 mm)'), ('A5', 'A5 (148 x 210 mm)'), ('A6', 'A6 (105 x 148 mm)')], max_length=50)), + ('colour', models.CharField(max_length=50)), + ('marger', models.CharField(max_length=50)), + ('content', models.TextField(null=True, blank=True)), + ], + options={ + 'abstract': False, + }, + ), + ] diff --git a/design/migrations/0002_auto_20160322_1520.py b/design/migrations/0002_auto_20160322_1520.py new file mode 100644 index 0000000..81046dd --- /dev/null +++ b/design/migrations/0002_auto_20160322_1520.py @@ -0,0 +1,19 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('design', '0001_initial'), + ] + + operations = [ + migrations.AlterField( + model_name='designorder', + name='uuid', + field=models.UUIDField(unique=True), + ), + ] diff --git a/design/migrations/__init__.py b/design/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/design/models.py b/design/models.py index a2a3240..8ec15f3 100644 --- a/design/models.py +++ b/design/models.py @@ -1,6 +1,7 @@ from bestilling.models import Order from django.db import models + class DesignOrder(Order): PAPER_SIZES = [ ('A1', 'A1 (594 x 841 mm)'), diff --git a/design/tests.py b/design/tests.py index 501deb7..2e9cb5f 100644 --- a/design/tests.py +++ b/design/tests.py @@ -1,16 +1 @@ -""" -This file demonstrates writing tests using the unittest module. These will pass -when you run "manage.py test". - -Replace this with more appropriate tests for your application. -""" - from django.test import TestCase - - -class SimpleTest(TestCase): - def test_basic_addition(self): - """ - Tests that 1 + 1 always equals 2. - """ - self.assertEqual(1 + 1, 2) diff --git a/design/urls.py b/design/urls.py index de9b267..93e6937 100644 --- a/design/urls.py +++ b/design/urls.py @@ -1,8 +1,8 @@ -from django.conf.urls import patterns +from django.conf.urls import url + from design.views import DesignFormView, DesignOrderView -urlpatterns = patterns( - 'design.views', - (r'^$', DesignFormView.as_view()), - (r'^order/(?P[a-zA-Z0-9-]+)/', DesignOrderView.as_view()), -) +urlpatterns = [ + url(r'^$', DesignFormView.as_view()), + url(r'^order/(?P[a-zA-Z0-9-]+)/', DesignOrderView.as_view()), +] diff --git a/design/views.py b/design/views.py index 820be3a..63754fc 100644 --- a/design/views.py +++ b/design/views.py @@ -38,17 +38,17 @@ class DesignFormView(BaseFormView): def _get_errors(self, params): errors = super(DesignFormView, self)._get_errors(params) errors.update({ - 'format_error' : params['format'] == '' or len(params['format']) > 50, - 'format_other_error' : params['format'] == 'other' and (params['format_other'] == '' or len(params['format_other']) > 50), - 'paper_size_error' : params['paper_size'] == '' or len(params['paper_size']) > 50, - 'paper_size_other_error' : params['paper_size'] == 'other' and (params['paper_size_other'] == '' or len(params['paper_size_other']) > 50), - 'colour_error' : params['colour'] == '' or len(params['colour']) > 50, - 'marger_error' : params['marger'] == '' or len(params['marger']) > 50, - 'content_error' : False, + 'format_error': params['format'] == '' or len(params['format']) > 50, + 'format_other_error': params['format'] == 'other' and (params['format_other'] == '' or len(params['format_other']) > 50), + 'paper_size_error': params['paper_size'] == '' or len(params['paper_size']) > 50, + 'paper_size_other_error': params['paper_size'] == 'other' and (params['paper_size_other'] == '' or len(params['paper_size_other']) > 50), + 'colour_error': params['colour'] == '' or len(params['colour']) > 50, + 'marger_error': params['marger'] == '' or len(params['marger']) > 50, + 'content_error': False, }) # Filter out all errors that are False: - return dict((error, True) for error, has_happened in errors.iteritems() if has_happened is True) + return dict((error, True) for error, has_happened in errors.items() if has_happened is True) def _get_order_url(self, request, order): return request.build_absolute_uri('/design/order/{uuid}/'.format(uuid=order.uuid)) @@ -60,26 +60,26 @@ class DesignFormView(BaseFormView): deadline = datetime.strptime(params['deadline'], '%Y-%m-%d') card = self._save_to_trello( - card_name = params['client'], - card_description = "", + card_name=params['client'], + card_description="", card_due=datetime.strftime(deadline, '%m/%d/%y'), ) card_id = card.id order = DesignOrder( - client = params['client'], - deadline = deadline.date(), - contact_name = params['contact_name'], - contact_email = params['contact_email'], - contact_number = params['contact_number'], - format_type = params['format_type'], - paper_size = params['paper_size'], - colour = params['colour'], - marger = params['marger'], - content = params['content'], - trello_card_id = str(card_id) - ) + client=params['client'], + deadline=deadline.date(), + contact_name=params['contact_name'], + contact_email=params['contact_email'], + contact_number=params['contact_number'], + format_type=params['format_type'], + paper_size=params['paper_size'], + colour=params['colour'], + marger=params['marger'], + content=params['content'], + trello_card_id=str(card_id) + ) order.save() params['url'] = request.build_absolute_uri('/design/order/{uuid}/'.format(uuid=order.uuid)) @@ -89,6 +89,7 @@ class DesignFormView(BaseFormView): return order + class DesignOrderView(BaseOrderView): template_name = "design/order.html" diff --git a/prm/migrations/0001_initial.py b/prm/migrations/0001_initial.py new file mode 100644 index 0000000..b5c0b8c --- /dev/null +++ b/prm/migrations/0001_initial.py @@ -0,0 +1,33 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import migrations, models +import django_extensions.db.fields + + +class Migration(migrations.Migration): + + dependencies = [ + ] + + operations = [ + migrations.CreateModel( + name='PrmOrder', + fields=[ + ('id', models.AutoField(verbose_name='ID', auto_created=True, serialize=False, primary_key=True)), + ('uuid', django_extensions.db.fields.UUIDField(editable=False, version=1, blank=True, unique=True)), + ('client', models.CharField(max_length=50)), + ('deadline', models.DateField()), + ('contact_name', models.CharField(max_length=50)), + ('contact_email', models.CharField(max_length=50)), + ('contact_number', models.CharField(null=True, max_length=20, blank=True)), + ('created', models.DateTimeField(auto_now_add=True)), + ('trello_card_id', models.CharField(max_length=40)), + ('assignment_type', models.CharField(max_length=200)), + ('content', models.TextField(null=True, blank=True)), + ], + options={ + 'abstract': False, + }, + ), + ] diff --git a/prm/migrations/0002_auto_20160322_1520.py b/prm/migrations/0002_auto_20160322_1520.py new file mode 100644 index 0000000..cc4f0ac --- /dev/null +++ b/prm/migrations/0002_auto_20160322_1520.py @@ -0,0 +1,19 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('prm', '0001_initial'), + ] + + operations = [ + migrations.AlterField( + model_name='prmorder', + name='uuid', + field=models.UUIDField(unique=True), + ), + ] diff --git a/prm/migrations/__init__.py b/prm/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/prm/tests.py b/prm/tests.py index 501deb7..2e9cb5f 100644 --- a/prm/tests.py +++ b/prm/tests.py @@ -1,16 +1 @@ -""" -This file demonstrates writing tests using the unittest module. These will pass -when you run "manage.py test". - -Replace this with more appropriate tests for your application. -""" - from django.test import TestCase - - -class SimpleTest(TestCase): - def test_basic_addition(self): - """ - Tests that 1 + 1 always equals 2. - """ - self.assertEqual(1 + 1, 2) diff --git a/prm/urls.py b/prm/urls.py index a9a3cc1..26b3092 100644 --- a/prm/urls.py +++ b/prm/urls.py @@ -1,8 +1,7 @@ -from django.conf.urls import patterns +from django.conf.urls import url from prm.views import PrmFormView, PrmOrderView -urlpatterns = patterns( - 'tekst.views', - (r'^$', PrmFormView.as_view()), - (r'^order/(?P[a-zA-Z0-9-]+)/', PrmOrderView.as_view()), -) +urlpatterns = [ + url(r'^$', PrmFormView.as_view()), + url(r'^order/(?P[a-zA-Z0-9-]+)/', PrmOrderView.as_view()), +] diff --git a/prm/views.py b/prm/views.py index dd040a2..706b707 100644 --- a/prm/views.py +++ b/prm/views.py @@ -34,7 +34,7 @@ class PrmFormView(BaseFormView): }) # Filter out all errors that are False: - return dict((error, True) for error, has_happened in errors.iteritems() if has_happened is True) + return dict((error, True) for error, has_happened in errors.items() if has_happened is True) def _get_order_url(self, request, order): return request.build_absolute_uri('/prm/order/{uuid}/'.format(uuid=order.uuid)) diff --git a/requirements.txt b/requirements.txt index d5a8f58..a15fb80 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,7 +1,6 @@ -Django>=1.6,<1.7 -django-extensions==1.5.2 -djangorestframework==2.4.4 -mysqlclient==1.3.6 -python-dateutil==2.4.2 -py-trello==0.1.6 -South==1.0.2 +Django>=1.8,<1.9 +django-extensions==1.6.1 +djangorestframework==3.3.3 +mysqlclient==1.3.7 +python-dateutil==2.5.1 +py-trello==0.4.3 diff --git a/static/js/attachments.js b/static/js/attachments.js index e10d559..c5030e4 100644 --- a/static/js/attachments.js +++ b/static/js/attachments.js @@ -7,7 +7,7 @@ $(function () { }, dataType: 'json', done: function (e, data) { - $('.attachments ul').append('
  • '+ + $('.attachments ul').append('
  • '+ data.files[0].name + ' (ny)
  • '); /* Reset progress */ diff --git a/tekst/migrations/0001_initial.py b/tekst/migrations/0001_initial.py new file mode 100644 index 0000000..a4a5038 --- /dev/null +++ b/tekst/migrations/0001_initial.py @@ -0,0 +1,37 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import migrations, models +import django_extensions.db.fields + + +class Migration(migrations.Migration): + + dependencies = [ + ] + + operations = [ + migrations.CreateModel( + name='TekstOrder', + fields=[ + ('id', models.AutoField(verbose_name='ID', auto_created=True, serialize=False, primary_key=True)), + ('uuid', django_extensions.db.fields.UUIDField(editable=False, version=1, blank=True, unique=True)), + ('client', models.CharField(max_length=50)), + ('deadline', models.DateField()), + ('contact_name', models.CharField(max_length=50)), + ('contact_email', models.CharField(max_length=50)), + ('contact_number', models.CharField(null=True, max_length=20, blank=True)), + ('created', models.DateTimeField(auto_now_add=True)), + ('trello_card_id', models.CharField(max_length=40)), + ('text_type', models.CharField(max_length=50)), + ('length', models.CharField(max_length=50)), + ('image', models.CharField(max_length=50)), + ('interview_name', models.CharField(max_length=20)), + ('interview_contact', models.TextField(null=True, blank=True)), + ('content', models.TextField(null=True, blank=True)), + ], + options={ + 'abstract': False, + }, + ), + ] diff --git a/tekst/migrations/0002_auto_20160322_1520.py b/tekst/migrations/0002_auto_20160322_1520.py new file mode 100644 index 0000000..49bb43c --- /dev/null +++ b/tekst/migrations/0002_auto_20160322_1520.py @@ -0,0 +1,19 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('tekst', '0001_initial'), + ] + + operations = [ + migrations.AlterField( + model_name='tekstorder', + name='uuid', + field=models.UUIDField(unique=True), + ), + ] diff --git a/tekst/migrations/__init__.py b/tekst/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tekst/urls.py b/tekst/urls.py index 0d3abff..8230af4 100644 --- a/tekst/urls.py +++ b/tekst/urls.py @@ -1,8 +1,7 @@ -from django.conf.urls import patterns +from django.conf.urls import url from tekst.views import TekstFormView, TekstOrderView -urlpatterns = patterns( - 'tekst.views', - (r'^$', TekstFormView.as_view()), - (r'^order/(?P[a-zA-Z0-9-]+)/', TekstOrderView.as_view()), -) +urlpatterns = [ + url(r'^$', TekstFormView.as_view()), + url(r'^order/(?P[a-zA-Z0-9-]+)/', TekstOrderView.as_view()), +] diff --git a/tekst/views.py b/tekst/views.py index de038f0..9aab1f2 100644 --- a/tekst/views.py +++ b/tekst/views.py @@ -40,7 +40,7 @@ class TekstFormView(BaseFormView): }) # Filter out all errors that are False: - return dict((error, True) for error, has_happened in errors.iteritems() if has_happened is True) + return dict((error, True) for error, has_happened in errors.items() if has_happened is True) def _get_order_url(self, request, order): return request.build_absolute_uri('/tekst/order/{uuid}/'.format(uuid=order.uuid)) diff --git a/templates/form_base.html b/templates/form_base.html index 0736085..29d647b 100644 --- a/templates/form_base.html +++ b/templates/form_base.html @@ -1,4 +1,4 @@ - + {% block title %}{% endblock %} diff --git a/templates/form_success.html b/templates/form_success.html index 9b216fa..2a2d935 100644 --- a/templates/form_success.html +++ b/templates/form_success.html @@ -1,4 +1,4 @@ - + Kommunikasjonsavdelingen - Bestillingen er sendt diff --git a/templates/order_base.html b/templates/order_base.html index 3e7c766..3488bf9 100644 --- a/templates/order_base.html +++ b/templates/order_base.html @@ -1,4 +1,4 @@ - + {% block title %}{% endblock %}