sync-tabellio: sync document types (#3544)

This commit is contained in:
Frédéric Péters 2013-09-10 16:55:06 +02:00
parent 696054321b
commit c365f1a6aa
1 changed files with 28 additions and 1 deletions

View File

@ -8,7 +8,8 @@ from django.core.management.base import BaseCommand, CommandError
from django.db import transaction
from django.template.defaultfilters import slugify
from docbow_project.docbow.models import MailingList, DocbowProfile
from docbow_project.docbow.models import MailingList, DocbowProfile, FileType
from docbow_project.pfwb.models import TabellioDocType
# Generate passwords using capitals and numbers, but no 1 or I, O or 0
@ -203,4 +204,30 @@ class Command(BaseCommand):
ministres_list.members.add(user)
ministres_list.save()
# get list of document types
cur.execute('''SELECT id, descr
FROM t_typedoc''')
while True:
t = cur.fetchone()
if not t:
break
id, descr = t
try:
doctype = TabellioDocType.objects.get(tabellio_doc_type=id)
except TabellioDocType.DoesNotExist:
filetype = FileType()
filetype.name = descr
filetype.save()
doctype = TabellioDocType()
doctype.tabellio_doc_type = id
doctype.filetype = filetype
doctype.save()
else:
if doctype.filetype.name != descr:
doctype.filetype.name = descr
doctype.filetype.save()
cur.close()