def version_edit(request, addon_id, addon, version_id): show_features = addon.is_packaged formdata = request.POST if request.method == 'POST' else None version = get_object_or_404(Version, pk=version_id, addon=addon) version.addon = addon # Avoid extra useless query. form = AppVersionForm(formdata, instance=version) all_forms = [form] if show_features: appfeatures = version.features appfeatures_form = AppFeaturesForm(request.POST or None, instance=appfeatures) all_forms.append(appfeatures_form) if request.method == 'POST' and all(f.is_valid() for f in all_forms): [f.save() for f in all_forms] create_comm_note(addon, addon.current_version, request.amo_user, f.data['approvalnotes'], note_type=comm.REVIEWER_COMMENT) messages.success(request, _('Version successfully edited.')) return redirect(addon.get_dev_url('versions')) context = { 'addon': addon, 'version': version, 'form': form } if show_features: context.update({ 'appfeatures_form': appfeatures_form, 'appfeatures': appfeatures, 'feature_list': [unicode(f) for f in appfeatures.to_list()] }) return jingo.render(request, 'developers/apps/version_edit.html', context)
def status(request, addon_id, addon, webapp=False): form = forms.AppAppealForm(request.POST, product=addon) upload_form = NewWebappVersionForm(request.POST or None, is_packaged=True, addon=addon, request=request) if request.method == 'POST': if 'resubmit-app' in request.POST and form.is_valid(): form.save() create_comm_note(addon, addon.current_version, request.amo_user, form.data['notes'], note_type=comm.RESUBMISSION) messages.success(request, _('App successfully resubmitted.')) return redirect(addon.get_dev_url('versions')) elif 'upload-version' in request.POST and upload_form.is_valid(): mobile_only = (addon.latest_version and addon.latest_version.features.has_qhd) ver = Version.from_upload(upload_form.cleaned_data['upload'], addon, [amo.PLATFORM_ALL]) # Update addon status now that the new version was saved. addon.update_status() res = run_validator(ver.all_files[0].file_path) validation_result = json.loads(res) # Set all detected features as True and save them. keys = ['has_%s' % feature.lower() for feature in validation_result['feature_profile']] data = defaultdict.fromkeys(keys, True) # Set "Smartphone-Sized Displays" if it's a mobile-only app. qhd_devices = (set((amo.DEVICE_GAIA,)), set((amo.DEVICE_MOBILE,)), set((amo.DEVICE_GAIA, amo.DEVICE_MOBILE,))) if set(addon.device_types) in qhd_devices or mobile_only: data['has_qhd'] = True # Update feature profile for this version. ver.features.update(**data) messages.success(request, _('New version successfully added.')) log.info('[Webapp:%s] New version created id=%s from upload: %s' % (addon, ver.pk, upload_form.cleaned_data['upload'])) return redirect(addon.get_dev_url('versions.edit', args=[ver.pk])) ctx = {'addon': addon, 'webapp': webapp, 'form': form, 'upload_form': upload_form} # Used in the delete version modal. if addon.is_packaged: versions = addon.versions.values('id', 'version') version_strings = dict((v['id'], v) for v in versions) version_strings['num'] = len(versions) ctx['version_strings'] = json.dumps(version_strings) if addon.status == amo.STATUS_REJECTED: try: entry = (AppLog.objects .filter(addon=addon, activity_log__action=amo.LOG.REJECT_VERSION.id) .order_by('-created'))[0] except IndexError: entry = None # This contains the rejection reason and timestamp. ctx['rejection'] = entry and entry.activity_log if waffle.switch_is_active('preload-apps'): test_plan = PreloadTestPlan.objects.filter( addon=addon, status=amo.STATUS_PUBLIC) if test_plan.exists(): test_plan = test_plan[0] if (test_plan.last_submission < settings.PREINSTALL_TEST_PLAN_LATEST): ctx['outdated_test_plan'] = True ctx['next_step_suffix'] = 'submit' else: ctx['next_step_suffix'] = 'home' ctx['test_plan'] = test_plan return jingo.render(request, 'developers/apps/status.html', ctx)
def _create_comm_note(self, note_type): self.comm_thread, self.comm_note = create_comm_note( self.addon, self.version, self.request.amo_user, self.data['comments'], note_type=note_type, perms=self.data['action_visibility'])