Beispiel #1
0
def site_config(request):
    config = get_site_config()

    if request.method == "POST":
        form = SiteConfigForm(instance=config, data=request.POST)
        if form.is_valid():
            form.save()
            cache.delete(SITE_CONFIG_CACHE_KEY)
            return HttpResponseRedirect(reverse('admin:index'))
    else:
        form = SiteConfigForm(instance=config)

    return TemplateResponse(request, 'admin/site_config.html', {"form": form})
def site_config(request):
    return {"site_config": get_site_config()}
    def test_get_config_uses_module_cache(self):
        cache.set(utils.SITE_CONFIG_CACHE_KEY, "somethingthatsnotamodelobject")
        conf = utils.get_site_config()

        self.assertEqual(conf, "somethingthatsnotamodelobject")
 def test_get_config_ignores_other_ids(self):
     conf = SiteConfig.objects.create(id=utils.SITE_CONFIG_ID + 10)
     new_conf = utils.get_site_config()
     self.assertNotEqual(conf.id, new_conf.id)
 def test_get_config_creates_only_one(self):
     conf = SiteConfig.objects.create(id=utils.SITE_CONFIG_ID)
     new_conf = utils.get_site_config()
     self.assertEqual(conf.id, new_conf.id)
 def test_get_config_creates(self):
     self.assertEqual(SiteConfig.objects.count(), 0)
     utils.get_site_config()
     self.assertEqual(SiteConfig.objects.count(), 1)