Note that there are some explanatory texts on larger screens.

plurals
  1. POAlternating settings at django runtime
    primarykey
    data
    text
    <p>I need to keep some settings in RAM. I created file "cache_values.py"</p> <pre><code>class CacheValue: pass </code></pre> <p>I want to use it as variable container for my needs.</p> <p>I'm writing some settings to "CacheValue" on server start:</p> <pre><code>from cms.models.pagemodel import Page from modifier.cache_values import CacheValue def cache_start_values(): CacheValue.page_publish_dates={} pages=Page.objects.all() for page in pages: CacheValue.page_publish_dates[page.pk]=page.last_publish_date CacheValue.last_publish_date=max(CacheValue.page_publish_dates.values()) </code></pre> <p>Also, when I'm saving some model - I change these settings</p> <pre><code>CacheValue.page_publish_dates[self.pk]=self.last_publish_date CacheValue.last_publish_date=max(CacheValue.page_publish_dates.values()) </code></pre> <p>But when I want to use this settings in my templates, by adding them with context processor as variables - some magic begins.</p> <pre><code>from modifier.cache_values import CacheValue def add_for_cache_info(request): context_extras = {} context_extras['page_publish_dates']=CacheValue.page_publish_dates context_extras['last_publish_date_all_pages']=CacheValue.last_publish_date if "current_page" in request.__dict__: context_extras['last_publish_date']=CacheValue.page_publish_dates[request.current_page.pk] return context_extras </code></pre> <p>In template </p> <pre><code> {{ page_publish_dates }} {{ last_publish_date_all_pages }} </code></pre> <p>Values that I see in rendered template alternates between old(before model save) and new(after model save) every time I refersh a page. 0_0 0_0</p> <p>If I save model(change value) second time - it will alterante between the oldest value and the new one.</p> <p>Why? </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload