-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[DONE] Use cache to store video data (#969)
* Use cache to store video data - get it in context - create command to store video data * change name of video context processor * add some pydoc * update cache timeout to 600 seconds - use DRY and call context cache video data instead of repeat code * use delete many to clear cache
- Loading branch information
Showing
3 changed files
with
73 additions
and
31 deletions.
There are no files selected for viewing
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
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
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,28 @@ | ||
from django.core.management.base import BaseCommand | ||
from django.core.cache import cache | ||
from pod.video.context_processors import context_video_data | ||
from django.core import serializers | ||
import json | ||
|
||
|
||
class Command(BaseCommand): | ||
"""Command to store video data in cache.""" | ||
help = "Store video data in django cache : " \ | ||
+ "types, discipline, video count and videos duration" | ||
|
||
def handle(self, *args, **options): | ||
"""Function called to store video data in cache.""" | ||
cache.delete_many(['DISCIPLINES', 'VIDEOS_COUNT', 'VIDEOS_DURATION', 'TYPES']) | ||
video_data = context_video_data(request=None) | ||
msg = 'Successfully store video data in cache' | ||
for data in video_data: | ||
try: | ||
msg += "\n %s : %s" % ( | ||
data, | ||
json.dumps(serializers.serialize("json", video_data[data])) | ||
) | ||
except (TypeError, AttributeError): | ||
msg += "\n %s : %s" % (data, video_data[data]) | ||
self.stdout.write( | ||
self.style.SUCCESS(msg) | ||
) |