From 29233724888b7188113bf186f8f5b1c8f6ee8b0f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=AD=C3=B0ir=20Valberg=20Gu=C3=B0mundsson?= Date: Fri, 22 Apr 2016 22:38:44 +0200 Subject: [PATCH] Adding tickets app, removing signup from camps app, setting dev db to postgres. --- bornhack/settings/base.py | 1 + bornhack/settings/development.py | 8 ++- camps/admin.py | 12 +--- camps/migrations/0003_auto_20160422_2019.py | 26 +++++++++ camps/models.py | 32 ----------- tickets/__init__.py | 0 tickets/admin.py | 29 ++++++++++ tickets/apps.py | 5 ++ tickets/migrations/0001_initial.py | 62 +++++++++++++++++++++ tickets/migrations/__init__.py | 0 tickets/models.py | 60 ++++++++++++++++++++ tickets/tests.py | 3 + tickets/views.py | 3 + 13 files changed, 196 insertions(+), 45 deletions(-) create mode 100644 camps/migrations/0003_auto_20160422_2019.py create mode 100644 tickets/__init__.py create mode 100644 tickets/admin.py create mode 100644 tickets/apps.py create mode 100644 tickets/migrations/0001_initial.py create mode 100644 tickets/migrations/__init__.py create mode 100644 tickets/models.py create mode 100644 tickets/tests.py create mode 100644 tickets/views.py diff --git a/bornhack/settings/base.py b/bornhack/settings/base.py index f0d7a5b8..31e32b80 100644 --- a/bornhack/settings/base.py +++ b/bornhack/settings/base.py @@ -23,6 +23,7 @@ INSTALLED_APPS = [ 'profiles', 'camps', + 'tickets', 'allauth', 'allauth.account', diff --git a/bornhack/settings/development.py b/bornhack/settings/development.py index 0b08e734..a58764ff 100644 --- a/bornhack/settings/development.py +++ b/bornhack/settings/development.py @@ -7,8 +7,12 @@ DEBUG = True DATABASES = { 'default': { - 'ENGINE': 'django.db.backends.sqlite3', - 'NAME': local_dir('db.sqlite3'), + 'ENGINE': 'django.db.backends.postgresql_psycopg2', + 'NAME': 'bornhack_dev', + 'USER': 'bornhack', + 'PASSWORD': 'bornhack', + 'HOST': 'localhost', + 'PORT': 5432, } } diff --git a/camps/admin.py b/camps/admin.py index b1188ff7..54fda1ab 100644 --- a/camps/admin.py +++ b/camps/admin.py @@ -1,6 +1,6 @@ from django.contrib import admin -from .models import Camp, Day, Expense, Signup +from .models import Camp, Day, Expense @admin.register(Expense) @@ -12,15 +12,6 @@ class ExpenseInlineAdmin(admin.TabularInline): model = Expense -@admin.register(Signup) -class SignupAdmin(admin.ModelAdmin): - pass - - -class SignupInlineAdmin(admin.TabularInline): - model = Signup - - @admin.register(Day) class DayAdmin(admin.ModelAdmin): pass @@ -35,5 +26,4 @@ class CampAdmin(admin.ModelAdmin): inlines = [ DayInlineAdmin, ExpenseInlineAdmin, - SignupInlineAdmin ] diff --git a/camps/migrations/0003_auto_20160422_2019.py b/camps/migrations/0003_auto_20160422_2019.py new file mode 100644 index 00000000..108b78ba --- /dev/null +++ b/camps/migrations/0003_auto_20160422_2019.py @@ -0,0 +1,26 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.9.2 on 2016-04-22 20:19 +from __future__ import unicode_literals + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('camps', '0002_auto_20160117_1718'), + ] + + operations = [ + migrations.RemoveField( + model_name='signup', + name='camp', + ), + migrations.RemoveField( + model_name='signup', + name='user', + ), + migrations.DeleteModel( + name='Signup', + ), + ] diff --git a/camps/models.py b/camps/models.py index dcf77461..89e5e312 100644 --- a/camps/models.py +++ b/camps/models.py @@ -118,35 +118,3 @@ class Expense(CreatedUpdatedModel, UUIDModel): self.get_currency_display(), self.camp, ) - - -class Signup(CreatedUpdatedModel, UUIDModel): - class Meta: - verbose_name = _('Signup') - verbose_name_plural = _('Signups') - - camp = models.ForeignKey( - 'camps.Camp', - verbose_name=_('Camp'), - help_text=_('The camp that has been signed up for.'), - ) - - user = models.ForeignKey( - 'auth.User', - verbose_name=_('User'), - help_text=_('The user that has signed up.'), - ) - - cost = models.DecimalField( - verbose_name=_('Cost'), - help_text=_('What the user should/is willing to pay for this signup.'), - max_digits=7, - decimal_places=2, - default=1500.0 - ) - - paid = models.BooleanField( - verbose_name=_('Paid?'), - help_text=_('Whether the user has paid.'), - default=False, - ) diff --git a/tickets/__init__.py b/tickets/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/tickets/admin.py b/tickets/admin.py new file mode 100644 index 00000000..d3a14445 --- /dev/null +++ b/tickets/admin.py @@ -0,0 +1,29 @@ +from django.contrib import admin + +from .models import Ticket, TicketType + + +@admin.register(Ticket) +class TicketAdmin(admin.ModelAdmin): + list_display = [ + 'user', + 'ticket_type', + 'camp', + 'paid', + ] + + list_filter = [ + 'paid', + 'ticket_type', + 'camp', + ] + + +@admin.register(TicketType) +class TicketTypeAdmin(admin.ModelAdmin): + list_display = [ + 'name', + 'price', + 'available_in', + 'camp', + ] diff --git a/tickets/apps.py b/tickets/apps.py new file mode 100644 index 00000000..3ea742ac --- /dev/null +++ b/tickets/apps.py @@ -0,0 +1,5 @@ +from django.apps import AppConfig + + +class TicketsConfig(AppConfig): + name = 'tickets' diff --git a/tickets/migrations/0001_initial.py b/tickets/migrations/0001_initial.py new file mode 100644 index 00000000..f70ef453 --- /dev/null +++ b/tickets/migrations/0001_initial.py @@ -0,0 +1,62 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.9.2 on 2016-04-22 20:19 +from __future__ import unicode_literals + +from django.conf import settings +import django.contrib.postgres.fields.ranges +from django.db import migrations, models +import django.db.models.deletion +import uuid + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + ('camps', '0003_auto_20160422_2019'), + migrations.swappable_dependency(settings.AUTH_USER_MODEL), + ] + + operations = [ + migrations.CreateModel( + name='Ticket', + fields=[ + ('created', models.DateTimeField(auto_now_add=True)), + ('updated', models.DateTimeField(auto_now=True)), + ('uuid', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)), + ('paid', models.BooleanField(default=False, help_text='Whether the user has paid.', verbose_name='Paid?')), + ('camp', models.ForeignKey(help_text='The camp this ticket is for.', on_delete=django.db.models.deletion.CASCADE, to='camps.Camp', verbose_name='Camp')), + ], + options={ + 'verbose_name_plural': 'Tickets', + 'verbose_name': 'Ticket', + }, + ), + migrations.CreateModel( + name='TicketType', + fields=[ + ('created', models.DateTimeField(auto_now_add=True)), + ('updated', models.DateTimeField(auto_now=True)), + ('uuid', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)), + ('name', models.CharField(max_length=100)), + ('price', models.IntegerField(help_text='Price of the ticket (in DKK).')), + ('available_in', django.contrib.postgres.fields.ranges.DateTimeRangeField(help_text='Which period is this ticket available for purchase?')), + ('camp', models.ForeignKey(help_text='The camp this ticket type is for.', on_delete=django.db.models.deletion.CASCADE, to='camps.Camp', verbose_name='Camp')), + ], + options={ + 'verbose_name_plural': 'Ticket Types', + 'verbose_name': 'Ticket Type', + }, + ), + migrations.AddField( + model_name='ticket', + name='ticket_type', + field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='tickets.TicketType'), + ), + migrations.AddField( + model_name='ticket', + name='user', + field=models.ForeignKey(help_text='The user this ticket belongs to.', on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL, verbose_name='User'), + ), + ] diff --git a/tickets/migrations/__init__.py b/tickets/migrations/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/tickets/models.py b/tickets/models.py new file mode 100644 index 00000000..2edeedc6 --- /dev/null +++ b/tickets/models.py @@ -0,0 +1,60 @@ +from django.db import models +from django.contrib.postgres.fields import DateTimeRangeField +from django.utils.translation import ugettext_lazy as _ + +from bornhack.utils import CreatedUpdatedModel, UUIDModel + + +class Ticket(CreatedUpdatedModel, UUIDModel): + class Meta: + verbose_name = _('Ticket') + verbose_name_plural = _('Tickets') + + camp = models.ForeignKey( + 'camps.Camp', + verbose_name=_('Camp'), + help_text=_('The camp this ticket is for.'), + ) + + user = models.ForeignKey( + 'auth.User', + verbose_name=_('User'), + help_text=_('The user this ticket belongs to.'), + ) + + paid = models.BooleanField( + verbose_name=_('Paid?'), + help_text=_('Whether the user has paid.'), + default=False, + ) + + ticket_type = models.ForeignKey( + 'tickets.TicketType', + verbose_name=_('Ticket type'), + help_text=_('The type of the ticket.'), + ) + + +class TicketType(CreatedUpdatedModel, UUIDModel): + class Meta: + verbose_name = _('Ticket Type') + verbose_name_plural = _('Ticket Types') + + name = models.CharField(max_length=150) + + camp = models.ForeignKey( + 'camps.Camp', + verbose_name=_('Camp'), + help_text=_('The camp this ticket type is for.'), + ) + + price = models.IntegerField( + help_text=_('Price of the ticket (in DKK).') + ) + + available_in = DateTimeRangeField( + help_text=_('Which period is this ticket available for purchase?') + ) + + def __str__(self): + return self.name diff --git a/tickets/tests.py b/tickets/tests.py new file mode 100644 index 00000000..7ce503c2 --- /dev/null +++ b/tickets/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/tickets/views.py b/tickets/views.py new file mode 100644 index 00000000..91ea44a2 --- /dev/null +++ b/tickets/views.py @@ -0,0 +1,3 @@ +from django.shortcuts import render + +# Create your views here.