def app_settings(request, app_name=None, template='appsettings/settings.html', base_template='index.html'): editor = forms.settings_form() if request.POST: form = editor(request.POST) if form.is_valid(): for key, value in form.fields.iteritems(): app, group, name = key.split('-') val = form.cleaned_data[key] if val != getattr(settingsinst, app)._vals[group]._vals[name].initial: setattr(getattr(settingsinst, app)._vals[group], name, val) else: initial = {} for app_name in sorted(vars(settingsinst).keys()): app = getattr(settingsinst, app_name) for group_name, group in app._vals.iteritems(): if group._readonly: continue for key, value in group._vals.iteritems(): field_name = u'%s-%s-%s' % (app_name, group_name, key) initial[field_name] = getattr(group, key) form = editor(initial) return render_to_response(template, { 'app': app_name, 'form': form, 'base_template': base_template }, context_instance=RequestContext(request))
def GET(self): f = settings_form() settings = self.get_settings() f.title.value = settings["title"].value f.subtitle.value = settings["subtitle"].value f.notice.value = settings["notice"].value f.keywords.value = settings["keywords"].value f.description.value = settings["description"].value f.email.value = settings["email"].value f.domain.value = settings["domain"].value return admin_render.settings(form=f)
def POST(self): f = settings_form() if not f.validates(): msg = "settings not saved!" return admin_render.settings(form=f, msg=msg) else: web.ctx.orm.query(Option).filter(Option.name == "blog_title").update({"value": f.title.value}) web.ctx.orm.query(Option).filter(Option.name == "blog_subtitle").update({"value": f.subtitle.value}) web.ctx.orm.query(Option).filter(Option.name == "blog_notice").update({"value": f.notice.value}) web.ctx.orm.query(Option).filter(Option.name == "blog_keywords").update({"value": f.keywords.value}) web.ctx.orm.query(Option).filter(Option.name == "blog_description").update({"value": f.description.value}) web.ctx.orm.query(Option).filter(Option.name == "blog_admin_email").update({"value": f.email.value}) web.ctx.orm.query(Option).filter(Option.name == "blog_domain").update({"value": f.domain.value}) msg = "settings has been saved!" return admin_render.settings(form=f, msg=msg)
def app_settings(request, app_name=None, template = 'appsettings/settings.html', base_template = 'index.html'): editor = forms.settings_form() if request.POST: form = editor(request.POST) if form.is_valid(): for key, value in form.fields.iteritems(): app, group, name = key.split('-') val = form.cleaned_data[key] if val != getattr(settingsinst, app)._vals[group]._vals[name].initial: setattr(getattr(settingsinst, app)._vals[group], name, val) else: form = editor() return render_to_response(template, {'app':app_name,'form':form, 'base_template':base_template}, context_instance=RequestContext(request))
def app_settings(request, app_name=None, template = 'appsettings/settings.html', base_template = 'index.html'): editor = forms.settings_form() if request.POST: form = editor(request.POST) if form.is_valid(): for key, value in form.fields.iteritems(): app, group, name = key.split('-') val = form.cleaned_data[key] if val != getattr(settingsinst, app)._vals[group]._vals[name].initial: setattr(getattr(settingsinst, app)._vals[group], name, val) else: initial = {} for app_name in sorted(vars(settingsinst).keys()): app = getattr(settingsinst, app_name) for group_name, group in app._vals.iteritems(): if group._readonly:continue for key, value in group._vals.iteritems(): field_name = u'%s-%s-%s' % (app_name, group_name, key) initial[field_name] = getattr(group, key) form = editor(initial) return render_to_response(template, {'app':app_name,'form':form, 'base_template':base_template}, context_instance=RequestContext(request))