# Path: openwatch/recordings/models.py
# class Recording(models.Model):
#     name = models.CharField(max_length=200)
#     email = models.EmailField(max_length=254, blank=True)
#     date = models.DateTimeField('date uploaded', blank=True, default=datetime.now())
#     location = models.CharField(max_length='200')
#     lat = models.FloatField(null=True, blank=True)
#     lon = models.FloatField(null=True, blank=True)
#     vimeo = models.CharField(max_length='200', blank=True)
#     vimeo_dl = models.CharField(max_length='200', blank=True)
#     liveleak = models.CharField(max_length='200', blank=True)
#     youtube = models.CharField(max_length='200', blank=True)
#     local = models.CharField(max_length='200', blank=True)
#     rec_file = models.FileField(upload_to='recordings', storage=attachment_file_storage)
#     file_loc = models.CharField(max_length='200', blank=True)
#     mimetype = models.CharField(max_length='200', blank=True)
#     approved = models.BooleanField(default=False, blank=True)
#     # org_approved applies if tagged with an org tag
#     # if tags contains a tag from recording_tags
#     org_approved = models.BooleanField(default=False, blank=True)
#     org_flagged = models.BooleanField(default=False, blank=True)
#     featured = models.BooleanField(default=False, blank=True)
#     tags = TagField()
# 
#     public_description = models.TextField()
#     private_description = models.TextField(blank=True)
# 
#     def save(self):
#         if self.org_flagged == True and self.org_approved == True:
#             self.org_approved = False
# 
#         super(Recording, self).save()
# 
#         # New recording, let me know about it
#         if not self.approved and int(self.rec_file.file.size) > 204800:
#             send_mail('New recording: ' + self.name, 'Public: \n ' + self.public_description + 'Private: \n' + self.private_description + '\nSize:\n:' + str(self.rec_file.file.size) + '\nFile: ' + str(self.rec_file) + ' ' + str(self.file_loc) + "\nMIME: " + str(self.mimetype), 'openwatchnotifier@gmail.com', ['rich@anomos.info'], fail_silently=True)
# 
#         #XXX: Move the shit to static if approved!
#         if len(self.vimeo) == 0 and self.approved and "video" in self.mimetype:
#             pass
#             #XXX: Vimeo upload https://github.com/dkm/python-vimeo
# 
# 
#     def to_dict(self):
#         if ',' in self.location:
#             lat, lon = self.location.split(",", 1)
#         else:
#             lat = 0.0
#             lon = 0.0
# 
#         # Date conversion
#         return {'id': self.pk, 'email': self.email, 'rec_file': str(self.rec_file), 'title': self.name, 'tags': self.tags, 'url': 'http://openwatch.net/view/' + str(self.pk), 'about': self.public_description, 'lat': lat, 'lon': lon, 'location': self.location, 'date': self.date.strftime("%s %s" % (DATE_FORMAT, TIME_FORMAT))}
# 
#     def get_tags(self):
#         return Tag.objects.get_for_object(self)
# 
#     def add_tag(self, tag):
#         if self.tags == '':
#             self.tags = tag
#         else:
#             self.tags = self.tags + ', ' + tag
#         #self.save()
# 
#     def __unicode__(self):
#         return self.name + ': ' + self.public_description 
# 
# class UserProfile(models.Model):
#     user = models.OneToOneField(User)
#     can_moderate = models.BooleanField(default=False)
#     org_tag = TagField()  # If user has an org_tag they may only moderate recordings sharing the tag


from django.contrib import admin
from openwatch.recordings.models import Recording, UserProfile
from django.contrib.auth.models import User
from django.contrib.auth.admin import UserAdmin
        """
        qs = super(RecordingAdmin, self).queryset(request)

        org_tag = request.user.get_profile().org_tag
        if org_tag != '':
            return qs.filter(tags__contains=org_tag)
        else:
            return qs

        #print request.user.get_profile()
        return qs

    def get_readonly_fields(self, request, obj=None):
        ''' Define which fields are editable in the admin
            based on the user's tags. If a user has an
            org tag, we restrict editing on all fields
            except tags, and org_approved
        '''
        org_tag = request.user.get_profile().org_tag
        if org_tag != '':
            # If the user belongs to an org
            # Restrict editing of certain fields
            return ('name', 'email', 'date', 'location', 'approved', 'vimeo', 'vimeo_dl', 'liveleak', 'youtube', 'local', 'rec_file', 'file_loc', 'mimetype', 'featured', 'public_description', 'private_description')
        else:
            # Return all Recordings
            return ()





# Path: openwatch/recordings/models.py
# class Recording(models.Model):
#     name = models.CharField(max_length=200)
#     email = models.EmailField(max_length=254, blank=True)
#     date = models.DateTimeField('date uploaded', blank=True, default=datetime.now())
#     location = models.CharField(max_length='200')
#     lat = models.FloatField(null=True, blank=True)
#     lon = models.FloatField(null=True, blank=True)
#     vimeo = models.CharField(max_length='200', blank=True)
#     vimeo_dl = models.CharField(max_length='200', blank=True)
#     liveleak = models.CharField(max_length='200', blank=True)
#     youtube = models.CharField(max_length='200', blank=True)
#     local = models.CharField(max_length='200', blank=True)
#     rec_file = models.FileField(upload_to='recordings', storage=attachment_file_storage)
#     file_loc = models.CharField(max_length='200', blank=True)
#     mimetype = models.CharField(max_length='200', blank=True)
#     approved = models.BooleanField(default=False, blank=True)
#     # org_approved applies if tagged with an org tag
#     # if tags contains a tag from recording_tags
#     org_approved = models.BooleanField(default=False, blank=True)
#     org_flagged = models.BooleanField(default=False, blank=True)
#     featured = models.BooleanField(default=False, blank=True)
#     tags = TagField()
# 
#     public_description = models.TextField()
#     private_description = models.TextField(blank=True)
# 
#     def save(self):
#         if self.org_flagged == True and self.org_approved == True:
#             self.org_approved = False
# 
#         super(Recording, self).save()
# 
#         # New recording, let me know about it
#         if not self.approved and int(self.rec_file.file.size) > 204800:
#             send_mail('New recording: ' + self.name, 'Public: \n ' + self.public_description + 'Private: \n' + self.private_description + '\nSize:\n:' + str(self.rec_file.file.size) + '\nFile: ' + str(self.rec_file) + ' ' + str(self.file_loc) + "\nMIME: " + str(self.mimetype), 'openwatchnotifier@gmail.com', ['rich@anomos.info'], fail_silently=True)
# 
#         #XXX: Move the shit to static if approved!
#         if len(self.vimeo) == 0 and self.approved and "video" in self.mimetype:
#             pass
#             #XXX: Vimeo upload https://github.com/dkm/python-vimeo
# 
# 
#     def to_dict(self):
#         if ',' in self.location:
#             lat, lon = self.location.split(",", 1)
#         else:
#             lat = 0.0
#             lon = 0.0
# 
#         # Date conversion
#         return {'id': self.pk, 'email': self.email, 'rec_file': str(self.rec_file), 'title': self.name, 'tags': self.tags, 'url': 'http://openwatch.net/view/' + str(self.pk), 'about': self.public_description, 'lat': lat, 'lon': lon, 'location': self.location, 'date': self.date.strftime("%s %s" % (DATE_FORMAT, TIME_FORMAT))}
# 
#     def get_tags(self):
#         return Tag.objects.get_for_object(self)
# 
#     def add_tag(self, tag):
#         if self.tags == '':
#             self.tags = tag
#         else:
#             self.tags = self.tags + ', ' + tag
#         #self.save()
# 
#     def __unicode__(self):
#         return self.name + ': ' + self.public_description 
# 
# class UserProfile(models.Model):
#     user = models.OneToOneField(User)
#     can_moderate = models.BooleanField(default=False)
#     org_tag = TagField()  # If user has an org_tag they may only moderate recordings sharing the tag


# Path: openwatch/recordings/admin.py
from django.contrib import admin
from openwatch.recordings.models import Recording, UserProfile
from django.contrib.auth.models import User
from django.contrib.auth.admin import UserAdmin

        """
        qs = super(RecordingAdmin, self).queryset(request)

        org_tag = request.user.get_profile().org_tag
        if org_tag != '':
            return qs.filter(tags__contains=org_tag)
        else:
            return qs

        #print request.user.get_profile()
        return qs

    def get_readonly_fields(self, request, obj=None):
        ''' Define which fields are editable in the admin
            based on the user's tags. If a user has an
            org tag, we restrict editing on all fields
            except tags, and org_approved
        '''
        org_tag = request.user.get_profile().org_tag
        if org_tag != '':
            # If the user belongs to an org
            # Restrict editing of certain fields
            return ('name', 'email', 'date', 'location', 'approved', 'vimeo', 'vimeo_dl', 'liveleak', 'youtube', 'local', 'rec_file', 'file_loc', 'mimetype', 'featured', 'public_description', 'private_description')
        else:
            # Return all Recordings
            return ()





admin.site.register(Recording, RecordingAdmin)