def create_or_update_user_details(self, user_dict, repository_user = None):
     if repository_user is None:
         repository_user = RepositoryUser()
     extra_data = {}
     for key, value in user_dict.iteritems():
         if key == "_attrs":
             continue
         if key in ['login', 'name', 'email', 'blog','following','followers','public_repos','created_at']:
             setattr(repository_user, key, value)
         else:
             if isinstance(value, datetime):
                 extra_data[key] = value.__str__()
             else:
                 extra_data[key] = value
     repository_user.extra_data = json.dumps(extra_data)
     repository_user.host = self.host
     return repository_user
    def create_or_update_user_details(self, user_dict, repository_user = None):
        extra_data = {}
        if repository_user is None:
            repository_user = RepositoryUser()
        if ('first_name' in user_dict and user_dict['first_name']!='')  or ('last_name' in user_dict and user_dict['last_name']!=''):
            if 'first_name' in user_dict and user_dict['first_name']!='' and 'last_name' in user_dict and user_dict['last_name']!='':
                repository_user.name = ' '.join((user_dict['first_name'],user_dict['last_name']))
            elif 'first_name' in user_dict and user_dict['first_name']!='':
                repository_user.name = user_dict['first_name']
            elif 'last_name' in user_dict and user_dict['last_name']!='':
                repository_user.name = user_dict['last_name']
        for key,value in user_dict.iteritems():

            if key == 'username':
                repository_user.login = value
            elif key =='first_name':
                pass
            elif key =='last_name':
                pass
            else:
                if isinstance(value, datetime):
                    extra_data[key] = value.__str__()
                else:
                    extra_data[key] = value

        repository_user.extra_data = json.dumps(extra_data)
        repository_user.host = self.host
        return repository_user
