Browse Source

Fixed migration and ban caching

Rafał Pitoń 11 years ago
parent
commit
6fffa5624e
3 changed files with 6 additions and 5 deletions
  1. 3 3
      misago/users/bans.py
  2. 1 1
      misago/users/migrations/0001_initial.py
  3. 2 1
      misago/users/models/bans.py

+ 3 - 3
misago/users/bans.py

@@ -50,10 +50,10 @@ def get_user_ban(user):
             _set_user_ban_cache(user)
     except BanCache.DoesNotExist:
         user.ban_cache = BanCache(user=user)
-        ban_cache = _set_user_ban_cache(user)
+        user.ban_cache = _set_user_ban_cache(user)
 
-    if ban_cache.ban:
-        return ban_cache
+    if user.ban_cache.ban:
+        return user.ban_cache
     else:
         return None
 

+ 1 - 1
misago/users/migrations/0001_initial.py

@@ -144,7 +144,6 @@ class Migration(migrations.Migration):
                 ('staff_message', models.TextField(null=True, blank=True)),
                 ('valid_until', models.DateField(null=True, blank=True, db_index=True)),
                 ('is_valid', models.BooleanField(default=True, db_index=True)),
-                ('ban', models.ForeignKey(on_delete=django.db.models.deletion.SET_NULL, blank=True, to='misago_users.Ban', null=True)),
             ],
             bases=(models.Model,),
         ),
@@ -155,6 +154,7 @@ class Migration(migrations.Migration):
                 ('staff_message', models.TextField(null=True, blank=True)),
                 ('bans_version', models.PositiveIntegerField(default=0)),
                 ('valid_until', models.DateField(null=True, blank=True)),
+                ('ban', models.ForeignKey(on_delete=django.db.models.deletion.SET_NULL, blank=True, to='misago_users.Ban', null=True)),
                 ('user', models.OneToOneField(primary_key=True, serialize=False, to=settings.AUTH_USER_MODEL)),
             ],
             options={

+ 2 - 1
misago/users/models/bans.py

@@ -133,6 +133,7 @@ class BanCache(models.Model):
     def is_valid(self):
         version_is_valid = cachebuster.is_valid(BAN_CACHEBUSTER,
                                                 self.bans_version)
-        not_expired = not self.valid_until or self.valid_until < date.today()
+        date_today = timezone.now().date()
+        not_expired = not self.valid_until or self.valid_until > date_today
 
         return version_is_valid and not_expired