diff --git a/docs/manual.md b/docs/manual.md index e7a7438d..a1e6427f 100644 --- a/docs/manual.md +++ b/docs/manual.md @@ -966,10 +966,10 @@ Näin tietokantaa voi olla vaikea enään muokata päivityksen jälkeen. On suositeltavaa varmuuskopioida ja nollata tietokanta aina ennen päivittämistä. ``` -python manage.py reset tupa +python manage.py flush ``` -Nollaa tietokannan. Poistaa kaikki tietokantataulut. +Tyhjentää kaikki tietokantataulut. ### Järjestelmän Asetukset - settings.py diff --git a/web/legacy/RenameFixture.py b/web/legacy/RenameFixture.py deleted file mode 100644 index 650b5604..00000000 --- a/web/legacy/RenameFixture.py +++ /dev/null @@ -1,7 +0,0 @@ -if __name__ == "__main__": - source = open("fixtures/old.xml", "r") - koodi = source.read() - source.close() - koodi = koodi.replace("legacy", "tupa") - source = open("fixtures/old.xml", "w") - source.write(koodi) diff --git a/web/legacy/__init__.py b/web/legacy/__init__.py deleted file mode 100644 index e69de29b..00000000 diff --git a/web/legacy/models.py b/web/legacy/models.py deleted file mode 100644 index f7e3a73a..00000000 --- a/web/legacy/models.py +++ /dev/null @@ -1,170 +0,0 @@ -# encoding: utf-8 -# KiPa(KisaPalvelu), tuloslaskentajarjestelma partiotaitokilpailuihin -# Copyright (C) 2010 Espoon Partiotuki ry. ept@partio.fi - - -#!/usr/bin/python - -from django.db import models - - -class Kisa(models.Model): - # gen_legacy_class Kisa - id = models.IntegerField(primary_key=True) - nimi = models.CharField(max_length=255) - aika = models.CharField(max_length=255, blank=True) - paikka = models.CharField(max_length=255) - - class Meta: - db_table = u"tupa_kisa" - - # end_legacy_class - - -class Sarja(models.Model): - # gen_legacy_class Sarja - id = models.IntegerField(primary_key=True) - nimi = models.CharField(max_length=255) - vartion_maksimikoko = models.IntegerField(null=True, blank=True) - vartion_minimikoko = models.IntegerField(null=True, blank=True) - kisa = models.ForeignKey(Kisa) - - class Meta: - db_table = u"tupa_sarja" - - # end_legacy_class - - -class Vartio(models.Model): - # gen_legacy_class Vartio - id = models.IntegerField(primary_key=True) - nro = models.IntegerField() - nimi = models.CharField(max_length=255) - sarja = models.ForeignKey(Sarja) - piiri = models.CharField(max_length=255) - lippukunta = models.CharField(max_length=255) - puhelinnro = models.CharField(max_length=255) - sahkoposti = models.CharField(max_length=255) - osoite = models.CharField(max_length=255) - keskeyttanyt = models.IntegerField(null=True, blank=True) - ulkopuolella = models.IntegerField(null=True, blank=True) - - class Meta: - db_table = u"tupa_vartio" - - # end_legacy_class - - -class Henkilo(models.Model): - # gen_legacy_class Henkilo - id = models.IntegerField(primary_key=True) - nimi = models.CharField(max_length=255) - syntymavuosi = models.IntegerField(null=True, blank=True) - lippukunta = models.CharField(max_length=255, blank=True) - jasennumero = models.CharField(max_length=15, blank=True) - puhelin_nro = models.CharField(max_length=15, blank=True) - homma = models.CharField(max_length=255, blank=True) - - class Meta: - db_table = u"tupa_henkilo" - - # end_legacy_class - - -class Tehtava(models.Model): - # gen_legacy_class Tehtava - id = models.IntegerField(primary_key=True) - nimi = models.CharField(max_length=255) - tehtavaryhma = models.CharField(max_length=255) - tehtavaluokka = models.CharField(max_length=255) - rastikasky = models.TextField() - jarjestysnro = models.IntegerField() - kaava = models.CharField(max_length=255) - sarja = models.ForeignKey(Sarja) - tarkistettu = models.BooleanField() - - class Meta: - db_table = u"tupa_tehtava" - - # end_legacy_class - - -class Osatehtava(models.Model): - # gen_legacy_class Osatehtava - id = models.IntegerField(primary_key=True) - nimi = models.CharField(max_length=255) - tyyppi = models.CharField(max_length=255) - kaava = models.CharField(max_length=255) - tehtava = models.ForeignKey(Tehtava) - - class Meta: - db_table = u"tupa_osatehtava" - - # end_legacy_class - - -class Syotemaarite(models.Model): - # gen_legacy_class Syotemaarite - id = models.IntegerField(primary_key=True) - nimi = models.CharField(max_length=255) - tyyppi = models.CharField(max_length=255) - kali_vihje = models.CharField(max_length=255, blank=True) - osa_tehtava = models.ForeignKey(Osatehtava) - - class Meta: - db_table = u"tupa_syotemaarite" - - # end_legacy_class - - -class Syote(models.Model): - # gen_legacy_class Syote - id = models.IntegerField(primary_key=True) - arvo = models.CharField(max_length=255, blank=True) - vartio = models.ForeignKey(Vartio, null=True, blank=True) - maarite = models.ForeignKey(Syotemaarite) - tarkistus = models.CharField(max_length=255, blank=True) - - class Meta: - db_table = u"tupa_syote" - - # end_legacy_class - - -class Tuomarineuvostulos(models.Model): - # gen_legacy_class Tuomarineuvostulos - id = models.IntegerField(primary_key=True) - vartio = models.ForeignKey(Vartio) - tehtava = models.ForeignKey(Tehtava) - pisteet = models.CharField(max_length=255) - - class Meta: - db_table = u"tupa_tuomarineuvostulos" - - # end_legacy_class - - -class Testaustulos(models.Model): - # gen_legacy_class Testaustulos - id = models.IntegerField(primary_key=True) - vartio = models.ForeignKey(Vartio) - tehtava = models.ForeignKey(Tehtava) - pisteet = models.CharField(max_length=255) - - class Meta: - db_table = u"tupa_testaustulos" - - # end_legacy_class - - -class Parametri(models.Model): - # gen_legacy_class Parametri - id = models.IntegerField(primary_key=True) - nimi = models.CharField(max_length=255) - arvo = models.CharField(max_length=255) - osa_tehtava = models.ForeignKey(Osatehtava) - - class Meta: - db_table = u"tupa_parametri" - - # end_legacy_class diff --git a/web/legacySettings.py b/web/legacySettings.py deleted file mode 100644 index 4d52f733..00000000 --- a/web/legacySettings.py +++ /dev/null @@ -1,3 +0,0 @@ -from settings import * - -INSTALLED_APPS.append("legacy") diff --git a/web/manage.py b/web/manage.py index f90bb5cc..dddd4fb9 100755 --- a/web/manage.py +++ b/web/manage.py @@ -7,7 +7,6 @@ try: import settings # - import legacySettings # Legacy settings for exporting an legacy db except ImportError: import sys @@ -18,8 +17,4 @@ sys.exit(1) if __name__ == "__main__": - set = settings - if len(sys.argv): - if sys.argv[1] == "dumpdata": - set = legacySettings - execute_manager(set) + execute_manager(settings) diff --git a/web/tupa/management/commands/backup_data.py b/web/tupa/management/commands/backup_data.py deleted file mode 100644 index 77865ba5..00000000 --- a/web/tupa/management/commands/backup_data.py +++ /dev/null @@ -1,203 +0,0 @@ -from django.core.exceptions import ImproperlyConfigured -from django.core.management.base import BaseCommand, CommandError -from django.core import serializers -from django.db import connections, router, DEFAULT_DB_ALIAS -from django.utils.datastructures import SortedDict - -from optparse import make_option - - -class Command(BaseCommand): - option_list = BaseCommand.option_list + ( - make_option( - "--format", - default="json", - dest="format", - help="Specifies the output serialization format for fixtures.", - ), - make_option( - "--indent", - default=None, - dest="indent", - type="int", - help="Specifies the indent level to use when pretty-printing output", - ), - make_option( - "--database", - action="store", - dest="database", - default=DEFAULT_DB_ALIAS, - help="Nominates a specific database to load " - 'fixtures into. Defaults to the "default" database.', - ), - make_option( - "-e", - "--exclude", - dest="exclude", - action="append", - default=[], - help="App to exclude (use multiple --exclude to exclude multiple apps).", - ), - make_option( - "-n", - "--natural", - action="store_true", - dest="use_natural_keys", - default=False, - help="Use natural keys if they are available.", - ), - ) - help = "Output the contents of the database as a fixture of the given format." - args = "[appname appname.ModelName ...]" - - def handle(self, *app_labels, **options): - from django.db.models import get_app, get_apps, get_models, get_model - - format = options.get("format", "json") - indent = options.get("indent", None) - using = options.get("database", DEFAULT_DB_ALIAS) - connection = connections[using] - exclude = options.get("exclude", []) - show_traceback = options.get("traceback", False) - use_natural_keys = options.get("use_natural_keys", False) - - excluded_apps = set(get_app(app_label) for app_label in exclude) - - if len(app_labels) == 0: - app_list = SortedDict( - (app, None) for app in get_apps() if app not in excluded_apps - ) - else: - app_list = SortedDict() - for label in app_labels: - try: - app_label, model_label = label.split(".") - try: - app = get_app(app_label) - except ImproperlyConfigured: - raise CommandError("Unknown application: %s" % app_label) - - model = get_model(app_label, model_label) - if model is None: - raise CommandError( - "Unknown model: %s.%s" % (app_label, model_label) - ) - - if app in app_list.keys(): - if app_list[app] and model not in app_list[app]: - app_list[app].append(model) - else: - app_list[app] = [model] - except ValueError: - # This is just an app - no model qualifier - app_label = label - try: - app = get_app(app_label) - except ImproperlyConfigured: - raise CommandError("Unknown application: %s" % app_label) - app_list[app] = None - - # Check that the serialization format exists; this is a shortcut to - # avoid collating all the objects and _then_ failing. - if format not in serializers.get_public_serializer_formats(): - raise CommandError("Unknown serialization format: %s" % format) - - try: - serializers.get_serializer(format) - except KeyError: - raise CommandError("Unknown serialization format: %s" % format) - - # Now collate the objects to be serialized. - objects = [] - for model in sort_dependencies(app_list.items()): - if not model._meta.proxy and router.allow_syncdb(using, model): - objects.extend(model._default_manager.using(using).all()) - - try: - return serializers.serialize( - format, objects, indent=indent, use_natural_keys=use_natural_keys - ) - except Exception, e: - if show_traceback: - raise - raise CommandError("Unable to serialize database: %s" % e) - - -def sort_dependencies(app_list): - """Sort a list of app,modellist pairs into a single list of models. - - The single list of models is sorted so that any model with a natural key - is serialized before a normal model, and any model with a natural key - dependency has it's dependencies serialized first. - """ - from django.db.models import get_model, get_models - - # Process the list of models, and get the list of dependencies - model_dependencies = [] - models = set() - for app, model_list in app_list: - if model_list is None: - model_list = get_models(app) - - for model in model_list: - models.add(model) - # Add any explicitly defined dependencies - if hasattr(model, "natural_key"): - deps = getattr(model.natural_key, "dependencies", []) - if deps: - deps = [get_model(*d.split(".")) for d in deps] - else: - deps = [] - - # Now add a dependency for any FK or M2M relation with - # a model that defines a natural key - for field in model._meta.fields: - if hasattr(field.rel, "to"): - rel_model = field.rel.to - if hasattr(rel_model, "natural_key"): - deps.append(rel_model) - for field in model._meta.many_to_many: - rel_model = field.rel.to - if hasattr(rel_model, "natural_key"): - deps.append(rel_model) - model_dependencies.append((model, deps)) - - model_dependencies.reverse() - # Now sort the models to ensure that dependencies are met. This - # is done by repeatedly iterating over the input list of models. - # If all the dependencies of a given model are in the final list, - # that model is promoted to the end of the final list. This process - # continues until the input list is empty, or we do a full iteration - # over the input models without promoting a model to the final list. - # If we do a full iteration without a promotion, that means there are - # circular dependencies in the list. - model_list = [] - while model_dependencies: - skipped = [] - changed = False - while model_dependencies: - model, deps = model_dependencies.pop() - - # If all of the models in the dependency list are either already - # on the final model list, or not on the original serialization list, - # then we've found another model with all it's dependencies satisfied. - found = True - for candidate in ((d not in models or d in model_list) for d in deps): - if not candidate: - found = False - if found: - model_list.append(model) - changed = True - else: - skipped.append((model, deps)) - if not changed: - raise CommandError( - "Can't resolve dependencies for %s in serialized app list." - % ", ".join( - "%s.%s" % (model._meta.app_label, model._meta.object_name) - for model, deps in sorted(skipped, key=lambda obj: obj[0].__name__) - ) - ) - model_dependencies = skipped - - return model_list diff --git a/web/tupa/management/commands/inspectlegacy.py b/web/tupa/management/commands/inspectlegacy.py deleted file mode 100644 index 839904fb..00000000 --- a/web/tupa/management/commands/inspectlegacy.py +++ /dev/null @@ -1,208 +0,0 @@ -import keyword -from optparse import make_option -import re -from django.core.management.base import NoArgsCommand, CommandError -from django.db import connection - - -class Command(NoArgsCommand): - help = "Introspects the database tables in the given database and outputs a Django model module." - - option_list = NoArgsCommand.option_list + ( - make_option( - "--database", - action="store", - dest="database", - help="Nominates a database to " - 'introspect. Defaults to using the "default" database.', - ), - ) - - requires_model_validation = False - - db_module = "django.db" - - def handle_noargs(self, **options): - source = open("legacy/models.py", "r") - koodi = source.read() - source.close() - try: - koodi = self.handle_inspection(options, koodi) - source = open("legacy/models.py", "w") - source.write(koodi) - except NotImplementedError: - raise CommandError( - "Database inspection isn't supported for the currently selected database backend." - ) - - def handle_inspection(self, options, koodi): - table2model = ( - lambda table_name: table_name.title() - .replace("_", "") - .replace(" ", "") - .replace("-", "") - ) - - cursor = connection.cursor() - - for table_name in connection.introspection.get_table_list(cursor): - - # yield 'class %s(models.Model):' % table2model(table_name) - luokka = table2model(table_name).replace("Tupa", "") - # print luokka - runko = "" - sisennys_haku = re.search( - ".*?(?=#gen_legacy_class " + luokka + "\n)", koodi - ) - sisennys = "" - if sisennys_haku: - sisennys = len(sisennys_haku.group(0)) * " " - - try: - relations = connection.introspection.get_relations(cursor, table_name) - except NotImplementedError: - relations = {} - try: - indexes = connection.introspection.get_indexes(cursor, table_name) - except NotImplementedError: - indexes = {} - for i, row in enumerate( - connection.introspection.get_table_description(cursor, table_name) - ): - column_name = row[0] - att_name = column_name.lower() - comment_notes = ( - [] - ) # Holds Field notes, to be displayed in a Python comment. - extra_params = {} # Holds Field parameters such as 'db_column'. - - # If the column name can't be used verbatim as a Python - # attribute, set the "db_column" for this Field. - if ( - " " in att_name - or "-" in att_name - or keyword.iskeyword(att_name) - or column_name != att_name - ): - extra_params["db_column"] = column_name - - # Modify the field name to make it Python-compatible. - if " " in att_name: - att_name = att_name.replace(" ", "_") - comment_notes.append("Field renamed to remove spaces.") - if "-" in att_name: - att_name = att_name.replace("-", "_") - comment_notes.append("Field renamed to remove dashes.") - if keyword.iskeyword(att_name): - att_name += "_field" - comment_notes.append( - "Field renamed because it was a Python reserved word." - ) - if column_name != att_name: - comment_notes.append("Field name made lowercase.") - - if i in relations: - rel_to = ( - relations[i][1] == table_name - and "'self'" - or table2model(relations[i][1]) - ) - field_type = "ForeignKey(%s" % rel_to - if att_name.endswith("_id"): - att_name = att_name[:-3] - else: - extra_params["db_column"] = column_name - else: - # Calling `get_field_type` to get the field type string and any - # additional paramters and notes. - field_type, field_params, field_notes = self.get_field_type( - connection, table_name, row - ) - extra_params.update(field_params) - comment_notes.extend(field_notes) - - # Add primary_key and unique, if necessary. - if column_name in indexes: - if indexes[column_name]["primary_key"]: - extra_params["primary_key"] = True - elif indexes[column_name]["unique"]: - extra_params["unique"] = True - - field_type += "(" - - # Don't output 'id = meta.AutoField(primary_key=True)', because - # that's assumed if it doesn't exist. - if ( - att_name == "id" - and field_type == "AutoField(" - and extra_params == {"primary_key": True} - ): - continue - - # Add 'null' and 'blank', if the 'null_ok' flag was present in the - # table description. - if row[6]: # If it's NULL... - extra_params["blank"] = True - if not field_type in ("TextField(", "CharField("): - extra_params["null"] = True - - field_desc = "%s = models.%s" % (att_name, field_type) - if extra_params: - if not field_desc.endswith("("): - field_desc += ", " - field_desc += ", ".join( - ["%s=%r" % (k, v) for k, v in extra_params.items()] - ) - field_desc += ")" - if comment_notes: - field_desc += " # " + " ".join(comment_notes) - runko += sisennys + field_desc + "\n" - runko = runko.replace("Tupa", "") - for meta_line in self.get_meta(table_name): - runko += sisennys + meta_line + "\n" - koodi = re.sub( - r"(?s)(?<=#gen_legacy_class " + luokka + "\n).*?#end_legacy_class", - runko + "\n" + sisennys + r"#end_legacy_class", - koodi, - ) - - return koodi - - def get_field_type(self, connection, table_name, row): - """ - Given the database connection, the table name, and the cursor row - description, this routine will return the given field type name, as - well as any additional keyword parameters and notes for the field. - """ - field_params = {} - field_notes = [] - - try: - field_type = connection.introspection.get_field_type(row[1], row) - except KeyError: - field_type = "TextField" - field_notes.append("This field type is a guess.") - - # This is a hook for DATA_TYPES_REVERSE to return a tuple of - # (field_type, field_params_dict). - if type(field_type) is tuple: - field_type, new_params = field_type - field_params.update(new_params) - - # Add max_length for all CharFields. - if field_type == "CharField" and row[3]: - field_params["max_length"] = row[3] - - if field_type == "DecimalField": - field_params["max_digits"] = row[4] - field_params["decimal_places"] = row[5] - - return field_type, field_params, field_notes - - def get_meta(self, table_name): - """ - Return a sequence comprising the lines of code necessary - to construct the inner Meta class for the model corresponding - to the given database table name. - """ - return ["class Meta:", " db_table = %r" % table_name, ""] diff --git a/web/update_db.bat b/web/update_db.bat deleted file mode 100644 index 3b8539bc..00000000 --- a/web/update_db.bat +++ /dev/null @@ -1,20 +0,0 @@ -@echo off -cd /d %~dp0 -rem -r fixtures\old.xml -echo Luodaan legacy datamalli legacy/models.py -..\python\python.exe manage.py inspectlegacy -echo Kopioidaan vanha data tiedostoon fixtures/old.xml -..\python\python.exe manage.py dumpdata tupa --format=xml --indent=4 > fixtures\old.xml -..\python\python.exe legacy\RenameFixture.py -echo Luodaan uuden tietokannan malli tupa\tietokata.dia tiedostosta models.py tiedostoon. -..\python\python.exe tupa\dia2django.py tupa/tietokanta.dia tupa/models.py -echo Nollataan ja p�ivitet��n tietokantataulut. -..\python\python.exe manage.py reset --noinput tupa -echo Ladataan fixturen data uuteen tietokantaan. -..\python\python.exe manage.py loaddata fixture fixtures/old.xml -echo Luodaan tietokantataulu tuloscachelle: -..\python\python.exe manage.py createcachetable tupa_tulos_cache -echo Valmis! -pause - - diff --git a/web/update_db.sh b/web/update_db.sh deleted file mode 100755 index af308344..00000000 --- a/web/update_db.sh +++ /dev/null @@ -1,18 +0,0 @@ -#!/bin/bash -echo Poistetaan vanha tietokanta fixtuuri fixtures/old.xml -rm -r fixtures/old.xml -echo Luodaan legacy datamalli legacy/models.py -python manage.py inspectlegacy -echo Kopioidaan vanha data tiedostoon fixtures/old.xml -python manage.py dumpdata tupa --format=xml --indent=4 > fixtures/old.xml -python legacy/RenameFixture.py -echo Luodaan uuden tietokannan malli tupa/tietokata.dia tiedostosta models.py tiedostoon. -python tupa/dia2django.py tupa/tietokanta.dia tupa/models.py -echo Nollataan ja päivitetään tietokantataulut. -python manage.py reset --noinput tupa -echo Ladataan data uuteen tietokantaan. -python manage.py loaddata fixture fixtures/old.xml -echo Luodaan tietokantataulu tuloscachelle: -python manage.py createcachetable tupa_tulos_cache -echo Valmis! -