Beispiel #1
0
def repo(request, repoId):
    context = RequestContext(request)
    context_dict = views.getBaseTemplateData(request)

    cache1 = get_cache('default')

    try:
        repo = Repository.objects.get(id=repoId, users=request.user)

        context_dict['repo'] = repo
        activeRepo = {"repo": repo, "icon": views.envIcons[repo.environment.name]}
        context_dict['activeRepo'] = activeRepo
        latestQueries = GithubSearchResult.objects.filter(commit__repository=repo, user=request.user).order_by('-modified')[:5]
        latestClicks = Page.objects.filter(commit__repository=repo, user=request.user).order_by('-modified')[:3]

        context_dict['repo'] = {"repo": repo, "queries": latestQueries, "clicks":latestClicks}

        commits = Commit.objects.filter(repository=repo).order_by('-date')

        if (Commit.objects.filter(repository=repo).count() == 0):
            commit, created = Commit.objects.get_or_create(repository=repo, sha="firstCommit", message="Joining SearchDemon commit!", date=repo.last_modified)

        queries = GithubSearchResult.objects.filter(commit__repository=repo)
        context_dict["queries"] = queries
        ps = Page.objects.filter(commit__repository=repo)
        context_dict["ps"] = ps

        commitstuff = []

        for co in commits:
            print co
            newl = {}
            pag = []
            pages = Page.objects.filter(user=request.user, commit=co).order_by("-modified")
            newPages = []
            c=0
            for x in pages:
                pageNum = c / 5
                newPages.append({"page":x, "pageNum":pageNum})
                c = c + 1

            searchresults = GithubSearchResult.objects.filter(commit=co, user=request.user, commit__repository=repo).reverse()
            for s in searchresults:
                cr = Page.objects.filter(user=request.user, commit=co, query=s.title)
                if cr.__len__() != 0: newl[s.title] = cr

            clickresults = Page.objects.filter(user=request.user, commit=co).order_by("-views")
            tempC = [co, searchresults, clickresults, newl, newPages]
            commitstuff.append(tempC)
        context_dict['commits'] = commitstuff

    except:
        print "fail"

    choices = (['web', 'Web'], ['news', 'News'], ['image', 'Image'])
    context_dict['choices'] = choices
    if request.method == 'POST':
        context_dict = search.searchFunction(request, context_dict, repo)
        return render_to_response('searchdemon/search.html', context_dict, context_instance=RequestContext(request))
    return render_to_response('searchdemon/repo.html', context_dict, context_instance=RequestContext(request))
Beispiel #2
0
def repos(request):
    context = RequestContext(request)
    context_dict = views.getBaseTemplateData(request)
    repo_list = context_dict["repo_list"]

    for dic in repo_list:
        latestQueries = GithubSearchResult.objects.filter(commit__repository=dic["repo"], user=request.user).order_by('-modified')[:5]
        dic["queries"] = latestQueries

    context_dict['repo_list'] = repo_list

    return render_to_response('searchdemon/repos.html', context_dict, context)
Beispiel #3
0
def searchCustomTab(request):
    context_dict = views.getBaseTemplateData(request)

    dom = request.POST["dom"]
    query = request.POST["query"]
    source = "web"
    rpp = 10

    env, created = Environment.objects.get_or_create(user=request.user, name="Global")
    whitelist = ListEntry.objects.filter(user=request.user, white=True, environment=env, domain=dom)

    nQuery = query + " site:" + dom
    r = run_query(nQuery, source, rpp)

    context_dict["query"] = query
    context_dict['t'] = r

    return render_to_response('searchdemon/customtab.html', context_dict, context_instance=RequestContext(request))
Beispiel #4
0
def search(request):
    context_dict = views.getBaseTemplateData(request)

    if request.user.__class__.__name__ == "AnonymousUser":
        context_dict = simpleSearch(request, context_dict)
    elif Repository.objects.filter(users=request.user).count() == 0:
        context_dict = simpleSearch(request, context_dict)
        print "SIMPLE SEARCH HAHA"
    elif context_dict["settings"].simpleSite == True:
        context_dict = simpleSearch(request, context_dict)
    else:
        try:
            r = context_dict["activeRepo"]["repo"]

        except Exception as e:
            print e.message

        if request.method == 'POST' or request.GET.has_key("q"):
            context_dict = searchFunction(request, context_dict)

    return render_to_response('searchdemon/search.html', context_dict, context_instance=RequestContext(request))