mirror of
https://github.com/nottinghamtec/PyRIGS.git
synced 2026-01-17 05:22:16 +00:00
Organisational import
This commit is contained in:
@@ -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()
|
||||
30
RIGS/migrations/0004_organisation.py
Normal file
30
RIGS/migrations/0004_organisation.py
Normal 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),
|
||||
),
|
||||
]
|
||||
@@ -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
|
||||
Reference in New Issue
Block a user