示例#1
0
def get_std_classification(request):

    default_classification = {}

    try:

        user_is_authenticated = request.user.is_authenticated()
        user_has_web_access = request.user.has_perm('auth.web_access')
        user_has_app_management = request.user.has_perm('auth.application_management')
        user_has_create_views = request.user.has_perm('auth.create_views')

        if user_is_authenticated and user_has_web_access and (user_has_app_management or user_has_create_views):

            default_classification = get_default_classification()

    except Exception:

        logger.error(request._get_request)
        logger.exception('An error occured:')

    return HttpResponse(json.dumps(default_classification, sort_keys=False), mimetype='application/json')
示例#2
0
def get_legend_tree(request):

    return_set = []

    try:

        user_is_authenticated = request.user.is_authenticated()
        user_has_web_access = request.user.has_perm('auth.web_access')
        user_has_app_management = request.user.has_perm('auth.application_management')
        user_has_create_views = request.user.has_perm('auth.create_views')
        user_has_display_views = request.user.has_perm('auth.display_views')

        # Build root node
        root_node = {
            'name': _('Legenda'),
            'parent': None,
            'value': _('Legenda'),
            'type': ['root'],
            'has_children': True,
            'style': None,
            'id': 0
        }
        return_set.append(root_node)

        if user_is_authenticated and user_has_web_access and (user_has_app_management or user_has_create_views or user_has_display_views):

            i = 1
            default_classification = get_default_classification()
            default_style_node = {
                'opacity': float(default_classification[0]['opacity']),
                'lineWidth': default_classification[0]['lineWidth'],
                'fillColor': default_classification[0]['backgroundColor'],
                'lineColor': default_classification[0]['color']
            }
            default_classification_node = {
                'name': _('Standaard'),
                'classification_id': -1,
                'parent': 0,
                'value': _('Standaard'),
                'type': ['default_classification'],
                'has_children': False,
                'style': default_style_node,
                'id': i
            }
            return_set.append(default_classification_node)
            i += 1

            post_data = json.loads(request.POST.items()[0][0])  # We receive stringified data
            post_classification_ids = post_data['classification_ids']
            #post_classification_ids = [3,1]

            # Get classifications
            classifications = Classification.objects.filter(id__in=post_classification_ids).order_by('name')
            for classification in classifications:
                classification_node = {
                    'name': classification.name,
                    'classification_id': classification.id,
                    'parent': 0,
                    'value': classification.name,
                    'type': ['classification'],
                    'has_children': True,
                    'style': None,
                    'id': i
                }
                classification_id = i
                return_set.append(classification_node)
                i += 1

                # Get classification rows for this classification
                classification_rows = ClassificationRow.objects.filter(classification=classification).order_by('order')
                for classification_row in classification_rows:
                    style_node = {
                        'opacity': float(classification_row.style.opacity),
                        'lineWidth': classification_row.style.line_width,
                        'fillColor': classification_row.style.fill_color,
                        'lineColor': classification_row.style.line_color
                    }
                    classification_row_node = {
                        'name': classification_row.label,
                        'classification_row_id': classification_row.id,
                        'parent': classification_id,
                        'value': classification_row.label,
                        'type': ['classification_row'],
                        'has_children': False,
                        'style': style_node,
                        'id': i
                    }
                    return_set.append(classification_row_node)
                    i += 1

    except Exception:

        logger.error(request._get_request)
        logger.exception('An error occured:')

    return HttpResponse(json.dumps(return_set, sort_keys=False), mimetype='application/json')