Exemplo n.º 1
0
def see_notifications(request,
                      source,
                      page,
                      template_name='notifications.html'):

    if not request.user.is_authenticated():
        return HttpResponse("Must be logged in to see notifications",
                            status=403)

    rows = define_rows(request)

    notifications = Notification.objects.filter(
        destiny=request.user, type=Notification.SYSTEM,
        removed=False).order_by('-created_date')

    notifications_unread = notifications.filter(read=False)
    notifications_read = notifications.filter(read=True)

    myPaginator = Paginator(notifications, rows)
    myPaginator_unread = Paginator(notifications_unread, rows)
    myPaginator_read = Paginator(notifications_read, rows)

    pager = pager_unread = pager_read = None

    if source == '0':
        try:
            pager = myPaginator.page(page)
        except PageNotAnInteger, e:
            pager = myPaginator.page(1)

        pager_unread = myPaginator_unread.page(1)
        pager_read = myPaginator_read.page(1)
Exemplo n.º 2
0
def databases(request, page=1, template_name='results.html', force=False):

     #first lets clean the query session log
    if 'query' in request.session:
        del request.session['query']
    if 'advparams' in request.session:
        del request.session['advparams']
    if 'isAdvanced' in request.session:
        del request.session['isAdvanced']

    if 'query_id' in request.session:
        del request.session['query_id']
    if 'query_type' in request.session:
        del request.session['query_type']

    request.session['list_origin'] = 'personal'

    # Get the list of databases for a specific user
    user = request.user

    _filter = "user_t:" + '"' + user.username + '"'
    if user.is_superuser:
        _filter = "user_t:*"

    rows = define_rows(request)
    if request.POST and not force:
        page = request.POST["page"]

    if page == None:
        page = 1

    (sortString, filterString, sort_params, range) = paginator_process_params(request.POST, page, rows)

    sort_params["base_filter"] = _filter;

    #print filterString

    if len(filterString) > 0:
        _filter += " AND " + filterString

    #print _filter

    (list_databases,hits) = get_databases_from_solr_v2(request, _filter, sort=sortString, rows=rows, start=range)
    if range > hits and force < 2:
        return databases(request, page=1, force=True)

    #print "Range: "+str(range)
    #print "hits: "+str(hits)
    #print "len: "+str(len(list_databases))

    list_databases = paginator_process_list(list_databases, hits, range)

    #print "len: "+str(len(list_databases))
    ## Paginator ##
    myPaginator = Paginator(list_databases, rows)
    try:
        pager =  myPaginator.page(page)
    except PageNotAnInteger, e:
        pager =  myPaginator.page(page)
Exemplo n.º 3
0
def all_databases_user(request, page=1, template_name='results.html', force=False):

    rows = define_rows(request)

    if request.POST and not force:
        page = request.POST["page"]

    if page == None:
        page = 1
    # lets clear the geolocation session search filter (if any)
    try:
        del request.session['query']
        del request.session['advparams']
        del request.session['isAdvanced']
        del request.session['serialized_query']
    except:
        pass

    request.session['list_origin'] = 'all'

    emifprofile = request.user.get_profile()
    interests = emifprofile.interests.all()

    type_t_list = ""
    if interests:
        for i in interests:
            type_t = i.slug.replace(" ", "").lower()
            type_t_list+=(type_t + ",")

        type_t_list = type_t_list[:-1]

        query = "type_t:" + type_t_list
        (sortString, filterString, sort_params, start) = paginator_process_params(request.POST, page, rows)
        sort_params["base_filter"] = query;
        if len(filterString) > 0:
            query += " AND " + filterString

        #print query

        (list_databases,hits) = get_databases_from_solr_v2(request, query, sort=sortString, rows=rows, start=start)

        list_databases = paginator_process_list(list_databases, hits, start)
        if start > hits and not force:
            return all_databases_user(request, 1, force=True)

    else:
        list_databases = []
        #list_databases = get_databases_from_solr(request, "*:*")

    ## Paginator ##
    myPaginator = Paginator(list_databases, rows)
    try:
        pager =  myPaginator.page(page)
    except PageNotAnInteger, e:
        pager =  myPaginator.page(1)
Exemplo n.º 4
0
def create_auth_token(request, page=1, templateName='api-key.html', force=False):
    """
    Method to create token to authenticate when calls REST API
    """

    if not config.extra_information:
        raise Http404

    rows = define_rows(request)
    if request.POST and not force:
        page = request.POST["page"]

    if page == None:
        page = 1

    user = request.user
    if not Token.objects.filter(user=user).exists():
        token = Token.objects.create(user=request.user)
    else:
        token = Token.objects.get(user=user)

    _filter = "user_t:" + '"' + user.username + '"'

    (sortString, filterString, sort_params, range) = paginator_process_params(request.POST, page, rows)

    sort_params["base_filter"] = _filter;

    if len(filterString) > 0:
        _filter += " AND " + filterString

    (list_databases,hits) = get_databases_from_solr_v2(request, _filter, sort=sortString, rows=rows, start=range)
    if range > hits and force < 2:
        return create_auth_token(request, page=1, force=True)

    list_databases = paginator_process_list(list_databases, hits, range)

    myPaginator = Paginator(list_databases, rows)
    try:
        pager =  myPaginator.page(page)
    except PageNotAnInteger, e:
        pager =  myPaginator.page(1)
Exemplo n.º 5
0
def more_like_that(request, doc_id, mlt_query=None, page=1, template_name='more_like_this.html', force=False):

    if not config.more_like_this:
        raise Http404
    #first lets clean the query session log
    if 'query' in request.session:
        del request.session['query']

    if 'advparams' in request.session:
        del request.session['advparams']

    if 'isAdvanced' in request.session:
        del request.session['isAdvanced']

    if 'query_id' in request.session:
        del request.session['query_id']
    if 'query_type' in request.session:
        del request.session['query_type']

    database_name = ""

    fingerprint = Fingerprint.objects.get(fingerprint_hash=doc_id)

    if mlt_query == None:
        (_filter, database_name) = get_query_from_more_like_this(request, doc_id, fingerprint.questionnaire.slug)
    else:
        _filter = mlt_query

    if not _filter:
        return render(request, template_name, {'request': request,
                                       'num_results': 0, 'page_obj': None,
                                       'page_rows': 0,'breadcrumb': True,
                                       "breadcrumb_text": "More Like - "+database_name,
                                       'database_name': database_name, 'isAdvanced': False,
                                       'hide_add': True, 'more_like_this': True,
                                       "sort_params": None, "page":None})

    rows = define_rows(request)
    if request.POST and not force:
        page = request.POST["page"]

    if page == None:
        page = 1

    (sortString, filterString, sort_params, range) = paginator_process_params(request.POST, page, rows, default_mode={"score":"desc"})
    sort_params["base_filter"] = _filter;

    #print filterString

    if len(filterString) > 0:
        _filter += " AND " + filterString

    #print _filter

    def fn(res, lst):
        m = {}
        for r in res:
            if "id" in r and "score" in r:
                m[r["id"]] = r

        for d in lst:
            if d.id in m:
                d.score = str(round(float( m[d.id]["score"]), 3) )
        return lst

    (list_databases,hits) = get_databases_from_solr_v2(request, _filter, sort=sortString, rows=rows, start=range, fl="*, score", post_process=fn)
    if range > hits and force < 2:
        return databases(request, page=1, force=True)

    #print "Range: "+str(range)
    #print "hits: "+str(hits)
    #print "len: "+str(len(list_databases))

    list_databases = paginator_process_list(list_databases, hits, range)

    #print "len: "+str(len(list_databases))
    ## Paginator ##
    myPaginator = Paginator(list_databases, rows)
    try:
        pager =  myPaginator.page(page)
    except PageNotAnInteger, e:
        pager =  myPaginator.page(page)
Exemplo n.º 6
0
def results_fulltext_aux(request, query, page=1, template_name='results.html', isAdvanced=False, force=False, query_reference=None, advparams=None):

    rows = define_rows(request)
    if request.POST and "page" in request.POST and not force:
        page = request.POST["page"]

    if page == None:
        page = 1

    if query == "" or query == "text_t:" or query.strip()=="text_t:*" :
        return render(request, "results.html", {'request': request, 'breadcrumb': True,  'isSearch': True,
                                                'results': True, 'hide_add': True,
                                                'num_results': 0, 'page_obj': None})

    query = query + " AND " + typeFilter(request.user)

    (sortString, filterString, sort_params, range) = paginator_process_params(request.POST, page, rows)
    sort_params["base_filter"] = query;
    query_filtered=query
    if len(filterString) > 0:
        query_filtered += " AND " + filterString

    try:
        hlfl = ",".join(advparams)
    except:
        hlfl = None

    if isAdvanced:
        (list_databases, hits, hi) = get_databases_from_solr_with_highlight(request, query_filtered, sort=sortString, rows=rows, start=range, hlfl=hlfl)
    else:
        (list_databases, hits, hi) = get_databases_from_solr_with_highlight(request, query_filtered, sort=sortString, rows=rows, start=range)

    if not isAdvanced:
        hi = merge_highlight_results( '"'+escapeSolrArg(request.session["query"])+'"' , hi)
    else:
        hi = merge_highlight_results( None , hi)


    if range > hits and not force:
        return results_fulltext_aux(request, query, 1, isAdvanced=isAdvanced, force=True)

    request.session["highlight_results"] = hi

    if len(list_databases) == 0 :
        query_old = request.session.get('query', "")
        if isAdvanced == True:
            return render(request, "results.html", {'request': request, 'breadcrumb': True,  'isSearch': True,
                                                'results': True, 'hide_add': True,
                                                'num_results': 0, 'page_obj': None, 'isAdvanced': True})
        else:
            return render(request, "results.html", {'request': request, 'breadcrumb': True, 'isSearch': True,
                                                'results': True, 'hide_add': True,
                                                'num_results': 0, 'page_obj': None, 'search_old': query_old, 'isAdvanced': False})

    list_databases = paginator_process_list(list_databases, hits, range)

    # only execute if this if we are not posting back, we dont want to do this on changing page or applying filters
    if request.POST.get('page') == None and query_reference != None:
        # anotate the databases appearing on results
        anotateshowonresults.delay(query_filtered, request.user, isAdvanced, query_reference)

    myPaginator = Paginator(list_databases, rows)
    try:
        pager =  myPaginator.page(page)
    except PageNotAnInteger, e:
        pager =  myPaginator.page(page)