def obj_update(self, bundle, request, **kwargs): data = bundle.data try: obj = self.get_object_list(bundle.request).get(**kwargs) except Webapp.DoesNotExist: raise ImmediateHttpResponse(response=http.HttpNotFound()) if not AppOwnerAuthorization().is_authorized(request, object=obj): raise ImmediateHttpResponse(response=http.HttpForbidden()) data['slug'] = data.get('slug', obj.app_slug) data.update(self.formset(data)) data.update(self.devices(data)) forms = [ AppDetailsBasicForm(data, instance=obj, request=request), DeviceTypeForm(data, addon=obj), CategoryFormSet(data, addon=obj, request=request) ] valid = all([f.is_valid() for f in forms]) if not valid: raise self.form_errors(forms) forms[0].save(obj) forms[1].save(obj) forms[2].save() log.info('App updated: %s' % obj.pk) bundle.obj = obj return bundle
def obj_update(self, bundle, request, **kwargs): data = bundle.data obj = self.get_and_check_ownership(request, **kwargs) bundle.obj = obj data['app_slug'] = data.get('app_slug', obj.app_slug) data.update(self.formset(data)) data.update(self.devices(data)) self.update_premium_type(bundle) # TODO: renable when regions are sorted out. # if 'regions' in data: # data['regions'] = [REGIONS_DICT[r['slug']].id for r in data['regions'] # if r.get('slug') in REGIONS_DICT] forms = [AppDetailsBasicForm(data, instance=obj, request=request), DeviceTypeForm(data, addon=obj), # RegionForm(data, product=obj), CategoryFormSet(data, addon=obj, request=request), CategoryForm({'categories': data['form-0-categories']})] valid = all([f.is_valid() for f in forms]) if not valid: raise self.form_errors(forms) forms[0].save(obj) forms[1].save(obj) forms[2].save() # forms[3].save() log.info('App updated: %s' % obj.pk) return bundle
def obj_update(self, bundle, request, **kwargs): data = bundle.data obj = self.get_and_check_ownership(request, **kwargs) data['app_slug'] = data.get('app_slug', obj.app_slug) data.update(self.formset(data)) data.update(self.devices(data)) forms = [ AppDetailsBasicForm(data, instance=obj, request=request), DeviceTypeForm(data, addon=obj), CategoryFormSet(data, addon=obj, request=request), CategoryForm({'categories': data['form-0-categories']}) ] valid = all([f.is_valid() for f in forms]) if not valid: raise self.form_errors(forms) forms[0].save(obj) forms[1].save(obj) forms[2].save() log.info('App updated: %s' % obj.pk) bundle.obj = obj return bundle
def details(request, addon_id, addon): # Name, Slug, Summary, Description, Privacy Policy, # Homepage URL, Support URL, Support Email. form_basic = AppDetailsBasicForm(request.POST or None, instance=addon, request=request) form_cats = CategoryForm(request.POST or None, product=addon, request=request) form_devices = DeviceTypeForm(request.POST or None, addon=addon) form_icon = AppFormMedia(request.POST or None, request.FILES or None, instance=addon, request=request) form_previews = PreviewFormSet(request.POST or None, prefix='files', queryset=addon.get_previews()) # For empty webapp-locale (or no-locale) fields that have # form-locale values, duplicate them to satisfy the requirement. form_locale = request.COOKIES.get("current_locale", "") app_locale = to_language(addon.default_locale) for name, value in request.POST.items(): if value: if name.endswith(form_locale): basename = name[:-len(form_locale)] else: basename = name + '_' othername = basename + app_locale if not request.POST.get(othername, None): request.POST[othername] = value forms = { 'form_basic': form_basic, 'form_devices': form_devices, 'form_cats': form_cats, 'form_icon': form_icon, 'form_previews': form_previews, } if request.POST and all(f.is_valid() for f in forms.itervalues()): addon = form_basic.save(addon) form_devices.save(addon) form_cats.save() form_icon.save(addon) for preview in form_previews.forms: preview.save(addon) tasks.generate_image_assets.delay(addon) AppSubmissionChecklist.objects.get(addon=addon).update(details=True) addon.mark_done() return redirect('submit.app.done', addon.app_slug) ctx = { 'step': 'details', 'addon': addon, } ctx.update(forms) return jingo.render(request, 'submit/details.html', ctx)
def details(request, addon_id, addon): # Name, Slug, Description, Privacy Policy, Homepage URL, Support URL, # Support Email. form_basic = AppDetailsBasicForm(request.POST or None, instance=addon, request=request) form_cats = CategoryForm(request.POST or None, product=addon, request=request) form_icon = AppFormMedia(request.POST or None, request.FILES or None, instance=addon, request=request) form_previews = PreviewFormSet(request.POST or None, prefix='files', queryset=addon.get_previews()) # For empty webapp-locale (or no-locale) fields that have # form-locale values, duplicate them to satisfy the requirement. form_locale = request.COOKIES.get('current_locale', '') app_locale = to_language(addon.default_locale) for name, value in request.POST.items(): if value: if name.endswith(form_locale): basename = name[:-len(form_locale)] else: basename = name + '_' othername = basename + app_locale if not request.POST.get(othername, None): request.POST[othername] = value forms = { 'form_basic': form_basic, 'form_cats': form_cats, 'form_icon': form_icon, 'form_previews': form_previews, } if request.POST and all(f.is_valid() for f in forms.itervalues()): addon = form_basic.save(addon) form_cats.save() form_icon.save(addon) for preview in form_previews.forms: preview.save(addon) # If this is an incomplete app from the legacy submission flow, it may # not have device types set yet - so assume it works everywhere. if not addon.device_types: for device in amo.DEVICE_TYPES: addon.addondevicetype_set.create(device_type=device) AppSubmissionChecklist.objects.get(addon=addon).update(details=True) make_public = (amo.PUBLIC_IMMEDIATELY if form_basic.cleaned_data.get('publish') else amo.PUBLIC_WAIT) # Free apps get pushed for review. if addon.premium_type == amo.ADDON_FREE: # The developer doesn't want the app published immediately upon # review. addon.update(status=amo.STATUS_PENDING, make_public=make_public) else: # Paid apps get STATUS_NULL until payment information has been # entered. addon.update(status=amo.STATUS_NULL, highest_status=amo.STATUS_PENDING, make_public=make_public) # Mark the app as excluded in regions that don't support payments. for region in mkt.regions.ALL_REGIONS: if not region.has_payments: AddonExcludedRegion.objects.get_or_create(addon=addon, region=region.id) record_action('app-submitted', request, {'app-id': addon.pk}) return redirect('submit.app.done', addon.app_slug) ctx = { 'step': 'details', 'addon': addon, } ctx.update(forms) return jingo.render(request, 'submit/details.html', ctx)
def details(request, addon_id, addon): # Name, Slug, Description, Privacy Policy, Homepage URL, Support URL, # Support Email. form_basic = AppDetailsBasicForm(request.POST or None, instance=addon, request=request) form_cats = CategoryForm(request.POST or None, product=addon, request=request) form_icon = AppFormMedia(request.POST or None, request.FILES or None, instance=addon, request=request) form_previews = PreviewFormSet(request.POST or None, prefix='files', queryset=addon.get_previews()) # For empty webapp-locale (or no-locale) fields that have # form-locale values, duplicate them to satisfy the requirement. form_locale = request.COOKIES.get('current_locale', '') app_locale = to_language(addon.default_locale) for name, value in request.POST.items(): if value: if name.endswith(form_locale): basename = name[:-len(form_locale)] else: basename = name + '_' othername = basename + app_locale if not request.POST.get(othername, None): request.POST[othername] = value forms = { 'form_basic': form_basic, 'form_cats': form_cats, 'form_icon': form_icon, 'form_previews': form_previews, } if request.POST and all(f.is_valid() for f in forms.itervalues()): addon = form_basic.save(addon) form_cats.save() form_icon.save(addon) for preview in form_previews.forms: preview.save(addon) # If this is an incomplete app from the legacy submission flow, it may # not have device types set yet - so assume it works everywhere. if not addon.device_types: for device in mkt.DEVICE_TYPES: addon.addondevicetype_set.create(device_type=device) AppSubmissionChecklist.objects.get(addon=addon).update(details=True) if addon.needs_payment(): # Paid apps get STATUS_NULL until payment information and content # ratings entered. addon.update(status=mkt.STATUS_NULL, highest_status=mkt.STATUS_PENDING) # Mark as pending in special regions (i.e., China). # By default, the column is set to pending when the row is inserted. # But we need to set a nomination date so we know to list the app # in the China Review Queue now (and sort it by that date too). for region in mkt.regions.SPECIAL_REGIONS: addon.geodata.set_nominated_date(region, save=True) log.info(u'[Webapp:%s] Setting nomination date to ' u'now for region (%s).' % (addon, region.slug)) record_action('app-submitted', request, {'app-id': addon.pk}) return redirect('submit.app.done', addon.app_slug) ctx = { 'step': 'details', 'addon': addon, } ctx.update(forms) return render(request, 'submit/details.html', ctx)