Exemplo n.º 1
0
def view(request,link_title):
	if not request.user.is_authenticated():
		return redirect('/accounts/login/?next=%s' % request.path)
	
	t = loader.get_template('content.html')
	try:
		view = View.objects.get(link_title=link_title)
	except:
		return HttpResponse(status=404)
	
	page_list = view.pages.filter(groupdisplaypermission__hmi_group__in=request.user.groups.iterator).distinct()

	sliding_panel_list = view.sliding_panel_menus.filter(groupdisplaypermission__hmi_group__in=request.user.groups.iterator).distinct()
	
	visable_widget_list = Widget.objects.filter(groupdisplaypermission__hmi_group__in=request.user.groups.iterator,page__in=page_list.iterator).values_list('pk',flat=True)		
	visable_chart_list = Chart.objects.filter(groupdisplaypermission__hmi_group__in=request.user.groups.iterator).values_list('pk',flat=True)
	visable_control_element_list = GroupDisplayPermission.objects.filter(hmi_group__in=request.user.groups.iterator).values_list('control_items',flat=True)

	panel_list   = sliding_panel_list.filter(position__in=(1,2,))
	control_list = sliding_panel_list.filter(position=0)
	

	c = RequestContext(request,{
		'page_list': page_list,
		'visable_chart_list':visable_chart_list,
		'visable_control_element_list':visable_control_element_list,
		'visable_widget_list':visable_widget_list,
		'panel_list': panel_list,
		'control_list':control_list,
		'user': request.user,
		'view_title':view.title
	})
	log.webnotice('open hmi',request.user)
	return HttpResponse(t.render(c))
Exemplo n.º 2
0
def view(request, link_title):
    if not request.user.is_authenticated():
        return redirect('/accounts/login/?next=%s' % request.path)

    page_template = loader.get_template('content_page.html')
    widget_row_template = loader.get_template('widget_row.html')

    try:
        view = View.objects.get(link_title=link_title)
    except:
        return HttpResponse(status=404)

    page_list = view.pages.filter(groupdisplaypermission__hmi_group__in=request
                                  .user.groups.iterator()).distinct()

    sliding_panel_list = view.sliding_panel_menus.filter(
        groupdisplaypermission__hmi_group__in=request.user.groups.iterator(
        )).distinct()

    visible_widget_list = Widget.objects.filter(
        groupdisplaypermission__hmi_group__in=request.user.groups.iterator(),
        page__in=page_list.iterator()).values_list('pk', flat=True)
    visible_custom_html_panel_list = CustomHTMLPanel.objects.filter(
        groupdisplaypermission__hmi_group__in=request.user.groups.iterator(
        )).values_list('pk', flat=True)
    visible_chart_list = Chart.objects.filter(
        groupdisplaypermission__hmi_group__in=request.user.groups.iterator(
        )).values_list('pk', flat=True)

    visible_control_element_list = GroupDisplayPermission.objects.filter(
        hmi_group__in=request.user.groups.iterator()).values_list(
            'control_items', flat=True)

    panel_list = sliding_panel_list.filter(position__in=(
        1,
        2,
    ))
    control_list = sliding_panel_list.filter(position=0)

    current_row = 0
    has_chart = False
    widgets = []
    widget_rows_html = ""
    pages_html = ""
    for page in view.pages.filter(
            groupdisplaypermission__hmi_group__in=request.user.groups.iterator(
            )).distinct():
        current_row = 0
        has_chart = False
        widgets = []
        widget_rows_html = ""
        for widget in page.widget_set.all():
            # check if row has changed
            if current_row <> widget.row:
                # render new widget row and reset all loop variables
                widget_rows_html += widget_row_template.render(
                    RequestContext(
                        request, {
                            'row':
                            current_row,
                            'has_chart':
                            has_chart,
                            'widgets':
                            widgets,
                            'visible_control_element_list':
                            visible_control_element_list
                        }))
                current_row = widget.row
                has_chart = False
                widgets = []
            if not widget.pk in visible_widget_list:
                continue
            if not widget.visable:
                continue
            if widget.chart:
                if not widget.chart.visable():
                    continue
                if not widget.chart.pk in visible_chart_list:
                    continue
                has_chart = True
                widgets.append(widget)
            elif widget.control_panel:
                widgets.append(widget)
            elif widget.process_flow_diagram:
                widgets.append(widget)
            elif widget.custom_html_panel:
                if not widget.custom_html_panel.pk in visible_custom_html_panel_list:
                    continue
                widgets.append(widget)
        widget_rows_html += widget_row_template.render(
            RequestContext(
                request, {
                    'row': current_row,
                    'has_chart': has_chart,
                    'widgets': widgets,
                    'visible_control_element_list':
                    visible_control_element_list
                }))
        pages_html += page_template.render(
            RequestContext(request, {
                'page': page,
                'widget_rows_html': widget_rows_html
            }))

    c = {
        'page_list': page_list,
        'pages_html': pages_html,
        'panel_list': panel_list,
        'control_list': control_list,
        'user': request.user,
        'visible_control_element_list': visible_control_element_list,
        'view_title': view.title,
        'version_string': core_version
    }

    log.webnotice('open hmi', request.user)
    return TemplateResponse(request, 'view.html', c)
Exemplo n.º 3
0
def logout_view(request):
    log.webnotice('logout', request.user)
    logout(request)
    # Redirect to a success page.
    return redirect('/accounts/login/?next=/')