# Path: apps/link/control.py
# def valid_profile_format(profile, site):
# def can_create(account, site, profile):
# def ensure_https(profile):
# def create(account, site, profile):
# 
# 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']


import os
from django.core.exceptions import PermissionDenied
from django.shortcuts import get_object_or_404
from django.contrib.sites.models import Site
from allauth.account.models import EmailAddress
from apps.link import control as link_control
from apps.borrow.models import Borrow
from apps.account.models import Account
from apps.common.shortcuts import get_object_or_none
    return bool(account.passport)


def has_required_info(account):
    return (has_fullname(account) and 
            has_mobile(account) and 
            has_passport(account))


#########
# LINKS #
#########


def site_link_exists(account, site):
    return bool(list(account.links.filter(site=site)))


def can_create_link(account, site, profile):
    exists = site_link_exists(account, site)
    return link_control.valid_profile_format(profile, site) and not exists


def can_delete_link(account, link):
    return link in account.links.all()


def link_create(account, site, profile):
    if not can_create_link(account, site, profile):
        raise PermissionDenied

# Path: apps/link/control.py
# def valid_profile_format(profile, site):
# def can_create(account, site, profile):
# def ensure_https(profile):
# def create(account, site, profile):
# 
# 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/account/control.py
import os
from django.core.exceptions import PermissionDenied
from django.shortcuts import get_object_or_404
from django.contrib.sites.models import Site
from allauth.account.models import EmailAddress
from apps.link import control as link_control
from apps.borrow.models import Borrow
from apps.account.models import Account
from apps.common.shortcuts import get_object_or_none

    return bool(account.passport)


def has_required_info(account):
    return (has_fullname(account) and 
            has_mobile(account) and 
            has_passport(account))


#########
# LINKS #
#########


def site_link_exists(account, site):
    return bool(list(account.links.filter(site=site)))


def can_create_link(account, site, profile):
    exists = site_link_exists(account, site)
    return link_control.valid_profile_format(profile, site) and not exists


def can_delete_link(account, link):
    return link in account.links.all()


def link_create(account, site, profile):
    if not can_create_link(account, site, profile):
        raise PermissionDenied

    link = link_control.create(account, site, profile)