def SaveIWidget(iwidget, user, tab, initial_variable_values): widget_uri = iwidget.get("widget") (widget_vendor, widget_name, widget_version) = widget_uri.split("/") resource = CatalogueResource.objects.select_related("widget").get( vendor=widget_vendor, short_name=widget_name, version=widget_version ) if not resource.is_available_for(user): raise Http403 iwidget_name = iwidget.get("name", resource.display_name) width = iwidget.get("width", 0) height = iwidget.get("height", 0) top = iwidget.get("top", 0) left = iwidget.get("left", 0) icon_top = iwidget.get("icon_top", 0) icon_left = iwidget.get("icon_left", 0) zIndex = iwidget.get("zIndex", 0) layout = iwidget.get("layout", 0) # Creates IWidget position position = Position( posX=left, posY=top, posZ=zIndex, height=height, width=width, minimized=False, fulldragboard=False ) position.save() # Creates IWidget icon position icon_position = Position(posX=icon_left, posY=icon_top) icon_position.save() new_iwidget = IWidget( name=iwidget_name, widget=resource.widget, tab=tab, layout=layout, position=position, icon_position=icon_position, ) new_iwidget.save() variableDefs = VariableDef.objects.filter(widget=resource.widget) 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 addIWidgetVariable(new_iwidget, varDef, initial_value) from wirecloud.platform.get_data import _invalidate_cached_variable_values _invalidate_cached_variable_values(new_iwidget.tab.workspace) return new_iwidget
def SaveIWidget(iwidget, user, tab, initial_variable_values): widget_uri = iwidget.get('widget') (widget_vendor, widget_name, widget_version) = widget_uri.split('/') resource = CatalogueResource.objects.select_related('widget').get(vendor=widget_vendor, short_name=widget_name, version=widget_version) if not resource.is_available_for(user): raise CatalogueResource.DoesNotExist iwidget_name = iwidget.get('name', None) if iwidget_name is None: iwidget_name = resource.get_processed_info()['title'] width = iwidget.get('width', 0) height = iwidget.get('height', 0) top = iwidget.get('top', 0) left = iwidget.get('left', 0) icon_top = iwidget.get('icon_top', 0) icon_left = iwidget.get('icon_left', 0) zIndex = iwidget.get('zIndex', 0) layout = iwidget.get('layout', 0) # Creates IWidget position position = Position(posX=left, posY=top, posZ=zIndex, height=height, width=width, minimized=False, fulldragboard=False) position.save() # Creates IWidget icon position icon_position = Position(posX=icon_left, posY=icon_top) icon_position.save() new_iwidget = IWidget(name=iwidget_name, widget=resource.widget, tab=tab, layout=layout, position=position, icon_position=icon_position) new_iwidget.save() variableDefs = VariableDef.objects.filter(widget=resource.widget) 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 addIWidgetVariable(new_iwidget, varDef, initial_value) return new_iwidget
def SaveIWidget(iwidget, user, tab, initial_variable_values=None, commit=True): new_iwidget = IWidget(tab=tab) resource = update_widget_value(new_iwidget, iwidget, user, required=True) iwidget_info = resource.get_processed_info() new_iwidget.name = iwidget_info['title'] new_iwidget.layout = iwidget.get('layout', 0) # set default positions new_iwidget.positions = { 'widget': { 'top': 0, 'left': 0, 'zIndex': 0, 'height': 0, 'width': 0, 'minimized': False, 'fulldragboard': False, }, 'icon': { 'top': 0, 'left': 0, }, } if initial_variable_values is not None: set_initial_values(new_iwidget, initial_variable_values, iwidget_info) update_title_value(new_iwidget, iwidget) update_position(new_iwidget, 'widget', iwidget) update_icon_position(new_iwidget, iwidget) if commit: new_iwidget.save() return new_iwidget