Beispiel #3
0
def authed(request):
    user = request.user
    bitbucket_authed = True
    github_authed = True
    bitbucket_user_events = []
    github_user_events = []
    github_repository_user = None
    bitbucket_repository_user = None
    try:
        github_username = user.social_auth.get(provider='github').extra_data['username']
        github_provider = GithubProvider(user)
        update = False

        # Get user information
        try:
            github_repository_user = github_provider.retrieve_user_details(github_username)
        except ObjectDoesNotExist:
            update = True
            github_repository_user = RepositoryUser()
        if update or (datetime.now() - github_repository_user.last_modified) > timedelta(days = 1):
            github_user_dict = github_provider.get_user_details(github_username)
            github_repository_user = github_provider.create_or_update_user_details(github_user_dict, github_repository_user)
            github_repository_user.save()
        github_user_events = github_provider.get_user_events(github_username)
        for github_user_event in github_user_events:
            github_user_event['host'] = 'github'
            github_user_event['created_on'] = dateutil.parser.parse(github_user_event['created_at'])

        # Get repository information
        repositories, _ = github_provider.retrieve_starred_repositories_list(github_username)

        if len(repositories) == 0:
            repo_link_type, _ = LinkType.objects.get_or_create(name = "starred")
            if not github_repository_user:
                github_repository_user,_ = RepositoryUser.objects.get_or_create(login=github_username,host='github')
            watched = github_provider.get_starred_repositories(github_username)
            for repo in watched:
                update = False
                try:
                    repository = Repository.objects.get(host_slug= 'github/'+repo['owner'].lower() + '/' + repo['name'].lower())
                except ObjectDoesNotExist:
                    update = True
                    repository = Repository()
                if update or (datetime.now() - repository.last_modified) > timedelta(days = 1):
                    repository = github_provider.create_or_update_repository_details(repo, repository)
                    if not repository.private:
                        repository.save()
                    RepositoryCategory.objects.get_or_create(name = repository.language)
                if not repository.private:
                    RepositoryUserRepositoryLink.objects.get_or_create(user = github_repository_user, repository = repository, link_type = repo_link_type)

                repositories.append(repository)
        github_repository_user.starred = len(repositories)
        github_repository_user.save()

        # Get repository information
        repositories, _ = github_provider.retrieve_watched_repositories_list(github_username)

        if len(repositories) == 0:
            repo_link_type, _ = LinkType.objects.get_or_create(name = "watched")
            if not github_repository_user:
                github_repository_user,_ = RepositoryUser.objects.get_or_create(login=github_username,host='github')
            watched = github_provider.get_watched_repositories(github_username)
            for repo in watched:
                update = False
                try:
                    repository = Repository.objects.get(host_slug= 'github/'+repo['owner'].lower() + '/' + repo['name'].lower())
                except ObjectDoesNotExist:
                    update = True
                    repository = Repository()
                if update or (datetime.now() - repository.last_modified) > timedelta(days = 1):
                    repository = github_provider.create_or_update_repository_details(repo, repository)
                    if not repository.private:
                        repository.save()
                    RepositoryCategory.objects.get_or_create(name = repository.language)
                if not repository.private:
                    RepositoryUserRepositoryLink.objects.get_or_create(user = github_repository_user, repository = repository, link_type = repo_link_type)

                repositories.append(repository)
        github_repository_user.watched = len(repositories)
        github_repository_user.save()
    except ObjectDoesNotExist:
        github_authed = False

    try:
        bitbucket_username = user.social_auth.get(provider='bitbucket').extra_data['username']
        bitbucket_provider = BitbucketProvider(user)
        # Get user information
        update = False
        try:
            bitbucket_repository_user = bitbucket_provider.retrieve_user_details(bitbucket_username)
        except ObjectDoesNotExist:
            update = True
            bitbucket_repository_user = RepositoryUser()
        if update or (datetime.now() - bitbucket_repository_user.last_modified) > timedelta(days = 1):
            user_dict = bitbucket_provider.get_user_details(bitbucket_username)
            bitbucket_repository_user = bitbucket_provider.create_or_update_user_details(user_dict, bitbucket_repository_user)
            bitbucket_repository_user.save()
        bitbucket_user_events = bitbucket_provider.get_user_events(bitbucket_username)
        for bitbucket_user_event in bitbucket_user_events:
            bitbucket_user_event['host'] = 'bitbucket'
            bitbucket_user_event['created_on'] = dateutil.parser.parse(bitbucket_user_event['utc_created_on'])
        # Get repository information
        owned_repositories, _ = bitbucket_provider.retrieve_owned_repositories_list(bitbucket_username)
        watched_repositories, _ = bitbucket_provider.retrieve_watched_repositories_list(bitbucket_username)

        if len(owned_repositories) == 0:
            owned = bitbucket_provider.get_owned_repositories(bitbucket_username)
            for repo in owned:
                update = False
                try:
                    repository = bitbucket_provider.retrieve_repository_details(repo['owner'], repo['name'])
                except ObjectDoesNotExist:
                    update = True
                    repository = Repository()
                if update or (datetime.now() - repository.last_modified) > timedelta(days = 1):
                    repository = bitbucket_provider.create_or_update_repository_details(repo, repository)
                    if not repository.private:
                        repository.save()
                    RepositoryCategory.objects.get_or_create(name=repository.language)
                if not repository.private:
                    RepositoryUserRepositoryLink.objects.get_or_create(user=bitbucket_repository_user, repository = repository, owned = True)
                owned_repositories.append(repository)
            bitbucket_repository_user.public_repos = len(owned_repositories)
            bitbucket_repository_user.save()

        if len(watched_repositories) == 0:
            watched = bitbucket_provider.get_watched_repositories(bitbucket_username)
            for repo in watched:
                update = False
                try:
                    repository = bitbucket_provider.retrieve_repository_details(repo['owner'], repo['name'])
                except ObjectDoesNotExist:
                    update = True
                    repository = Repository()
                if update or (datetime.now() - repository.last_modified) > timedelta(days = 1):
                    repository = bitbucket_provider.create_or_update_repository_details(repo, repository)
                    if not repository.private:
                        repository.save()
                watched_repositories.append(repository)
            bitbucket_repository_user.starred = len(watched_repositories)
    except ObjectDoesNotExist:
        bitbucket_authed = False

    user_events = sorted(github_user_events + bitbucket_user_events,key=itemgetter('created_on'), reverse = True)[:30]

    return render_to_response('authed.html', {'user_events':user_events,'github_repository_user':github_repository_user,'bitbucket_repository_user':bitbucket_repository_user,'github_authed':github_authed,'bitbucket_authed':bitbucket_authed}, context_instance=RequestContext(request))
