# Path: apps/account/models.py
# class Account(Model):
# 
#     # main data
#     user = ForeignKey('auth.User', unique=True, related_name="accounts")
#     description = TextField(blank=True)
#     source = CharField(max_length=64, choices=SOURCE_CHOICES, default='OTHER')
#     mobile = CharField(max_length=1024, blank=True)
#     links = ManyToManyField('link.Link', null=True, blank=True) 
#     passport = ProcessedImageField(upload_to=_upload_to, null=True, blank=True, 
#                                    processors=[ResizeToFit(1024, 768)],
#                                    format='JPEG', options={'quality': 90})
# 
#     # meta
#     # created_by = self
#     # updated_by = self
#     created_on = DateTimeField(auto_now_add=True)
#     updated_on = DateTimeField(auto_now=True)
# 
#     def get_name():
#         return self.user.username
# 
#     def __unicode__(self):
#         return self.user.username
# 
#     class Meta:
# 
#         ordering = ['user__username']
# 
# Path: apps/station/control.py
# def can_edit(account, station):
# def in_use(station):
# def can_delete(account, station):
# def can_deactivate(account, station):
# def create( account, team, responsible, 
#             active, street, city, postalcode ):
# def edit( account, station, responsible, 
#           active, street, city, postalcode ):
# def delete(account, station):


from django.utils.translation import ugettext as _
from django import forms
from django.forms import ValidationError
from apps.account.models import Account
from apps.common.shortcuts import COUNTRIES
from apps.station import control
    active = forms.BooleanField(label=_("ACTIVE"), required=False)

    def __init__(self, *args, **kwargs):
        self.station = kwargs.pop("station")
        self.account = kwargs.pop("account")
        super(Edit, self).__init__(*args, **kwargs)
        self.fields["responsible"].queryset = self.station.team.members.all()
        self.fields["responsible"].initial = self.station.responsible
        self.fields["postalcode"].initial = self.station.postalcode
        self.fields["city"].initial = self.station.city
        self.fields["street"].initial = self.station.street
        self.fields["active"].initial = self.station.active

    def clean(self):
        cleaned_data = super(Edit, self).clean()
        if (not cleaned_data.get("active") and 
                not control.can_deactivate(self.account, self.station)):
            raise ValidationError(_("ERROR_CANNOT_DEACTIVATE_STATION_IN_USE"))
        return cleaned_data


class Delete(forms.Form):

    def __init__(self, *args, **kwargs):
        self.station = kwargs.pop("station")
        self.account = kwargs.pop("account")
        super(Delete, self).__init__(*args, **kwargs)

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

# Path: apps/account/models.py
# class Account(Model):
# 
#     # main data
#     user = ForeignKey('auth.User', unique=True, related_name="accounts")
#     description = TextField(blank=True)
#     source = CharField(max_length=64, choices=SOURCE_CHOICES, default='OTHER')
#     mobile = CharField(max_length=1024, blank=True)
#     links = ManyToManyField('link.Link', null=True, blank=True) 
#     passport = ProcessedImageField(upload_to=_upload_to, null=True, blank=True, 
#                                    processors=[ResizeToFit(1024, 768)],
#                                    format='JPEG', options={'quality': 90})
# 
#     # meta
#     # created_by = self
#     # updated_by = self
#     created_on = DateTimeField(auto_now_add=True)
#     updated_on = DateTimeField(auto_now=True)
# 
#     def get_name():
#         return self.user.username
# 
#     def __unicode__(self):
#         return self.user.username
# 
#     class Meta:
# 
#         ordering = ['user__username']
# 
# Path: apps/station/control.py
# def can_edit(account, station):
# def in_use(station):
# def can_delete(account, station):
# def can_deactivate(account, station):
# def create( account, team, responsible, 
#             active, street, city, postalcode ):
# def edit( account, station, responsible, 
#           active, street, city, postalcode ):
# def delete(account, station):


# Path: apps/station/forms.py
from django.utils.translation import ugettext as _
from django import forms
from django.forms import ValidationError
from apps.account.models import Account
from apps.common.shortcuts import COUNTRIES
from apps.station import control

    active = forms.BooleanField(label=_("ACTIVE"), required=False)

    def __init__(self, *args, **kwargs):
        self.station = kwargs.pop("station")
        self.account = kwargs.pop("account")
        super(Edit, self).__init__(*args, **kwargs)
        self.fields["responsible"].queryset = self.station.team.members.all()
        self.fields["responsible"].initial = self.station.responsible
        self.fields["postalcode"].initial = self.station.postalcode
        self.fields["city"].initial = self.station.city
        self.fields["street"].initial = self.station.street
        self.fields["active"].initial = self.station.active

    def clean(self):
        cleaned_data = super(Edit, self).clean()
        if (not cleaned_data.get("active") and 
                not control.can_deactivate(self.account, self.station)):
            raise ValidationError(_("ERROR_CANNOT_DEACTIVATE_STATION_IN_USE"))
        return cleaned_data


class Delete(forms.Form):

    def __init__(self, *args, **kwargs):
        self.station = kwargs.pop("station")
        self.account = kwargs.pop("account")
        super(Delete, self).__init__(*args, **kwargs)

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

        if not control.can_delete(self.account, self.station):