# Path: apps/bike/models.py
# SIZE_CHOICES = [      # Body Hight
#     ('SMALL', _('SMALL')),  # 0cm - 145cm
#     ('MEDIUM', _('MEDIUM')), # 145cm - 175cm
#     ('LARGE', _('LARGE'))   # 175cm + 
# ]
# 
# Path: apps/bike/control.py
# def team_bikes(team, include_reserve=False, include_inactive=False):
# def available(team, start, finish, include_reserve=False, 
#               include_inactive=False, include_bike=None):
# def has_future_borrows(bike):
# def currently_borrowed(bike):
# def can_change_station(account, bike, station):
# def can_deactivate(account, bike):
# def can_delete(account, bike):
# def create( account, team, name, image, description, active, reserve, station, 
#             lockcode, size, lights ):
# def edit_is_allowed(account, bike, name, description, active, reserve, station, 
#                     lockcode, size, lights):
# def _change_station(account, bike, station):
# def edit( account, bike, name, description, active, reserve, station, lockcode, 
#           size, lights ):
# def delete(account, bike):
# def update_stations():


import datetime
from django.utils.translation import ugettext as _
from django.forms import ValidationError
from django.forms import Form
from django.forms import Textarea
from django.forms import ModelChoiceField
from django.forms import CharField
from django.forms import BooleanField
from django.forms import ChoiceField
from django.forms import ImageField
from django.forms import DateField
from django.forms.widgets import DateInput
from django.forms.widgets import CheckboxInput
from django.forms import Select
from apps.bike.models import SIZE_CHOICES
from apps.bike import control
    station = ModelChoiceField(label=_("STATION"), queryset=None, required=True)
    lockcode = CharField(label=_("LOCKCODE"))
    size = ChoiceField(choices=SIZE_CHOICES, label=_("SIZE"), initial="MEDIUM")
    lights = BooleanField(label=_("LIGHTS"), initial=False, required=False)
    description = CharField(label=_("DESCRIPTION"), widget=Textarea)

    def __init__(self, *args, **kwargs):
        self.bike = kwargs.pop("bike")
        self.account = kwargs.pop("account")
        super(Edit, self).__init__(*args, **kwargs)
        self.fields["name"].initial = self.bike.name
        self.fields["active"].initial = self.bike.active
        self.fields["reserve"].initial = self.bike.reserve
        self.fields["station"].queryset = self.bike.team.stations.filter(active=True)
        self.fields["station"].initial = self.bike.station
        self.fields["lockcode"].initial = self.bike.lockcode
        self.fields["size"].initial = self.bike.size
        self.fields["lights"].initial = self.bike.lights
        self.fields["description"].initial = self.bike.description

    def clean(self):
        cleaned_data = super(Edit, self).clean()
        station = cleaned_data.get("station")
        active = cleaned_data.get("active")

        if (not active and self.bike.active and
                not control.can_deactivate(self.account, self.bike)):
            raise ValidationError(_("ERROR_CANNOT_DEACTIVATE_BIKE_IN_USE"))

        if (station and station != self.bike.station and

# Path: apps/bike/models.py
# SIZE_CHOICES = [      # Body Hight
#     ('SMALL', _('SMALL')),  # 0cm - 145cm
#     ('MEDIUM', _('MEDIUM')), # 145cm - 175cm
#     ('LARGE', _('LARGE'))   # 175cm + 
# ]
# 
# Path: apps/bike/control.py
# def team_bikes(team, include_reserve=False, include_inactive=False):
# def available(team, start, finish, include_reserve=False, 
#               include_inactive=False, include_bike=None):
# def has_future_borrows(bike):
# def currently_borrowed(bike):
# def can_change_station(account, bike, station):
# def can_deactivate(account, bike):
# def can_delete(account, bike):
# def create( account, team, name, image, description, active, reserve, station, 
#             lockcode, size, lights ):
# def edit_is_allowed(account, bike, name, description, active, reserve, station, 
#                     lockcode, size, lights):
# def _change_station(account, bike, station):
# def edit( account, bike, name, description, active, reserve, station, lockcode, 
#           size, lights ):
# def delete(account, bike):
# def update_stations():


# Path: apps/bike/forms.py
import datetime
from django.utils.translation import ugettext as _
from django.forms import ValidationError
from django.forms import Form
from django.forms import Textarea
from django.forms import ModelChoiceField
from django.forms import CharField
from django.forms import BooleanField
from django.forms import ChoiceField
from django.forms import ImageField
from django.forms import DateField
from django.forms.widgets import DateInput
from django.forms.widgets import CheckboxInput
from django.forms import Select
from apps.bike.models import SIZE_CHOICES
from apps.bike import control

    station = ModelChoiceField(label=_("STATION"), queryset=None, required=True)
    lockcode = CharField(label=_("LOCKCODE"))
    size = ChoiceField(choices=SIZE_CHOICES, label=_("SIZE"), initial="MEDIUM")
    lights = BooleanField(label=_("LIGHTS"), initial=False, required=False)
    description = CharField(label=_("DESCRIPTION"), widget=Textarea)

    def __init__(self, *args, **kwargs):
        self.bike = kwargs.pop("bike")
        self.account = kwargs.pop("account")
        super(Edit, self).__init__(*args, **kwargs)
        self.fields["name"].initial = self.bike.name
        self.fields["active"].initial = self.bike.active
        self.fields["reserve"].initial = self.bike.reserve
        self.fields["station"].queryset = self.bike.team.stations.filter(active=True)
        self.fields["station"].initial = self.bike.station
        self.fields["lockcode"].initial = self.bike.lockcode
        self.fields["size"].initial = self.bike.size
        self.fields["lights"].initial = self.bike.lights
        self.fields["description"].initial = self.bike.description

    def clean(self):
        cleaned_data = super(Edit, self).clean()
        station = cleaned_data.get("station")
        active = cleaned_data.get("active")

        if (not active and self.bike.active and
                not control.can_deactivate(self.account, self.bike)):
            raise ValidationError(_("ERROR_CANNOT_DEACTIVATE_BIKE_IN_USE"))

        if (station and station != self.bike.station and

                not control.can_change_station(self.account, self.bike, station)):