Beispiel #4
0
def github_username(request, username):
    username = urllib.unquote(username)
    user = request.user
    repository_user = None
    update = False
    github_provider = GithubProvider(user)
    # Get user information
    try:
        repository_user = github_provider.retrieve_user_details(username)
    except ObjectDoesNotExist:
        update = True
        repository_user = RepositoryUser()
    if update or (datetime.now() - repository_user.last_modified) > timedelta(days = 1):

        github_user_dict = github_provider.get_user_details(username)
        repository_user = github_provider.create_or_update_user_details(github_user_dict, repository_user)
        repository_user.save()

    user_events = github_provider.get_user_events(username)

    # Get repository information
    repositories, _ = github_provider.retrieve_starred_repositories_list(username)
    if len(repositories) == 0:
        repo_link_type, _ = LinkType.objects.get_or_create(name = "starred")
        for repo in github_provider.get_starred_repositories(username):
            update = False
            try:
                repository = Repository.objects.get(host_slug= 'github/'+repo['owner'].lower() + '/' + repo['name'].lower())
            except ObjectDoesNotExist:
                update = True
                repository = Repository()
            if update or (datetime.now() - repository.last_modified) > timedelta(days = 1):
                repository = github_provider.create_or_update_repository_details(repo, repository)
                if not repository.private:
                    repository.save()
                repository = repository
                RepositoryCategory.objects.get_or_create(name = repository.language)
            if not repository.private:
                RepositoryUserRepositoryLink.objects.get_or_create(user = repository_user, repository = repository, link_type = repo_link_type)

            repositories.append(repository)
    repository_user.starred = len(repositories)

    # Get repository information
    repositories, _ = github_provider.retrieve_watched_repositories_list(username)
    if len(repositories) == 0:
        repo_link_type, _ = LinkType.objects.get_or_create(name = "watched")
        for repo in github_provider.get_watched_repositories(username):
            update = False
            try:
                repository = Repository.objects.get(host_slug= 'github/'+repo['owner'].lower() + '/' + repo['name'].lower())
            except ObjectDoesNotExist:
                update = True
                repository = Repository()
            if update or (datetime.now() - repository.last_modified) > timedelta(days = 1):
                repository = github_provider.create_or_update_repository_details(repo, repository)
                if not repository.private:
                    repository.save()
                repository = repository
                RepositoryCategory.objects.get_or_create(name = repository.language)
            if not repository.private:
                RepositoryUserRepositoryLink.objects.get_or_create(user = repository_user, repository = repository, link_type = repo_link_type)

            repositories.append(repository)
    repository_user.watched = len(repositories)
    repository_user.save()

    return render_to_response('github_username.html', {'user_events':user_events,'repository_user':repository_user},context_instance=RequestContext(request))
