Organisational import

This commit is contained in:
Tom Price
2014-11-04 03:39:11 +00:00
parent a7384c1dd2
commit e5d89068fb
6 changed files with 755 additions and 5 deletions

View File

@@ -27,10 +27,7 @@ def import_people():
sql = """SELECT `id`, `name`, `phone`, `email`, `address`, `status` FROM `people`"""
cursor.execute(sql)
resp = cursor.fetchall()
i=0
for row in resp:
if (i+1) > 1:
break
email = row[3]
if email is not "" and "@" not in email:
email += "@nottingham.ac.uk"
@@ -47,8 +44,32 @@ def import_people():
else:
print("Found: " + person.__unicode__())
def import_organisations():
cursor = setup_cursor()
if cursor is None:
return
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":
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)
if created:
print("Created: " + object.__unicode__())
with transaction.atomic(), reversion.create_revision():
object.save()
else:
print("Found: " + object.__unicode__())
def main():
import_people()
#import_people()
import_organisations()
if __name__=="__main__":
main()

View File

@@ -0,0 +1,30 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
import RIGS.models
class Migration(migrations.Migration):
dependencies = [
('RIGS', '0003_auto_20141031_0219'),
]
operations = [
migrations.CreateModel(
name='Organisation',
fields=[
('id', models.AutoField(verbose_name='ID', auto_created=True, primary_key=True, serialize=False)),
('name', models.CharField(max_length=50)),
('phone', models.CharField(null=True, blank=True, max_length=15)),
('email', models.EmailField(null=True, blank=True, max_length=75)),
('address', models.TextField(null=True, blank=True)),
('notes', models.TextField(null=True, blank=True)),
('unionAccount', models.BooleanField(default=False)),
],
options={
},
bases=(models.Model, RIGS.models.RevisionMixin),
),
]

View File

@@ -44,3 +44,19 @@ class Person(models.Model, RevisionMixin):
string += "*"
return string
@reversion.register
class Organisation(models.Model, RevisionMixin):
name = models.CharField(max_length=50)
phone = models.CharField(max_length=15, blank=True, null=True)
email = models.EmailField(blank=True, null=True)
address = models.TextField(blank=True, null=True)
notes = models.TextField(blank=True, null=True)
unionAccount = models.BooleanField(default=False)
def __unicode__(self):
string = self.name
if len(self.notes) > 0:
string += "*"
return string