added lectures migrator
This commit is contained in:
parent
65b95cddfb
commit
8dea8a0cc8
@ -1,3 +1,7 @@
|
|||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
|
from apps.donar.models import Room, Lecture, Lecture_Terms, VGN_Coords
|
||||||
# Register your models here.
|
# Register your models here.
|
||||||
|
admin.site.register(Room)
|
||||||
|
admin.site.register(Lecture)
|
||||||
|
admin.site.register(Lecture_Terms)
|
||||||
|
admin.site.register(VGN_Coords)
|
||||||
14
ofu_app/apps/donar/management/commands/import_lectures.py
Normal file
14
ofu_app/apps/donar/management/commands/import_lectures.py
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
from django.core.management.base import BaseCommand, CommandError
|
||||||
|
from apps.donar.models import Room
|
||||||
|
from apps.donar.utils import migrate_data_lectures
|
||||||
|
|
||||||
|
|
||||||
|
class Command(BaseCommand):
|
||||||
|
help = "Imports Lectures from UnivIS PRG. Requires Room import"
|
||||||
|
|
||||||
|
def add_arguments(self, parser):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def handle(self, *args, **options):
|
||||||
|
migrate_data_lectures.main()
|
||||||
|
self.stdout.write(self.style.SUCCESS('Successfully migrate data'))
|
||||||
@ -1,6 +1,6 @@
|
|||||||
from django.core.management.base import BaseCommand, CommandError
|
from django.core.management.base import BaseCommand, CommandError
|
||||||
from apps.donar.models import Room
|
from apps.donar.models import Room
|
||||||
from apps.donar.utils import migrate_data
|
from apps.donar.utils import migrate_data_rooms
|
||||||
|
|
||||||
|
|
||||||
class Command(BaseCommand):
|
class Command(BaseCommand):
|
||||||
@ -10,5 +10,5 @@ class Command(BaseCommand):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
def handle(self, *args, **options):
|
def handle(self, *args, **options):
|
||||||
migrate_data.main()
|
migrate_data_rooms.main()
|
||||||
self.stdout.write(self.style.SUCCESS('Successfully migrate data'))
|
self.stdout.write(self.style.SUCCESS('Successfully migrate data'))
|
||||||
|
|||||||
11
ofu_app/apps/donar/management/commands/import_vgn_coords.py
Normal file
11
ofu_app/apps/donar/management/commands/import_vgn_coords.py
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
from django.core.management.base import BaseCommand, CommandError
|
||||||
|
from apps.donar.utils import migrate_data_vgn_coords
|
||||||
|
|
||||||
|
class Command(BaseCommand):
|
||||||
|
help = "Imports Rooms from Univis PRG"
|
||||||
|
|
||||||
|
def add_arguments(self, parser):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def handle(self, *args, **options):
|
||||||
|
migrate_data_vgn_coords.migrate()
|
||||||
@ -1,8 +1,10 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
# Generated by Django 1.11.2 on 2017-10-03 22:01
|
# Generated by Django 1.11.2 on 2017-10-28 17:00
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
import datetime
|
||||||
from django.db import migrations, models
|
from django.db import migrations, models
|
||||||
|
from django.utils.timezone import utc
|
||||||
|
|
||||||
|
|
||||||
class Migration(migrations.Migration):
|
class Migration(migrations.Migration):
|
||||||
@ -13,17 +15,58 @@ class Migration(migrations.Migration):
|
|||||||
]
|
]
|
||||||
|
|
||||||
operations = [
|
operations = [
|
||||||
|
migrations.CreateModel(
|
||||||
|
name='Lecture',
|
||||||
|
fields=[
|
||||||
|
('id', models.AutoField(primary_key=True, serialize=False)),
|
||||||
|
('univis_ref', models.CharField(max_length=60, unique=True)),
|
||||||
|
('univis_id', models.CharField(max_length=60, unique=True)),
|
||||||
|
('name', models.CharField(max_length=60)),
|
||||||
|
('short', models.CharField(max_length=60)),
|
||||||
|
('type', models.CharField(max_length=60)),
|
||||||
|
('lecturer_id', models.CharField(max_length=60)),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
migrations.CreateModel(
|
||||||
|
name='Lecture_Terms',
|
||||||
|
fields=[
|
||||||
|
('id', models.AutoField(primary_key=True, serialize=False)),
|
||||||
|
('starttime', models.TimeField(default=datetime.datetime(2017, 10, 28, 17, 0, 39, 511935, tzinfo=utc))),
|
||||||
|
],
|
||||||
|
),
|
||||||
migrations.CreateModel(
|
migrations.CreateModel(
|
||||||
name='Room',
|
name='Room',
|
||||||
fields=[
|
fields=[
|
||||||
('id', models.AutoField(primary_key=True, serialize=False)),
|
('id', models.AutoField(primary_key=True, serialize=False)),
|
||||||
('key', models.CharField(max_length=60)),
|
('key', models.CharField(default='', max_length=60)),
|
||||||
('address', models.CharField(max_length=60)),
|
('address', models.CharField(default='', max_length=60)),
|
||||||
('building_key', models.CharField(max_length=60)),
|
('building_key', models.CharField(default='', max_length=60)),
|
||||||
('floor', models.CharField(max_length=60)),
|
('floor', models.CharField(default='', max_length=60)),
|
||||||
('name', models.CharField(max_length=60)),
|
('name', models.CharField(default='', max_length=60)),
|
||||||
('orgname', models.CharField(max_length=60)),
|
('orgname', models.CharField(default='', max_length=60)),
|
||||||
('short', models.CharField(max_length=60)),
|
('short', models.CharField(max_length=60, unique=True)),
|
||||||
|
('size', models.CharField(default='', max_length=60)),
|
||||||
|
('description', models.CharField(default='', max_length=200)),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
migrations.CreateModel(
|
||||||
|
name='VGN_Coords',
|
||||||
|
fields=[
|
||||||
|
('id', models.AutoField(primary_key=True, serialize=False)),
|
||||||
|
('name', models.CharField(max_length=60, unique=True)),
|
||||||
|
('coords', models.CharField(max_length=60, unique=True)),
|
||||||
|
('longitude', models.CharField(max_length=60, unique=True)),
|
||||||
|
('latitude', models.CharField(max_length=60, unique=True)),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='lecture_terms',
|
||||||
|
name='room',
|
||||||
|
field=models.ManyToManyField(blank=True, to='donar.Room'),
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='lecture',
|
||||||
|
name='term',
|
||||||
|
field=models.ManyToManyField(to='donar.Lecture_Terms'),
|
||||||
|
),
|
||||||
]
|
]
|
||||||
|
|||||||
@ -1,20 +0,0 @@
|
|||||||
# -*- coding: utf-8 -*-
|
|
||||||
# Generated by Django 1.11.2 on 2017-10-03 22:16
|
|
||||||
from __future__ import unicode_literals
|
|
||||||
|
|
||||||
from django.db import migrations, models
|
|
||||||
|
|
||||||
|
|
||||||
class Migration(migrations.Migration):
|
|
||||||
|
|
||||||
dependencies = [
|
|
||||||
('donar', '0001_initial'),
|
|
||||||
]
|
|
||||||
|
|
||||||
operations = [
|
|
||||||
migrations.AlterField(
|
|
||||||
model_name='room',
|
|
||||||
name='short',
|
|
||||||
field=models.CharField(max_length=60, unique=True),
|
|
||||||
),
|
|
||||||
]
|
|
||||||
22
ofu_app/apps/donar/migrations/0002_auto_20171028_1904.py
Normal file
22
ofu_app/apps/donar/migrations/0002_auto_20171028_1904.py
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
# Generated by Django 1.11.2 on 2017-10-28 17:04
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
import datetime
|
||||||
|
from django.db import migrations, models
|
||||||
|
from django.utils.timezone import utc
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('donar', '0001_initial'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='lecture_terms',
|
||||||
|
name='starttime',
|
||||||
|
field=models.TimeField(default=datetime.datetime(2017, 10, 28, 17, 4, 19, 160312, tzinfo=utc)),
|
||||||
|
),
|
||||||
|
]
|
||||||
@ -1,55 +0,0 @@
|
|||||||
# -*- coding: utf-8 -*-
|
|
||||||
# Generated by Django 1.11.2 on 2017-10-04 00:11
|
|
||||||
from __future__ import unicode_literals
|
|
||||||
|
|
||||||
from django.db import migrations, models
|
|
||||||
|
|
||||||
|
|
||||||
class Migration(migrations.Migration):
|
|
||||||
|
|
||||||
dependencies = [
|
|
||||||
('donar', '0002_auto_20171004_0016'),
|
|
||||||
]
|
|
||||||
|
|
||||||
operations = [
|
|
||||||
migrations.AddField(
|
|
||||||
model_name='room',
|
|
||||||
name='description',
|
|
||||||
field=models.CharField(default='', max_length=200),
|
|
||||||
),
|
|
||||||
migrations.AddField(
|
|
||||||
model_name='room',
|
|
||||||
name='size',
|
|
||||||
field=models.CharField(default='', max_length=60),
|
|
||||||
),
|
|
||||||
migrations.AlterField(
|
|
||||||
model_name='room',
|
|
||||||
name='address',
|
|
||||||
field=models.CharField(default='', max_length=60),
|
|
||||||
),
|
|
||||||
migrations.AlterField(
|
|
||||||
model_name='room',
|
|
||||||
name='building_key',
|
|
||||||
field=models.CharField(default='', max_length=60),
|
|
||||||
),
|
|
||||||
migrations.AlterField(
|
|
||||||
model_name='room',
|
|
||||||
name='floor',
|
|
||||||
field=models.CharField(default='', max_length=60),
|
|
||||||
),
|
|
||||||
migrations.AlterField(
|
|
||||||
model_name='room',
|
|
||||||
name='key',
|
|
||||||
field=models.CharField(default='', max_length=60),
|
|
||||||
),
|
|
||||||
migrations.AlterField(
|
|
||||||
model_name='room',
|
|
||||||
name='name',
|
|
||||||
field=models.CharField(default='', max_length=60),
|
|
||||||
),
|
|
||||||
migrations.AlterField(
|
|
||||||
model_name='room',
|
|
||||||
name='orgname',
|
|
||||||
field=models.CharField(default='', max_length=60),
|
|
||||||
),
|
|
||||||
]
|
|
||||||
22
ofu_app/apps/donar/migrations/0003_auto_20171028_1959.py
Normal file
22
ofu_app/apps/donar/migrations/0003_auto_20171028_1959.py
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
# Generated by Django 1.11.2 on 2017-10-28 17:59
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
import datetime
|
||||||
|
from django.db import migrations, models
|
||||||
|
from django.utils.timezone import utc
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('donar', '0002_auto_20171028_1904'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='lecture_terms',
|
||||||
|
name='starttime',
|
||||||
|
field=models.TimeField(default=datetime.datetime(2017, 10, 28, 17, 59, 39, 456896, tzinfo=utc)),
|
||||||
|
),
|
||||||
|
]
|
||||||
@ -1,37 +0,0 @@
|
|||||||
# -*- coding: utf-8 -*-
|
|
||||||
# Generated by Django 1.11.2 on 2017-10-17 14:03
|
|
||||||
from __future__ import unicode_literals
|
|
||||||
|
|
||||||
from django.db import migrations, models
|
|
||||||
|
|
||||||
|
|
||||||
class Migration(migrations.Migration):
|
|
||||||
|
|
||||||
dependencies = [
|
|
||||||
('donar', '0004_vgn_coords'),
|
|
||||||
]
|
|
||||||
|
|
||||||
operations = [
|
|
||||||
migrations.AddField(
|
|
||||||
model_name='vgn_coords',
|
|
||||||
name='latitude',
|
|
||||||
field=models.CharField(default=0, max_length=60, unique=True),
|
|
||||||
preserve_default=False,
|
|
||||||
),
|
|
||||||
migrations.AddField(
|
|
||||||
model_name='vgn_coords',
|
|
||||||
name='longitude',
|
|
||||||
field=models.CharField(default=0, max_length=60, unique=True),
|
|
||||||
preserve_default=False,
|
|
||||||
),
|
|
||||||
migrations.AlterField(
|
|
||||||
model_name='vgn_coords',
|
|
||||||
name='coords',
|
|
||||||
field=models.CharField(max_length=60, unique=True),
|
|
||||||
),
|
|
||||||
migrations.AlterField(
|
|
||||||
model_name='vgn_coords',
|
|
||||||
name='name',
|
|
||||||
field=models.CharField(max_length=60, unique=True),
|
|
||||||
),
|
|
||||||
]
|
|
||||||
@ -17,6 +17,9 @@ class Room(models.Model):
|
|||||||
size = models.CharField(max_length=MAX_LENGTH, default="")
|
size = models.CharField(max_length=MAX_LENGTH, default="")
|
||||||
description = models.CharField(max_length=200, default="")
|
description = models.CharField(max_length=200, default="")
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return "%s - size: %s" % (self.short, str(self.size))
|
||||||
|
|
||||||
|
|
||||||
class VGN_Coords(models.Model):
|
class VGN_Coords(models.Model):
|
||||||
id = models.AutoField(primary_key=True)
|
id = models.AutoField(primary_key=True)
|
||||||
@ -25,6 +28,9 @@ class VGN_Coords(models.Model):
|
|||||||
longitude = models.CharField(max_length=MAX_LENGTH, unique=True)
|
longitude = models.CharField(max_length=MAX_LENGTH, unique=True)
|
||||||
latitude = models.CharField(max_length=MAX_LENGTH, unique=True)
|
latitude = models.CharField(max_length=MAX_LENGTH, unique=True)
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return "%s" % self.name
|
||||||
|
|
||||||
|
|
||||||
class Lecture(models.Model):
|
class Lecture(models.Model):
|
||||||
id = models.AutoField(primary_key=True)
|
id = models.AutoField(primary_key=True)
|
||||||
@ -36,8 +42,14 @@ class Lecture(models.Model):
|
|||||||
lecturer_id = models.CharField(max_length=MAX_LENGTH)
|
lecturer_id = models.CharField(max_length=MAX_LENGTH)
|
||||||
term = models.ManyToManyField('Lecture_Terms', blank=False)
|
term = models.ManyToManyField('Lecture_Terms', blank=False)
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return "%s - Type: %s" % (self.short, str(self.type))
|
||||||
|
|
||||||
|
|
||||||
class Lecture_Terms(models.Model):
|
class Lecture_Terms(models.Model):
|
||||||
id = models.AutoField(primary_key=True)
|
id = models.AutoField(primary_key=True)
|
||||||
starttime = time = models.TimeField(blank=False, default=timezone.now())
|
starttime = models.TimeField(blank=False, default=timezone.now())
|
||||||
room = models.ManyToManyField('Room', blank=False, blank=True, null=True)
|
room = models.ManyToManyField('Room', blank=True)
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return "%s" % self.starttime.strftime("%Y-%m-%d")
|
||||||
|
|||||||
@ -1,10 +1,8 @@
|
|||||||
|
from apps.donar.models import Room, Lecture_Terms, Lecture
|
||||||
|
from datetime import datetime
|
||||||
import json
|
import json
|
||||||
from pprint import pprint
|
from pprint import pprint
|
||||||
from django.db.utils import IntegrityError
|
from django.db.utils import IntegrityError
|
||||||
from datetime import datetime
|
|
||||||
|
|
||||||
from apps.donar.models import Room, Lecture_Terms, Lecture
|
|
||||||
from apps.donar.utils.parser import univis_rooms_parser
|
|
||||||
from apps.donar.utils.parser import univis_lectures_parser
|
from apps.donar.utils.parser import univis_lectures_parser
|
||||||
|
|
||||||
# CONFIG Fakultaet
|
# CONFIG Fakultaet
|
||||||
@ -29,42 +27,6 @@ def getJsonFromFile(path):
|
|||||||
return json.load(file)
|
return json.load(file)
|
||||||
|
|
||||||
|
|
||||||
def writeUnivisRoomDataInDB(data):
|
|
||||||
for room in data:
|
|
||||||
try:
|
|
||||||
key = ""
|
|
||||||
address = ""
|
|
||||||
building_key = ""
|
|
||||||
floor = ""
|
|
||||||
name = ""
|
|
||||||
orgname = ""
|
|
||||||
short = ""
|
|
||||||
size = ""
|
|
||||||
description = ""
|
|
||||||
if '@key' in room:
|
|
||||||
key = room['@key']
|
|
||||||
if 'address' in room:
|
|
||||||
address = room['address']
|
|
||||||
if 'buildingkey' in room:
|
|
||||||
building_key = room['buildingkey']
|
|
||||||
if 'floor' in room:
|
|
||||||
floor = room['floor']
|
|
||||||
if 'name' in room:
|
|
||||||
name = room['name']
|
|
||||||
if 'short' in room:
|
|
||||||
short = room['short']
|
|
||||||
if 'size' in room:
|
|
||||||
size = room['size']
|
|
||||||
if 'description' in room:
|
|
||||||
description = room['description']
|
|
||||||
|
|
||||||
Room.objects.create(key=key, address=address, building_key=building_key, floor=floor, name=name,
|
|
||||||
orgname=orgname, short=short, size=size, description=description)
|
|
||||||
except IntegrityError:
|
|
||||||
# ignored
|
|
||||||
break
|
|
||||||
|
|
||||||
|
|
||||||
def writeUnivisLectureTermsInDB(lecture, lecture_obj):
|
def writeUnivisLectureTermsInDB(lecture, lecture_obj):
|
||||||
if 'terms' in lecture:
|
if 'terms' in lecture:
|
||||||
if type(lecture['terms']['term']) == list:
|
if type(lecture['terms']['term']) == list:
|
||||||
@ -74,10 +36,10 @@ def writeUnivisLectureTermsInDB(lecture, lecture_obj):
|
|||||||
starttime = "00:00"
|
starttime = "00:00"
|
||||||
if 'starttime' in term:
|
if 'starttime' in term:
|
||||||
starttime = term['starttime']
|
starttime = term['starttime']
|
||||||
term_obj.starttime = datetime.strptime(starttime, "%H%H:%M%M")
|
term_obj.starttime = datetime.strptime(starttime, "%H:%M")
|
||||||
if 'room' in term:
|
if 'room' in term:
|
||||||
room_id = term['room']['UnivISRef']['@key']
|
room_id = term['room']['UnivISRef']['@key']
|
||||||
term_obj.room = Room.objects.get(key=room_id)
|
term_obj.room = [Room.objects.get(key=room_id)]
|
||||||
term_obj.save()
|
term_obj.save()
|
||||||
lecture_obj.term.add(term_obj)
|
lecture_obj.term.add(term_obj)
|
||||||
except IntegrityError as err:
|
except IntegrityError as err:
|
||||||
@ -86,13 +48,16 @@ def writeUnivisLectureTermsInDB(lecture, lecture_obj):
|
|||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
term_obj = Lecture_Terms.objects.create()
|
term_obj = Lecture_Terms.objects.create()
|
||||||
starttime = "00:00"
|
univis_starttime = "00:00"
|
||||||
if 'starttime' in lecture['terms']['term']:
|
if 'starttime' in lecture['terms']['term']:
|
||||||
starttime = lecture['terms']['term']['starttime']
|
univis_starttime = lecture['terms']['term']['starttime']
|
||||||
term_obj.starttime = datetime.strptime(starttime, "%H%H:%M%M")
|
term_obj.starttime = datetime.strptime(univis_starttime, '%H:%M')
|
||||||
if 'room' in lecture['terms']['term']:
|
if 'room' in lecture['terms']['term']:
|
||||||
room_id = lecture['terms']['term']['room']['UnivISRef']['@key']
|
room_id = lecture['terms']['term']['room']['UnivISRef']['@key']
|
||||||
term_obj.room = Room.objects.get(key=room_id)
|
pprint("Room: " + room_id)
|
||||||
|
Room.objects.get(key=room_id)
|
||||||
|
term_obj.room = [Room.objects.get(key=room_id)]
|
||||||
|
|
||||||
term_obj.save()
|
term_obj.save()
|
||||||
lecture_obj.term.add(term_obj)
|
lecture_obj.term.add(term_obj)
|
||||||
except IntegrityError as err:
|
except IntegrityError as err:
|
||||||
@ -124,24 +89,35 @@ def writeUnivisLectureDataInDB(data):
|
|||||||
lecture_type = lecture['type']
|
lecture_type = lecture['type']
|
||||||
if 'dozs' in lecture:
|
if 'dozs' in lecture:
|
||||||
lecturer_id = dict(lecture['dozs']['doz']['UnivISRef'])['@key']
|
lecturer_id = dict(lecture['dozs']['doz']['UnivISRef'])['@key']
|
||||||
|
print("Lecture: " + name)
|
||||||
lecture_obj = Lecture.objects.create(univis_ref=key, univis_id=univis_id, name=name, short=short,
|
lecture_obj = Lecture.objects.create(univis_ref=key, univis_id=univis_id, name=name, short=short,
|
||||||
type=lecture_type, lecturer_id=lecture_type)
|
type=lecture_type, lecturer_id=lecturer_id)
|
||||||
writeUnivisLectureTermsInDB(lecture, lecture_obj)
|
writeUnivisLectureTermsInDB(lecture, lecture_obj)
|
||||||
lecture_obj.save()
|
lecture_obj.save()
|
||||||
except IntegrityError as err:
|
except IntegrityError as err:
|
||||||
print()
|
print(err.args)
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
||||||
|
def showStatus(status: str):
|
||||||
|
print(status)
|
||||||
|
pprint("Lectures: " + str(Lecture.objects.count()))
|
||||||
|
pprint("Lecture Terms: " + str(Lecture_Terms.objects.count()))
|
||||||
|
pprint("Room: " + str(Room.objects.count()))
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
# get food jsons
|
# get food jsons
|
||||||
# writeUnivisRoomDataInDB(univis_rooms_parser.parsePage(univis_rooms(FAKULTAET_GuK)))
|
showStatus("Start with:")
|
||||||
# writeUnivisRoomDataInDB(univis_rooms_parser.parsePage(univis_rooms(FAKULTAET_SoWi)))
|
# writeUnivisLectureDataInDB(univis_lectures_parser.parsePage(univis_lectures(FAKULTAET_SoWi)))
|
||||||
# writeUnivisRoomDataInDB(univis_rooms_parser.parsePage(univis_rooms(FAKULTAET_HuWi)))
|
showStatus("After SoWi:")
|
||||||
# writeUnivisRoomDataInDB(univis_rooms_parser.parsePage(univis_rooms(FAKULTAET_WIAI)))
|
# writeUnivisLectureDataInDB(univis_lectures_parser.parsePage(univis_lectures(FAKULTAET_GuK)))
|
||||||
pprint("Room: " + str(Room.objects.count()))
|
showStatus("After GuK:")
|
||||||
|
writeUnivisLectureDataInDB(univis_lectures_parser.parsePage(univis_lectures(FAKULTAET_HuWi)))
|
||||||
|
showStatus("After HuWi:")
|
||||||
writeUnivisLectureDataInDB(univis_lectures_parser.parsePage(univis_lectures(FAKULTAET_WIAI)))
|
writeUnivisLectureDataInDB(univis_lectures_parser.parsePage(univis_lectures(FAKULTAET_WIAI)))
|
||||||
|
showStatus("After WIAI:")
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
108
ofu_app/apps/donar/utils/migrate_data_rooms.py
Normal file
108
ofu_app/apps/donar/utils/migrate_data_rooms.py
Normal file
@ -0,0 +1,108 @@
|
|||||||
|
import json
|
||||||
|
from pprint import pprint
|
||||||
|
from django.db.utils import IntegrityError
|
||||||
|
|
||||||
|
from apps.donar.models import Room, Lecture_Terms, Lecture
|
||||||
|
from apps.donar.utils.parser import univis_rooms_parser
|
||||||
|
from apps.donar.utils.parser import univis_lectures_parser
|
||||||
|
|
||||||
|
# CONFIG Fakultaet
|
||||||
|
FAKULTAET_GuK = "Fakult%E4t%20Geistes-%20und%20Kulturwissenschaften"
|
||||||
|
FAKULTAET_SoWi = "Fakult%E4t%20Sozial-%20und%20Wirtschaftswissenschaften"
|
||||||
|
FAKULTAET_HuWi = "Fakult%E4t%20Humanwissenschaften"
|
||||||
|
FAKULTAET_WIAI = "Fakult%E4t%20Wirtschaftsinformatik"
|
||||||
|
|
||||||
|
# CONFIG Locations
|
||||||
|
RZ = "http://univis.uni-bamberg.de/prg?search=rooms&name=rz&show=xml"
|
||||||
|
WEBEREI = "http://univis.uni-bamberg.de/prg?search=rooms&name=we&show=xml"
|
||||||
|
FEKI = "http://univis.uni-bamberg.de/prg?search=rooms&name=f&show=xml"
|
||||||
|
MARKUSHAUS = "http://univis.uni-bamberg.de/prg?search=rooms&name=m&show=xml"
|
||||||
|
UNIVERSITAET = "http://univis.uni-bamberg.de/prg?search=rooms&name=u&show=xml"
|
||||||
|
KAPUZINERSTR = "http://univis.uni-bamberg.de/prg?search=rooms&name=k&show=xml"
|
||||||
|
ZWINGER = "http://univis.uni-bamberg.de/prg?search=rooms&name=z&show=xml"
|
||||||
|
AULA = "http://univis.uni-bamberg.de/prg?search=rooms&name=a&show=xml"
|
||||||
|
ZWINGER = "http://univis.uni-bamberg.de/prg?search=rooms&name=k&show=xml"
|
||||||
|
ZWINGER = "http://univis.uni-bamberg.de/prg?search=rooms&name=k&show=xml"
|
||||||
|
|
||||||
|
|
||||||
|
# CONFIG ROOMS
|
||||||
|
def univis_rooms(fakultaet):
|
||||||
|
return "http://univis.uni-bamberg.de/prg?search=rooms&department=" + fakultaet + "&show=xml"
|
||||||
|
|
||||||
|
|
||||||
|
# CONFIG LECTURES
|
||||||
|
def univis_lectures(fakultaet):
|
||||||
|
return "http://univis.uni-bamberg.de/prg?search=lectures&department=" + fakultaet + "&show=exml"
|
||||||
|
|
||||||
|
|
||||||
|
def univis_rooms_loc(kuerzel):
|
||||||
|
return "http://univis.uni-bamberg.de/prg?search=rooms&name=" + kuerzel + "&show=xml"
|
||||||
|
|
||||||
|
|
||||||
|
def getJsonFromFile(path):
|
||||||
|
with open(path, "r") as file:
|
||||||
|
return json.load(file)
|
||||||
|
|
||||||
|
|
||||||
|
def writeUnivisRoomDataInDB(data):
|
||||||
|
for room in data:
|
||||||
|
try:
|
||||||
|
key = ""
|
||||||
|
address = ""
|
||||||
|
building_key = ""
|
||||||
|
floor = ""
|
||||||
|
name = ""
|
||||||
|
orgname = ""
|
||||||
|
short = ""
|
||||||
|
size = ""
|
||||||
|
description = ""
|
||||||
|
if '@key' in room:
|
||||||
|
key = room['@key']
|
||||||
|
if 'address' in room:
|
||||||
|
address = room['address']
|
||||||
|
if 'buildingkey' in room:
|
||||||
|
building_key = room['buildingkey']
|
||||||
|
if 'floor' in room:
|
||||||
|
floor = room['floor']
|
||||||
|
if 'name' in room:
|
||||||
|
name = room['name']
|
||||||
|
if 'short' in room:
|
||||||
|
short = room['short']
|
||||||
|
if 'size' in room:
|
||||||
|
size = room['size']
|
||||||
|
if 'description' in room:
|
||||||
|
description = room['description']
|
||||||
|
|
||||||
|
Room.objects.create(key=key, address=address, building_key=building_key, floor=floor, name=name,
|
||||||
|
orgname=orgname, short=short, size=size, description=description)
|
||||||
|
except IntegrityError as err:
|
||||||
|
pprint(err.args)
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
# get food jsons
|
||||||
|
pprint("Begin: Room: " + str(Room.objects.count()))
|
||||||
|
writeUnivisRoomDataInDB(univis_rooms_parser.parsePage(univis_rooms(FAKULTAET_GuK)))
|
||||||
|
writeUnivisRoomDataInDB(univis_rooms_parser.parsePage(univis_rooms(FAKULTAET_SoWi)))
|
||||||
|
writeUnivisRoomDataInDB(univis_rooms_parser.parsePage(univis_rooms(FAKULTAET_HuWi)))
|
||||||
|
writeUnivisRoomDataInDB(univis_rooms_parser.parsePage(univis_rooms(FAKULTAET_WIAI)))
|
||||||
|
writeUnivisRoomDataInDB(univis_rooms_parser.parsePage(univis_rooms_loc("k")))
|
||||||
|
writeUnivisRoomDataInDB(univis_rooms_parser.parsePage(univis_rooms_loc("z")))
|
||||||
|
writeUnivisRoomDataInDB(univis_rooms_parser.parsePage(univis_rooms_loc("u")))
|
||||||
|
writeUnivisRoomDataInDB(univis_rooms_parser.parsePage(univis_rooms_loc("w")))
|
||||||
|
writeUnivisRoomDataInDB(univis_rooms_parser.parsePage(univis_rooms_loc("f")))
|
||||||
|
writeUnivisRoomDataInDB(univis_rooms_parser.parsePage(univis_rooms_loc("r")))
|
||||||
|
writeUnivisRoomDataInDB(univis_rooms_parser.parsePage(univis_rooms_loc("h")))
|
||||||
|
writeUnivisRoomDataInDB(univis_rooms_parser.parsePage(univis_rooms_loc("l")))
|
||||||
|
writeUnivisRoomDataInDB(univis_rooms_parser.parsePage(univis_rooms_loc("m")))
|
||||||
|
writeUnivisRoomDataInDB(univis_rooms_parser.parsePage(univis_rooms_loc("o")))
|
||||||
|
writeUnivisRoomDataInDB(univis_rooms_parser.parsePage(univis_rooms_loc("p")))
|
||||||
|
writeUnivisRoomDataInDB(univis_rooms_parser.parsePage(univis_rooms_loc("v")))
|
||||||
|
writeUnivisRoomDataInDB(univis_rooms_parser.parsePage(univis_rooms_loc("w")))
|
||||||
|
writeUnivisRoomDataInDB(univis_rooms_parser.parsePage(univis_rooms_loc("d")))
|
||||||
|
|
||||||
|
pprint("Now: Room: " + str(Room.objects.count()))
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
||||||
@ -1,8 +1,7 @@
|
|||||||
from django.core.management.base import BaseCommand, CommandError
|
|
||||||
from apps.donar.models import VGN_Coords
|
from apps.donar.models import VGN_Coords
|
||||||
|
|
||||||
|
|
||||||
def migrate_locations():
|
def migrate():
|
||||||
locations = []
|
locations = []
|
||||||
locations.append(
|
locations.append(
|
||||||
{'location': 'Erba', 'vgn_key': 'coord%3A4418901%3A629758%3ANAV4%3ABamberg%2C An der Weberei 5',
|
{'location': 'Erba', 'vgn_key': 'coord%3A4418901%3A629758%3ANAV4%3ABamberg%2C An der Weberei 5',
|
||||||
@ -65,13 +64,3 @@ def migrate_locations():
|
|||||||
location_obj.coords = location['vgn_key']
|
location_obj.coords = location['vgn_key']
|
||||||
location_obj.latitude = location['lat']
|
location_obj.latitude = location['lat']
|
||||||
location_obj.longitude = location['lon']
|
location_obj.longitude = location['lon']
|
||||||
|
|
||||||
|
|
||||||
class Command(BaseCommand):
|
|
||||||
help = "Imports Rooms from Univis PRG"
|
|
||||||
|
|
||||||
def add_arguments(self, parser):
|
|
||||||
pass
|
|
||||||
|
|
||||||
def handle(self, *args, **options):
|
|
||||||
migrate_locations()
|
|
||||||
@ -1,6 +1,6 @@
|
|||||||
from django.shortcuts import render, redirect
|
from django.shortcuts import render, redirect
|
||||||
|
from django.db.models import Min
|
||||||
from apps.donar.models import Room
|
from apps.donar.models import Room, Lecture, Lecture_Terms
|
||||||
from apps.donar.models import VGN_Coords
|
from apps.donar.models import VGN_Coords
|
||||||
|
|
||||||
|
|
||||||
@ -15,11 +15,12 @@ def all_rooms(request):
|
|||||||
|
|
||||||
|
|
||||||
def search_room(request):
|
def search_room(request):
|
||||||
id = request.GET.get('search_room', None)
|
token = request.GET.get('search_room', None)
|
||||||
if id:
|
if token:
|
||||||
# create a form instance and populate it with data from the request:
|
# create a form instance and populate it with data from the request:
|
||||||
rooms = Room.objects.filter(short__contains=id)
|
rooms_by_id = Room.objects.filter(short__contains=token)
|
||||||
return render(request, 'donar/search_rooms.jinja', {'id': id, 'rooms': rooms})
|
lectures = Lecture.objects.annotate(min_starttime=Min('term__starttime')).filter(name__contains=token).order_by('min_starttime')
|
||||||
|
return render(request, 'donar/search_rooms.jinja', {'id': token, 'rooms': rooms_by_id, 'lectures': lectures})
|
||||||
|
|
||||||
return render(request, 'donar/search_rooms.jinja', {})
|
return render(request, 'donar/search_rooms.jinja', {})
|
||||||
|
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
# Generated by Django 1.11.2 on 2017-10-17 13:34
|
# Generated by Django 1.11.2 on 2017-10-28 17:00
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
from django.db import migrations, models
|
from django.db import migrations, models
|
||||||
@ -8,16 +8,15 @@ from django.db import migrations, models
|
|||||||
class Migration(migrations.Migration):
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
dependencies = [
|
dependencies = [
|
||||||
('donar', '0003_auto_20171004_0211'),
|
('food', '0005_auto_20171020_0549'),
|
||||||
]
|
]
|
||||||
|
|
||||||
operations = [
|
operations = [
|
||||||
migrations.CreateModel(
|
migrations.CreateModel(
|
||||||
name='VGN_Coords',
|
name='Allergene',
|
||||||
fields=[
|
fields=[
|
||||||
('id', models.AutoField(primary_key=True, serialize=False)),
|
('id', models.AutoField(primary_key=True, serialize=False)),
|
||||||
('name', models.CharField(default='', max_length=60, unique=True)),
|
('name', models.CharField(max_length=60, unique=True)),
|
||||||
('coords', models.CharField(default='', max_length=60, unique=True)),
|
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
]
|
]
|
||||||
Binary file not shown.
Binary file not shown.
@ -7,24 +7,45 @@
|
|||||||
<div class="row pt-5">
|
<div class="row pt-5">
|
||||||
<form type="get" action="{{ url('search-rooms') }}" style="margin: 0">
|
<form type="get" action="{{ url('search-rooms') }}" style="margin: 0">
|
||||||
<input id="search_room" type="text" name="search_room" placeholder="Search...">
|
<input id="search_room" type="text" name="search_room" placeholder="Search...">
|
||||||
<button id="search_submit" type="submit">Submit</button>
|
<button id="search_submit" type="submit">Search</button>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
<div class="row mt-4">
|
{% if id %}
|
||||||
{% if id %}
|
<div class="row mt-4">
|
||||||
<h2>Ergebnisse für: {{ id }}</h2>
|
<h2>Ergebnisse für: {{ id }}</h2>
|
||||||
{% endif %}
|
</div>
|
||||||
</div>
|
<div class="row">
|
||||||
<div class="row">
|
{% if rooms %}
|
||||||
{% if rooms %}
|
<h3>Ergebnisse Räume:</h3>
|
||||||
{% for room in rooms %}
|
{% for room in rooms %}
|
||||||
<div class="col-12 p-1">
|
<div class="col-12 p-1">
|
||||||
<div class="p-2 border border-dark rounded-3 border border-dark rounded bg-light text-dark">
|
<div class="p-2 border border-dark rounded-3 border border-dark rounded bg-light text-dark">
|
||||||
<a href="{{ url('show-room', args=[room.short]) }}"><p><strong>Short:</strong> {{ room.short }}</p></a>
|
<a href="{{ url('show-room', args=[room.short]) }}"><p>
|
||||||
|
<strong>Raum:</strong> {{ room.short }}</p></a>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
{% endfor %}
|
||||||
{% endfor %}
|
{% endif %}
|
||||||
{% endif %}
|
</div>
|
||||||
</div>
|
<div class="row">
|
||||||
|
{% if lectures %}
|
||||||
|
<h3>Ergebnisse Lehrveranstaltungen:</h3>
|
||||||
|
{% for lecture in lectures %}
|
||||||
|
<div class="col-12 p-1">
|
||||||
|
<div class="p-2 border border-dark rounded-3 border border-dark rounded bg-light text-dark">
|
||||||
|
<h5>{{ lecture.name }}</h5>
|
||||||
|
{% for term in lecture.term.all() %}
|
||||||
|
<small>Start: {{ term.starttime.strftime("%H:%M") }}</small>
|
||||||
|
{% for room in term.room.all() %}
|
||||||
|
<a href="{{ url('show-room', args=[room.short]) }}"><p>
|
||||||
|
<strong>Raum:</strong> {{ room.short }}</p></a>
|
||||||
|
{% endfor %}
|
||||||
|
{% endfor %}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{% endfor %}
|
||||||
|
{% endif %}
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|||||||
Reference in New Issue
Block a user