def plugin_upload(request): """ This is the "single step" way to create new plugins: uploads a package and creates a new Plugin with a new PluginVersion """ if request.method == 'POST': form = PackageUploadForm(request.POST, request.FILES) if form.is_valid(): try: plugin_data = { 'name': form.cleaned_data['name'], 'package_name': form.cleaned_data['package_name'], 'description': form.cleaned_data['description'], 'created_by': request.user, 'published': request.user.has_perm('plugins.can_publish'), 'icon': form.cleaned_data['icon_file'], } new_plugin = Plugin(**plugin_data) new_plugin.save() plugin_notify(new_plugin) version_data = { 'plugin': new_plugin, 'min_qg_version': form.cleaned_data['qgisMinimumVersion'], 'version': form.cleaned_data['version'], 'current': True, 'created_by': request.user, 'package': form.cleaned_data['package'] } new_version = PluginVersion(**version_data) new_version.save() msg = _("The Plugin has been successfully created.") messages.success(request, msg, fail_silently=True) if not request.user.has_perm('plugins.can_publish'): msg = _( "Your plugin is awaiting approval from a staff member and will be published as soon as possible." ) messages.warning(request, msg, fail_silently=True) except (IntegrityError, ValidationError), e: messages.error(request, e, fail_silently=True) if not new_plugin.pk: return render_to_response( 'plugins/plugin_upload.html', {'form': form}, context_instance=RequestContext(request)) return HttpResponseRedirect(new_plugin.get_absolute_url())
def plugin_upload(request): """ This is the "single step" way to create new plugins: uploads a package and creates a new Plugin with a new PluginVersion """ if request.method == 'POST': form = PackageUploadForm(request.POST, request.FILES) if form.is_valid(): try: plugin_data = { 'name' : form.cleaned_data['name'], 'package_name' : form.cleaned_data['package_name'], 'description' : form.cleaned_data['description'], 'created_by' : request.user, 'icon' : form.cleaned_data['icon_file'], } new_plugin = Plugin(**plugin_data) new_plugin.save() plugin_notify(new_plugin) version_data = { 'plugin' : new_plugin, 'min_qg_version' : form.cleaned_data['qgisMinimumVersion'], 'version' : form.cleaned_data['version'], 'created_by' : request.user, 'package' : form.cleaned_data['package'], 'approved' : request.user.has_perm('plugins.can_approve'), 'experimental' : form.cleaned_data['experimental'], } new_version = PluginVersion(**version_data) new_version.save() msg = _("The Plugin has been successfully created.") messages.success(request, msg, fail_silently=True) if not request.user.has_perm('plugins.can_approve'): msg = _("Your plugin is awaiting approval from a staff member and will be approved as soon as possible.") messages.warning(request, msg, fail_silently=True) except (IntegrityError, ValidationError), e: messages.error(request, e, fail_silently=True) if not new_plugin.pk: return render_to_response('plugins/plugin_upload.html', { 'form' : form }, context_instance=RequestContext(request)) return HttpResponseRedirect(new_plugin.get_absolute_url())
def plugin_upload(request): """ This is the "single step" way to create new plugins: uploads a package and creates a new Plugin with a new PluginVersion """ if request.method == 'POST': form = PackageUploadForm(request.POST, request.FILES) if form.is_valid(): try: plugin_data = { 'name' : form.cleaned_data['name'], 'package_name' : form.cleaned_data['package_name'], 'description' : form.cleaned_data['description'], 'created_by' : request.user, 'published' : request.user.has_perm('plugins.can_publish'), 'icon' : form.cleaned_data['icon_file'], } #import ipy; ipy.shell() new_plugin = Plugin(**plugin_data) new_plugin.save() plugin_notify(new_plugin) version_data = { 'plugin' : new_plugin, 'min_qg_version' : form.cleaned_data['qgisMinimumVersion'], 'version' : form.cleaned_data['version'], 'current' : True, 'created_by' : request.user, 'package' : form.cleaned_data['package'] } new_version = PluginVersion(**version_data) new_version.save() msg = _("The Plugin has been successfully created.") messages.success(request, msg, fail_silently=True) except (IntegrityError, ValidationError), e: messages.error(request, e, fail_silently=True) if not new_plugin.pk: return render_to_response('plugins/plugin_upload.html', { 'form' : form }, context_instance=RequestContext(request)) return HttpResponseRedirect(new_plugin.get_absolute_url())
def plugin_upload(request): """ This is the "single step" way to create new plugins: uploads a package and creates a new Plugin with a new PluginVersion can also update an existing plugin """ if request.method == 'POST': form = PackageUploadForm(request.POST, request.FILES) if form.is_valid(): try: plugin_data = { 'name' : form.cleaned_data['name'], 'package_name' : form.cleaned_data['package_name'], 'description' : form.cleaned_data['description'], 'created_by' : request.user, 'author' : form.cleaned_data['author'], 'email' : form.cleaned_data['email'], 'created_by' : request.user, 'icon' : form.cleaned_data['icon_file'], } # Gets existing plugin try: plugin = Plugin.objects.get(package_name=plugin_data['package_name']) if not check_plugin_access(request.user, plugin): return render_to_response('plugins/plugin_permission_deny.html', {}, context_instance=RequestContext(request)) # Apply new values plugin.name = plugin_data['name'] plugin.description = plugin_data['description'] plugin.author = plugin_data['author'] plugin.email = plugin_data['email'] is_new = False except Plugin.DoesNotExist: plugin = Plugin(**plugin_data) is_new = True # Check icon, don't change if not valid if plugin_data['icon']: plugin.icon = plugin_data['icon'] # Server is optional plugin.server = form.cleaned_data.get('server', False) # Other optional fields warnings = [] if form.cleaned_data.get('homepage'): plugin.homepage = form.cleaned_data.get('homepage') elif not plugin.homepage: warnings.append(_('<strong>homepage</strong> field is empty, this field is not required but is recommended, please consider adding it to metadata.')) if form.cleaned_data.get('tracker'): plugin.tracker = form.cleaned_data.get('tracker') elif not plugin.tracker: raise ValidationError(_('"tracker" metadata is required! Please add it to <code>metadata.txt</code>.')) if form.cleaned_data.get('repository'): plugin.repository = form.cleaned_data.get('repository') elif not plugin.repository: raise ValidationError(_('"repository" metadata is required! Please add it to <code>metadata.txt</code>.')) if form.cleaned_data.get('about'): plugin.about = form.cleaned_data.get('about') elif not plugin.about: raise ValidationError(_('"about" metadata is required! Please add it to <code>metadata.txt</code>.')) # Save main Plugin object plugin.save() if is_new: plugin_notify(plugin) # Takes care of tags if form.cleaned_data.get('tags'): plugin.tags.set(*[t.strip().lower() for t in form.cleaned_data.get('tags').split(',')]) version_data = { 'plugin' : plugin, 'min_qg_version' : form.cleaned_data.get('qgisMinimumVersion'), 'max_qg_version' : form.cleaned_data.get('qgisMaximumVersion'), 'version' : form.cleaned_data.get('version'), 'created_by' : request.user, 'package' : form.cleaned_data.get('package'), 'approved' : request.user.has_perm('plugins.can_approve') or plugin.approved, 'experimental' : form.cleaned_data.get('experimental'), 'changelog' : form.cleaned_data.get('changelog', ''), 'external_deps' : form.cleaned_data.get('external_deps', ''), } new_version = PluginVersion(**version_data) new_version.save() msg = _("The Plugin has been successfully created.") messages.success(request, msg, fail_silently=True) if not new_version.approved: msg = _("Your plugin is awaiting approval from a staff member and will be approved as soon as possible.") warnings.append(msg) if not is_new: version_notify(new_version) if not form.cleaned_data.get('metadata_source') == 'metadata.txt': msg = _("Your plugin does not contain a metadata.txt file, metadata have been read from the __init__.py file. This is deprecated and its support will eventually cease.") warnings.append(msg) # Grouped messages: if warnings: messages.warning(request, _('<p><strong>Warnings:</strong></p>') + '\n'.join(["<p>%s</p>" % unicode(w) for w in warnings]), fail_silently=True) except (IntegrityError, ValidationError, DjangoUnicodeDecodeError), e: connection.close() messages.error(request, e, fail_silently=True) if not plugin.pk: return render_to_response('plugins/plugin_upload.html', { 'form' : form }, context_instance=RequestContext(request)) return HttpResponseRedirect(plugin.get_absolute_url())
def plugin_upload(request): """ This is the "single step" way to create new plugins: uploads a package and creates a new Plugin with a new PluginVersion can also update an existing plugin """ if request.method == 'POST': form = PackageUploadForm(request.POST, request.FILES) if form.is_valid(): try: plugin_data = { 'name': form.cleaned_data['name'], 'package_name': form.cleaned_data['package_name'], 'description': form.cleaned_data['description'], 'created_by': request.user, 'icon': form.cleaned_data['icon_file'], } # Gets existing plugin try: plugin = Plugin.objects.get( package_name=plugin_data['package_name']) # Apply new values plugin.name = plugin_data['name'] plugin.description = plugin_data['description'] plugin.icon = plugin_data['icon'] is_new = False except Plugin.DoesNotExist: plugin = Plugin(**plugin_data) is_new = True # Other optional fields if form.cleaned_data.get('homepage'): plugin.homepage = form.cleaned_data.get('homepage') elif not plugin.homepage: messages.warning( request, _('Homepage field is empty, this field is not required but is recommended, please consider adding it to metadata.' ), fail_silently=True) if form.cleaned_data.get('tracker'): plugin.tracker = form.cleaned_data.get('tracker') elif not plugin.tracker: messages.warning( request, _('Tracker field is empty, this field is not required but is recommended, please consider adding it to metadata.' ), fail_silently=True) if form.cleaned_data.get('repository'): plugin.repository = form.cleaned_data.get('repository') elif not plugin.repository: messages.warning( request, _('Repository field is empty, this field is not required but is recommended, please consider adding it to metadata.' ), fail_silently=True) plugin.save() if is_new: plugin_notify(plugin) # Takes care of tags if form.cleaned_data.get('tags'): plugin.tags.set(*form.cleaned_data.get('tags').split(',')) version_data = { 'plugin': plugin, 'min_qg_version': form.cleaned_data.get('qgisMinimumVersion'), 'version': form.cleaned_data.get('version'), 'created_by': request.user, 'package': form.cleaned_data.get('package'), 'approved': request.user.has_perm('plugins.can_approve') or plugin.approved, 'experimental': form.cleaned_data.get('experimental'), 'changelog': form.cleaned_data.get('changelog', ''), } new_version = PluginVersion(**version_data) new_version.save() msg = _("The Plugin has been successfully created.") messages.success(request, msg, fail_silently=True) if not request.user.has_perm('plugins.can_approve'): msg = _( "Your plugin is awaiting approval from a staff member and will be approved as soon as possible." ) messages.warning(request, msg, fail_silently=True) if not form.cleaned_data.get( 'metadata_source') == 'metadata.txt': msg = _( "Your plugin does not contain a metadata.txt file, metadata have been read from the __init__.py file. This is deprecated and its support will eventually cease." ) messages.warning(request, msg, fail_silently=True) except (IntegrityError, ValidationError), e: connection.close() messages.error(request, e, fail_silently=True) if not plugin.pk: return render_to_response( 'plugins/plugin_upload.html', {'form': form}, context_instance=RequestContext(request)) return HttpResponseRedirect(plugin.get_absolute_url())
def plugin_upload(request): """ This is the "single step" way to create new plugins: uploads a package and creates a new Plugin with a new PluginVersion can also update an existing plugin """ if request.method == 'POST': form = PackageUploadForm(request.POST, request.FILES) if form.is_valid(): try: plugin_data = { 'name' : form.cleaned_data['name'], 'package_name' : form.cleaned_data['package_name'], 'description' : form.cleaned_data['description'], 'created_by' : request.user, 'icon' : form.cleaned_data['icon_file'], } # Gets existing plugin try: plugin = Plugin.objects.get(package_name=plugin_data['package_name']) # Apply new values plugin.name = plugin_data['name'] plugin.description = plugin_data['description'] plugin.icon = plugin_data['icon'] is_new = False except Plugin.DoesNotExist: plugin = Plugin(**plugin_data) is_new = True # Other optional fields if form.cleaned_data.get('homepage'): plugin.homepage = form.cleaned_data.get('homepage') elif not plugin.homepage: messages.warning(request, _('Homepage field is empty, this field is not required but is recommended, please consider adding it to metadata.'), fail_silently=True) if form.cleaned_data.get('tracker'): plugin.tracker = form.cleaned_data.get('tracker') elif not plugin.tracker: messages.warning(request, _('Tracker field is empty, this field is not required but is recommended, please consider adding it to metadata.'), fail_silently=True) if form.cleaned_data.get('repository'): plugin.repository = form.cleaned_data.get('repository') elif not plugin.repository: messages.warning(request, _('Repository field is empty, this field is not required but is recommended, please consider adding it to metadata.'), fail_silently=True) plugin.save() if is_new: plugin_notify(plugin) # Takes care of tags if form.cleaned_data.get('tags'): plugin.tags.set(*form.cleaned_data.get('tags').split(',')) version_data = { 'plugin' : plugin, 'min_qg_version' : form.cleaned_data.get('qgisMinimumVersion'), 'version' : form.cleaned_data.get('version'), 'created_by' : request.user, 'package' : form.cleaned_data.get('package'), 'approved' : request.user.has_perm('plugins.can_approve') or plugin.approved, 'experimental' : form.cleaned_data.get('experimental'), 'changelog' : form.cleaned_data.get('changelog', ''), } new_version = PluginVersion(**version_data) new_version.save() msg = _("The Plugin has been successfully created.") messages.success(request, msg, fail_silently=True) if not request.user.has_perm('plugins.can_approve'): msg = _("Your plugin is awaiting approval from a staff member and will be approved as soon as possible.") messages.warning(request, msg, fail_silently=True) if not form.cleaned_data.get('metadata_source') == 'metadata.txt': msg = _("Your plugin does not contain a metadata.txt file, metadata have been read from the __init__.py file. This is deprecated and its support will eventually cease.") messages.warning(request, msg, fail_silently=True) except (IntegrityError, ValidationError), e: connection.close() messages.error(request, e, fail_silently=True) if not plugin.pk: return render_to_response('plugins/plugin_upload.html', { 'form' : form }, context_instance=RequestContext(request)) return HttpResponseRedirect(plugin.get_absolute_url())