Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions apps/web/forms.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
from django import forms
from . import models


class SearchJourney(forms.Form):
city_from = forms.CharField()
city_to = forms.CharField()


class Journey(forms.ModelForm):
#waypoints_count = forms.CharField(widget=forms.HiddenInput())
waypoints_count = forms.CharField()

class Meta:
model = models.Journey
fields = ['seats', 'date', 'approx', 'approx_note', 'currency']

def __init__(self, *args, **kwargs):
extra_fields = kwargs.pop('extra', 0)

super(Journey, self).__init__(*args, **kwargs)
self.fields['waypoints_count'].initial = extra_fields

#for index in range(int(extra_fields)):
if True:
index=''
# generate extra fields in the number specified via extra_fields
self.fields['waypoint_{index}_place'.format(index=index)] = \
forms.CharField()
self.fields['waypoint_{index}_note'.format(index=index)] = \
forms.CharField()
self.fields['waypoint_{index}_output_only'.format(index=index)] = \
forms.BooleanField()
self.fields['waypoint_{index}_price'.format(index=index)] = \
forms.FloatField()
24 changes: 24 additions & 0 deletions apps/web/migrations/0002_auto_20160214_1254.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.9.2 on 2016-02-14 12:54
from __future__ import unicode_literals

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('web', '0001_initial'),
]

operations = [
migrations.RemoveField(
model_name='journey',
name='price',
),
migrations.AddField(
model_name='journey',
name='seats',
field=models.IntegerField(default=0, verbose_name='Amount of availabe seats for this journey'),
),
]
20 changes: 20 additions & 0 deletions apps/web/migrations/0003_auto_20160223_2303.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.9.2 on 2016-02-23 23:03
from __future__ import unicode_literals

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('web', '0002_auto_20160214_1254'),
]

operations = [
migrations.AlterField(
model_name='journey',
name='seats',
field=models.IntegerField(default=0, verbose_name='Amount of available seats for this journey'),
),
]
30 changes: 12 additions & 18 deletions apps/web/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from django.db import models
from django.conf import settings
from django.db.models import signals
#from django.contrib.gis.db import models as gis_models
from django.contrib.auth.models import User


Expand Down Expand Up @@ -35,9 +34,12 @@ def create_user_profile(sender, instance, created, **kwargs):
# Create your models here.
class Waypoint(models.Model):
city = models.CharField(max_length=100)
#distinct = models.CharField(max_length=100,
# help_text=_('Okres'),
# blank=True,
# null=True)
lat = models.FloatField(verbose_name=_('Lattitude'), default=0)
long = models.FloatField(verbose_name=_('Longtitude'), default=0)
#coord = gis_models.PointField(geography=True)

def __str__(self):
return self.city
Expand All @@ -64,16 +66,6 @@ def __str__(self):


class Journey(models.Model):
# city_from = models.ForeignKey(
# Waypoint,
# on_delete=models.CASCADE,
# related_name='wpt_from'
# )
# city_to = models.ForeignKey(
# Waypoint,
# on_delete=models.CASCADE,
# related_name='wpt_to'
# )
CZK = 'CZK'
EUR = 'EUR'

Expand All @@ -82,23 +74,23 @@ class Journey(models.Model):
(EUR, 'Eur'),
)

price = models.FloatField(
seats = models.IntegerField(
default=0,
help_text=_('Price for whole journey from beginning to end.')
verbose_name=_('Amount of available seats for this journey')
)
date = models.DateTimeField(
default=timezone.now,
verbose_name='Date/time of start of journey'
verbose_name=_('Date/time of start of journey')
)
approx = models.BooleanField(
default='',
verbose_name='Driver is not sure about exact time of departure'
verbose_name=_('Driver is not sure about exact time of departure')
)
approx_note = models.CharField(
max_length=100,
blank=True,
verbose_name=('If approx is applied, this can be used for short note '
'to departure'))
verbose_name=_('If approx is applied, this can be used for short note '
'to departure'))
waypoints = models.ManyToManyField(Waypoint, through='JourneyWaypoints')
currency = models.CharField(
max_length=3,
Expand Down Expand Up @@ -166,6 +158,8 @@ class Meta:
def __str__(self):
return '%s [#%s]: %s' % (self.journey, self.order, self.waypoint)

def free_seats(self):
return self.journey.seats - self.passangers.filter(state__exact=Passanger.SUBSCRIBED).count()


class Passanger(models.Model):
Expand Down
Loading