-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
regularly schedule file count updates for #377
- Loading branch information
Showing
3 changed files
with
27 additions
and
11 deletions.
There are no files selected for viewing
13 changes: 2 additions & 11 deletions
13
karmaworld/apps/courses/management/commands/fix_note_counts.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,9 @@ | ||
from django.core.management.base import BaseCommand | ||
from karmaworld.apps.notes.models import * | ||
from karmaworld.apps.courses.models import * | ||
from karmaworld.apps.courses.tasks import fix_note_counts | ||
|
||
class Command(BaseCommand): | ||
help = """Set the field file_count on every Course and School | ||
to the correct value.""" | ||
|
||
def handle(self, *args, **kwargs): | ||
for c in Course.objects.all(): | ||
c.update_note_count() | ||
print "Updated course {c}".format(c=c) | ||
|
||
for s in School.objects.all(): | ||
s.update_note_count() | ||
print "Updated school {s}".format(s=s) | ||
|
||
|
||
fix_note_counts() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
from karmaworld.apps.courses.models import Course | ||
from karmaworld.apps.courses.models import School | ||
|
||
from celery import task | ||
from celery.utils.log import get_task_logger | ||
|
||
logger = get_task_logger(__name__) | ||
|
||
@task(name="fix_note_counts") | ||
def fix_note_counts(): | ||
""" | ||
Set the field file_count on every Course and School to the correct value. | ||
""" | ||
|
||
for c in Course.objects.all(): | ||
c.update_note_count() | ||
print "Updated course {c}".format(c=c) | ||
|
||
for s in School.objects.all(): | ||
s.update_note_count() | ||
print "Updated school {s}".format(s=s) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters