Exemplo n.º 1
0
def suggest(request):
    account = request.user.account
    preferences = account.get_preferences()
    language = request.auth_manager.language

    builder = ThemeBuilder(preferences, False, language, account)
    data = builder.parse()

    if data['federated_accounts_ids']:
        federated_accounts = data['federated_accounts']
        account_id = data['federated_accounts_ids']+[account.id]
    else:
        account_id = account.id

    query = request.GET.get('term', '')
    ids = request.GET.get('ids', '')
    resources = request.GET.getlist('resources[]', None)
    fm = FinderManager(ThemeFinder)

    if query:
        results, time, facets = fm.search(account_id=account_id, query=query, resource=resources)
        # optionally shows extra info
        # results.append({"extras": {"query": fm.get_finder().last_query, "time": time, "facets": facets}})
    elif ids:
        results, time, facets = fm.search(account_id=account_id, ids=ids, resource=resources)
    else:
        results = ''
    data = render_to_response('personalizeHome/suggest.json', {'objects': results})

    return HttpResponse(data,  content_type='application/json')
Exemplo n.º 2
0
def suggest(request):
    account = request.user.account
    preferences = account.get_preferences()
    language = request.auth_manager.language

    builder = ThemeBuilder(preferences, False, language, account)
    data = builder.parse()

    if data['federated_accounts_ids']:
        federated_accounts = data['federated_accounts']
        account_id = data['federated_accounts_ids'] + [account.id]
    else:
        account_id = account.id

    query = request.GET.get('term', '')
    ids = request.GET.get('ids', '')
    resources = request.GET.getlist('resources[]', None)
    fm = FinderManager(ThemeFinder)

    if query:
        results, time, facets = fm.search(account_id=account_id,
                                          query=query,
                                          resource=resources)
        # optionally shows extra info
        # results.append({"extras": {"query": fm.get_finder().last_query, "time": time, "facets": facets}})
    elif ids:
        results, time, facets = fm.search(account_id=account_id,
                                          ids=ids,
                                          resource=resources)
    else:
        results = ''
    data = render_to_response('personalizeHome/suggest.json',
                              {'objects': results})

    return HttpResponse(data, content_type='application/json')
Exemplo n.º 3
0
def load(request):
    """
    Shows the microsite's home page
    :param request:
    """
    jsonObject = None
    language = request.auth_manager.language
    account = request.account
    preferences = request.preferences
    is_preview = 'preview' in request.GET and request.GET['preview'] == 'true'

    builder = ThemeBuilder(preferences, is_preview, language, request.user)

    resources = ["ds", "vz"]
    resources.extend([
        finder.doc_type
        for finder in DatalPluginPoint.get_active_with_att('finder')
    ])

    if account.get_preference("account.dataset.show"):
        resources.append("dt")

    if is_preview or preferences["account_home"]:
        """ shows the home page new version"""
        data = builder.parse()

        if data:

            accounts_ids = data['federated_accounts_ids'] + [account.id]

            queryset = FinderQuerySet(FinderManager(HomeFinder),
                                      max_results=250,
                                      account_id=accounts_ids,
                                      resource=resources)

            paginator = Paginator(queryset, 25)
            revisions = paginator.page(1)

            if data['federated_accounts_ids']:
                add_domains_to_permalinks(revisions.object_list)

            context = data.copy()
            context['has_federated_accounts'] = data[
                'federated_accounts_ids'] != []
            context['request'] = request
            context['paginator'] = paginator
            context['revisions'] = revisions
            context['categories'] = Category.objects.get_for_home(
                language, accounts_ids)

            context['categories_dict'] = {}
            for cat in context['categories']:
                key = str(cat['id'])
                context['categories_dict'][key] = cat['name']

            return render_to_response(data['template_path'],
                                      context,
                                      context_instance=RequestContext(request))

    return redirect('/search/')
Exemplo n.º 4
0
def load(request):
    """
    Shows the microsite's home page
    :param request:
    """
    jsonObject = None
    language = request.auth_manager.language
    account = request.account
    preferences = request.preferences
    is_preview = 'preview' in request.GET and request.GET['preview'] == 'true'

    builder = ThemeBuilder(preferences, is_preview, language, request.user)

    resources = ["ds", "vz"]
    resources.extend([finder.doc_type for finder in DatalPluginPoint.get_active_with_att('finder')])

    if account.get_preference("account.dataset.show"):
        resources.append("dt")

    if is_preview or preferences["account_home"]:
        """ shows the home page new version"""
        data = builder.parse()

        if data:

            accounts_ids=data['federated_accounts_ids'] + [account.id]

            queryset = FinderQuerySet(FinderManager(HomeFinder), 
                max_results=250, account_id=accounts_ids, resource=resources )

            paginator = Paginator(queryset, 25)
            revisions = paginator.page(1)

            if data['federated_accounts_ids']:
                add_domains_to_permalinks(revisions.object_list)

            context = data.copy()
            context['has_federated_accounts'] = data['federated_accounts_ids'] != []
            context['request'] = request
            context['paginator'] = paginator
            context['revisions'] = revisions
            context['categories'] = Category.objects.get_for_home(language, accounts_ids)

            context['categories_dict'] = {}
            for cat in context['categories']:
                key = str(cat['id'])
                context['categories_dict'][key] = cat['name']

            return render_to_response(data['template_path'], context, context_instance=RequestContext(request))
       
    return redirect('/search/')
