diff --git a/app/cache.py b/app/cache.py index e5811fd..65f7428 100644 --- a/app/cache.py +++ b/app/cache.py @@ -12,17 +12,29 @@ def create_timeline_cache(): template = loader.get_template('objects/courses_timeline.html') timeline_html = template.render(RequestContext(HttpRequest(),context)) - cache = HomeCache(cached_html=timeline_html) + cache = TimelineCache(cached_html=timeline_html) cache.save() def delete_timeline_cache(): - old_cache = HomeCache.objects.earliest('create_time') + old_cache = TimelineCache.objects.earliest('create_time') old_cache.delete() +def mark_timeline_cache(): + cache = TimelineCache.objects.latest('create_time') + cache.should_change_mark = True + cache.save() + +def is_marked_timeline_cache(): + cache = TimelineCache.objects.latest('create_time') + return cache.should_change_mark + def get_timeline_context(): context = {} - cache = HomeCache.objects.latest('create_time') + if not TimelineCache.objects.all().count(): + create_timeline_cache() + + cache = TimelineCache.objects.latest('create_time') timeline_html = cache.cached_html context["timeline"] = timeline_html diff --git a/app/models.py b/app/models.py index 7a7f490..1f6a7a6 100644 --- a/app/models.py +++ b/app/models.py @@ -68,6 +68,7 @@ class Comment(models.Model): def __unicode__(self): return "Comm" + str(self.id) -class HomeCache(models.Model): - cached_html = models.CharField(max_length=10000) +class TimelineCache(models.Model): + cached_html = models.CharField(max_length=2000000) + should_change_mark = models.NullBooleanField() create_time = models.DateTimeField(auto_now=True) diff --git a/app/views.py b/app/views.py index 20388b3..ec87d5b 100644 --- a/app/views.py +++ b/app/views.py @@ -72,6 +72,10 @@ def vote_course(request): rating.rating = rating_value rating.save() + + if rating_type == OVERALL_R: + mark_timeline_cache() + return redirect(form.cleaned_data['url']) diff --git a/jCourse/db/database.db b/jCourse/db/database.db index 8187fd9..751d327 100644 Binary files a/jCourse/db/database.db and b/jCourse/db/database.db differ diff --git a/scripts/force_remake_cache.py b/scripts/force_remake_cache.py new file mode 100644 index 0000000..ab40940 --- /dev/null +++ b/scripts/force_remake_cache.py @@ -0,0 +1,4 @@ +from app.cache import * + +create_timeline_cache() +delete_timeline_cache() \ No newline at end of file diff --git a/scripts/remake_cache.py b/scripts/remake_cache.py index ab40940..d701f1c 100644 --- a/scripts/remake_cache.py +++ b/scripts/remake_cache.py @@ -1,4 +1,8 @@ from app.cache import * -create_timeline_cache() -delete_timeline_cache() \ No newline at end of file +if is_marked_timeline_cache(): + create_timeline_cache() + delete_timeline_cache() + + +# Its important to have two newlines after each script block \ No newline at end of file