# Path: apps/gallery/models.py
# class Gallery(models.Model):
# 
#     team = models.ForeignKey(
#         'team.Team', related_name="galleries", null=True, blank=True
#     )
# 
#     primary = models.ForeignKey(
#         'gallery.Picture', related_name="primary", null=True, blank=True
#     )
# 
#     # metadata
#     created_by  = models.ForeignKey(Account, related_name="galleries_created")
#     created_on  = models.DateTimeField(auto_now_add=True)
#     updated_by  = models.ForeignKey(Account, related_name="galleries_updated")
#     updated_on  = models.DateTimeField(auto_now=True)
# 
#     def __unicode__(self):
#         return u"%s" % self.id
# 
# Path: apps/gallery/models.py
# class Picture(models.Model):
# 
#     gallery = models.ForeignKey('gallery.Gallery', related_name="pictures")
# 
#     image = ProcessedImageField(
#         upload_to=_image_upload_to, 
#         processors=[ResizeToFill(640, 480)],
#         format='JPEG', options={'quality': 90}
#     )
# 
#     preview = ProcessedImageField(
#         upload_to=_preview_upload_to, 
#         processors=[ResizeToFill(320, 240)],
#         format='JPEG', options={'quality': 90}
#     )
# 
#     thumbnail = ProcessedImageField(
#         upload_to=_thumbnail_upload_to, 
#         processors=[ResizeToFill(100, 75)],
#         format='JPEG', options={'quality': 90}
#     )
# 
#     # metadata
#     created_by  = models.ForeignKey(Account, related_name="pictures_created")
#     created_on  = models.DateTimeField(auto_now_add=True)
#     updated_by  = models.ForeignKey(Account, related_name="pictures_updated")
#     updated_on  = models.DateTimeField(auto_now=True)
# 
#     def __unicode__(self):
#         return u"%s" % self.id
# 
# Path: apps/team/utils.py
# def assert_member(account, team):
#     if not control.is_member(account, team):
#         raise PermissionDenied
# 
# 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):


import os
from django.core.exceptions import PermissionDenied
from apps.gallery.models import Gallery
from apps.gallery.models import Picture
from apps.team.utils import assert_member
from apps.team import control as team_control
# -*- coding: utf-8 -*-
# Copyright (c) 2012 Fabian Barkhau <fabian.barkhau@gmail.com>                  
# License: MIT (see LICENSE.TXT file) 




def can_edit(account, gallery):
    return not ((gallery.team and not team_control.is_member(account, gallery.team)) or 
                (not gallery.team and gallery.created_by != account))


def _assert_can_edit(account, gallery):
    if not can_edit(account, gallery):

# Path: apps/gallery/models.py
# class Gallery(models.Model):
# 
#     team = models.ForeignKey(
#         'team.Team', related_name="galleries", null=True, blank=True
#     )
# 
#     primary = models.ForeignKey(
#         'gallery.Picture', related_name="primary", null=True, blank=True
#     )
# 
#     # metadata
#     created_by  = models.ForeignKey(Account, related_name="galleries_created")
#     created_on  = models.DateTimeField(auto_now_add=True)
#     updated_by  = models.ForeignKey(Account, related_name="galleries_updated")
#     updated_on  = models.DateTimeField(auto_now=True)
# 
#     def __unicode__(self):
#         return u"%s" % self.id
# 
# Path: apps/gallery/models.py
# class Picture(models.Model):
# 
#     gallery = models.ForeignKey('gallery.Gallery', related_name="pictures")
# 
#     image = ProcessedImageField(
#         upload_to=_image_upload_to, 
#         processors=[ResizeToFill(640, 480)],
#         format='JPEG', options={'quality': 90}
#     )
# 
#     preview = ProcessedImageField(
#         upload_to=_preview_upload_to, 
#         processors=[ResizeToFill(320, 240)],
#         format='JPEG', options={'quality': 90}
#     )
# 
#     thumbnail = ProcessedImageField(
#         upload_to=_thumbnail_upload_to, 
#         processors=[ResizeToFill(100, 75)],
#         format='JPEG', options={'quality': 90}
#     )
# 
#     # metadata
#     created_by  = models.ForeignKey(Account, related_name="pictures_created")
#     created_on  = models.DateTimeField(auto_now_add=True)
#     updated_by  = models.ForeignKey(Account, related_name="pictures_updated")
#     updated_on  = models.DateTimeField(auto_now=True)
# 
#     def __unicode__(self):
#         return u"%s" % self.id
# 
# Path: apps/team/utils.py
# def assert_member(account, team):
#     if not control.is_member(account, team):
#         raise PermissionDenied
# 
# 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/gallery/control.py
import os
from django.core.exceptions import PermissionDenied
from apps.gallery.models import Gallery
from apps.gallery.models import Picture
from apps.team.utils import assert_member
from apps.team import control as team_control

# -*- coding: utf-8 -*-
# Copyright (c) 2012 Fabian Barkhau <fabian.barkhau@gmail.com>                  
# License: MIT (see LICENSE.TXT file) 




def can_edit(account, gallery):
    return not ((gallery.team and not team_control.is_member(account, gallery.team)) or 
                (not gallery.team and gallery.created_by != account))


def _assert_can_edit(account, gallery):
    if not can_edit(account, gallery):

        raise PermissionDenied