def create_widget_from_wgt(wgt_file, user, deploy_only=False): if not isinstance(wgt_file, WgtFile): raise TypeError() template = wgt_deployer.deploy(wgt_file) if template.get_resource_type() != 'widget': raise Exception() if not deploy_only: widget_info = template.get_resource_info() check_requirements(widget_info) widget = Widget() widget.resource = CatalogueResource.objects.get( vendor=template.get_resource_vendor(), short_name=template.get_resource_name(), version=template.get_resource_version()) widget_code = template.get_absolute_url(widget_info['contents']['src']) widget.xhtml = XHTML.objects.create( uri=widget.uri + "/xhtml", url=widget_code, content_type=widget_info['contents']['contenttype'], use_platform_style=widget_info['contents']['useplatformstyle'], cacheable=widget_info['contents']['cacheable']) widget.save() return widget