Exemplo n.º 5
0
def load(request):
    """
    Shows the microsite's home page
    :param request:
    """
    jsonObject = None
    language = request.auth_manager.language
    account = request.account
    preferences = request.preferences
    is_preview = 'preview' in request.GET and request.GET['preview'] == 'true'

    
    builder = ThemeBuilder(preferences, is_preview, language, account)

    if is_preview or preferences["account_home"]:
        """ shows the home page new version"""
        data = builder.parse()

        if data:

            accounts_ids=data['federated_accounts_ids'] + [account.id]

            queryset = FinderQuerySet(FinderManager(HomeFinder), 
                max_results=250, account_id=accounts_ids )

            paginator = Paginator(queryset, 25)
            revisions = paginator.page(1)

            if data['federated_accounts_ids']:
                add_domains_to_permalinks(revisions.object_list)

            context = data.copy()
            context['has_federated_accounts'] = data['federated_accounts_ids'] != []
            context['request'] = request
            context['paginator'] = paginator
            context['revisions'] = revisions
            context['categories'] = Category.objects.get_for_home(language, accounts_ids)

            context['categories_dict'] = {}
            for cat in context['categories']:
                key = str(cat['id'])
                context['categories_dict'][key] = cat['name']

            return render_to_response(data['template_path'], context)
        else:
            # For the moment, redirect to search
            return redirect('/search/')
    else:
        # For the moment, redirect to search, but this needs to be erased
        return redirect('/search/')
Exemplo n.º 6
0
def update_categories(request):
    language = request.auth_manager.language
    params = request.GET
    account_id = params.get('account_id','')

    # we need a full categories list in case is a "federated account" (have childs accounts)
    if account_id == '':
        account = request.account
        preferences = request.preferences
        builder = ThemeBuilder(preferences, False, language, account)
        data = builder.parse()

        if data['federated_accounts_ids']:
            federated_accounts=data['federated_accounts']
    
        categories = data['categories']
    else:
        # account_id is single account or a list of federated accounts
        categories = Category.objects.get_for_home(language, account_id)

    return render_to_response('loadHome/categories.js', locals(), mimetype="text/javascript")
Exemplo n.º 7
0
def update_list(request):
    account = request.account
    auth_manager = request.auth_manager
    preferences = account.get_preferences()
    language = request.auth_manager.language

    resources = ["ds", "vz"]
    resources.extend([
        finder.doc_type
        for finder in DatalPluginPoint.get_active_with_att('finder')
    ])

    if account.get_preference("account.dataset.show"):
        resources.append("dt")

    form = QueryDatasetForm(request.POST)
    if form.is_valid():
        query = form.cleaned_data.get('search')
        page = form.cleaned_data.get('page')
        order = form.cleaned_data.get('order')
        order_elastic = None
        if order == "0":
            order_elastic = "title"
        elif order == "1":
            order_elastic = "last"

        order_type = form.cleaned_data.get('order_type')
        reverse = order_type.lower() == 'ascending'

        category_filters = form.cleaned_data.get('category_filters')
        if category_filters:
            category_filters = category_filters.split(",")

        builder = ThemeBuilder(preferences, False, language, request.user)
        data = builder.parse()

        if data['federated_accounts_ids']:

            entity = form.cleaned_data.get('entity_filters')
            if entity:
                accounts_ids = [int(entity)]
            else:
                accounts_ids = data['federated_accounts_ids'] + [account.id]

            typef = form.cleaned_data.get('type_filters')
            if typef:
                if typef in resources:
                    resources = [typef]

            queryset = FinderQuerySet(FinderManager(HomeFinder),
                                      query=query,
                                      max_results=250,
                                      account_id=accounts_ids,
                                      resource=resources,
                                      category_filters=category_filters,
                                      order=order_elastic,
                                      reverse=reverse)

        else:
            all_resources = form.cleaned_data.get('all')
            if not all_resources:
                resources_type = form.cleaned_data.get('type')
                aux = []
                for resource_name in resources_type.split(','):
                    if resource_name in resources:
                        aux.append(resource_name)

                resources = aux

            queryset = FinderQuerySet(FinderManager(HomeFinder),
                                      category_filters=category_filters,
                                      query=query,
                                      resource=resources,
                                      max_results=250,
                                      order=order_elastic,
                                      reverse=reverse,
                                      account_id=account.id)

        paginator = Paginator(queryset, 25)

        revisions = paginator.page(page and page or 1)
        if data['federated_accounts_ids']:
            add_domains_to_permalinks(revisions.object_list)
        error = ''

        results = revisions.object_list
    else:
        error = 'Invalid data'
        results = []
        categories = []

    t = loader.get_template('loadHome/table.json')
    c = Context(locals())
    return HttpResponse(t.render(c), content_type="application/json")
Exemplo n.º 8
0
def update_list(request):
    account         = request.account
    auth_manager    = request.auth_manager
    preferences     = account.get_preferences()
    language        = request.auth_manager.language

    resources = ["ds", "vz"]
    resources.extend([finder.doc_type for finder in DatalPluginPoint.get_active_with_att('finder')])
        
    if account.get_preference("account.dataset.show"):
        resources.append("dt")


    form = QueryDatasetForm(request.POST)
    if form.is_valid():
        query = form.cleaned_data.get('search')
        page = form.cleaned_data.get('page')
        order = form.cleaned_data.get('order')
        order_elastic = None
        if order == "0":
            order_elastic = "title"
        elif order == "1":
            order_elastic = "last"

        order_type = form.cleaned_data.get('order_type')
        reverse = order_type.lower() == 'ascending'

        category_filters = form.cleaned_data.get('category_filters')
        if category_filters:
            category_filters=category_filters.split(",")

        builder = ThemeBuilder(preferences, False, language, request.user)
        data = builder.parse()

        if data['federated_accounts_ids']:

            entity = form.cleaned_data.get('entity_filters')
            if entity:
                accounts_ids = [int(entity)]
            else:
                accounts_ids = data['federated_accounts_ids'] + [account.id]

            typef = form.cleaned_data.get('type_filters')
            if typef:
                if typef in resources:
                    resources = [typef]

            queryset = FinderQuerySet(FinderManager(HomeFinder), 
                query = query,
                max_results = 250,
                account_id = accounts_ids,
                resource = resources,
                category_filters=category_filters,
                order = order_elastic,
                reverse = reverse
            ) 

        else:
            all_resources = form.cleaned_data.get('all')
            if not all_resources:
                resources_type = form.cleaned_data.get('type')
                aux = []
                for resource_name in resources_type.split(','):
                    if resource_name in resources:
                        aux.append(resource_name)

                resources=aux

            queryset = FinderQuerySet(FinderManager(HomeFinder), 
                category_filters= category_filters,
                query=query,
                resource=resources,
                max_results=250,
                order=order_elastic,
                reverse = reverse,
                account_id=account.id
            )

        paginator = Paginator(queryset, 25)

        revisions = paginator.page(page and page or 1)
        if data['federated_accounts_ids']:
            add_domains_to_permalinks(revisions.object_list)
        error = ''

        results = revisions.object_list
    else:
        error = 'Invalid data'
        results=[]
        categories=[]

    t = loader.get_template('loadHome/table.json')
    c = Context(locals())
    return HttpResponse(t.render(c), content_type="application/json")
Exemplo n.º 9
0
def update_list(request):
    account         = request.account
    auth_manager    = request.auth_manager
    preferences     = account.get_preferences()
    language        = request.auth_manager.language

    form = QueryDatasetForm(request.POST)
    if form.is_valid():
        query = form.cleaned_data.get('search')
        page = form.cleaned_data.get('page')
        order = form.cleaned_data.get('order')
        order_type = form.cleaned_data.get('order_type')

        resources = ['ds', 'db', 'vz', 'dt']
        category_filters = form.cleaned_data.get('category_filters')
        if category_filters:
            category_filters=category_filters.split(",")

        builder = ThemeBuilder(preferences, False, language, account)
        data = builder.parse()

        if data['federated_accounts_ids']:

            entity = form.cleaned_data.get('entity_filters')
            if entity:
                accounts_ids = [int(entity)]
            else:
                accounts_ids = data['federated_accounts_ids'] + [account.id]

            typef = form.cleaned_data.get('type_filters')
            if typef:
                resources = [typef]

            queryset = FinderQuerySet(FinderManager(HomeFinder), 
                query = query,
                max_results = 250,
                account_id = accounts_ids,
                resource = resources,
                category_filters=category_filters,
                order = order,
                order_type = order_type
            ) 

        else:
            all_resources = form.cleaned_data.get('all')
            if not all_resources:
                resources_type = form.cleaned_data.get('type')
                resources = []
                for resource_name in resources_type.split(','):
                    resources.append(resource_name)

            queryset = FinderQuerySet(FinderManager(HomeFinder), 
                category_filters= category_filters,
                query=query,
                resource=resources,
                max_results=250,
                order=order,
                order_type=order_type,
                account_id=account.id
            )

        paginator = Paginator(queryset, 25)

        revisions = paginator.page(page and page or 1)
        if data['federated_accounts_ids']:
            add_domains_to_permalinks(revisions.object_list)
        error = ''

        results = revisions.object_list
    else:
        error = 'Invalid data'
        results=[]
        categories=[]

    t = loader.get_template('loadHome/table.json')
    c = Context(locals())
    return HttpResponse(t.render(c), content_type="application/json")