# 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/team/control.py
# def get_team_emails(team, excludes=None):
# def get_teams(account):
# def get_or_404(link):
# def is_member(account, team):
# def create(account, name, country, logo, application):
# def notify_staff_team_created(sender, **kwargs):
# def notify_team_join_request_created(sender, **kwargs):
# def notify_team_join_request_processed(sender, **kwargs):
# def notify_concerned_remove_request_created(sender, **kwargs):
# def notify_team_remove_request_created(sender, **kwargs):
# def notify_team_remove_request_processed(sender, **kwargs):
# def can_replace_logo(account, team):
# def replace_logo(account, team, logo):
# def can_join(account, team):
# def create_join_request(account, team, application):
# def can_process_join_request(account, join_request):
# def process_join_request(account, join_request, response, status):
# def has_remove_request(concerned, team):
# def can_create_remove_request(requester, concerned, team):
# def can_process_remove_request(account, remove_request):
# def create_remove_request(requester, concerned, team, reason):
# def process_remove_request(account, remove_request, response, status):
# def site_link_exists(team, site):
# def can_create_link(account, team, site, profile):
# def can_delete_link(account, team, link):
# def link_create(account, team, site, profile):
# def link_delete(account, team, link):
# 
# Path: apps/account/control.py
# def get_site_account():
# def get_email_or_404(account):
# def get_staff_emails():
# def get_superuser_emails():
# def set_passport(account, passport):
# def can_view_account(current_account, view_account):
# def edit(account, username, first_name, last_name, mobile, source, description):
# def has_fullname(account):
# def has_mobile(account):
# def has_passport(account):
# def has_required_info(account):
# def site_link_exists(account, site):
# def can_create_link(account, site, profile):
# def can_delete_link(account, link):
# def link_create(account, site, profile):
# def link_delete(account, link):
# 
# Path: apps/station/forms.py
# def validate_station_active(station):
#     if not station.active:
#         raise ValidationError(_("ERROR_STATION_MUST_BE_ACTIVE"))
# 
# Path: config/settings.py
# BORROW_MIN_BOOK_IN_ADVANCE_DAYS = 2


import datetime
from django.utils.translation import ugettext as _
from django.forms import Form
from django.forms import BooleanField
from django.forms import DateField
from django.forms import ValidationError
from django.forms import CharField
from django.forms import Textarea
from django.forms import ChoiceField
from django.forms import TypedChoiceField
from django.forms import RadioSelect
from django.forms.widgets import DateInput
from django.core.exceptions import PermissionDenied
from django.forms import ModelChoiceField
from django.utils.safestring import mark_safe
from apps.borrow.models import Borrow
from apps.borrow.models import RATING_CHOICES, STATE_FILTER_CHOICES
from apps.borrow import control
from apps.bike import control as bike_control
from apps.team import control as team_control
from apps.account import control as account_control
from apps.station.forms import validate_station_active
from config.settings import BORROW_MIN_BOOK_IN_ADVANCE_DAYS as MIN_DAYS
        self.bike = kwargs.pop("bike")
        self.account = kwargs.pop("account")
        self.is_lender = kwargs.pop("is_lender")
        start = kwargs.pop("start")
        finish = kwargs.pop("finish")
        super(Create, self).__init__(*args, **kwargs)
        today = datetime.datetime.now()
        start = start and start or (today + datetime.timedelta(days=MIN_DAYS)) 
        finish = finish and finish or (start + datetime.timedelta(days=7))
        self.fields["start"].initial = start
        self.fields["finish"].initial = finish

    def clean(self):
        cleaned_data = super(Create, self).clean()

        # check timeframe
        start = cleaned_data.get("start")
        finish = cleaned_data.get("finish")
        _validate_borrow_timeframe(self.account, self.bike, start, finish, 
                                   self.is_lender)

        # must accept terms
        if not cleaned_data.get("terms_accepted"):
            raise ValidationError(_("ERROR_MUST_ACCEPT_TERMS"))

        # must have full name
        if not account_control.has_fullname(self.account):
            raise ValidationError(_("ERROR_ACCOUNT_REQUIRES_FULLNAME"))

        # must have a mobile

