Exemplo n.º 1
0
def SaveIGadget(igadget, user, tab):
    gadget_uri = igadget.get('gadget')
    igadget_code = igadget.get('code')
    igadget_name = igadget.get('name')
    width = igadget.get('width')
    height = igadget.get('height')
    top = igadget.get('top')
    left = igadget.get('left')

    # Creates IGadget position
    position = Position(posX=left, posY=top, height=height, width=width, minimized=False)
    position.save()

    # Creates the new IGadget
    try:
        # Gadget uri does not contain the prefix "/user" yet
        if gadget_uri.startswith("/user") or gadget_uri.startswith("user"):
            gadget_uri_parts = gadget_uri.split("/")
            gadget_uri = "/" + "/".join(gadget_uri_parts[gadget_uri_parts.index("gadgets"):])

        gadget = Gadget.objects.get(uri=gadget_uri, users=user)

        new_igadget = IGadget(code=igadget_code, name=igadget_name, gadget=gadget, tab=tab, position=position)
        new_igadget.save()

        variableDefs = VariableDef.objects.filter(gadget=gadget)
        for varDef in variableDefs:
            # Sets the default value of variable
            if varDef.default_value:
                var_value = varDef.default_value
            else:
                var_value = ''
            
             # Creating the Abstract Variable
            abstractVar = AbstractVariable(type="IGADGET", name=varDef.name)  
            abstractVar.save()
            
            # Creating Value for Abstract Variable
            variableValue =  VariableValue (user=user, value=var_value, abstract_variable=abstractVar)
            variableValue.save()
                
            var = Variable(vardef=varDef, igadget=new_igadget, abstract_variable=abstractVar)
            var.save()
            
            #Wiring related vars (SLOT&EVENTS) have implicit connectables!
            connectableId = createConnectable(var)
        
        transaction.commit()
        
        igadget_data =  serializers.serialize('python', [new_igadget], ensure_ascii=False)
        
        ids = get_igadget_data(igadget_data[0], user, tab.workspace)
        
        return ids

    except Gadget.DoesNotExist:
        raise Gadget.DoesNotExist(_('referred gadget %(gadget_uri)s does not exist.') % {'gadget_uri': gadget_uri})
    except VariableDef.DoesNotExist:
        #iGadget has no variables. It's normal
        pass
Exemplo n.º 2
0
def SaveIGadget(igadget, user, tab, request):
    gadget_uri = igadget.get('gadget')
    igadget_name = igadget.get('name')
    width = igadget.get('width')
    height = igadget.get('height')
    top = igadget.get('top')
    left = igadget.get('left')
    icon_top = igadget.get('icon_top')
    icon_left = igadget.get('icon_left')
    zIndex = igadget.get('zIndex')
    layout = igadget.get('layout')
    menu_color = igadget.get('menu_color')

    # Creates IGadget position
    position = Position(posX=left, posY=top, posZ=zIndex, height=height, width=width, minimized=False, fulldragboard=False)
    position.save()

    # Creates IGadget icon position
    icon_position = Position(posX=icon_left, posY=icon_top)
    icon_position.save()

    # Creates the new IGadget
    try:
        # Gadget uri does not contain the prefix "/user" yet
        if gadget_uri.startswith("/user") or gadget_uri.startswith("user"):
            gadget_uri_parts = gadget_uri.split("/")
            gadget_uri = "/" + "/".join(gadget_uri_parts[gadget_uri_parts.index("gadgets"):])

        gadget = Gadget.objects.get(uri=gadget_uri, users=user)

        new_igadget = IGadget(name=igadget_name, gadget=gadget, tab=tab, layout=layout, position=position, icon_position=icon_position, transparency=False, menu_color=menu_color)
        new_igadget.save()

        initial_variable_values = None
        if 'variable_values' in request.POST:
            initial_variable_values = simplejson.loads(request.POST['variable_values'])

        variableDefs = VariableDef.objects.filter(gadget=gadget)
        for varDef in variableDefs:
            try:
                initial_value = initial_variable_values[varDef.name]
            except:
                initial_value = None
            addIGadgetVariable(new_igadget, user, varDef, initial_value)

        transaction.commit()

        ids = get_igadget_data(new_igadget, user, tab.workspace)

        return ids

    except Gadget.DoesNotExist, e:
        msg = _('referred gadget %(gadget_uri)s does not exist.') % {'gadget_uri': gadget_uri}

        raise TracedServerError(e, {'igadget': igadget, 'user': user, 'tab': tab}, request, msg)
