Added organisation things. Need to do the form. Committing to push and pull onto server with access to legacy database.

This commit is contained in:
tomtom5152
2014-11-05 15:22:50 +00:00
parent 046683ee5b
commit 21530b978a
7 changed files with 246 additions and 13 deletions

View File

@@ -1,7 +1,9 @@
__author__ = 'Ghost'
import os
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "PyRIGS.settings")
import django
django.setup()
from django.db import connections
@@ -11,6 +13,7 @@ from django.db import transaction
from RIGS import models
import reversion
def setup_cursor():
try:
cursor = connections['legacy'].cursor()
@@ -20,6 +23,7 @@ def setup_cursor():
print(connections._databases)
return None
def import_people():
cursor = setup_cursor()
if cursor is None:
@@ -33,10 +37,11 @@ def import_people():
email += "@nottingham.ac.uk"
notes = ""
if row[5] != "Normal":
if row[5] != "Normal":
notes = row[5]
person, created = models.Person.objects.get_or_create(pk=row[0], name=row[1], phone=row[2], email=email, address=row[4], notes=notes)
person, created = models.Person.objects.get_or_create(pk=row[0], name=row[1], phone=row[2], email=email,
address=row[4], notes=notes)
if created:
print("Created: " + person.__unicode__())
with transaction.atomic(), reversion.create_revision():
@@ -44,6 +49,7 @@ def import_people():
else:
print("Found: " + person.__unicode__())
def import_organisations():
cursor = setup_cursor()
if cursor is None:
@@ -51,15 +57,13 @@ def import_organisations():
sql = """SELECT `id`, `name`, `phone`, `address`, `union_account`, `status` FROM `organisations`"""
cursor.execute(sql)
for row in cursor.fetchall():
unionAccount = False
if row[4] == "1":
unionAccount = True
notes = ""
if row[5] != "Normal":
if row[5] != "Normal":
notes = row[5]
object, created = models.Organisation.objects.get_or_create(pk=row[0], name=row[1], phone=row[2], address=row[3], unionAccount=unionAccount, notes=notes)
object, created = models.Organisation.objects.get_or_create(pk=row[0], name=row[1], phone=row[2],
address=row[3],
unionAccount=row[4], notes=notes)
if created:
print("Created: " + object.__unicode__())
with transaction.atomic(), reversion.create_revision():
@@ -67,9 +71,11 @@ def import_organisations():
else:
print("Found: " + object.__unicode__())
def main():
#import_people()
# import_people()
import_organisations()
if __name__=="__main__":
if __name__ == "__main__":
main()