Beispiel #5
0
def bitbucket_username(request, username):
    username = urllib.unquote(username)
    user = request.user
    repository_user = None
    update = False
    response = None

    bitbucket_provider = BitbucketProvider(user)
    # Get user information
    try:
        repository_user = bitbucket_provider.retrieve_user_details(username)
    except ObjectDoesNotExist:
        update = True
        repository_user = RepositoryUser()
    if update or (datetime.now() -
                  repository_user.last_modified) > timedelta(days=1):
        user_dict = bitbucket_provider.get_user_details(username)
        repository_user = bitbucket_provider.create_or_update_user_details(
            user_dict, repository_user)
        repository_user.save()

    user_events = bitbucket_provider.get_user_events(username)
    # Get repository information
    owned_repositories, repository_user = bitbucket_provider.retrieve_owned_repositories_list(
        username)
    watched_repositories, repository_user = bitbucket_provider.retrieve_watched_repositories_list(
        username)

    if len(owned_repositories) == 0:
        repo_link_type, _ = LinkType.objects.get_or_create(name="owned")
        owned = bitbucket_provider.get_owned_repositories(username)
        for repo in owned:
            update = False
            try:
                repository = bitbucket_provider.retrieve_repository_details(
                    repo['owner'], repo['name'])
            except ObjectDoesNotExist:
                update = True
                repository = Repository()
            if update or (datetime.now() -
                          repository.last_modified) > timedelta(days=1):
                repository = bitbucket_provider.create_or_update_repository_details(
                    repo, repository)
                if not repository.private:
                    repository.save()
                RepositoryCategory.objects.get_or_create(
                    name=repository.language)
            if not repository.private:
                RepositoryUserRepositoryLink.objects.get_or_create(
                    user=repository_user,
                    repository=repository,
                    link_type=repo_link_type)
            owned_repositories.append(repository)
        repository_user.public_repos = len(owned_repositories)
        repository_user.save()

    if len(watched_repositories) == 0:
        watched = bitbucket_provider.get_watched_repositories(username)
        for repo in watched:
            update = False
            try:
                repository = bitbucket_provider.retrieve_repository_details(
                    repo['owner'], repo['name'])
            except ObjectDoesNotExist:
                update = True
                repository = Repository()
            if update or (datetime.now() -
                          repository.last_modified) > timedelta(days=1):
                repository = bitbucket_provider.create_or_update_repository_details(
                    repo, repository)
                if not repository.private:
                    repository.save()
            watched_repositories.append(repository)
        repository_user.starred = len(watched_repositories)
    return render_to_response('bitbucket_username.html', {
        'user_events': user_events,
        'repository_user': repository_user
    },
                              context_instance=RequestContext(request))
Beispiel #6
0
def bitbucket_username(request, username):
    username = urllib.unquote(username)
    user = request.user
    repository_user = None
    update = False
    response = None

    bitbucket_provider = BitbucketProvider(user)
    # Get user information
    try:
        repository_user = bitbucket_provider.retrieve_user_details(username)
    except ObjectDoesNotExist:
        update = True
        repository_user = RepositoryUser()
    if update or (datetime.now() - repository_user.last_modified) > timedelta(days = 1):
        user_dict = bitbucket_provider.get_user_details(username)
        repository_user = bitbucket_provider.create_or_update_user_details(user_dict, repository_user)
        repository_user.save()

    user_events = bitbucket_provider.get_user_events(username)
    # Get repository information
    owned_repositories, repository_user = bitbucket_provider.retrieve_owned_repositories_list(username)
    watched_repositories, repository_user = bitbucket_provider.retrieve_watched_repositories_list(username)

    if len(owned_repositories) == 0:
        repo_link_type, _ = LinkType.objects.get_or_create(name = "owned")
        owned = bitbucket_provider.get_owned_repositories(username)
        for repo in owned:
            update = False
            try:
                repository = bitbucket_provider.retrieve_repository_details(repo['owner'], repo['name'])
            except ObjectDoesNotExist:
                update = True
                repository = Repository()
            if update or (datetime.now() - repository.last_modified) > timedelta(days = 1):
                repository = bitbucket_provider.create_or_update_repository_details(repo, repository)
                if not repository.private:
                    repository.save()
                RepositoryCategory.objects.get_or_create(name=repository.language)
            if not repository.private:
                RepositoryUserRepositoryLink.objects.get_or_create(user=repository_user, repository = repository, link_type = repo_link_type)
            owned_repositories.append(repository)
        repository_user.public_repos = len(owned_repositories)
        repository_user.save()

    if len(watched_repositories) == 0:
        watched = bitbucket_provider.get_watched_repositories(username)
        for repo in watched:
            update = False
            try:
                repository = bitbucket_provider.retrieve_repository_details(repo['owner'], repo['name'])
            except ObjectDoesNotExist:
                update = True
                repository = Repository()
            if update or (datetime.now() - repository.last_modified) > timedelta(days = 1):
                repository = bitbucket_provider.create_or_update_repository_details(repo, repository)
                if not repository.private:
                    repository.save()
            watched_repositories.append(repository)
        repository_user.starred = len(watched_repositories)
    return render_to_response('bitbucket_username.html', {'user_events':user_events,'repository_user':repository_user},context_instance=RequestContext(request))