Exemplo n.º 3
0
def SaveIGadget(igadget, user, tab, initial_variable_values):
    gadget_uri = igadget.get('gadget')
    igadget_name = igadget.get('name')
    width = igadget.get('width')
    height = igadget.get('height')
    top = igadget.get('top')
    left = igadget.get('left')
    icon_top = igadget.get('icon_top')
    icon_left = igadget.get('icon_left')
    zIndex = igadget.get('zIndex')
    layout = igadget.get('layout')
    menu_color = igadget.get('menu_color')

    # Creates IGadget position
    position = Position(posX=left, posY=top, posZ=zIndex, height=height, width=width, minimized=False, fulldragboard=False)
    position.save()

    # Creates IGadget icon position
    icon_position = Position(posX=icon_left, posY=icon_top)
    icon_position.save()

    # Gadget uri does not contain the prefix "/user" yet
    if gadget_uri.startswith("/user") or gadget_uri.startswith("user"):
        gadget_uri_parts = gadget_uri.split("/")
        gadget_uri = "/" + "/".join(gadget_uri_parts[gadget_uri_parts.index("gadgets"):])

    gadget = Gadget.objects.get(uri=gadget_uri, users=user)

    new_igadget = IGadget(name=igadget_name, gadget=gadget, tab=tab, layout=layout, position=position, icon_position=icon_position, transparency=False, menu_color=menu_color)
    new_igadget.save()

    variableDefs = VariableDef.objects.filter(gadget=gadget)
    for varDef in variableDefs:
        if initial_variable_values and varDef.name in initial_variable_values:
            initial_value = initial_variable_values[varDef.name]
        else:
            initial_value = None
        addIGadgetVariable(new_igadget, varDef, initial_value)

    from commons.get_data import _invalidate_cached_variable_values
    _invalidate_cached_variable_values(new_igadget.tab.workspace)

    return new_igadget
Exemplo n.º 4
0
def UpdateIGadget(igadget, user, tab):

    igadget_pk = igadget.get('id')

    # Checks
    ig = get_object_or_404(IGadget, tab=tab, pk=igadget_pk)

    if 'name' in igadget:
        name = igadget['name']
        ig.name = name

    if 'tab' in igadget:
        newtab_id = igadget['tab']
        if newtab_id < 0:
            raise Exception(_('Malformed iGadget JSON'))

        if newtab_id != tab.id:
            newtab = Tab.objects.get(workspace__users__id=user.id, workspace__pk=tab.workspace_id, pk=newtab_id)
            ig.tab = newtab

    if 'menu_color' in igadget:
        menu_color = igadget['menu_color']
        ig.menu_color = menu_color

    if 'layout' in igadget:
        layout = igadget['layout']
        ig.layout = layout

    if 'transparency' in igadget:
        ig.transparency = igadget['transparency']

    if 'icon_top' in igadget and 'icon_left' in igadget:
        icon_position = ig.icon_position
        if icon_position:
            icon_position.posX = igadget["icon_left"]
            icon_position.posY = igadget["icon_top"]
        else:  # backward compatibility (old gadgets without icon position)
            icon_position = Position(posX=igadget["icon_left"], posY=igadget["icon_top"])
        icon_position.save()
        ig.icon_position = icon_position

    if 'refused_version' in igadget:
        refused_version = igadget['refused_version']
        ig.refused_version = refused_version

    ig.save()

    # get IGadget's position
    position = ig.position

    # update the requested attributes
    if 'width' in igadget:
        width = igadget['width']
        if width <= 0:
            raise Exception(_('Malformed iGadget JSON'))
        position.width = width

    if 'height' in igadget:
        height = igadget['height']
        if height <= 0:
            raise Exception(_('Malformed iGadget JSON'))
        position.height = height

    if 'top' in igadget:
        top = igadget['top']
        if top < 0:
            raise Exception(_('Malformed iGadget JSON'))
        position.posY = top

    if 'left' in igadget:
        left = igadget['left']
        if left < 0:
            raise Exception(_('Malformed iGadget JSON'))
        position.posX = left

    if 'zIndex' in igadget:
        zIndex = igadget['zIndex']
        if not isinstance(zIndex, int):
            raise Exception(_('Malformed iGadget JSON'))
        position.posZ = zIndex

    if 'minimized' in igadget:
        minimized = igadget['minimized']
        if not isinstance(minimized, bool) and not isinstance(minimized, int):
            raise Exception(_('Malformed iGadget JSON'))
        position.minimized = minimized

    if 'fulldragboard' in igadget:
        fulldragboard = igadget['fulldragboard']
        if not isinstance(fulldragboard, bool) and not isinstance(fulldragboard, int):
            raise Exception(_('Malformed iGadget JSON'))
        position.fulldragboard = fulldragboard

    # save the changes
    position.save()
