Beispiel #1
0
def pp_get_cached_data(context, nodelist, *args, **kwargs):
    """
    This templatetag is called only when the page is initially loaded, to
    give the template access to 

    :param object: id of django.db.models.Model object
    :type object: str 
    :param user: djngo.contrib.auth.models.User object
    :returns:
        * pp_consensus.consensus
            This is the consensus object itself
        * pp_consensus.interest
            Holds the interest integer generated by the ranking algorithm
        * pp_consensus.controversy
            Holds the controversy rating generated by the controversy ranking algorithm
        * pp_consensus.consensus
            This is the consensus object itself
        * pp_consensus.votes
            Number of votes on this object
    :requires user:
        * pp_consensus.user_updown
            Returns user voting information if parameter is present
        * pp_consensus.user_rating
            Returns user voting information if parameter is present

    An example HTML template:

    .. code-block:: html
        :linenos:

        {% pp_consensus_get object=object user=request.user %}
                
                {{pp_consensus.interest}}
                
                {{pp_consensus.consensus}}

                <p> Object has {{pp_consensus.votes}} votes </p>
        {% endpp_consensus_get %}

    """
    context.push()
    namespace = get_namespace(context)

    request = kwargs.get('request', None)

    if request.META['PATH_INFO'][0:3] == '/p/':
        renderdict = render_hashed(request, None, None, extracontext={'TYPE': 'HTML'})

        namespace['key'] = request.META['PATH_INFO'].replace('/', '')
        namespace['rendertype'] = renderdict['rendertype']
        namespace['data'] = renderdict['renders']
        namespace['DOMAIN'] = DOMAIN
        namespace['object'] = renderdict['object']
        namespace['rendered_list'] = None

        namespace['nojs'] = True
    output = nodelist.render(context)
    context.pop()

    return output
Beispiel #2
0
def oa_get_dashboard(context, nodelist, *args, **kwargs):
    context.push()
    namespace = get_namespace(context)

    request = kwargs.get('request', None)
    user = kwargs.get('user', None)
    dashboard_id = kwargs.get('dashboard_id', None)
    boards = []
    namespace['boards'] = {}
    if user is not None and user.is_authenticated() and dashboard_id is not None:
        #get platform for this contenttype and user
        boards = DashboardPanel.objects.filter(user=user,
                dashboard_id=dashboard_id).order_by('priority')
    elif not user.is_authenticated():
        try:
            us = User.objects.get(username='******')
            boards = DashboardPanel.objects.filter(user=us,
                dashboard_id=dashboard_id).order_by('priority')
        except:
            pass
        #for each board, render the respective information
    dash = []
    for board in boards:
        key, rendertype, paramdict = interpret_hash(board.plank)
        #add start and end information for pagination
        plank = board.plank + '/s-0/e-20'
        renderdict = render_hashed(request, plank, user, extracontext={'dashobj': board, 'TYPE': 'HTML', 'start': 0, 'end': 20})
        if 'DIM_KEY' in paramdict:
            dim = paramdict['DIM_KEY']
        else:
            dim = ''
        print board
        #if there is a total count for a list in this we need to add that so that the dash renders it might fine
        if renderdict['rendertype'] in renderdict['counts']:
            count = renderdict['counts'][renderdict['rendertype']]
        else:
            count = None
        dash.append((renderdict['renders'], renderdict['object'], board, renderdict['rendertype'], dim, 0, 20, count))
    namespace['boards'] = dash
    output = nodelist.render(context)
    context.pop()

    return output
Beispiel #3
0
def add_board(request):
    if not request.user.is_authenticated()  or not request.user.is_active:
        #needs to popup registration dialog instead
        return HttpResponse(simplejson.dumps({'FAIL': True}),
                                mimetype='application/json')
    try:
        results = {}
        if request.method == 'POST':
            path = request.POST[u'path']
            dashboard_id = request.POST[u'dashboard_id']
            dashpk = request.POST.get(u'dashobj', None)
            functype = request.POST[u'type']
            boardname = request.POST[u'boardname']
            start = request.POST.get('start', 0)
            key, rendertype, db = interpret_hash(path)
            dimension = db.get('DIM_KEY', None)
            end = request.POST.get('end', 20)
            #for pagination

            if functype != 'refresh':
                dashobj = save_board(path, dashboard_id, request.user, boardname)
            else:
                dashobj = DashboardPanel.objects.get(pk=dashpk)
            path += '/s-' + str(start) + '/e-' + str(end)

            renderdict = render_hashed(request, path, request.user, extracontext={'dimension': dimension, 'dashobj': dashobj, 'start': int(start), 'end': int(end)})

            if renderdict['rendertype'] == 'chat':
                width = render_to_string('stream/stream_width.html', {'dashobj': dashobj})
                height = render_to_string('stream/stream_height.html', {'dashobj': dashobj})
                results = {'width': width, 'height': height}
            if renderdict['rendertype'] in renderdict['counts']:
                count = renderdict['counts'][renderdict['rendertype']]
            else:
                count = None
            html = render_to_string('nav/board_template.html', {'dimension': dimension, 'board': renderdict['renders'], 'obj': renderdict['object'], 'dashobj': dashobj, 'start': int(start), 'end': int(end), 'count': count})
            if functype == 'refresh':
                soup = BeautifulSoup.BeautifulSoup(html)
                v = soup.find("div", id='content' + str(dashobj.pk))
                html = unicode(v.prettify())
            results.update({'FAIL': False, 'html': html, 'dashpk': dashobj.pk, 'dashzoom_y': dashobj.zoom_y, 'dashzoom_x': dashobj.zoom_x, 'rendertype': renderdict['rendertype']})
    except Exception, e:
        results = {'err': str(e)}
