Exemple #1
0
def get_available_data_views( request ):
    """ Returns a list of all available data views.
    """
    all_views = DataView.objects.order_by("position")
    dataviews = map(dataview_to_dict, all_views)

    return HttpResponse(json.dumps(makeJSON_legacy_list(dataviews)), content_type="application/json")
Exemple #2
0
def get_available_data_views(request: HttpRequest) -> JsonResponse:
    """ Returns a list of all available data views.
    """
    all_views = DataView.objects.order_by("position")
    dataviews = map(dataview_to_dict, all_views)

    return JsonResponse(makeJSON_legacy_list(dataviews), safe=False)
Exemple #3
0
def list_messages(request, project_id=None):
    messages = Message.objects.filter(
        user=request.user,
        read=False).extra(select={
        'time_formatted': 'to_char("time", \'YYYY-MM-DD HH24:MI:SS TZ\')'})\
    .order_by('-time')

    def message_to_dict(message):
        return {
            'id': message.id,
            'title': message.title,
            'action': message.action,
            'text': message.text,
            # time does not correspond exactly to PHP version, lacks
            # timezone postfix. Can't find docs anywhere on how to get it.
            # Doesn't seem to be used though, luckily.
            'time': str(message.time),
            'time_formatted': message.time_formatted
        }

    messages = map(message_to_dict, messages)

    # Add a dummy message that includes the count of open notifications.
    # This is used to add the red badge to the notifications icon.
    crs = ChangeRequest.objects.filter(recipient=request.user,
                                       status=ChangeRequest.OPEN)
    messages += [{
        'id': -1,
        'notification_count': len(crs)
    }]

    return HttpResponse(json.dumps(makeJSON_legacy_list(messages)))
Exemple #4
0
def get_available_data_views( request ):
    """ Returns a list of all available data views.
    """
    all_views = DataView.objects.order_by("position")
    dataviews = map(dataview_to_dict, all_views)

    return HttpResponse(json.dumps(makeJSON_legacy_list(dataviews)), content_type="application/json")
Exemple #5
0
def get_available_data_views( request ):
    """ Returns a list of all available data views.
    """
    all_views = DataView.objects.order_by("position")
    dataviews = map(dataview_to_dict, all_views)

    return JsonResponse(makeJSON_legacy_list(dataviews), safe=False)
Exemple #6
0
def list_messages(request, project_id=None):
    messages = Message.objects.filter(
        user=request.user,
        read=False).extra(select={
        'time_formatted': 'to_char("time", \'YYYY-MM-DD HH24:MI:SS TZ\')'})\
    .order_by('-time')

    def message_to_dict(message):
        return {
            'id': message.id,
            'title': message.title,
            'action': message.action,
            'text': message.text,
            # time does not correspond exactly to PHP version, lacks
            # timezone postfix. Can't find docs anywhere on how to get it.
            # Doesn't seem to be used though, luckily.
            'time': str(message.time),
            'time_formatted': message.time_formatted
        }

    messages = map(message_to_dict, messages)

    # Add a dummy message that includes the count of open notifications.
    # This is used to add the red badge to the notifications icon.
    crs = ChangeRequest.objects.filter(recipient = request.user, status = ChangeRequest.OPEN);
    messages += [{'id': -1, 'notification_count': len(crs)}];

    return HttpResponse(json.dumps(makeJSON_legacy_list(messages)))
Exemple #7
0
def list_messages(request, project_id=None):
    messages = Message.objects.filter(
        user=request.user,
        read=False)\
    .order_by('-time')

    def message_to_dict(message):
        return {
            'id': message.id,
            'title': message.title,
            'action': message.action,
            'text': message.text,
            'time': str(message.time)
        }

    messages = list(imap(message_to_dict, messages))

    # Add a dummy message that includes the count of open notifications.
    # This is used to add the red badge to the notifications icon.
    crs = ChangeRequest.objects.filter(recipient = request.user, status = ChangeRequest.OPEN)
    messages += [{'id': -1, 'notification_count': len(crs)}]

    return HttpResponse(json.dumps(makeJSON_legacy_list(messages)))
