Exemple #1
0
    def handle(self, *args, **options):
        if len(args) < 1:
            raise CommandError(_('Wrong number of arguments'))

        if not options['deploy_only']:
            user = User.objects.get(pk=1)
        else:
            user = FakeUser('admin')

        for file_name in args:
            try:
                wgt_file = WgtFile(file_name)
            except:
                print _('Failed to parse %(file_name)s') % {'file_name': file_name}
                continue

            try:
                template_contents = wgt_file.get_template()
                template = TemplateParser(template_contents)
                try:
                    create_widget_from_wgt(wgt_file, user, deploy_only=options['deploy_only'])
                except IntegrityError:
                    if not options['reinstall']:
                        raise
                    else:
                        deleteWidget(user, template.get_resource_name(),
                            template.get_resource_vendor(),
                            template.get_resource_version()
                        )
                        create_widget_from_wgt(wgt_file, user)

                wgt_file.close()
                print _('Successfully imported %(name)s widget') % {'name': template.get_resource_name()}
            except IntegrityError:
                print _('Version %(version)s of the %(name)s widget (from %(vendor)s) already exists') % {
                    'name': template.get_resource_name(),
                    'version': template.get_resource_version(),
                    'vendor': template.get_resource_vendor(),
                }
            except:
                print _('Failed to import widget from %(file_name)s') % {'file_name': file_name}
Exemple #2
0
def delete_resource(resource, user):

    # Delete the resource only if this user is the owner
    if not user.is_superuser and resource.creator != user:
        msg = _("user %(username)s is not the owner of the resource %(resource_id)s") % {'username': user.username, 'resource_id': resource.id}

        raise Http403(msg)

    result = {'removedIWidgets': []}
    if 'wirecloud.platform' in settings.INSTALLED_APPS and resource.resource_type() == 'widget':
        from wirecloud.platform.widget.views import deleteWidget

        # Remove the widget from the showcase
        result = deleteWidget(user, resource.short_name, resource.vendor, resource.version)

    # Delete the object
    resource.delete()

    return result