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_webapp(data['upload'], self.webapp) 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.webapp and self.webapp.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.webapp) except forms.ValidationError, e: errors.append(e.message) if self.webapp and origin != self.webapp.app_domain: errors.append(_('Changes to "origin" are not allowed.'))
def from_upload(cls, upload, webapp, send_signal=True): data = utils.parse_webapp(upload, webapp) max_len = cls._meta.get_field_by_name('_developer_name')[0].max_length developer = data.get('developer_name', '')[:max_len] v = cls.objects.create(webapp=webapp, 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=[webapp.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. private_storage.delete(upload.path) if send_signal: version_uploaded.send(sender=v) # If packaged app and app is blocked, put in escalation queue. if webapp.is_packaged and webapp.status == mkt.STATUS_BLOCKED: # To avoid circular import. from mkt.reviewers.models import EscalationQueue EscalationQueue.objects.create(webapp=webapp) return v