# 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/team/control.py
# def get_team_emails(team, excludes=None):
# def get_teams(account):
# def get_or_404(link):
# def is_member(account, team):
# def create(account, name, country, logo, application):
# def notify_staff_team_created(sender, **kwargs):
# def notify_team_join_request_created(sender, **kwargs):
# def notify_team_join_request_processed(sender, **kwargs):
# def notify_concerned_remove_request_created(sender, **kwargs):
# def notify_team_remove_request_created(sender, **kwargs):
# def notify_team_remove_request_processed(sender, **kwargs):
# def can_replace_logo(account, team):
# def replace_logo(account, team, logo):
# def can_join(account, team):
# def create_join_request(account, team, application):
# def can_process_join_request(account, join_request):
# def process_join_request(account, join_request, response, status):
# def has_remove_request(concerned, team):
# def can_create_remove_request(requester, concerned, team):
# def can_process_remove_request(account, remove_request):
# def create_remove_request(requester, concerned, team, reason):
# def process_remove_request(account, remove_request, response, status):
# def site_link_exists(team, site):
# def can_create_link(account, team, site, profile):
# def can_delete_link(account, team, link):
# def link_create(account, team, site, profile):
# def link_delete(account, team, link):
# 
# Path: apps/account/control.py
# def get_site_account():
# def get_email_or_404(account):
# def get_staff_emails():
# def get_superuser_emails():
# def set_passport(account, passport):
# def can_view_account(current_account, view_account):
# def edit(account, username, first_name, last_name, mobile, source, description):
# def has_fullname(account):
# def has_mobile(account):
# def has_passport(account):
# def has_required_info(account):
# def site_link_exists(account, site):
# def can_create_link(account, site, profile):
# def can_delete_link(account, link):
# def link_create(account, site, profile):
# def link_delete(account, link):
# 
# Path: apps/station/forms.py
# def validate_station_active(station):
#     if not station.active:
#         raise ValidationError(_("ERROR_STATION_MUST_BE_ACTIVE"))
# 
# Path: config/settings.py
# BORROW_MIN_BOOK_IN_ADVANCE_DAYS = 2


# Path: apps/borrow/forms.py
import datetime
from django.utils.translation import ugettext as _
from django.forms import Form
from django.forms import BooleanField
from django.forms import DateField
from django.forms import ValidationError
from django.forms import CharField
from django.forms import Textarea
from django.forms import ChoiceField
from django.forms import TypedChoiceField
from django.forms import RadioSelect
from django.forms.widgets import DateInput
from django.core.exceptions import PermissionDenied
from django.forms import ModelChoiceField
from django.utils.safestring import mark_safe
from apps.borrow.models import Borrow
from apps.borrow.models import RATING_CHOICES, STATE_FILTER_CHOICES
from apps.borrow import control
from apps.bike import control as bike_control
from apps.team import control as team_control
from apps.account import control as account_control
from apps.station.forms import validate_station_active
from config.settings import BORROW_MIN_BOOK_IN_ADVANCE_DAYS as MIN_DAYS

        self.bike = kwargs.pop("bike")
        self.account = kwargs.pop("account")
        self.is_lender = kwargs.pop("is_lender")
        start = kwargs.pop("start")
        finish = kwargs.pop("finish")
        super(Create, self).__init__(*args, **kwargs)
        today = datetime.datetime.now()
        start = start and start or (today + datetime.timedelta(days=MIN_DAYS)) 
        finish = finish and finish or (start + datetime.timedelta(days=7))
        self.fields["start"].initial = start
        self.fields["finish"].initial = finish

    def clean(self):
        cleaned_data = super(Create, self).clean()

        # check timeframe
        start = cleaned_data.get("start")
        finish = cleaned_data.get("finish")
        _validate_borrow_timeframe(self.account, self.bike, start, finish, 
                                   self.is_lender)

        # must accept terms
        if not cleaned_data.get("terms_accepted"):
            raise ValidationError(_("ERROR_MUST_ACCEPT_TERMS"))

        # must have full name
        if not account_control.has_fullname(self.account):
            raise ValidationError(_("ERROR_ACCOUNT_REQUIRES_FULLNAME"))

        # must have a mobile

        if not account_control.has_mobile(self.account):