Browse files

Fix #6506

  • Loading branch information...
1 parent 0efbf62 commit a0d606b2b9dd7b55a529eba26cac4b0957715bc6 @elpaso elpaso committed Oct 16, 2012
View
40 qgis-app/plugins/tests/HelloWorld/1.6-full-md-no-init-unicode-error/HelloWorld/HelloWorld.py
@@ -0,0 +1,40 @@
+# -*- coding: utf-8 -*-
+# Import the PyQt and QGIS libraries
+from PyQt4.QtCore import *
+from PyQt4.QtGui import *
+from qgis.core import *
+
+
+class HelloWorld:
+
+ def __init__(self, iface):
+ # Save reference to the QGIS interface
+ self.iface = iface
+ self.canvas = iface.mapCanvas()
+
+ def initGui(self):
+ # Create action that will start plugin
+ self.action = QAction(QIcon(":/plugins/"), "&HelloWorld", self.iface.mainWindow())
+ # connect the action to the run method
+ QObject.connect(self.action, SIGNAL("activated()"), self.hello_world)
+
+ # Add toolbar button and menu item
+ self.iface.addPluginToMenu("HelloWorld", self.action)
+
+
+ def unload(self):
+ # Remove the plugin menu item and icon
+ self.iface.removePluginMenu("HelloWorld",self.action)
+
+
+
+ # run
+ def hello_world(self):
+ QMessageBox.information(self.iface.mainWindow(), QCoreApplication.translate('HelloWorld', "HelloWorld"), QCoreApplication.translate('HelloWorld', "HelloWorld"))
+ return
+
+
+
+
+if __name__ == "__main__":
+ pass
View
4 qgis-app/plugins/tests/HelloWorld/1.6-full-md-no-init-unicode-error/HelloWorld/__init__.py
@@ -0,0 +1,4 @@
+# -*- coding: utf-8 -*-
+"""
+ This script initializes the plugin, making it known to QGIS.
+"""
View
BIN qgis-app/plugins/tests/HelloWorld/1.6-full-md-no-init-unicode-error/HelloWorld/icon.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
31 qgis-app/plugins/tests/HelloWorld/1.6-full-md-no-init-unicode-error/HelloWorld/metadata.txt
@@ -0,0 +1,31 @@
+[general]
+name=HelloWorld
+qgisMinimumVersion=1.8
+description=This is a test plugin for greeting the
+ (going multiline) world, version is 1.6
+version=version 1.6
+author=Alessandr� Pasott�
+email=apasotti@gmail.com
+
+
+changelog=this is a very
+ very<br/>
+ very
+ very
+ very
+ very long multiline changelog
+
+
+tags= wkt, raster,hello world, spaced tag , tag
+
+tracker=http://bugs.itopen.it
+homepage=http://www.itopen.it
+repository=http://www.itopen.it/repo
+
+
+
+experimental=True
+
+
+; change icon...
+icon=icon.png
View
40 ...-app/plugins/tests/HelloWorld/1.7-full-md-no-init-subfolder-icon/HelloWorld/HelloWorld.py
@@ -0,0 +1,40 @@
+# -*- coding: utf-8 -*-
+# Import the PyQt and QGIS libraries
+from PyQt4.QtCore import *
+from PyQt4.QtGui import *
+from qgis.core import *
+
+
+class HelloWorld:
+
+ def __init__(self, iface):
+ # Save reference to the QGIS interface
+ self.iface = iface
+ self.canvas = iface.mapCanvas()
+
+ def initGui(self):
+ # Create action that will start plugin
+ self.action = QAction(QIcon(":/plugins/"), "&HelloWorld", self.iface.mainWindow())
+ # connect the action to the run method
+ QObject.connect(self.action, SIGNAL("activated()"), self.hello_world)
+
+ # Add toolbar button and menu item
+ self.iface.addPluginToMenu("HelloWorld", self.action)
+
+
+ def unload(self):
+ # Remove the plugin menu item and icon
+ self.iface.removePluginMenu("HelloWorld",self.action)
+
+
+
+ # run
+ def hello_world(self):
+ QMessageBox.information(self.iface.mainWindow(), QCoreApplication.translate('HelloWorld', "HelloWorld"), QCoreApplication.translate('HelloWorld', "HelloWorld"))
+ return
+
+
+
+
+if __name__ == "__main__":
+ pass
View
4 qgis-app/plugins/tests/HelloWorld/1.7-full-md-no-init-subfolder-icon/HelloWorld/__init__.py
@@ -0,0 +1,4 @@
+# -*- coding: utf-8 -*-
+"""
+ This script initializes the plugin, making it known to QGIS.
+"""
View
BIN ...app/plugins/tests/HelloWorld/1.7-full-md-no-init-subfolder-icon/HelloWorld/icons/icon.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
31 qgis-app/plugins/tests/HelloWorld/1.7-full-md-no-init-subfolder-icon/HelloWorld/metadata.txt
@@ -0,0 +1,31 @@
+[general]
+name=HelloWorld
+qgisMinimumVersion=1.8
+description=This is a test plugin for greeting the
+ (going multiline) world, version is 1.7
+version=version 1.7
+author=Alessandro Pasotti
+email=apasotti@gmail.com
+
+
+changelog=this is a very
+ very<br/>
+ very
+ very
+ very
+ very long multiline changelog
+
+
+tags= wkt, raster,hello world, spaced tag , tag
+
+tracker=http://bugs.itopen.it
+homepage=http://www.itopen.it
+repository=http://www.itopen.it/repo
+
+
+
+experimental=True
+
+
+; change icon...
+icon=icons/icon.png
View
65 qgis-app/plugins/views.py
@@ -217,12 +217,15 @@ def plugin_upload(request):
plugin.description = plugin_data['description']
plugin.author = plugin_data['author']
plugin.email = plugin_data['email']
- plugin.icon = plugin_data['icon']
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']
+
# Other optional fields
warnings = []
if form.cleaned_data.get('homepage'):
@@ -238,7 +241,8 @@ def plugin_upload(request):
elif not plugin.repository:
warnings.append(_('<strong>repository</strong> field is empty, this field is not required but is recommended, please consider adding it to metadata.'))
-
+
+ # Save main Plugin object
plugin.save()
if is_new:
@@ -544,9 +548,13 @@ def _main_plugin_update(request, plugin, form):
Updates the main plugin object from version metadata
"""
# Update plugin from metadata
- for f in ['icon', 'name', 'author', 'email', 'description', 'homepage', 'tracker']:
+ for f in ['name', 'author', 'email', 'description', 'homepage', 'tracker']:
if form.cleaned_data.get(f):
setattr(plugin, f, form.cleaned_data.get(f))
+
+ # Icon has a special treatment
+ if form.cleaned_data.get('icon_file'):
+ setattr(plugin, 'icon', form.cleaned_data.get('icon_file'))
if form.cleaned_data.get('tags'):
plugin.tags.set(*[t.strip().lower() for t in form.cleaned_data.get('tags').split(',')])
plugin.save()
@@ -568,20 +576,26 @@ def version_create(request, package_name):
form = PluginVersionForm(request.POST, request.FILES, instance=version, is_trusted=request.user.has_perm('plugins.can_approve'))
if form.is_valid():
- new_object = form.save()
- msg = _("The Plugin Version has been successfully created.")
- messages.success(request, msg, fail_silently=True)
- # The approved flag is also controlled in the form, but we
- # are checking it here in any case for additional security
- if not request.user.has_perm('plugins.can_approve'):
- new_object.approved = False
- new_object.save()
- messages.warning(request, _('You do not have approval permissions, plugin version has been set unapproved.'), fail_silently=True)
- if form.cleaned_data.get('icon_file'):
- form.cleaned_data['icon'] = form.cleaned_data.get('icon_file')
- _main_plugin_update(request, new_object.plugin, form)
- _check_optional_metadata(form, request)
- return HttpResponseRedirect(new_object.plugin.get_absolute_url())
+ try:
+ new_object = form.save()
+ msg = _("The Plugin Version has been successfully created.")
+ messages.success(request, msg, fail_silently=True)
+ # The approved flag is also controlled in the form, but we
+ # are checking it here in any case for additional security
+ if not request.user.has_perm('plugins.can_approve'):
+ new_object.approved = False
+ new_object.save()
+ messages.warning(request, _('You do not have approval permissions, plugin version has been set unapproved.'), fail_silently=True)
+ if form.cleaned_data.get('icon_file'):
+ form.cleaned_data['icon'] = form.cleaned_data.get('icon_file')
+ _main_plugin_update(request, new_object.plugin, form)
+ _check_optional_metadata(form, request)
+ return HttpResponseRedirect(new_object.plugin.get_absolute_url())
+ except (IntegrityError, ValidationError, DjangoUnicodeDecodeError), e:
+ messages.error(request, e, fail_silently=True)
+ transaction.rollback()
+ connection.close()
+ return HttpResponseRedirect(plugin.get_absolute_url())
else:
form = PluginVersionForm(is_trusted=request.user.has_perm('plugins.can_approve'))
@@ -601,12 +615,17 @@ def version_update(request, package_name, version):
if request.method == 'POST':
form = PluginVersionForm(request.POST, request.FILES, instance=version, is_trusted=request.user.has_perm('plugins.can_approve'))
if form.is_valid():
- new_object = form.save()
- # update metadata for the main plugin object
- _main_plugin_update(request, new_object.plugin, form)
- msg = _("The Plugin Version has been successfully updated.")
- messages.success(request, msg, fail_silently=True)
- return HttpResponseRedirect(new_object.plugin.get_absolute_url())
+ try:
+ new_object = form.save()
+ # update metadata for the main plugin object
+ _main_plugin_update(request, new_object.plugin, form)
+ msg = _("The Plugin Version has been successfully updated.")
+ messages.success(request, msg, fail_silently=True)
+ except (IntegrityError, ValidationError, DjangoUnicodeDecodeError), e:
+ messages.error(request, e, fail_silently=True)
+ transaction.rollback()
+ connection.close()
+ return HttpResponseRedirect(plugin.get_absolute_url())
else:
form = PluginVersionForm(instance=version, is_trusted=request.user.has_perm('plugins.can_approve'))

0 comments on commit a0d606b

Please sign in to comment.