# Path: codebox/utils/models.py
# class Model(object):
#     __metaclass__ = ModelDescriptor
# 
#     DoesNotExist = DoesNotExist
#     DuplicateKeyError = DuplicateKeyError
# 
#     def __init__(self, pk, **kwargs):
#         self._storage = RedisHashMap(g.redis, '%s:items:%s' % (self._meta.db_name, pk))
#         self.pk = pk
#         for attname, field in self._meta.fields.iteritems():
#             try:
#                 val = field.to_python(kwargs.pop(attname))
#             except KeyError:
#                 # This is done with an exception rather than the
#                 # default argument on pop because we don't want
#                 # get_default() to be evaluated, and then not used.
#                 # Refs #12057.
#                 val = field.get_default()
#             if val:
#                 setattr(self, attname, val)
#         if kwargs:
#             raise ValueError('%s are not part of the schema for %s' % (', '.join(kwargs.keys()), self.__class__.__name__))
# 
#     def __getattribute__(self, key):
#         if key in object.__getattribute__(self, '_meta').fields:
#             return self[key]
#         return object.__getattribute__(self, key)
# 
#     def __setattr__(self, key, value):
#         if key in object.__getattribute__(self, '_meta').fields:
#             self[key] = value
#         return object.__setattr__(self, key, value)
# 
#     def __getitem__(self, key):
#         return self._storage[key]
# 
#     def __setitem__(self, key, value):
#         field = self._meta.fields.get(key)
#         if field:
#             value = field.to_python(value)
#         self._storage[key] = value
#         # Store additional predefined index
#         if (key,) in self._meta.index or (key,) in self._meta.unique:
#             self.objects.add_to_index(self.pk, **{key: value})
# 
#     def __repr__(self):
#         return u'<%s: %s>' % (self.__class__.__name__, unicode(self))
# 
#     def __eq__(self, other):
#         if type(self) != type(other):
#             return False
#         return self.pk == other.pk
# 
#     def __unicode__(self):
#         return self.pk
# 
#     def __contains__(self, key):
#         return key in self._storage
# 
#     def update(self, **kwargs):
#         for k, v in kwargs.iteritems():
#             self[k] = v
#         if len(kwargs) > 1:
#             # Store composite indexes
#             for fields in itertools.chain(self._meta.index, self._meta.unique):
#                 if all([f in kwargs for f in fields]):
#                     idx_kwargs = dict((f, getattr(self, f)) for f in fields)
#                     self.objects.add_to_index(self.pk, **idx_kwargs)
# 
#     def delete(self):
#         # Clear all indexes first
#         #  Default index
#         g.redis.zrem(self.objects._get_default_index_key(), self.pk)
#         g.redis.decr(self.objects._get_default_count_key())
# 
#         #  Store additional predefined index
#         for fields in itertools.chain(self._meta.index, self._meta.unique):
#             idx_kwargs = dict((f, getattr(self, f)) for f in fields)
#             self.objects.remove_from_index(self.pk, **idx_kwargs)
# 
#         # Clear out the hash table for object
#         self._storage.clear()
# 
#     def post_create(self):
#         pass
# 
# class String(Field):
#     def to_python(self, value=None):
#         if value:
#             value = unicode(value)
#         return value
# 
# class Float(Field):
#     def to_python(self, value=None):
#         if value:
#             value = float(value)
#         else:
#             value = 0.0
#         return value
# 
# Path: codebox/apps/auth/models.py
# class User(Model):
#     name = String()
#     email = String(required=False)
#     avatar = String(required=False)
#     created_at = Float(default=time.time)
#     api_token = String(required=False)
# 
#     class Meta:
#         unique = (('email',), ('api_token',))
# 
#     def get_all_organizations(self, admin=False):
#         from codebox.apps.organizations.models import OrganizationMember, Organization
# 
#         memberships = list(OrganizationMember.objects.filter(user=self.pk))
#         orgs = Organization.objects.get_many([m.org for m in memberships])
#         if admin:
#             orgs = filter(lambda x: x.owned_by == self.pk, orgs)
#         return orgs
# 
#     def can_admin_org(self, org):
#         return org.owned_by == self.pk
# 
#     def get_relation(self, relation):
#         return list(relation.objects.filter(user=self.pk))


import time
from codebox.utils.models import Model, String, Float
from codebox.apps.auth.models import User
        from codebox.apps.organizations.models import Organization

    languages = [
        ('text', 'Plaintext'),
        ('diff', 'Diff'),
        ('javascript', 'JavaScript'),
        ('html', 'HTML'),
        ('php', 'PHP'),
        ('python', 'Python'),
        ('ruby', 'Ruby'),
        ('applescript', 'AppleScript'),
        ('bash', 'Bash'),
        ('c', 'C'),
        ('c++', 'C++'),
        ('css', 'CSS'),
        ('erlang', 'Erlang'),
        ('java', 'Java'),
        ('scala', 'Scala'),
        ('sql', 'SQL'),
        ('xml', 'XML'),
    ]

    class Meta:
        index = (('org',), ('user',))

    def post_create(self):
        # Fill our dashboard index
        for user in Organization.objects.get(self.org).get_all_members():
            Snippet.objects.add_to_index(self.pk, dashboard=user.pk)
    
    def get_user(self):

