# Path: apps/team/models.py
# class Team(Model):
# 
#     link        = SlugField(unique=True) # team url name 
#     links       = ManyToManyField('link.Link', null=True, blank=True) # team social media links
#     name        = CharField(max_length=1024, unique=True)
#     country     = CountryField()
#     members     = ManyToManyField(Account, null=True, blank=True, 
#                                   related_name="teams") 
#     logo        = ProcessedImageField(upload_to=_upload_to, 
#                                       processors=[ResizeToFill(525, 100)],
#                                       format='PNG', options={'quality': 90})
#     active      = BooleanField(default=False)
#     application = TextField() 
# 
#     # meta
#     created_by  = ForeignKey(Account, related_name='team_created')
#     created_on  = DateTimeField(auto_now_add=True)
#     updated_by  = ForeignKey(Account, related_name='team_updated')
#     updated_on  = DateTimeField(auto_now=True)
# 
#     def __unicode__(self):
#         return u"%s (%s)" % (self.name, self.country.name)
# 
#     class Meta:
#         
#         ordering = ['name']
# 
# Path: apps/blog/models.py
# class Blog(Model):
# 
#     team       = ForeignKey("team.Team", related_name="blogs")
#     name       = CharField(max_length=1024)
#     content    = SanitizedCharField(
#                    max_length=50000, allowed_tags=SANITIZER_ALLOWED_TAGS, 
#                    allowed_attributes=SANITIZER_ALLOWED_ATTRIBUTES, strip=False
#                )
# 
#     # meta
#     created_by = ForeignKey(Account, related_name="blogs_created")
#     created_on = DateTimeField(auto_now_add=True)
#     updated_by = ForeignKey(Account, related_name="blogs_updated")
#     updated_on = DateTimeField(auto_now=True)
# 
#     def __unicode__(self):
#         return u"%s: %s" % (self.team.name, self.name)
# 
#     class Meta:
#               
#         unique_together = (("team", "name")) 
#         ordering = ["-created_on"]
# 
# 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/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/team/utils.py
# def render_team_response(team, current, request, template, args):
#     args.update({
#         "team_menu_public" : _get_team_menue_public(team, current),
#         "team_menu_intern" : _get_team_menue_intern(team, current),
#         "current_team" : team,
#         "current_team_links" : team.links.all(),
#     })
#     return render_response(request, template, args)
# 
# Path: apps/team/utils.py
# def assert_member(account, team):
#     if not control.is_member(account, team):
#         raise PermissionDenied
# 
# Path: apps/blog/forms.py
# class Create(forms.Form):
# class Edit(forms.Form):
#     def __init__(self, *args, **kwargs):


from django.utils.translation import ugettext as _
from django.contrib.auth.decorators import login_required
from django.views.decorators.http import require_http_methods
from django.shortcuts import get_object_or_404
from django.http import HttpResponseRedirect
from apps.team.models import Team
from apps.blog.models import Blog
from apps.blog import control
from apps.team import control as team_control
from apps.account.models import Account
from apps.team.utils import render_team_response as rtr
from apps.team.utils import assert_member
from apps.blog import forms
from django.forms import Form
# -*- coding: utf-8 -*-
# Copyright (c) 2012 Fabian Barkhau <fabian.barkhau@gmail.com>                  
# License: MIT (see LICENSE.TXT file) 





@require_http_methods(["GET"])
def listing(request, team_link):
    team = team_control.get_or_404(team_link)

# Path: apps/team/models.py
# class Team(Model):
# 
#     link        = SlugField(unique=True) # team url name 
#     links       = ManyToManyField('link.Link', null=True, blank=True) # team social media links
#     name        = CharField(max_length=1024, unique=True)
#     country     = CountryField()
#     members     = ManyToManyField(Account, null=True, blank=True, 
#                                   related_name="teams") 
#     logo        = ProcessedImageField(upload_to=_upload_to, 
#                                       processors=[ResizeToFill(525, 100)],
#                                       format='PNG', options={'quality': 90})
#     active      = BooleanField(default=False)
#     application = TextField() 
# 
#     # meta
#     created_by  = ForeignKey(Account, related_name='team_created')
#     created_on  = DateTimeField(auto_now_add=True)
#     updated_by  = ForeignKey(Account, related_name='team_updated')
#     updated_on  = DateTimeField(auto_now=True)
# 
#     def __unicode__(self):
#         return u"%s (%s)" % (self.name, self.country.name)
# 
#     class Meta:
#         
#         ordering = ['name']
# 
# Path: apps/blog/models.py
# class Blog(Model):
# 
#     team       = ForeignKey("team.Team", related_name="blogs")
#     name       = CharField(max_length=1024)
#     content    = SanitizedCharField(
#                    max_length=50000, allowed_tags=SANITIZER_ALLOWED_TAGS, 
#                    allowed_attributes=SANITIZER_ALLOWED_ATTRIBUTES, strip=False
#                )
# 
#     # meta
#     created_by = ForeignKey(Account, related_name="blogs_created")
#     created_on = DateTimeField(auto_now_add=True)
#     updated_by = ForeignKey(Account, related_name="blogs_updated")
#     updated_on = DateTimeField(auto_now=True)
# 
#     def __unicode__(self):
#         return u"%s: %s" % (self.team.name, self.name)
# 
#     class Meta:
#               
#         unique_together = (("team", "name")) 
#         ordering = ["-created_on"]
# 
# 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/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/team/utils.py
# def render_team_response(team, current, request, template, args):
#     args.update({
#         "team_menu_public" : _get_team_menue_public(team, current),
#         "team_menu_intern" : _get_team_menue_intern(team, current),
#         "current_team" : team,
#         "current_team_links" : team.links.all(),
#     })
#     return render_response(request, template, args)
# 
# Path: apps/team/utils.py
# def assert_member(account, team):
#     if not control.is_member(account, team):
#         raise PermissionDenied
# 
# Path: apps/blog/forms.py
# class Create(forms.Form):
# class Edit(forms.Form):
#     def __init__(self, *args, **kwargs):


# Path: apps/blog/views.py
from django.utils.translation import ugettext as _
from django.contrib.auth.decorators import login_required
from django.views.decorators.http import require_http_methods
from django.shortcuts import get_object_or_404
from django.http import HttpResponseRedirect
from apps.team.models import Team
from apps.blog.models import Blog
from apps.blog import control
from apps.team import control as team_control
from apps.account.models import Account
from apps.team.utils import render_team_response as rtr
from apps.team.utils import assert_member
from apps.blog import forms
from django.forms import Form

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





@require_http_methods(["GET"])
def listing(request, team_link):
    team = team_control.get_or_404(team_link)

    blogs = Blog.objects.filter(team=team)