def list(request, scope, scope_category, template_name="site_settings/list.html"): if not has_perm(request.user, 'site_settings.change_setting'): raise Http403 settings = Setting.objects.filter( scope=scope, scope_category=scope_category).order_by('label') if not settings: raise Http404 # check if module setting is for theme editor if scope_category == 'theme_editor': theme_setting = Setting.objects.get(name='theme') # no need to update input values if there is no change if theme_setting.input_value != theme_options(): theme_setting.input_value = theme_options() theme_setting.save() # update queryset to include the changes done settings = Setting.objects.filter( scope=scope, scope_category=scope_category).order_by('label') if request.method == 'POST': form = build_settings_form(request.user, settings)(request.POST, request.FILES) if form.is_valid(): # this save method is overriden in the forms.py form.save() delete_settings_cache(scope, scope_category) try: if form.cleaned_data['theme']: from django.core.management import call_command call_command('hide_settings', 'theme') call_command( 'update_settings', 'themes.%s' % form.cleaned_data['theme'].lstrip()) except: pass EventLog.objects.log() msg_string = 'Successfully saved %s settings' % scope_category.replace( '_', ' ').title() messages.add_message(request, messages.SUCCESS, _(msg_string)) redirect_to = request.POST.get('next', '') if redirect_to: return HttpResponseRedirect(redirect_to) else: form = build_settings_form(request.user, settings)() # Log the get so we see if someone views setting values EventLog.objects.log() return render_to_resp(request=request, template_name=template_name, context={ 'form': form, 'scope_category': scope_category })
def save(self, *args, **kwargs): """The save method is overwritten because settings are referenced in several different ways. This is the cental command if we want to incorporate a process applicable for all those ways. Using signals is also feasable however there is a process order that must be followed (e.g. caching new value if not equal to old value) so we can leave that for a later time. """ try: #get the old value as reference for updating the cache orig = Setting.objects.get(pk=self.pk) except Setting.DoesNotExist: orig = None #call touch settings if this is the setting theme if self.name == 'theme': from tendenci.apps.theme.utils import theme_options self.input_value = theme_options() super(Setting, self).save(*args, **kwargs) call_command('clear_theme_cache') else: super(Setting, self).save(*args, **kwargs) #update the cache when value has changed if orig and self.value != orig.value: from tendenci.apps.site_settings.utils import ( delete_setting_cache, cache_setting, delete_all_settings_cache) from tendenci.apps.site_settings.cache import SETTING_PRE_KEY # delete the cache for all the settings to reset the context delete_all_settings_cache() # delete and set cache for single key and save the value in the database delete_setting_cache(self.scope, self.scope_category, self.name) cache_setting(self.scope, self.scope_category, self.name, self)
def save(self, *args, **kwargs): """The save method is overwritten because settings are referenced in several different ways. This is the cental command if we want to incorporate a process applicable for all those ways. Using signals is also feasable however there is a process order that must be followed (e.g. caching new value if not equal to old value) so we can leave that for a later time. """ try: #get the old value as reference for updating the cache orig = Setting.objects.get(pk = self.pk) except Setting.DoesNotExist: orig = None #call touch settings if this is the setting theme if self.name == 'theme': from tendenci.apps.theme.utils import theme_options self.input_value = theme_options() super(Setting, self).save(*args, **kwargs) call_command('clear_theme_cache') else: super(Setting, self).save(*args, **kwargs) #update the cache when value has changed if orig and self.value != orig.value: from tendenci.apps.site_settings.utils import (delete_setting_cache, cache_setting, delete_all_settings_cache) from tendenci.apps.site_settings.cache import SETTING_PRE_KEY # delete the cache for all the settings to reset the context delete_all_settings_cache() # delete and set cache for single key and save the value in the database delete_setting_cache(self.scope, self.scope_category, self.name) cache_setting(self.scope, self.scope_category, self.name, self)
def list(request, scope, scope_category, template_name="site_settings/list.html"): if not has_perm(request.user, 'site_settings.change_setting'): raise Http403 settings = Setting.objects.filter(scope=scope, scope_category=scope_category).order_by('label') if not settings: raise Http404 # check if module setting is for theme editor if scope_category == 'theme_editor': theme_setting = Setting.objects.get(name='theme') # no need to update input values if there is no change if theme_setting.input_value != theme_options(): theme_setting.input_value = theme_options() theme_setting.save() # update queryset to include the changes done settings = Setting.objects.filter(scope=scope, scope_category=scope_category).order_by('label') if request.method == 'POST': form = build_settings_form(request.user, settings)(request.POST, request.FILES) if form.is_valid(): # this save method is overriden in the forms.py form.save() delete_settings_cache(scope, scope_category) try: if form.cleaned_data['theme']: from django.core.management import call_command call_command('hide_settings', 'theme') call_command('update_settings', 'themes.%s' % form.cleaned_data['theme'].lstrip()) except: pass EventLog.objects.log() msg_string = 'Successfully saved %s settings' % scope_category.replace('_',' ').title() messages.add_message(request, messages.SUCCESS, _(msg_string)) redirect_to = request.REQUEST.get('next', '') if redirect_to: return HttpResponseRedirect(redirect_to) else: form = build_settings_form(request.user, settings)() # Log the get so we see if someone views setting values EventLog.objects.log() return render_to_response(template_name, {'form': form, 'scope_category': scope_category }, context_instance=RequestContext(request))
def save(self, *args, **kwargs): """The save method is overwritten because settings are referenced in several different ways. This is the central command if we want to incorporate a process applicable for all those ways. Using signals is also feasible however there is a process order that must be followed (e.g. caching new value if not equal to old value) so we can leave that for a later time. """ # Django 1.10 and later no longer accept "true" or "false" strings for # BooleanField values. Since these are used in many existing theme # settings files, we must still support them. if self.client_editable in ('true', 'false'): self.client_editable = self.client_editable == 'true' if self.store in ('true', 'false'): self.store = self.store == 'true' if self.is_secure in ('true', 'false'): self.is_secure = self.is_secure == 'true' try: #get the old value as reference for updating the cache orig = Setting.objects.get(pk=self.pk) except Setting.DoesNotExist: orig = None #call touch settings if this is the setting theme if self.name == 'theme': from tendenci.apps.theme.utils import theme_options self.input_value = theme_options() super(Setting, self).save(*args, **kwargs) call_command('clear_theme_cache') else: super(Setting, self).save(*args, **kwargs) #update the cache when value has changed if orig and self.value != orig.value: from tendenci.apps.site_settings.utils import ( delete_setting_cache, cache_setting, delete_all_settings_cache) # delete the cache for all the settings to reset the context delete_all_settings_cache() # delete and set cache for single key and save the value in the database delete_setting_cache(self.scope, self.scope_category, self.name) cache_setting(self.scope, self.scope_category, self.name, self)