Beispiel #4
0
def add_board(request):
    if not request.user.is_authenticated() or not request.user.is_active:
        #needs to popup registration dialog instead
        return HttpResponse(simplejson.dumps({'FAIL': True}),
                            mimetype='application/json')
    try:
        results = {}
        if request.method == 'POST':
            path = request.POST[u'path']
            dashboard_id = request.POST[u'dashboard_id']
            dashpk = request.POST.get(u'dashobj', None)
            functype = request.POST[u'type']
            boardname = request.POST[u'boardname']
            start = request.POST.get('start', 0)
            key, rendertype, db = interpret_hash(path)
            dimension = db.get('DIM_KEY', None)
            end = request.POST.get('end', 20)
            #for pagination

            if functype != 'refresh':
                dashobj = save_board(path, dashboard_id, request.user,
                                     boardname)
            else:
                dashobj = DashboardPanel.objects.get(pk=dashpk)
            path += '/s-' + str(start) + '/e-' + str(end)

            renderdict = render_hashed(request,
                                       path,
                                       request.user,
                                       extracontext={
                                           'dimension': dimension,
                                           'dashobj': dashobj,
                                           'start': int(start),
                                           'end': int(end)
                                       })

            if renderdict['rendertype'] == 'chat':
                width = render_to_string('stream/stream_width.html',
                                         {'dashobj': dashobj})
                height = render_to_string('stream/stream_height.html',
                                          {'dashobj': dashobj})
                results = {'width': width, 'height': height}
            if renderdict['rendertype'] in renderdict['counts']:
                count = renderdict['counts'][renderdict['rendertype']]
            else:
                count = None
            html = render_to_string(
                'nav/board_template.html', {
                    'dimension': dimension,
                    'board': renderdict['renders'],
                    'obj': renderdict['object'],
                    'dashobj': dashobj,
                    'start': int(start),
                    'end': int(end),
                    'count': count
                })
            if functype == 'refresh':
                soup = BeautifulSoup.BeautifulSoup(html)
                v = soup.find("div", id='content' + str(dashobj.pk))
                html = unicode(v.prettify())
            results.update({
                'FAIL': False,
                'html': html,
                'dashpk': dashobj.pk,
                'dashzoom_y': dashobj.zoom_y,
                'dashzoom_x': dashobj.zoom_x,
                'rendertype': renderdict['rendertype']
            })
    except Exception, e:
        results = {'err': str(e)}
Beispiel #5
0
def pp_get_cached_data(context, nodelist, *args, **kwargs):
    """
    This templatetag is called only when the page is initially loaded, to
    give the template access to 

    :param object: id of django.db.models.Model object
    :type object: str 
    :param user: djngo.contrib.auth.models.User object
    :returns:
        * pp_consensus.consensus
            This is the consensus object itself
        * pp_consensus.interest
            Holds the interest integer generated by the ranking algorithm
        * pp_consensus.controversy
            Holds the controversy rating generated by the controversy ranking algorithm
        * pp_consensus.consensus
            This is the consensus object itself
        * pp_consensus.votes
            Number of votes on this object
    :requires user:
        * pp_consensus.user_updown
            Returns user voting information if parameter is present
        * pp_consensus.user_rating
            Returns user voting information if parameter is present

    An example HTML template:

    .. code-block:: html
        :linenos:

        {% pp_consensus_get object=object user=request.user %}
                
                {{pp_consensus.interest}}
                
                {{pp_consensus.consensus}}

                <p> Object has {{pp_consensus.votes}} votes </p>
        {% endpp_consensus_get %}

    """
    context.push()
    namespace = get_namespace(context)

    request = kwargs.get('request', None)

    if request.META['PATH_INFO'][0:3] == '/p/':
        renderdict = render_hashed(request,
                                   None,
                                   None,
                                   extracontext={'TYPE': 'HTML'})

        namespace['key'] = request.META['PATH_INFO'].replace('/', '')
        namespace['rendertype'] = renderdict['rendertype']
        namespace['data'] = renderdict['renders']
        namespace['DOMAIN'] = DOMAIN
        namespace['object'] = renderdict['object']
        namespace['rendered_list'] = None

        namespace['nojs'] = True
    output = nodelist.render(context)
    context.pop()

    return output