mirror of
https://github.com/nottinghamtec/PyRIGS.git
synced 2026-01-22 07:52:15 +00:00
Changes to importer:
Added delete method to all importers Added nonrig importing Venue import optimisation Reran importer for empty DB Reset password appropriately Added view permission to all models where needed. Migrated DB to reflect. Fixed all print buttons on event detail.
This commit is contained in:
@@ -27,7 +27,9 @@ def setup_cursor():
|
|||||||
def clean_ascii(text):
|
def clean_ascii(text):
|
||||||
return ''.join([i if ord(i) < 128 else '' for i in text])
|
return ''.join([i if ord(i) < 128 else '' for i in text])
|
||||||
|
|
||||||
def import_users():
|
def import_users(delete=False):
|
||||||
|
if(delete):
|
||||||
|
models.Event.objects.get(is_rig=False).delete()
|
||||||
cursor = setup_cursor()
|
cursor = setup_cursor()
|
||||||
if cursor is None:
|
if cursor is None:
|
||||||
return
|
return
|
||||||
@@ -50,7 +52,9 @@ def import_users():
|
|||||||
print("Created " + str(object))
|
print("Created " + str(object))
|
||||||
|
|
||||||
|
|
||||||
def import_people():
|
def import_people(delete=False):
|
||||||
|
if(delete):
|
||||||
|
models.Event.objects.get(is_rig=False).delete()
|
||||||
cursor = setup_cursor()
|
cursor = setup_cursor()
|
||||||
if cursor is None:
|
if cursor is None:
|
||||||
return
|
return
|
||||||
@@ -76,7 +80,9 @@ def import_people():
|
|||||||
print("Found: " + person.__str__())
|
print("Found: " + person.__str__())
|
||||||
|
|
||||||
|
|
||||||
def import_organisations():
|
def import_organisations(delete=False):
|
||||||
|
if(delete):
|
||||||
|
models.Event.objects.get(is_rig=False).delete()
|
||||||
cursor = setup_cursor()
|
cursor = setup_cursor()
|
||||||
if cursor is None:
|
if cursor is None:
|
||||||
return
|
return
|
||||||
@@ -98,7 +104,9 @@ def import_organisations():
|
|||||||
print("Found: " + object.__str__())
|
print("Found: " + object.__str__())
|
||||||
|
|
||||||
|
|
||||||
def import_vat_rates():
|
def import_vat_rates(delete=False):
|
||||||
|
if(delete):
|
||||||
|
models.Event.objects.get(is_rig=False).delete()
|
||||||
cursor = setup_cursor()
|
cursor = setup_cursor()
|
||||||
if cursor is None:
|
if cursor is None:
|
||||||
return
|
return
|
||||||
@@ -122,7 +130,7 @@ def import_venues(delete=False):
|
|||||||
cursor = setup_cursor()
|
cursor = setup_cursor()
|
||||||
if cursor is None:
|
if cursor is None:
|
||||||
return
|
return
|
||||||
sql = """SELECT `venue`, `threephasepower` FROM `eventdetails` WHERE `venue` IS NOT NULL"""
|
sql = """SELECT `venue`, `threephasepower` FROM `eventdetails` GROUP BY `venue` WHERE `venue` IS NOT NULL"""
|
||||||
cursor.execute(sql)
|
cursor.execute(sql)
|
||||||
for row in cursor.fetchall():
|
for row in cursor.fetchall():
|
||||||
print(("Searching for %s", row[0]))
|
print(("Searching for %s", row[0]))
|
||||||
@@ -226,6 +234,26 @@ def import_eventitem(delete=True):
|
|||||||
with reversion.create_revision():
|
with reversion.create_revision():
|
||||||
event.save()
|
event.save()
|
||||||
|
|
||||||
|
def import_nonrigs(delete=False):
|
||||||
|
if(delete):
|
||||||
|
models.Event.objects.get(is_rig=False).delete()
|
||||||
|
cursor = setup_cursor()
|
||||||
|
if cursor is None:
|
||||||
|
return
|
||||||
|
sql = """SELECT name, start_date, start_time, end_date, end_time, description, user_id FROM non_rigs WHERE active = 1;"""
|
||||||
|
cursor.execute(sql)
|
||||||
|
for row in cursor.fetchall():
|
||||||
|
print(row)
|
||||||
|
with transaction.atomic(), reversion.create_revision():
|
||||||
|
event = models.Event()
|
||||||
|
event.name = row[0]
|
||||||
|
event.start_date = row[1]
|
||||||
|
event.start_time = row[2]
|
||||||
|
event.end_date = row[3]
|
||||||
|
event.end_time = row[4]
|
||||||
|
event.description = row[5]
|
||||||
|
event.mic = models.Profile.objects.get(pk=row[6])
|
||||||
|
event.save()
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
# import_users()
|
# import_users()
|
||||||
@@ -233,9 +261,9 @@ def main():
|
|||||||
# import_organisations()
|
# import_organisations()
|
||||||
# import_vat_rates()
|
# import_vat_rates()
|
||||||
# import_venues(True)
|
# import_venues(True)
|
||||||
# import_events()
|
|
||||||
# import_rigs(False)
|
# import_rigs(False)
|
||||||
import_eventitem(True)
|
# import_eventitem(True)
|
||||||
|
import_nonrigs(True)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|||||||
20
RIGS/migrations/0013_auto_20141202_0041.py
Normal file
20
RIGS/migrations/0013_auto_20141202_0041.py
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
from django.db import models, migrations
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('RIGS', '0012_auto_20141106_0253'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='event',
|
||||||
|
name='person',
|
||||||
|
field=models.ForeignKey(blank=True, null=True, to='RIGS.Person'),
|
||||||
|
preserve_default=True,
|
||||||
|
),
|
||||||
|
]
|
||||||
26
RIGS/migrations/0014_auto_20141208_0220.py
Normal file
26
RIGS/migrations/0014_auto_20141208_0220.py
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
from django.db import models, migrations
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('RIGS', '0013_auto_20141202_0041'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='event',
|
||||||
|
name='venue',
|
||||||
|
field=models.ForeignKey(blank=True, to='RIGS.Venue', null=True),
|
||||||
|
preserve_default=True,
|
||||||
|
),
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='eventitem',
|
||||||
|
name='event',
|
||||||
|
field=models.ForeignKey(related_name='items', blank=True, to='RIGS.Event'),
|
||||||
|
preserve_default=True,
|
||||||
|
),
|
||||||
|
]
|
||||||
30
RIGS/migrations/0015_auto_20141208_0233.py
Normal file
30
RIGS/migrations/0015_auto_20141208_0233.py
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
from django.db import models, migrations
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('RIGS', '0014_auto_20141208_0220'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterModelOptions(
|
||||||
|
name='event',
|
||||||
|
options={'permissions': (('view_event', 'Can view Events'),)},
|
||||||
|
),
|
||||||
|
migrations.AlterModelOptions(
|
||||||
|
name='organisation',
|
||||||
|
options={'permissions': (('view_organisation', 'Can view Organisations'),)},
|
||||||
|
),
|
||||||
|
migrations.AlterModelOptions(
|
||||||
|
name='person',
|
||||||
|
options={'permissions': (('view_person', 'Can view Persons'),)},
|
||||||
|
),
|
||||||
|
migrations.AlterModelOptions(
|
||||||
|
name='venue',
|
||||||
|
options={'permissions': (('view_venue', 'Can view Venues'),)},
|
||||||
|
),
|
||||||
|
]
|
||||||
@@ -24,6 +24,7 @@ class Profile(AbstractUser):
|
|||||||
def name(self):
|
def name(self):
|
||||||
return self.get_full_name() + ' "' + self.initials + '"'
|
return self.get_full_name() + ' "' + self.initials + '"'
|
||||||
|
|
||||||
|
|
||||||
class RevisionMixin(object):
|
class RevisionMixin(object):
|
||||||
@property
|
@property
|
||||||
def last_edited_at(self):
|
def last_edited_at(self):
|
||||||
@@ -52,6 +53,11 @@ class Person(models.Model, RevisionMixin):
|
|||||||
string += "*"
|
string += "*"
|
||||||
return string
|
return string
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
permissions = (
|
||||||
|
('view_person', 'Can view Persons'),
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
@reversion.register
|
@reversion.register
|
||||||
class Organisation(models.Model, RevisionMixin):
|
class Organisation(models.Model, RevisionMixin):
|
||||||
@@ -69,6 +75,11 @@ class Organisation(models.Model, RevisionMixin):
|
|||||||
if len(self.notes) > 0:
|
if len(self.notes) > 0:
|
||||||
string += "*"
|
string += "*"
|
||||||
return string
|
return string
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
permissions = (
|
||||||
|
('view_organisation', 'Can view Organisations'),
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class VatManager(models.Manager):
|
class VatManager(models.Manager):
|
||||||
@@ -120,6 +131,11 @@ class Venue(models.Model, RevisionMixin):
|
|||||||
if self.notes and len(self.notes) > 0:
|
if self.notes and len(self.notes) > 0:
|
||||||
string += "*"
|
string += "*"
|
||||||
return string
|
return string
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
permissions = (
|
||||||
|
('view_venue', 'Can view Venues'),
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class EventManager(models.Manager):
|
class EventManager(models.Manager):
|
||||||
@@ -170,7 +186,7 @@ class Event(models.Model, RevisionMixin):
|
|||||||
name = models.CharField(max_length=255)
|
name = models.CharField(max_length=255)
|
||||||
person = models.ForeignKey('Person', null=True, blank=True)
|
person = models.ForeignKey('Person', null=True, blank=True)
|
||||||
organisation = models.ForeignKey('Organisation', blank=True, null=True)
|
organisation = models.ForeignKey('Organisation', blank=True, null=True)
|
||||||
venue = models.ForeignKey('Venue')
|
venue = models.ForeignKey('Venue', blank=True, null=True)
|
||||||
description = models.TextField(blank=True, null=True)
|
description = models.TextField(blank=True, null=True)
|
||||||
notes = models.TextField(blank=True, null=True)
|
notes = models.TextField(blank=True, null=True)
|
||||||
status = models.IntegerField(choices=EVENT_STATUS_CHOICES, default=PROVISIONAL)
|
status = models.IntegerField(choices=EVENT_STATUS_CHOICES, default=PROVISIONAL)
|
||||||
@@ -229,6 +245,11 @@ class Event(models.Model, RevisionMixin):
|
|||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return str(self.pk) + ": " + self.name
|
return str(self.pk) + ": " + self.name
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
permissions = (
|
||||||
|
('view_event', 'Can view Events'),
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class EventItem(models.Model):
|
class EventItem(models.Model):
|
||||||
|
|||||||
@@ -107,7 +107,7 @@
|
|||||||
<div class="btn-group btn-page">
|
<div class="btn-group btn-page">
|
||||||
<a href="{% url 'event_update' event.pk %}" class="btn btn-default"><span
|
<a href="{% url 'event_update' event.pk %}" class="btn btn-default"><span
|
||||||
class="glyphicon glyphicon-edit"></span></a>
|
class="glyphicon glyphicon-edit"></span></a>
|
||||||
<a href="{#% url event_print event.pk %#}" class="btn btn-default"><span
|
<a href="{% url 'event_print' event.pk %}" class="btn btn-default"><span
|
||||||
class="glyphicon glyphicon-print"></span></a>
|
class="glyphicon glyphicon-print"></span></a>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -129,7 +129,7 @@
|
|||||||
<div class="btn-group btn-page">
|
<div class="btn-group btn-page">
|
||||||
<a href="{% url 'event_update' event.pk %}" class="btn btn-default"><span
|
<a href="{% url 'event_update' event.pk %}" class="btn btn-default"><span
|
||||||
class="glyphicon glyphicon-edit"></span></a>
|
class="glyphicon glyphicon-edit"></span></a>
|
||||||
<a href="{#% url event_print event.pk %#}" class="btn btn-default"><span
|
<a href="{% url 'event_print' event.pk %}" class="btn btn-default"><span
|
||||||
class="glyphicon glyphicon-print"></span></a>
|
class="glyphicon glyphicon-print"></span></a>
|
||||||
</div>
|
</div>
|
||||||
<div>Last edited at {{ object.last_edited_at|date:"SHORT_DATETIME_FORMAT" }} by {{ object.last_edited_by }}.
|
<div>Last edited at {{ object.last_edited_at|date:"SHORT_DATETIME_FORMAT" }} by {{ object.last_edited_by }}.
|
||||||
|
|||||||
Reference in New Issue
Block a user