From 592dbee99447d1cbff5d192bc5dd35c29e0ce32c Mon Sep 17 00:00:00 2001 From: Sanj Date: Fri, 13 May 2011 03:54:32 +0530 Subject: [PATCH] file_utils --- edgware/files/file_utils.py | 41 ++++++++++++++++++++++++++++++++++--- 1 file changed, 38 insertions(+), 3 deletions(-) diff --git a/edgware/files/file_utils.py b/edgware/files/file_utils.py index 6ab2bfa..9a79d88 100644 --- a/edgware/files/file_utils.py +++ b/edgware/files/file_utils.py @@ -1,4 +1,4 @@ -from models import File +from models import File, Category import os try: import json @@ -41,15 +41,50 @@ def manage_types(): types = ['image', 'audio', 'text', 'video', 'other'] for t in types: wooga[t] = 0 - + errors = 0 + errorsArr = [] + new_images = 0 for f in File.objects.all(): typ = f.type try: wooga[typ] += 1 except KeyError: - print typ + print f.file.url + # errorsArr.append(typ) + errors += 1 + if f.file.url.upper().endswith("JPG"): + f.type = 'image' + f.save() + elif f.file.url.upper().endswith("OGV"): + f.type = 'video' + f.save() + elif f.file.url.upper().endswith("PDF"): + f.type = 'text' + f.save() + elif f.file.url.upper().endswith("DOC"): + f.type = "text" + f.save() + elif f.file.url.upper().endswith("RTF"): + f.type = "text" + f.save() + else: + f.type = "other" +# errorsArr.append(f.file.url[-3:]) + wooga['errors'] = errors + wooga['errorsArray'] = errorsArr + wooga['new_images'] = new_images print json.dumps(wooga, indent=4) +def get_files_per_category(): + ret = {} + total = 0 + for c in Category.objects.all(): + no_of_files = c.file_set.count() + ret[c.name] = no_of_files + total += no_of_files + ret['total'] = total + print json.dumps(ret, indent=4) + def correct_types(): types = ['image', 'audio', 'text', 'video', 'other']