Exemple #1
0
def github_repo_star(request, owner, repo):
    user = request.user
    if user.is_authenticated():
        try:
            github_provider = GithubProvider(user)
            github_provider.star(owner, repo)
            data= {'outcome':'success'}
            github_username = None
            bitbucket_username = None
            try:
                github_username = user.social_auth.get(provider='github').extra_data['username']
                github_prefix = github_username
            except:
                github_prefix = ''
            try:
                bitbucket_username = user.social_auth.get(provider='bitbucket').extra_data['username']
                bitbucket_prefix=bitbucket_username
            except:
                bitbucket_prefix = ''
            custom_prefix = '.'.join((hashlib.md5(github_prefix).hexdigest(),hashlib.md5(bitbucket_prefix).hexdigest()))
            expire_view_cache('repowatcher.main.views.github_repo', kwargs = {'owner':owner,'repo':repo}, key_prefix=custom_prefix)
            return HttpResponse(json.dumps(data),mimetype="application/json")
        except ObjectDoesNotExist:
            pass
    res = HttpResponse("Unauthorized")
    res.status_code = 401
    return res
Exemple #2
0
def github_repo_unstar(request, owner, repo):
    repo_link_type, _ = LinkType.objects.get_or_create(name = "starred")
    user = request.user
    if user.is_authenticated():
        try:
            host_slug = ('/'.join(('github',owner,repo))).lower()
            profile = user.get_profile()
            repository = Repository.objects.get(host_slug= host_slug)
            UserRepositoryLink.objects.filter(user = profile).filter(repository = repository).filter(link_type = repo_link_type).delete()
            github_provider = GithubProvider(user)
            github_provider.unstar(owner, repo)
            data= {'outcome':'success'}
            github_username = None
            bitbucket_username = None
            try:
                github_username = user.social_auth.get(provider='github').extra_data['username']
                github_prefix = github_username
            except:
                github_prefix = ''
            try:
                bitbucket_username = user.social_auth.get(provider='bitbucket').extra_data['username']
                bitbucket_prefix=bitbucket_username
            except:
                bitbucket_prefix = ''
            custom_prefix = '.'.join((hashlib.md5(github_prefix).hexdigest(),hashlib.md5(bitbucket_prefix).hexdigest()))
            expire_view_cache('repowatcher.main.views.github_repo', kwargs = {'owner':owner,'repo':repo}, key_prefix=custom_prefix)
            return HttpResponse(json.dumps(data),mimetype="application/json")
        except ObjectDoesNotExist:
            pass
    res = HttpResponse("Unauthorized")
    res.status_code = 401
    return res
Exemple #3
0
def expire_cache(sender, instance, **kwargs):
    try:
        github_username = None
        bitbucket_username = None
        try:
            github_username = instance.user.social_auth.get(provider='github').extra_data['username']
            github_prefix = github_username
        except:
            github_prefix = ''
        try:
            bitbucket_username = instance.user.social_auth.get(provider='bitbucket').extra_data['username']
            bitbucket_prefix=bitbucket_username
        except:
            bitbucket_prefix = ''
        custom_prefix = '.'.join((hashlib.md5(github_prefix).hexdigest(),hashlib.md5(bitbucket_prefix).hexdigest()))
        expire_view_cache('authed_owned', key_prefix=custom_prefix)
        expire_view_cache('authed_watched', key_prefix=custom_prefix)
        if github_username:
            expire_view_cache('github_username_owned', kwargs = {'username':github_username}, key_prefix=custom_prefix)
            expire_view_cache('github_username_watched', kwargs = {'username':github_username}, key_prefix=custom_prefix)
        if bitbucket_username:
            expire_view_cache('bitbucket_username_owned', kwargs = {'username':bitbucket_username}, key_prefix=custom_prefix)
            expire_view_cache('bitbucket_username_watched', kwargs = {'username':bitbucket_username}, key_prefix=custom_prefix)

        category_links = instance.userrepositorylink_set.order_by('repository_category').distinct('repository_category')
        for category_link in category_links:
            expire_view_cache('authed_category_owned', kwargs = {'category':category_link.repository_category.name}, key_prefix=custom_prefix)
            expire_view_cache('authed_category_watched', kwargs = {'category':category_link.repository_category.name}, key_prefix=custom_prefix)
            if github_username:
                expire_view_cache('github_username_category_owned', kwargs = {'username':github_username,'category':category_link.repository_category.name}, key_prefix=custom_prefix)
                expire_view_cache('github_username_category_watched', kwargs = {'username':github_username,'category':category_link.repository_category.name}, key_prefix=custom_prefix)
            if bitbucket_username:
                expire_view_cache('bitbucket_username_category_owned', kwargs = {'username':bitbucket_username,'category':category_link.repository_category.name}, key_prefix=custom_prefix)
                expire_view_cache('bitbucket_username_category_watched', kwargs = {'username':bitbucket_username,'category':category_link.repository_category.name}, key_prefix=custom_prefix)
    except Exception as e:
        logger.error(e)
Exemple #4
0
def expire_cache(sender, instance, **kwargs):
    try:
        github_username = None
        bitbucket_username = None
        try:
            github_username = instance.user.social_auth.get(
                provider='github').extra_data['username']
            github_prefix = github_username
        except:
            github_prefix = ''
        try:
            bitbucket_username = instance.user.social_auth.get(
                provider='bitbucket').extra_data['username']
            bitbucket_prefix = bitbucket_username
        except:
            bitbucket_prefix = ''
        custom_prefix = '.'.join((hashlib.md5(github_prefix).hexdigest(),
                                  hashlib.md5(bitbucket_prefix).hexdigest()))
        expire_view_cache('authed_owned', key_prefix=custom_prefix)
        expire_view_cache('authed_watched', key_prefix=custom_prefix)
        if github_username:
            expire_view_cache('github_username_owned',
                              kwargs={'username': github_username},
                              key_prefix=custom_prefix)
            expire_view_cache('github_username_watched',
                              kwargs={'username': github_username},
                              key_prefix=custom_prefix)
        if bitbucket_username:
            expire_view_cache('bitbucket_username_owned',
                              kwargs={'username': bitbucket_username},
                              key_prefix=custom_prefix)
            expire_view_cache('bitbucket_username_watched',
                              kwargs={'username': bitbucket_username},
                              key_prefix=custom_prefix)

        category_links = instance.userrepositorylink_set.order_by(
            'repository_category').distinct('repository_category')
        for category_link in category_links:
            expire_view_cache(
                'authed_category_owned',
                kwargs={'category': category_link.repository_category.name},
                key_prefix=custom_prefix)
            expire_view_cache(
                'authed_category_watched',
                kwargs={'category': category_link.repository_category.name},
                key_prefix=custom_prefix)
            if github_username:
                expire_view_cache('github_username_category_owned',
                                  kwargs={
                                      'username':
                                      github_username,
                                      'category':
                                      category_link.repository_category.name
                                  },
                                  key_prefix=custom_prefix)
                expire_view_cache('github_username_category_watched',
                                  kwargs={
                                      'username':
                                      github_username,
                                      'category':
                                      category_link.repository_category.name
                                  },
                                  key_prefix=custom_prefix)
            if bitbucket_username:
                expire_view_cache('bitbucket_username_category_owned',
                                  kwargs={
                                      'username':
                                      bitbucket_username,
                                      'category':
                                      category_link.repository_category.name
                                  },
                                  key_prefix=custom_prefix)
                expire_view_cache('bitbucket_username_category_watched',
                                  kwargs={
                                      'username':
                                      bitbucket_username,
                                      'category':
                                      category_link.repository_category.name
                                  },
                                  key_prefix=custom_prefix)
    except Exception as e:
        logger.error(e)