# Path: repowatcher/main/models.py
# class RepositoryCategory(models.Model):
#     name = CharField(max_length=100)
# 
# class Repository(models.Model):
#     owner = CharField(max_length=100)
#     name = CharField(max_length=100)
#     slug = SlugField(max_length=201)
#     host_slug = SlugField(max_length=302, unique = True)
#     language = CharField(max_length=100, null = True)
#     html_url = URLField(null = True, max_length=400)
#     homepage = URLField(null = True, max_length=400)
#     watchers = PositiveIntegerField(null = True)
#     created_at = DateTimeField(null = True)
#     pushed_at = DateTimeField(null = True)
#     description = TextField(null = True)
#     extra_data = JSONField(null = True)
#     last_modified = DateTimeField(auto_now=True)
#     scm = CharField(max_length=100, choices=SCM_CHOICES, null = True)
#     host = CharField(max_length=100, choices=HOST_CHOICES)
#     private = BooleanField(default = False)
# 
#     class Meta:
#         unique_together = ("owner", "name", "host")
#         ordering = ['-watchers']
# 
#     def save(self, *args, **kwargs):
#         self.slug = self.owner.lower() + '/' + self.name.lower()
#         self.host_slug = self.host+'/'+self.slug
#         if self.html_url == None or self.html_url =='':
#             if self.host =='bitbucket':
#                 self.html_url = 'https://bitbucket.org/%s/%s' % (self.owner,self.name)
#             if self.host =='github':
#                 self.html_url = 'https://github.com/%s/%s' % (self.owner,self.name)
# 
#         super(Repository, self).save(*args, **kwargs)


from GithubProvider import GithubProvider
from collections import defaultdict
from datetime import timedelta, datetime
from django.conf import settings
from django.core.exceptions import ObjectDoesNotExist
from django.core.urlresolvers import reverse
from django.http import HttpResponseRedirect, HttpResponse
from django.shortcuts import render_to_response
from django.template.context import RequestContext
from django.views.decorators.cache import never_cache, cache_control
from oauth_hook import OAuthHook
from repowatcher.main.models import RepositoryCategory, Repository
from urllib import urlencode, quote
import json
import logging
import requests
import urllib
logger = logging.getLogger(__name__)

OAuthHook.consumer_key = settings.BITBUCKET_CONSUMER_KEY
OAuthHook.consumer_secret = settings.BITBUCKET_CONSUMER_SECRET

@never_cache
def index(request):
    """Home view, displays login mechanism"""
    if request.user.is_authenticated():
        return HttpResponseRedirect(reverse('repowatcher.main.views.authed'))
    else:
        return render_to_response('index.html', {}, RequestContext(request))

def about(request):
    used = [Repository(owner='django', name='django', host='github'),
            Repository(owner='omab', name='django-social-auth', host='github'),
            Repository(owner='copitux', name='python-github3', host='github'),
            Repository(owner='kennethreitz', name='requests', host='github'),
            Repository(owner='maraujop', name='requests-oauth',host='github'),
            Repository(owner='jquery', name='jquery', host='github'),
            Repository(owner='jquery', name='jquery-ui', host='github'),
            Repository(owner='twitter', name='bootstrap', host='github'),
            Repository(owner='desandro', name='masonry', host='github'),
            Repository(owner='rmm5t', name='jquery-timeago', host='github'),

# Path: repowatcher/main/models.py
# class RepositoryCategory(models.Model):
#     name = CharField(max_length=100)
# 
# class Repository(models.Model):
#     owner = CharField(max_length=100)
#     name = CharField(max_length=100)
#     slug = SlugField(max_length=201)
#     host_slug = SlugField(max_length=302, unique = True)
#     language = CharField(max_length=100, null = True)
#     html_url = URLField(null = True, max_length=400)
#     homepage = URLField(null = True, max_length=400)
#     watchers = PositiveIntegerField(null = True)
#     created_at = DateTimeField(null = True)
#     pushed_at = DateTimeField(null = True)
#     description = TextField(null = True)
#     extra_data = JSONField(null = True)
#     last_modified = DateTimeField(auto_now=True)
#     scm = CharField(max_length=100, choices=SCM_CHOICES, null = True)
#     host = CharField(max_length=100, choices=HOST_CHOICES)
#     private = BooleanField(default = False)
# 
#     class Meta:
#         unique_together = ("owner", "name", "host")
#         ordering = ['-watchers']
# 
#     def save(self, *args, **kwargs):
#         self.slug = self.owner.lower() + '/' + self.name.lower()
#         self.host_slug = self.host+'/'+self.slug
#         if self.html_url == None or self.html_url =='':
#             if self.host =='bitbucket':
#                 self.html_url = 'https://bitbucket.org/%s/%s' % (self.owner,self.name)
#             if self.host =='github':
#                 self.html_url = 'https://github.com/%s/%s' % (self.owner,self.name)
# 
#         super(Repository, self).save(*args, **kwargs)


# Path: repowatcher/main/views/general.py
from GithubProvider import GithubProvider
from collections import defaultdict
from datetime import timedelta, datetime
from django.conf import settings
from django.core.exceptions import ObjectDoesNotExist
from django.core.urlresolvers import reverse
from django.http import HttpResponseRedirect, HttpResponse
from django.shortcuts import render_to_response
from django.template.context import RequestContext
from django.views.decorators.cache import never_cache, cache_control
from oauth_hook import OAuthHook
from repowatcher.main.models import RepositoryCategory, Repository
from urllib import urlencode, quote
import json
import logging
import requests
import urllib

logger = logging.getLogger(__name__)

OAuthHook.consumer_key = settings.BITBUCKET_CONSUMER_KEY
OAuthHook.consumer_secret = settings.BITBUCKET_CONSUMER_SECRET

@never_cache
def index(request):
    """Home view, displays login mechanism"""
    if request.user.is_authenticated():
        return HttpResponseRedirect(reverse('repowatcher.main.views.authed'))
    else:
        return render_to_response('index.html', {}, RequestContext(request))

def about(request):
    used = [Repository(owner='django', name='django', host='github'),
            Repository(owner='omab', name='django-social-auth', host='github'),
            Repository(owner='copitux', name='python-github3', host='github'),
            Repository(owner='kennethreitz', name='requests', host='github'),
            Repository(owner='maraujop', name='requests-oauth',host='github'),
            Repository(owner='jquery', name='jquery', host='github'),
            Repository(owner='jquery', name='jquery-ui', host='github'),
            Repository(owner='twitter', name='bootstrap', host='github'),
            Repository(owner='desandro', name='masonry', host='github'),
            Repository(owner='rmm5t', name='jquery-timeago', host='github'),

            Repository(owner='ask', name='celery', host='github'),