basic text management
This commit is contained in:
commit
e55e78ba2d
19 changed files with 499 additions and 0 deletions
0
text/management/__init__.py
Normal file
0
text/management/__init__.py
Normal file
0
text/management/commands/__init__.py
Normal file
0
text/management/commands/__init__.py
Normal file
35
text/management/commands/import_text.py
Normal file
35
text/management/commands/import_text.py
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# vi:si:et:sw=4:sts=4:ts=4
|
||||
# Written 2009 by j@mailb.org
|
||||
|
||||
import os
|
||||
from glob import glob
|
||||
|
||||
import oxlib
|
||||
import oxlib.normalize
|
||||
|
||||
from django.core.management.base import BaseCommand, CommandError
|
||||
from django.conf import settings
|
||||
|
||||
from texts.text import models
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
"""
|
||||
import texts from media/text.
|
||||
"""
|
||||
help = 'import texts that are not in db.'
|
||||
args = ''
|
||||
|
||||
def handle(self, **options):
|
||||
for f in glob('%s/*/*/*' % settings.MEDIA_ROOT):
|
||||
if os.path.isfile(f):
|
||||
name = f[len(settings.MEDIA_ROOT)+1:]
|
||||
name = name.decode('utf-8')
|
||||
q = models.Text.objects.filter(file=name)
|
||||
if q.count() == 0:
|
||||
print 'adding', name
|
||||
text = models.Text()
|
||||
text.file.name = name
|
||||
text.parsePath()
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue