file_utils
This commit is contained in:
parent
ca6e910c8a
commit
592dbee994
|
@ -1,4 +1,4 @@
|
||||||
from models import File
|
from models import File, Category
|
||||||
import os
|
import os
|
||||||
try:
|
try:
|
||||||
import json
|
import json
|
||||||
|
@ -41,15 +41,50 @@ def manage_types():
|
||||||
types = ['image', 'audio', 'text', 'video', 'other']
|
types = ['image', 'audio', 'text', 'video', 'other']
|
||||||
for t in types:
|
for t in types:
|
||||||
wooga[t] = 0
|
wooga[t] = 0
|
||||||
|
errors = 0
|
||||||
|
errorsArr = []
|
||||||
|
new_images = 0
|
||||||
for f in File.objects.all():
|
for f in File.objects.all():
|
||||||
typ = f.type
|
typ = f.type
|
||||||
try:
|
try:
|
||||||
wooga[typ] += 1
|
wooga[typ] += 1
|
||||||
except KeyError:
|
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)
|
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():
|
def correct_types():
|
||||||
types = ['image', 'audio', 'text', 'video', 'other']
|
types = ['image', 'audio', 'text', 'video', 'other']
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user