# 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 
# 
# Path: openwatch/recording_tags.py
# ACLU_NJ = 'aclunj'


from django.http import HttpResponse, HttpResponseRedirect, HttpResponseNotFound
from django.template import Context, loader
from django.core.urlresolvers import reverse
from django.template import RequestContext
from django.shortcuts import get_object_or_404, render_to_response
from django.core.exceptions import ObjectDoesNotExist
from datetime import datetime
from tagging.models import Tag, TaggedItem
from django.views.decorators.csrf import csrf_exempt
from django.contrib.auth.models import User
from django.contrib.auth.decorators import login_required
from django.contrib.auth import authenticate, login
from django.core.mail import send_mail
from django.conf import settings
from django.http import Http404
from django.db.models import Q
from openwatch.recordings.models import Recording
from openwatch import recording_tags
import json
#     try:
#         location = Location.objects.get(zipcode=zipcode)
#     except:
#         return HttpResponseRedirect('/')
#     return render_to_response('map.html', {'total': total, 'location': location, 'zipcode': zipcode}, context_instance=RequestContext(request)) 

def size(request):
    featureset = Recording.objects.filter(~Q(lat=None), ~Q(lon=None), ~Q(jtype='organic')).exclude(location__exact='No description available').exclude(location__exact='0.0, 0.0').order_by('-date')
    total = len(featureset)
    return render_to_response('map.html', {'total': total}, context_instance=RequestContext(request)) 

def redir(self):
    return HttpResponseRedirect('/')

# def map_tag(request, tag=None):

#     #0 Responses
#     try:
#         query_tag = Tag.objects.get(name=tag)
#     except Exception, e:
#         return render_to_response('map.html', {'jobs': [], 'numcareers': 0, 'tag': tag}, context_instance=RequestContext(request)) 

#     entries = TaggedItem.objects.get_by_model(Recording, query_tag)
#     featureset = entries.filter(~Q(lat=None), ~Q(lon=None),).order_by('-date')


#     return render_to_response('map.html', {'jobs': featureset, 'numcareers': len(featureset), 'tag': tag}, context_instance=RequestContext(request))

def map_json(request):
    #featureset = Recording.objects.filter(~Q(lat=None), ~Q(lon=None), ~Q(jtype='organic')).order_by('-date')[:1000]

# 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 
# 
# Path: openwatch/recording_tags.py
# ACLU_NJ = 'aclunj'


# Path: openwatch/map/views.py
from django.http import HttpResponse, HttpResponseRedirect, HttpResponseNotFound
from django.template import Context, loader
from django.core.urlresolvers import reverse
from django.template import RequestContext
from django.shortcuts import get_object_or_404, render_to_response
from django.core.exceptions import ObjectDoesNotExist
from datetime import datetime
from tagging.models import Tag, TaggedItem
from django.views.decorators.csrf import csrf_exempt
from django.contrib.auth.models import User
from django.contrib.auth.decorators import login_required
from django.contrib.auth import authenticate, login
from django.core.mail import send_mail
from django.conf import settings
from django.http import Http404
from django.db.models import Q
from openwatch.recordings.models import Recording
from openwatch import recording_tags
import json

#     try:
#         location = Location.objects.get(zipcode=zipcode)
#     except:
#         return HttpResponseRedirect('/')
#     return render_to_response('map.html', {'total': total, 'location': location, 'zipcode': zipcode}, context_instance=RequestContext(request)) 

def size(request):
    featureset = Recording.objects.filter(~Q(lat=None), ~Q(lon=None), ~Q(jtype='organic')).exclude(location__exact='No description available').exclude(location__exact='0.0, 0.0').order_by('-date')
    total = len(featureset)
    return render_to_response('map.html', {'total': total}, context_instance=RequestContext(request)) 

def redir(self):
    return HttpResponseRedirect('/')

# def map_tag(request, tag=None):

#     #0 Responses
#     try:
#         query_tag = Tag.objects.get(name=tag)
#     except Exception, e:
#         return render_to_response('map.html', {'jobs': [], 'numcareers': 0, 'tag': tag}, context_instance=RequestContext(request)) 

#     entries = TaggedItem.objects.get_by_model(Recording, query_tag)
#     featureset = entries.filter(~Q(lat=None), ~Q(lon=None),).order_by('-date')


#     return render_to_response('map.html', {'jobs': featureset, 'numcareers': len(featureset), 'tag': tag}, context_instance=RequestContext(request))

def map_json(request):
    #featureset = Recording.objects.filter(~Q(lat=None), ~Q(lon=None), ~Q(jtype='organic')).order_by('-date')[:1000]

    featureset = Recording.objects.all().order_by('-date').filter(~Q(location='')).exclude(location__isnull=True).exclude(location__exact='')[:750]