def json_upload_detail(request, upload, addon=None): result = upload_validation_context(request, upload, addon=addon) if result["validation"]: if result["validation"]["errors"] == 0: try: parse_addon(upload, addon=addon) except django_forms.ValidationError, exc: m = [] for msg in exc.messages: # Simulate a validation error so the UI displays it. m.append({"type": "error", "message": msg, "tier": 1}) v = make_validation_result(dict(error="", validation=dict(messages=m))) return json_view.error(v)
def json_upload_detail(request, upload, addon=None): result = upload_validation_context(request, upload, addon=addon) if result['validation']: if result['validation']['errors'] == 0: try: parse_addon(upload, addon=addon) except django_forms.ValidationError, exc: m = [] for msg in exc.messages: # Simulate a validation error so the UI displays it. m.append({'type': 'error', 'message': msg, 'tier': 1}) v = make_validation_result(dict(error='', validation=dict(messages=m))) return json_view.error(v)
def json_upload_detail(request, upload, addon=None): result = upload_validation_context(request, upload, addon=addon) if result['validation']: if result['validation']['errors'] == 0: try: parse_addon(upload, addon=addon) except django_forms.ValidationError, exc: m = [] for msg in exc.messages: # Simulate a validation error so the UI displays it. m.append({'type': 'error', 'message': msg, 'tier': 1}) v = make_validation_result( dict(error='', validation=dict(messages=m))) return json_view.error(v)
def clean(self): data = self.cleaned_data if 'upload' not in self.cleaned_data: self._errors['upload'] = self.upload_error return if self.is_packaged(): # Now run the packaged app check, done in clean, because # clean_packaged needs to be processed first. try: pkg = parse_addon(data['upload'], self.addon) except forms.ValidationError, e: self._errors['upload'] = self.error_class(e.messages) return # Collect validation errors so we can display them at once. errors = [] ver = pkg.get('version') if (ver and self.addon and self.addon.versions.filter(version=ver).exists()): errors.append(_(u'Version %s already exists.') % ver) origin = pkg.get('origin') if origin: try: verify_app_domain(origin, packaged=True, exclude=self.addon) except forms.ValidationError, e: errors.append(e.message) if self.addon and origin != self.addon.app_domain: errors.append(_('Changes to "origin" are not allowed.'))
def clean(self): data = self.cleaned_data if 'upload' not in self.cleaned_data: self._errors['upload'] = self.upload_error return if self.is_packaged(): # Now run the packaged app check, done in clean, because # clean_packaged needs to be processed first. try: pkg = parse_addon(data['upload'], self.addon) except forms.ValidationError, e: self._errors['upload'] = self.error_class(e.messages) return ver = pkg.get('version') if (ver and self.addon and self.addon.versions.filter(version=ver).exists()): self._errors['upload'] = _(u'Version %s already exists') % ver return origin = pkg.get('origin') if origin: try: origin = verify_app_domain(origin, packaged=True, exclude=self.addon) except forms.ValidationError, e: self._errors['upload'] = self.error_class(e.messages) return if origin: data['origin'] = origin
def from_upload(cls, upload, addon, send_signal=True): data = utils.parse_addon(upload, addon) max_len = cls._meta.get_field_by_name('_developer_name')[0].max_length developer = data.get('developer_name', '')[:max_len] v = cls.objects.create(addon=addon, version=data['version'], _developer_name=developer) log.info('New version: %r (%s) from %r' % (v, v.id, upload)) # To avoid circular import. from mkt.webapps.models import AppManifest # Note: This must happen before we call `File.from_upload`. manifest = utils.WebAppParser().get_json_data(upload) AppManifest.objects.create( version=v, manifest=json.dumps(manifest)) File.from_upload(upload, v, parse_data=data) # Update supported locales from manifest. # Note: This needs to happen after we call `File.from_upload`. update_supported_locales_single.apply_async( args=[addon.id], kwargs={'latest': True}, eta=datetime.datetime.now() + datetime.timedelta(seconds=settings.NFS_LAG_DELAY) ) v.disable_old_files() # After the upload has been copied, remove the upload. storage.delete(upload.path) if send_signal: version_uploaded.send(sender=v) # If packaged app and app is blocked, put in escalation queue. if addon.is_packaged and addon.status == mkt.STATUS_BLOCKED: # To avoid circular import. from mkt.reviewers.models import EscalationQueue EscalationQueue.objects.create(addon=addon) return v
def from_upload(cls, upload, addon, send_signal=True): data = utils.parse_addon(upload, addon) max_len = cls._meta.get_field_by_name('_developer_name')[0].max_length developer = data.get('developer_name', '')[:max_len] v = cls.objects.create(addon=addon, version=data['version'], _developer_name=developer) log.info('New version: %r (%s) from %r' % (v, v.id, upload)) # To avoid circular import. from mkt.webapps.models import AppManifest # Note: This must happen before we call `File.from_upload`. manifest = utils.WebAppParser().get_json_data(upload) AppManifest.objects.create(version=v, manifest=json.dumps(manifest)) File.from_upload(upload, v, parse_data=data) # Update supported locales from manifest. # Note: This needs to happen after we call `File.from_upload`. update_supported_locales_single.apply_async( args=[addon.id], kwargs={'latest': True}, eta=datetime.datetime.now() + datetime.timedelta(seconds=settings.NFS_LAG_DELAY)) v.disable_old_files() # After the upload has been copied, remove the upload. storage.delete(upload.path) if send_signal: version_uploaded.send(sender=v) # If packaged app and app is blocked, put in escalation queue. if addon.is_packaged and addon.status == mkt.STATUS_BLOCKED: # To avoid circular import. from mkt.reviewers.models import EscalationQueue EscalationQueue.objects.create(addon=addon) return v