<s> from __future__ import absolute_import , unicode_literals <EOL> from django . contrib . auth . models import User <EOL> from django . core . exceptions import PermissionDenied <EOL> from django . core . urlresolvers import reverse <EOL> from django . db import models <EOL> from django . utils . encoding import python_2_unicode_compatible <EOL> from django . utils . translation import ugettext_lazy as _ <EOL> from acls . models import AccessControlList <EOL> from documents . models import Document <EOL> from documents . permissions import permission_document_view <EOL> from permissions import Permission <EOL> from . managers import FolderManager <EOL> @ python_2_unicode_compatible <EOL> class Folder ( models . Model ) : <EOL> label = models . CharField ( <EOL> db_index = True , max_length = <NUM_LIT> , verbose_name = _ ( '<STR_LIT>' ) <EOL> ) <EOL> user = models . ForeignKey ( User , verbose_name = _ ( '<STR_LIT>' ) ) <EOL> datetime_created = models . DateTimeField ( <EOL> auto_now_add = True , verbose_name = _ ( '<STR_LIT>' ) <EOL> ) <EOL> documents = models . ManyToManyField ( <EOL> Document , related_name = '<STR_LIT>' , verbose_name = _ ( '<STR_LIT>' ) <EOL> ) <EOL> objects = FolderManager ( ) <EOL> def __str__ ( self ) : <EOL> return self . label <EOL> def get_absolute_url ( self ) : <EOL> return reverse ( '<STR_LIT>' , args = ( self . pk , ) ) <EOL> def natural_key ( self ) : <EOL> return ( self . label , ) + self . user . natural_key ( ) <EOL> natural_key . dependencies = [ '<STR_LIT>' ] <EOL> class Meta : <EOL> ordering = ( '<STR_LIT:label>' , ) <EOL> unique_together = ( '<STR_LIT:label>' , '<STR_LIT:user>' ) <EOL> verbose_name = _ ( '<STR_LIT>' ) <EOL> verbose_name_plural = _ ( '<STR_LIT>' ) <EOL> def get_document_count ( self , user ) : <EOL> queryset = self . documents <EOL> try : <EOL> Permission . check_permissions ( user , ( permission_document_view , ) ) <EOL> except PermissionDenied : <EOL> queryset = AccessControlList . objects . filter_by_access ( <EOL> permission_document_view , user , queryset <EOL> ) <EOL> return queryset . count ( ) <EOL> class DocumentFolder ( Folder ) : <EOL> class Meta : <EOL> proxy = True <EOL> verbose_name = _ ( '<STR_LIT>' ) <EOL> verbose_name_plural = _ ( '<STR_LIT>' ) </s>
