Exemple #1
0
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))
Exemple #2
0
    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.core.theme.utils import theme_options
            self.input_value = theme_options()
            super(Setting, self).save(*args, **kwargs)
            call_command('touch_settings')
        else:
            super(Setting, self).save(*args, **kwargs)

        #update the cache when value has changed
        if orig and self.value != orig.value:
            from tendenci.core.site_settings.utils import (
                delete_setting_cache, cache_setting, delete_all_settings_cache)
            from tendenci.core.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)
Exemple #3
0
 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.core.theme.utils import theme_options
         self.input_value = theme_options()
         super(Setting, self).save(*args, **kwargs)
         call_command('touch_settings')
     else:
         super(Setting, self).save(*args, **kwargs)
     
     #update the cache when value has changed
     if orig and self.value != orig.value:
         from tendenci.core.site_settings.utils import (delete_setting_cache,
             cache_setting, delete_all_settings_cache)
         from tendenci.core.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)
Exemple #4
0
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))
Exemple #5
0
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

            #             # if localizationlanguage is changed, update local settings
            #             from django.conf import settings as django_settings
            #             lang = get_setting('site', 'global', 'localizationlanguage')
            #             #if lang in ['en-us', 'es']
            #             if django_settings.LANGUAGE_CODE <> lang:
            #                 local_setting_file = os.path.join(getattr(django_settings, 'PROJECT_ROOT'), 'local.py')
            #                 f = open(local_setting_file, 'r')
            #                 content = f.read()
            #                 f.close()
            #
            #                 if content.find('LANGUAGE_CODE') == -1:
            #                     # we don't have LANGUAGE_CODE in local_settings, just append to it
            #                     content = '%s\nLANGUAGE_CODE=\'%s\'\n' % (content, lang)
            #                 else:
            #                     p = re.compile(r'([\d\D\s\S\w\W]*?LANGUAGE_CODE\s*=\s*[\'\"])([\w-]+)([\'\"][\d\D\s\S\w\W]*?)')
            #
            #                     content = p.sub(r'\1%s\3' % lang, content)
            #
            #                 f = open(local_setting_file, 'w')
            #                 f.write(content)
            #                 f.close()
            #
            #                 from django.core.management import call_command
            #                 call_command('touch_settings')
            #                 #setattr(django_settings, 'LANGUAGE_CODE', lang)

            EventLog.objects.log()
            messages.add_message(
                request, messages.SUCCESS, "Successfully saved %s settings" % scope_category.replace("_", " ").title()
            )

            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)
    )
Exemple #6
0
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


#             # if localizationlanguage is changed, update local settings
#             from django.conf import settings as django_settings
#             lang = get_setting('site', 'global', 'localizationlanguage')
#             #if lang in ['en-us', 'es']
#             if django_settings.LANGUAGE_CODE <> lang:
#                 local_setting_file = os.path.join(getattr(django_settings, 'PROJECT_ROOT'), 'local.py')
#                 f = open(local_setting_file, 'r')
#                 content = f.read()
#                 f.close()
#
#                 if content.find('LANGUAGE_CODE') == -1:
#                     # we don't have LANGUAGE_CODE in local_settings, just append to it
#                     content = '%s\nLANGUAGE_CODE=\'%s\'\n' % (content, lang)
#                 else:
#                     p = re.compile(r'([\d\D\s\S\w\W]*?LANGUAGE_CODE\s*=\s*[\'\"])([\w-]+)([\'\"][\d\D\s\S\w\W]*?)')
#
#                     content = p.sub(r'\1%s\3' % lang, content)
#
#                 f = open(local_setting_file, 'w')
#                 f.write(content)
#                 f.close()
#
#                 from django.core.management import call_command
#                 call_command('touch_settings')
#                 #setattr(django_settings, 'LANGUAGE_CODE', lang)

            EventLog.objects.log()
            messages.add_message(
                request, messages.SUCCESS, 'Successfully saved %s settings' %
                scope_category.replace('_', ' ').title())

            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))