Exemplo n.º 5
0
def SaveIGadget(igadget, user, tab):
    gadget_uri = igadget.get('gadget')
    igadget_name = igadget.get('name')
    width = igadget.get('width')
    height = igadget.get('height')
    top = igadget.get('top')
    left = igadget.get('left')
    zIndex = igadget.get('zIndex')
    layout = igadget.get('layout')

    # Creates IGadget position
    position = Position(posX=left,
                        posY=top,
                        posZ=zIndex,
                        height=height,
                        width=width,
                        minimized=False)
    position.save()

    # Creates the new IGadget
    try:
        # Gadget uri does not contain the prefix "/user" yet
        if gadget_uri.startswith("/user") or gadget_uri.startswith("user"):
            gadget_uri_parts = gadget_uri.split("/")
            gadget_uri = "/" + "/".join(
                gadget_uri_parts[gadget_uri_parts.index("gadgets"):])

        gadget = Gadget.objects.get(uri=gadget_uri, users=user)

        new_igadget = IGadget(name=igadget_name,
                              gadget=gadget,
                              tab=tab,
                              layout=layout,
                              position=position,
                              transparency=False)
        new_igadget.save()

        variableDefs = VariableDef.objects.filter(gadget=gadget)
        for varDef in variableDefs:
            # Sets the default value of variable
            if varDef.default_value:
                var_value = varDef.default_value
            else:
                var_value = ''

            # Creating the Abstract Variable
            abstractVar = AbstractVariable(type="IGADGET", name=varDef.name)
            abstractVar.save()

            # Creating Value for Abstract Variable
            variableValue = VariableValue(user=user,
                                          value=var_value,
                                          abstract_variable=abstractVar)
            variableValue.save()

            var = Variable(vardef=varDef,
                           igadget=new_igadget,
                           abstract_variable=abstractVar)
            var.save()

            #Wiring related vars (SLOT&EVENTS) have implicit connectables!
            connectableId = createConnectable(var)

        transaction.commit()

        igadget_data = serializers.serialize('python', [new_igadget],
                                             ensure_ascii=False)

        ids = get_igadget_data(igadget_data[0], user, tab.workspace)

        return ids

    except Gadget.DoesNotExist:
        raise Gadget.DoesNotExist(
            _('referred gadget %(gadget_uri)s does not exist.') %
            {'gadget_uri': gadget_uri})
    except VariableDef.DoesNotExist:
        #iGadget has no variables. It's normal
        pass