Exemple #8
0
def list_messages(request:HttpRequest, project_id=None) -> JsonResponse:
    messages = Message.objects.filter(
        user=request.user,
        read=False,
    ).order_by('-time')

    def message_to_dict(message):
        return {
            'id': message.id,
            'title': message.title,
            'action': message.action,
            'text': message.text,
            'time': str(message.time)
        }

    messages = list(map(message_to_dict, messages))

    # Add a dummy message that includes the count of open notifications.
    # This is used to add the red badge to the notifications icon.
    crs = ChangeRequest.objects.filter(recipient = request.user, status = ChangeRequest.OPEN)
    messages += [{'id': -1, 'notification_count': len(crs)}]

    return JsonResponse(makeJSON_legacy_list(messages), safe=False)
Exemple #9
0
def textlabels(request: HttpRequest, project_id=None) -> JsonResponse:
    params = {'pid': project_id, 'uid': request.user.id}
    parameter_names = [
        'sid', 'z', 'top', 'left', 'width', 'height', 'scale', 'resolution'
    ]
    for p in parameter_names:
        if p in ['pid', 'sid']:
            params[p] = int(request.POST.get(p, 0))
        elif p in ['scale', 'resolution']:
            params[p] = float(request.POST.get(p, 1))
        else:
            params[p] = float(request.POST.get(p, 0))

    params['right'] = params['left'] + params['width']
    params['bottom'] = params['top'] + params['height']
    params['scale_div_res'] = params['scale'] / params['resolution']

    response_on_error = ''
    try:
        response_on_error = 'Could not retrieve textlabels.'
        c = connection.cursor()
        c.execute(
            '''
        SELECT	DISTINCT ON ( "tid" ) "textlabel"."id" AS "tid",
        "textlabel"."type" AS "type",
                        "textlabel"."text" AS "text",
                        "textlabel"."font_name" AS "font_name",
                        "textlabel"."font_style" AS "font_style",
                        "textlabel"."font_size" AS "font_size",
                        "textlabel"."scaling" AS "scaling",
                        floor(255*("textlabel"."colour")."r") AS "r",
                        floor(255*("textlabel"."colour")."g") AS "g",
                        floor(255*("textlabel"."colour")."b") AS "b",
                        ("textlabel"."colour")."a" AS "a",
                        ("textlabel_location"."location")."x" AS "x",
                        ("textlabel_location"."location")."y" AS "y",
                        ("textlabel_location"."location")."z" AS "z",
                        abs( ("textlabel_location"."location")."z" - ("textlabel_location"."location")."z" ) AS "z_diff"
        FROM "textlabel" INNER JOIN "textlabel_location" ON "textlabel"."id" = "textlabel_location"."textlabel_id"
        INNER JOIN "project" ON "project"."id" = "textlabel"."project_id"
        INNER JOIN "project_stack" ON "project"."id" = "project_stack"."project_id"
        INNER JOIN "stack" ON "stack"."id" = "project_stack"."stack_id"
        WHERE	"project"."id" = %(pid)s AND
                        "stack"."id" = %(sid)s AND
                        NOT "textlabel"."deleted" AND
                        NOT "textlabel_location"."deleted" AND
                        ("textlabel_location"."location")."x" >= %(left)s AND
                        ("textlabel_location"."location")."x" <= %(right)s AND
                        ("textlabel_location"."location")."y" >= %(top)s AND
                        ("textlabel_location"."location")."y" <= %(bottom)s AND
                        ("textlabel_location"."location")."z" >= %(z)s - 0.5 * ("stack"."resolution")."z" AND
                        ("textlabel_location"."location")."z" <= %(z)s + 0.5 * ("stack"."resolution")."z" AND
                        ( ( "textlabel"."scaling" AND "textlabel"."font_size" * %(scale_div_res)s >= 3 ) OR
                                NOT "textlabel"."scaling" )
        ORDER BY "tid", "z_diff"
        ''', params)
        textlabels = cursor_fetch_dictionary(c)

        response_on_error = 'Failed to format output'
        for tl in textlabels:
            tl['colour'] = {
                'r': tl['r'],
                'g': tl['g'],
                'b': tl['b'],
                'a': tl['a']
            }
            del (tl['r'])
            del (tl['g'])
            del (tl['b'])
            del (tl['a'])
            tl['location'] = {'x': tl['x'], 'y': tl['y'], 'z': tl['z']}
            del (tl['x'])
            del (tl['y'])
            del (tl['z'])
            if tl['scaling']:
                tl['scaling'] = 1
            else:
                tl['scaling'] = 0

        return JsonResponse(makeJSON_legacy_list(textlabels), safe=False)

    except Exception as e:
        raise Exception(response_on_error + ':' + str(e))
