Skip to content

Commit 426f688

Browse files
committed
removing south & markdown dependencies
1 parent f17dcf5 commit 426f688

10 files changed

+79
-274
lines changed

README.md

+6
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@ Django Fragment Cache Invalidation
33

44
Fragment cache invalidation by using a per model version token to prefix the cache keys. The version token can either be an internal memcached counter or a timestamped attribute from the model, such as `updated_at`.
55

6+
installation
7+
------------
8+
9+
Install with `pip` or with `python setup.py install` and add 'cachesweeper' to your `settings.INSTALLED_APPS`
10+
11+
612
post_save cache sweeper
713
-----------------------
814

myproject/db/README

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
sqlite3 db goes here

myproject/settings.py

-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,6 @@
9494
# Uncomment the next line to enable admin documentation:
9595
'django.contrib.admindocs',
9696
'django.contrib.markup',
97-
'south',
9897
'cachesweeper',
9998
)
10099

requirements.pip

-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,2 @@
11
django
22
python-memcached
3-
South
4-
Markdown

src/cachesweeper/migrations/0001_initial.py

-102
This file was deleted.

src/cachesweeper/migrations/0002_auto__add_vote__del_field_comment_likes__del_field_comment_dislikes.py

-104
This file was deleted.

src/cachesweeper/migrations/__init__.py

Whitespace-only changes.

src/cachesweeper/models.py

-64
Original file line numberDiff line numberDiff line change
@@ -1,64 +0,0 @@
1-
from django.db import models
2-
from django.db.models.signals import post_save
3-
from django.contrib.auth.models import User
4-
from django.core.cache import cache
5-
from cachesweeper.utils import invalidate_cache_handler, invalidate_cache_for
6-
7-
# Create your models here.
8-
class Article(models.Model):
9-
"""An article"""
10-
title = models.CharField(blank=True, max_length=100)
11-
text = models.TextField(blank=True)
12-
created_at = models.DateTimeField(auto_now_add=True)
13-
updated_at = models.DateTimeField(auto_now=True)
14-
15-
class Meta:
16-
get_latest_by = 'created_at'
17-
18-
def __unicode__(self):
19-
return self.title
20-
21-
22-
class Comment(models.Model):
23-
"""A comment for an article"""
24-
user = models.ForeignKey(User)
25-
article = models.ForeignKey(Article)
26-
content = models.TextField(blank=True)
27-
created_at = models.DateTimeField(auto_now_add=True)
28-
updated_at = models.DateTimeField(auto_now=True)
29-
30-
def likes(self):
31-
return self.vote_set.filter(direction='+')
32-
33-
def like_it(self):
34-
return self.vote_set.create(direction='+')
35-
36-
def dislikes(self):
37-
return self.vote_set.filter(direction='-')
38-
39-
def dislike_it(self):
40-
return self.vote_set.create(direction='-')
41-
42-
class Meta:
43-
get_latest_by = 'created_at'
44-
ordering = ['created_at']
45-
46-
def __unicode__(self):
47-
return u"Comment: %s" % u" - ".join(map(str, [self.article, self.user, self.content]))
48-
49-
50-
class Vote(models.Model):
51-
"""A like or a dislike"""
52-
comment = models.ForeignKey(Comment)
53-
direction = models.CharField(choices=(('+','Like'),('-','Dislike')), max_length=100)
54-
created_at = models.DateTimeField(auto_now_add=True)
55-
updated_at = models.DateTimeField(auto_now=True)
56-
57-
def __unicode__(self):
58-
return u"Vote %s1 for %s" % (self.direction, self.comment)
59-
60-
def invalidate_vote_cache(sender, **kwargs):
61-
instance = kwargs.get('instance')
62-
invalidate_cache_for(instance.comment)
63-
64-
post_save.connect(invalidate_vote_cache, sender=Vote)

src/cachesweeper/test_models.py

+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
from django.db import models
2+
from django.db.models.signals import post_save
3+
from django.contrib.auth.models import User
4+
from django.core.cache import cache
5+
from cachesweeper.utils import invalidate_cache_handler, invalidate_cache_for
6+
7+
# Create your models here.
8+
class Article(models.Model):
9+
"""An article"""
10+
title = models.CharField(blank=True, max_length=100)
11+
text = models.TextField(blank=True)
12+
created_at = models.DateTimeField(auto_now_add=True)
13+
updated_at = models.DateTimeField(auto_now=True)
14+
15+
class Meta:
16+
get_latest_by = 'created_at'
17+
18+
def __unicode__(self):
19+
return self.title
20+
21+
22+
class Comment(models.Model):
23+
"""A comment for an article"""
24+
user = models.ForeignKey(User)
25+
article = models.ForeignKey(Article)
26+
content = models.TextField(blank=True)
27+
created_at = models.DateTimeField(auto_now_add=True)
28+
updated_at = models.DateTimeField(auto_now=True)
29+
30+
def likes(self):
31+
return self.vote_set.filter(direction='+')
32+
33+
def like_it(self):
34+
return self.vote_set.create(direction='+')
35+
36+
def dislikes(self):
37+
return self.vote_set.filter(direction='-')
38+
39+
def dislike_it(self):
40+
return self.vote_set.create(direction='-')
41+
42+
class Meta:
43+
get_latest_by = 'created_at'
44+
ordering = ['created_at']
45+
46+
def __unicode__(self):
47+
return u"Comment: %s" % u" - ".join(map(str, [self.article, self.user, self.content]))
48+
49+
50+
class Vote(models.Model):
51+
"""A like or a dislike"""
52+
comment = models.ForeignKey(Comment)
53+
direction = models.CharField(choices=(('+','Like'),('-','Dislike')), max_length=100)
54+
created_at = models.DateTimeField(auto_now_add=True)
55+
updated_at = models.DateTimeField(auto_now=True)
56+
57+
def __unicode__(self):
58+
return u"Vote %s1 for %s" % (self.direction, self.comment)
59+
60+
def invalidate_vote_cache(sender, **kwargs):
61+
instance = kwargs.get('instance')
62+
invalidate_cache_for(instance.comment)
63+
64+
post_save.connect(invalidate_vote_cache, sender=Vote)

src/cachesweeper/tests.py

+8-1
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,20 @@
33
from django.core.urlresolvers import reverse
44
from django.utils.http import urlquote
55
from django.utils.hashcompat import md5_constructor
6-
from cachesweeper.models import Comment, Article
6+
from django.core.management import call_command
7+
78
from cachesweeper.utils import cache_token_key_for_record, generate_fragment_cache_key_for_record
9+
from cachesweeper.test_models import Comment, Article
810

911
class FragmentCacheInvalidation(TestCase):
1012

1113
fixtures = ['test_auth_data', 'test_cachesweeper_data']
1214

15+
def __init__(self, *args, **kwargs):
16+
# I only want the test_models available for when running the tests
17+
call_command('syncdb')
18+
super(FragmentCacheInvalidation, self).__init__(*args, **kwargs)
19+
1320
def setUp(self):
1421
pass
1522

0 commit comments

Comments
 (0)