Beispiel #7
0
def authed(request):
    user = request.user
    bitbucket_authed = True
    github_authed = True
    bitbucket_user_events = []
    github_user_events = []
    github_repository_user = None
    bitbucket_repository_user = None
    try:
        github_username = user.social_auth.get(
            provider='github').extra_data['username']
        github_provider = GithubProvider(user)
        update = False

        # Get user information
        try:
            github_repository_user = github_provider.retrieve_user_details(
                github_username)
        except ObjectDoesNotExist:
            update = True
            github_repository_user = RepositoryUser()
        if update or (datetime.now() - github_repository_user.last_modified
                      ) > timedelta(days=1):
            github_user_dict = github_provider.get_user_details(
                github_username)
            github_repository_user = github_provider.create_or_update_user_details(
                github_user_dict, github_repository_user)
            github_repository_user.save()
        github_user_events = github_provider.get_user_events(github_username)
        for github_user_event in github_user_events:
            github_user_event['host'] = 'github'
            github_user_event['created_on'] = dateutil.parser.parse(
                github_user_event['created_at'])

        # Get repository information
        repositories, _ = github_provider.retrieve_starred_repositories_list(
            github_username)

        if len(repositories) == 0:
            repo_link_type, _ = LinkType.objects.get_or_create(name="starred")
            if not github_repository_user:
                github_repository_user, _ = RepositoryUser.objects.get_or_create(
                    login=github_username, host='github')
            watched = github_provider.get_starred_repositories(github_username)
            for repo in watched:
                update = False
                try:
                    repository = Repository.objects.get(
                        host_slug='github/' + repo['owner'].lower() + '/' +
                        repo['name'].lower())
                except ObjectDoesNotExist:
                    update = True
                    repository = Repository()
                if update or (datetime.now() -
                              repository.last_modified) > timedelta(days=1):
                    repository = github_provider.create_or_update_repository_details(
                        repo, repository)
                    if not repository.private:
                        repository.save()
                    RepositoryCategory.objects.get_or_create(
                        name=repository.language)
                if not repository.private:
                    RepositoryUserRepositoryLink.objects.get_or_create(
                        user=github_repository_user,
                        repository=repository,
                        link_type=repo_link_type)

                repositories.append(repository)
        github_repository_user.starred = len(repositories)
        github_repository_user.save()

        # Get repository information
        repositories, _ = github_provider.retrieve_watched_repositories_list(
            github_username)

        if len(repositories) == 0:
            repo_link_type, _ = LinkType.objects.get_or_create(name="watched")
            if not github_repository_user:
                github_repository_user, _ = RepositoryUser.objects.get_or_create(
                    login=github_username, host='github')
            watched = github_provider.get_watched_repositories(github_username)
            for repo in watched:
                update = False
                try:
                    repository = Repository.objects.get(
                        host_slug='github/' + repo['owner'].lower() + '/' +
                        repo['name'].lower())
                except ObjectDoesNotExist:
                    update = True
                    repository = Repository()
                if update or (datetime.now() -
                              repository.last_modified) > timedelta(days=1):
                    repository = github_provider.create_or_update_repository_details(
                        repo, repository)
                    if not repository.private:
                        repository.save()
                    RepositoryCategory.objects.get_or_create(
                        name=repository.language)
                if not repository.private:
                    RepositoryUserRepositoryLink.objects.get_or_create(
                        user=github_repository_user,
                        repository=repository,
                        link_type=repo_link_type)

                repositories.append(repository)
        github_repository_user.watched = len(repositories)
        github_repository_user.save()
    except ObjectDoesNotExist:
        github_authed = False

    try:
        bitbucket_username = user.social_auth.get(
            provider='bitbucket').extra_data['username']
        bitbucket_provider = BitbucketProvider(user)
        # Get user information
        update = False
        try:
            bitbucket_repository_user = bitbucket_provider.retrieve_user_details(
                bitbucket_username)
        except ObjectDoesNotExist:
            update = True
            bitbucket_repository_user = RepositoryUser()
        if update or (datetime.now() - bitbucket_repository_user.last_modified
                      ) > timedelta(days=1):
            user_dict = bitbucket_provider.get_user_details(bitbucket_username)
            bitbucket_repository_user = bitbucket_provider.create_or_update_user_details(
                user_dict, bitbucket_repository_user)
            bitbucket_repository_user.save()
        bitbucket_user_events = bitbucket_provider.get_user_events(
            bitbucket_username)
        for bitbucket_user_event in bitbucket_user_events:
            bitbucket_user_event['host'] = 'bitbucket'
            bitbucket_user_event['created_on'] = dateutil.parser.parse(
                bitbucket_user_event['utc_created_on'])
        # Get repository information
        owned_repositories, _ = bitbucket_provider.retrieve_owned_repositories_list(
            bitbucket_username)
        watched_repositories, _ = bitbucket_provider.retrieve_watched_repositories_list(
            bitbucket_username)

        if len(owned_repositories) == 0:
            owned = bitbucket_provider.get_owned_repositories(
                bitbucket_username)
            for repo in owned:
                update = False
                try:
                    repository = bitbucket_provider.retrieve_repository_details(
                        repo['owner'], repo['name'])
                except ObjectDoesNotExist:
                    update = True
                    repository = Repository()
                if update or (datetime.now() -
                              repository.last_modified) > timedelta(days=1):
                    repository = bitbucket_provider.create_or_update_repository_details(
                        repo, repository)
                    if not repository.private:
                        repository.save()
                    RepositoryCategory.objects.get_or_create(
                        name=repository.language)
                if not repository.private:
                    RepositoryUserRepositoryLink.objects.get_or_create(
                        user=bitbucket_repository_user,
                        repository=repository,
                        owned=True)
                owned_repositories.append(repository)
            bitbucket_repository_user.public_repos = len(owned_repositories)
            bitbucket_repository_user.save()

        if len(watched_repositories) == 0:
            watched = bitbucket_provider.get_watched_repositories(
                bitbucket_username)
            for repo in watched:
                update = False
                try:
                    repository = bitbucket_provider.retrieve_repository_details(
                        repo['owner'], repo['name'])
                except ObjectDoesNotExist:
                    update = True
                    repository = Repository()
                if update or (datetime.now() -
                              repository.last_modified) > timedelta(days=1):
                    repository = bitbucket_provider.create_or_update_repository_details(
                        repo, repository)
                    if not repository.private:
                        repository.save()
                watched_repositories.append(repository)
            bitbucket_repository_user.starred = len(watched_repositories)
    except ObjectDoesNotExist:
        bitbucket_authed = False

    user_events = sorted(github_user_events + bitbucket_user_events,
                         key=itemgetter('created_on'),
                         reverse=True)[:30]

    return render_to_response('authed.html', {
        'user_events': user_events,
        'github_repository_user': github_repository_user,
        'bitbucket_repository_user': bitbucket_repository_user,
        'github_authed': github_authed,
        'bitbucket_authed': bitbucket_authed
    },
                              context_instance=RequestContext(request))