def add_plugin(): plugin_json = request.get_json() plugin = Plugin(plugin_json['video_url'], plugin_json['image_urls'], plugin_json['price'], plugin_json['name'], plugin_json['path'], plugin_json['description']) db.session.add(plugin) db.session.commit() return Response(status=201)
def upload(request): if request.method == 'POST': form = PluginForm(request.POST, request.FILES) if not request.FILES['archive'].content_type in \ ['application/gzip', 'application/x-gzip']: return render( request, 'upload.html', { 'form': form, 'function': 'plugin', 'message': 'File not of acceptable type', 'type': 'alert-danger' }) else: arch = request.FILES['archive'] arch = cStringIO.StringIO(arch.read()) t = tarfile.open(fileobj=arch) data = None for x in t.getmembers(): if '/manifest.json' in x.name: pid = x.name.split('/')[0] data = json.loads(t.extractfile(x).read()) if not data: return render( request, 'upload.html', { 'form': form, 'function': 'plugin', 'message': 'Malformed archive. Please resubmit in ' 'accordance with Genesis Plugin API guidelines.', 'type': 'alert-error' }) # If upgrading, check permission and backup old one if necessary if Plugin.objects.filter(PLUGIN_ID=pid, BACKUP=False).exists(): backup(Plugin.objects.get(PLUGIN_ID=pid, BACKUP=False)) # Update the database with the new plugin data f = Plugin(name=data['name'], archive=request.FILES['archive'], TYPE=data['type'], DESCRIPTION=data['description']['short'], LONG_DESCRIPTION=data['description'].get('long', ''), AUTHOR=data['author'], HOMEPAGE=data['homepage'], APP_AUTHOR=data.get('app_author', ''), APP_HOMEPAGE=data.get('app_homepage', ''), MODULES=json.dumps(data['modules']), CATEGORIES=json.dumps(data['categories']), VERSION=data['version'], DEPS=json.dumps(data['dependencies']), PLUGIN_ID=pid, ICON=data['icon'], BACKUP=False) f.save() if data.get('logo'): s = Image(itype="logo", plugin=f) s.image.save( "logo.png", t.extractfile(os.path.join(pid, 'assets/logo.png'))) s.save() if data.get('screenshots'): for x in data['screenshots']: s = Image(itype="screenshot", plugin=f) s.image.save("screen.jpg", t.extractfile(os.path.join(pid, 'assets', x))) s.save() # Display success message return render( request, 'upload.html', { 'form': form, 'function': 'plugin', 'message': 'Upload successful!', 'type': 'alert-success' }) else: form = PluginForm() return render(request, 'upload.html', {'form': form, 'function': 'plugin'})