Exemplo n.º 6
0
def UpdateIGadget(igadget, user, tab):

    igadget_pk = igadget.get('id')

    # Checks
    ig = get_object_or_404(IGadget, tab=tab, pk=igadget_pk)

    if igadget.has_key('name'):
        name = igadget.get('name')
        ig.name = name

    if igadget.has_key('tab'):
        newtab_id = igadget.get('tab')
        if newtab_id < 0:
            raise Exception(_('Malformed iGadget JSON'))

        if newtab_id != tab.id:
            newtab = Tab.objects.get(workspace__users__id=user.id,
                                     workspace__pk=tab.workspace_id,
                                     pk=newtab_id)
            ig.tab = newtab

    if igadget.has_key('menu_color'):
        menu_color = igadget.get('menu_color')
        ig.menu_color = menu_color

    if igadget.has_key('layout'):
        layout = igadget.get('layout')
        ig.layout = layout

    if igadget.has_key('transparency'):
        ig.transparency = igadget.get('transparency')

    if igadget.has_key("icon_top") and igadget.has_key("icon_left"):
        icon_position = ig.icon_position
        if icon_position:
            icon_position.posX = igadget.get("icon_left")
            icon_position.posY = igadget.get("icon_top")
        else:  #backward compatibility (old gadgets without icon position)
            icon_position = Position(posX=igadget.get("icon_left"),
                                     posY=igadget.get("icon_top"))
        icon_position.save()
        ig.icon_position = icon_position

    ig.save()

    # get IGadget's position
    position = ig.position

    # update the requested attributes
    if igadget.has_key('width'):
        width = igadget.get('width')
        if width <= 0:
            raise Exception(_('Malformed iGadget JSON'))
        position.width = width

    if igadget.has_key('height'):
        height = igadget.get('height')
        if height <= 0:
            raise Exception(_('Malformed iGadget JSON'))
        position.height = height

    if igadget.has_key('top'):
        top = igadget.get('top')
        if top < 0:
            raise Exception(_('Malformed iGadget JSON'))
        position.posY = top

    if igadget.has_key('left'):
        left = igadget.get('left')
        if left < 0:
            raise Exception(_('Malformed iGadget JSON'))
        position.posX = left

    if igadget.has_key('zIndex'):
        zIndex = igadget.get('zIndex')
        if not isinstance(zIndex, int):
            raise Exception(_('Malformed iGadget JSON'))
        position.posZ = zIndex

    if igadget.has_key('minimized'):
        minimized = igadget.get('minimized')
        if minimized == 'true':
            position.minimized = True
        else:
            position.minimized = False

    # save the changes
    position.save()
Exemplo n.º 7
0
def UpdateIGadget(igadget, user, tab):

    igadget_pk = igadget.get('id')

    # Checks
    ig = get_object_or_404(IGadget, tab=tab, pk=igadget_pk)

    if 'name' in igadget:
        name = igadget['name']
        ig.name = name

    if 'tab' in igadget:
        newtab_id = igadget['tab']
        if newtab_id < 0:
            raise Exception(_('Malformed iGadget JSON'))

        if newtab_id != tab.id:
            newtab = Tab.objects.get(workspace__users__id=user.id,
                                     workspace__pk=tab.workspace_id,
                                     pk=newtab_id)
            ig.tab = newtab

    if 'menu_color' in igadget:
        menu_color = igadget['menu_color']
        ig.menu_color = menu_color

    if 'layout' in igadget:
        layout = igadget['layout']
        ig.layout = layout

    if 'transparency' in igadget:
        ig.transparency = igadget['transparency']

    if 'icon_top' in igadget and 'icon_left' in igadget:
        icon_position = ig.icon_position
        if icon_position:
            icon_position.posX = igadget["icon_left"]
            icon_position.posY = igadget["icon_top"]
        else:  # backward compatibility (old gadgets without icon position)
            icon_position = Position(posX=igadget["icon_left"],
                                     posY=igadget["icon_top"])
        icon_position.save()
        ig.icon_position = icon_position

    if 'refused_version' in igadget:
        refused_version = igadget['refused_version']
        ig.refused_version = refused_version

    ig.save()

    # get IGadget's position
    position = ig.position

    # update the requested attributes
    if 'width' in igadget:
        width = igadget['width']
        if width <= 0:
            raise Exception(_('Malformed iGadget JSON'))
        position.width = width

    if 'height' in igadget:
        height = igadget['height']
        if height <= 0:
            raise Exception(_('Malformed iGadget JSON'))
        position.height = height

    if 'top' in igadget:
        top = igadget['top']
        if top < 0:
            raise Exception(_('Malformed iGadget JSON'))
        position.posY = top

    if 'left' in igadget:
        left = igadget['left']
        if left < 0:
            raise Exception(_('Malformed iGadget JSON'))
        position.posX = left

    if 'zIndex' in igadget:
        zIndex = igadget['zIndex']
        if not isinstance(zIndex, int):
            raise Exception(_('Malformed iGadget JSON'))
        position.posZ = zIndex

    if 'minimized' in igadget:
        minimized = igadget['minimized']
        if not isinstance(minimized, bool) and not isinstance(minimized, int):
            raise Exception(_('Malformed iGadget JSON'))
        position.minimized = minimized

    if 'fulldragboard' in igadget:
        fulldragboard = igadget['fulldragboard']
        if not isinstance(fulldragboard, bool) and not isinstance(
                fulldragboard, int):
            raise Exception(_('Malformed iGadget JSON'))
        position.fulldragboard = fulldragboard

    # save the changes
    position.save()
Exemplo n.º 8
0
def SaveIGadget(igadget, user, tab, request):
    gadget_uri = igadget.get('gadget')
    igadget_name = igadget.get('name')
    width = igadget.get('width')
    height = igadget.get('height')
    top = igadget.get('top')
    left = igadget.get('left')
    icon_top = igadget.get('icon_top')
    icon_left = igadget.get('icon_left')
    zIndex = igadget.get('zIndex')
    layout = igadget.get('layout')
    menu_color = igadget.get('menu_color')

    # Creates IGadget position
    position = Position(posX=left,
                        posY=top,
                        posZ=zIndex,
                        height=height,
                        width=width,
                        minimized=False,
                        fulldragboard=False)
    position.save()

    # Creates IGadget icon position
    icon_position = Position(posX=icon_left, posY=icon_top)
    icon_position.save()

    # Creates the new IGadget
    try:
        # Gadget uri does not contain the prefix "/user" yet
        if gadget_uri.startswith("/user") or gadget_uri.startswith("user"):
            gadget_uri_parts = gadget_uri.split("/")
            gadget_uri = "/" + "/".join(
                gadget_uri_parts[gadget_uri_parts.index("gadgets"):])

        gadget = Gadget.objects.get(uri=gadget_uri, users=user)

        new_igadget = IGadget(name=igadget_name,
                              gadget=gadget,
                              tab=tab,
                              layout=layout,
                              position=position,
                              icon_position=icon_position,
                              transparency=False,
                              menu_color=menu_color)
        new_igadget.save()

        initial_variable_values = None
        if 'variable_values' in request.POST:
            initial_variable_values = simplejson.loads(
                request.POST['variable_values'])

        variableDefs = VariableDef.objects.filter(gadget=gadget)
        for varDef in variableDefs:
            try:
                initial_value = initial_variable_values[varDef.name]
            except:
                initial_value = None
            addIGadgetVariable(new_igadget, user, varDef, initial_value)

        transaction.commit()

        ids = get_igadget_data(new_igadget, user, tab.workspace)

        return ids

    except Gadget.DoesNotExist, e:
        msg = _('referred gadget %(gadget_uri)s does not exist.') % {
            'gadget_uri': gadget_uri
        }

        raise TracedServerError(e, {
            'igadget': igadget,
            'user': user,
            'tab': tab
        }, request, msg)