Exemple #10
0
def textlabels(request, project_id=None):
    params = {'pid': project_id, 'uid': request.user.id}
    parameter_names = ['sid', 'z', 'top', 'left', 'width', 'height', 'scale', 'resolution']
    for p in parameter_names:
        if p in ['pid', 'sid']:
            params[p] = int(request.POST.get(p, 0))
        elif p in ['scale', 'resolution']:
            params[p] = float(request.POST.get(p, 1))
        else:
            params[p] = float(request.POST.get(p, 0))

    params['right'] = params['left'] + params['width']
    params['bottom'] = params['top'] + params['height']
    params['scale_div_res'] = params['scale'] / params['resolution']

    response_on_error = ''
    try:
        response_on_error = 'Could not retrieve textlabels.'
        c = connection.cursor()
        c.execute('''
        SELECT	DISTINCT ON ( "tid" ) "textlabel"."id" AS "tid",
        "textlabel"."type" AS "type",
                        "textlabel"."text" AS "text",
                        "textlabel"."font_name" AS "font_name",
                        "textlabel"."font_style" AS "font_style",
                        "textlabel"."font_size" AS "font_size",
                        "textlabel"."scaling" AS "scaling",
                        floor(255*("textlabel"."colour")."r") AS "r",
                        floor(255*("textlabel"."colour")."g") AS "g",
                        floor(255*("textlabel"."colour")."b") AS "b",
                        ("textlabel"."colour")."a" AS "a",
                        ("textlabel_location"."location")."x" AS "x",
                        ("textlabel_location"."location")."y" AS "y",
                        ("textlabel_location"."location")."z" AS "z",
                        abs( ("textlabel_location"."location")."z" - ("textlabel_location"."location")."z" ) AS "z_diff"
        FROM "textlabel" INNER JOIN "textlabel_location" ON "textlabel"."id" = "textlabel_location"."textlabel_id"
        INNER JOIN "project" ON "project"."id" = "textlabel"."project_id"
        INNER JOIN "project_stack" ON "project"."id" = "project_stack"."project_id"
        INNER JOIN "stack" ON "stack"."id" = "project_stack"."stack_id"
        WHERE	"project"."id" = %(pid)s AND
                        "stack"."id" = %(sid)s AND
                        NOT "textlabel"."deleted" AND
                        NOT "textlabel_location"."deleted" AND
                        ("textlabel_location"."location")."x" >= %(left)s AND
                        ("textlabel_location"."location")."x" <= %(right)s AND
                        ("textlabel_location"."location")."y" >= %(top)s AND
                        ("textlabel_location"."location")."y" <= %(bottom)s AND
                        ("textlabel_location"."location")."z" >= %(z)s - 0.5 * ("stack"."resolution")."z" AND
                        ("textlabel_location"."location")."z" <= %(z)s + 0.5 * ("stack"."resolution")."z" AND
                        ( ( "textlabel"."scaling" AND "textlabel"."font_size" * %(scale_div_res)s >= 3 ) OR
                                NOT "textlabel"."scaling" )
        ORDER BY "tid", "z_diff"
        ''', params)
        textlabels = cursor_fetch_dictionary(c)

        response_on_error = 'Failed to format output'
        for tl in textlabels:
            tl['colour'] = {'r': tl['r'], 'g': tl['g'], 'b': tl['b'], 'a': tl['a']}
            del(tl['r'])
            del(tl['g'])
            del(tl['b'])
            del(tl['a'])
            tl['location'] = {'x': tl['x'], 'y': tl['y'], 'z': tl['z']}
            del(tl['x'])
            del(tl['y'])
            del(tl['z'])
            if tl['scaling']:
                tl['scaling'] = 1
            else:
                tl['scaling'] = 0

        return JsonResponse(makeJSON_legacy_list(textlabels), safe=False)

    except Exception as e:
        raise Exception(response_on_error + ':' + str(e))