# Path: codebox/utils/models.py
# class Model(object):
#     __metaclass__ = ModelDescriptor
# 
#     DoesNotExist = DoesNotExist
#     DuplicateKeyError = DuplicateKeyError
# 
#     def __init__(self, pk, **kwargs):
#         self._storage = RedisHashMap(g.redis, '%s:items:%s' % (self._meta.db_name, pk))
#         self.pk = pk
#         for attname, field in self._meta.fields.iteritems():
#             try:
#                 val = field.to_python(kwargs.pop(attname))
#             except KeyError:
#                 # This is done with an exception rather than the
#                 # default argument on pop because we don't want
#                 # get_default() to be evaluated, and then not used.
#                 # Refs #12057.
#                 val = field.get_default()
#             if val:
#                 setattr(self, attname, val)
#         if kwargs:
#             raise ValueError('%s are not part of the schema for %s' % (', '.join(kwargs.keys()), self.__class__.__name__))
# 
#     def __getattribute__(self, key):
#         if key in object.__getattribute__(self, '_meta').fields:
#             return self[key]
#         return object.__getattribute__(self, key)
# 
#     def __setattr__(self, key, value):
#         if key in object.__getattribute__(self, '_meta').fields:
#             self[key] = value
#         return object.__setattr__(self, key, value)
# 
#     def __getitem__(self, key):
#         return self._storage[key]
# 
#     def __setitem__(self, key, value):
#         field = self._meta.fields.get(key)
#         if field:
#             value = field.to_python(value)
#         self._storage[key] = value
#         # Store additional predefined index
#         if (key,) in self._meta.index or (key,) in self._meta.unique:
#             self.objects.add_to_index(self.pk, **{key: value})
# 
#     def __repr__(self):
#         return u'<%s: %s>' % (self.__class__.__name__, unicode(self))
# 
#     def __eq__(self, other):
#         if type(self) != type(other):
#             return False
#         return self.pk == other.pk
# 
#     def __unicode__(self):
#         return self.pk
# 
#     def __contains__(self, key):
#         return key in self._storage
# 
#     def update(self, **kwargs):
#         for k, v in kwargs.iteritems():
#             self[k] = v
#         if len(kwargs) > 1:
#             # Store composite indexes
#             for fields in itertools.chain(self._meta.index, self._meta.unique):
#                 if all([f in kwargs for f in fields]):
#                     idx_kwargs = dict((f, getattr(self, f)) for f in fields)
#                     self.objects.add_to_index(self.pk, **idx_kwargs)
# 
#     def delete(self):
#         # Clear all indexes first
#         #  Default index
#         g.redis.zrem(self.objects._get_default_index_key(), self.pk)
#         g.redis.decr(self.objects._get_default_count_key())
# 
#         #  Store additional predefined index
#         for fields in itertools.chain(self._meta.index, self._meta.unique):
#             idx_kwargs = dict((f, getattr(self, f)) for f in fields)
#             self.objects.remove_from_index(self.pk, **idx_kwargs)
# 
#         # Clear out the hash table for object
#         self._storage.clear()
# 
#     def post_create(self):
#         pass
# 
# class String(Field):
#     def to_python(self, value=None):
#         if value:
#             value = unicode(value)
#         return value
# 
# class Float(Field):
#     def to_python(self, value=None):
#         if value:
#             value = float(value)
#         else:
#             value = 0.0
#         return value
# 
# Path: codebox/apps/auth/models.py
# class User(Model):
#     name = String()
#     email = String(required=False)
#     avatar = String(required=False)
#     created_at = Float(default=time.time)
#     api_token = String(required=False)
# 
#     class Meta:
#         unique = (('email',), ('api_token',))
# 
#     def get_all_organizations(self, admin=False):
#         from codebox.apps.organizations.models import OrganizationMember, Organization
# 
#         memberships = list(OrganizationMember.objects.filter(user=self.pk))
#         orgs = Organization.objects.get_many([m.org for m in memberships])
#         if admin:
#             orgs = filter(lambda x: x.owned_by == self.pk, orgs)
#         return orgs
# 
#     def can_admin_org(self, org):
#         return org.owned_by == self.pk
# 
#     def get_relation(self, relation):
#         return list(relation.objects.filter(user=self.pk))


# Path: codebox/apps/snippets/models.py
import time
from codebox.utils.models import Model, String, Float
from codebox.apps.auth.models import User
        from codebox.apps.organizations.models import Organization


    languages = [
        ('text', 'Plaintext'),
        ('diff', 'Diff'),
        ('javascript', 'JavaScript'),
        ('html', 'HTML'),
        ('php', 'PHP'),
        ('python', 'Python'),
        ('ruby', 'Ruby'),
        ('applescript', 'AppleScript'),
        ('bash', 'Bash'),
        ('c', 'C'),
        ('c++', 'C++'),
        ('css', 'CSS'),
        ('erlang', 'Erlang'),
        ('java', 'Java'),
        ('scala', 'Scala'),
        ('sql', 'SQL'),
        ('xml', 'XML'),
    ]

    class Meta:
        index = (('org',), ('user',))

    def post_create(self):
        # Fill our dashboard index
        for user in Organization.objects.get(self.org).get_all_members():
            Snippet.objects.add_to_index(self.pk, dashboard=user.pk)
    
    def get_user(self):

        return User.objects.get(self.user)