Exemplo n.º 9
0
def SaveIGadget(igadget, user, tab):
    gadget_uri = igadget.get('gadget')
    igadget_name = igadget.get('name')
    width = igadget.get('width')
    height = igadget.get('height')
    top = igadget.get('top')
    left = igadget.get('left')
    zIndex = igadget.get('zIndex')
    layout = igadget.get('layout')
    menu_color = igadget.get('menu_color')

    # Creates IGadget position
    position = Position(posX=left, posY=top, posZ=zIndex, height=height, width=width, minimized=False)
    position.save()

    # Creates the new IGadget
    try:
        # Gadget uri does not contain the prefix "/user" yet
        if gadget_uri.startswith("/user") or gadget_uri.startswith("user"):
            gadget_uri_parts = gadget_uri.split("/")
            gadget_uri = "/" + "/".join(gadget_uri_parts[gadget_uri_parts.index("gadgets"):])

        gadget = Gadget.objects.get(uri=gadget_uri, users=user)

        new_igadget = IGadget(name=igadget_name, gadget=gadget, tab=tab, layout=layout, position=position, transparency=False, menu_color=menu_color)
        new_igadget.save()

        variableDefs = VariableDef.objects.filter(gadget=gadget)
        for varDef in variableDefs:
            # Sets the default value of variable
            if varDef.default_value:
                var_value = varDef.default_value
            else:
                var_value = ''

             # Creating the Abstract Variable
            abstractVar = AbstractVariable(type="IGADGET", name=varDef.name)
            abstractVar.save()

            # Creating Value for Abstract Variable
            variableValue =  VariableValue (user=user, value=var_value, abstract_variable=abstractVar)
            variableValue.save()

            var = Variable(vardef=varDef, igadget=new_igadget, abstract_variable=abstractVar)
            var.save()

            #Wiring related vars (SLOT&EVENTS) have implicit connectables!
            connectableId = createConnectable(var)

        transaction.commit()

        igadget_data =  serializers.serialize('python', [new_igadget], ensure_ascii=False)

        ids = get_igadget_data(igadget_data[0], user, tab.workspace)

        return ids

    except Gadget.DoesNotExist, e:
        msg = _('referred gadget %(gadget_uri)s does not exist.') % {'gadget_uri': gadget_uri}

        raise TracedServerError(e, {'igadget': igadget, 'user': user, 'tab': tab}, request, msg)
Exemplo n.º 10
0
def UpdateIGadget(igadget, user, tab):

    igadget_pk = igadget.get('id')

    # Checks
    ig = get_object_or_404(IGadget, tab=tab, pk=igadget_pk)

    if igadget.has_key('name'):
        name = igadget.get('name')
        ig.name = name

    if igadget.has_key('tab'):
        newtab_id = igadget.get('tab');
        if newtab_id < 0:
            raise Exception(_('Malformed iGadget JSON'))

        if newtab_id != tab.id:
            newtab = Tab.objects.get(workspace__users__id=user.id, workspace__pk=tab.workspace_id, pk=newtab_id)
            ig.tab = newtab

    if igadget.has_key('menu_color'):
        menu_color = igadget.get('menu_color')
        ig.menu_color = menu_color

    if igadget.has_key('layout'):
        layout = igadget.get('layout')
        ig.layout = layout

    if igadget.has_key('transparency'):
        ig.transparency = igadget.get('transparency')
    
    if igadget.has_key("icon_top") and igadget.has_key("icon_left"):
        icon_position = ig.icon_position
        if icon_position:
            icon_position.posX = igadget.get("icon_left")
            icon_position.posY = igadget.get("icon_top")
        else: #backward compatibility (old gadgets without icon position)
            icon_position = Position(posX=igadget.get("icon_left"), posY=igadget.get("icon_top"))
        icon_position.save()
        ig.icon_position = icon_position

    ig.save()

    # get IGadget's position
    position = ig.position

    # update the requested attributes
    if igadget.has_key('width'):
        width = igadget.get('width')
        if width <= 0:
            raise Exception(_('Malformed iGadget JSON'))
        position.width = width

    if igadget.has_key('height'):
        height = igadget.get('height')
        if height <= 0:
            raise Exception(_('Malformed iGadget JSON'))
        position.height = height

    if igadget.has_key('top'):
        top = igadget.get('top')
        if top < 0:
            raise Exception(_('Malformed iGadget JSON'))
        position.posY = top

    if igadget.has_key('left'):
        left = igadget.get('left')
        if left < 0:
            raise Exception(_('Malformed iGadget JSON'))
        position.posX = left

    if igadget.has_key('zIndex'):
        zIndex = igadget.get('zIndex')
        if not isinstance(zIndex, int):
            raise Exception(_('Malformed iGadget JSON'))
        position.posZ = zIndex

    if igadget.has_key('minimized'):
        minimized = igadget.get('minimized')
        if minimized == 'true':
            position.minimized = True
        else:
            position.minimized = False

    # save the changes
    position.save()