diff options
| -rw-r--r-- | scripts/history_duplicate_clean.py | 31 | ||||
| -rwxr-xr-x | scripts/import_from_csv.py | 68 | 
2 files changed, 0 insertions, 99 deletions
| diff --git a/scripts/history_duplicate_clean.py b/scripts/history_duplicate_clean.py deleted file mode 100644 index 61d358720..000000000 --- a/scripts/history_duplicate_clean.py +++ /dev/null @@ -1,31 +0,0 @@ -""" -Clean duplicate in history. -This should be unecessary now. -""" - -import datetime -from archaeological_operations.models import Operation, AdministrativeAct -from archaeological_files.models import File -from archaeological_context_records.models import ContextRecord -from archaeological_finds.models import Find, BaseFind, Treatment - -nb_deleted = {} -to_delete = [] -for model in [Operation, File, ContextRecord, AdministrativeAct, Find, -              BaseFind, Treatment]: -    nb_deleted[model.__name__] = 0 -    for item in model.objects.all()[0:]: -        c_user, c_date = None, None -        for h in item.history.order_by('-history_modifier_id', '-history_date', -                                       '-history_id').all(): -            if c_user and c_date and h.history_modifier_id == c_user and \ -               c_date - h.history_date < datetime.timedelta(seconds=5): -                to_delete.append(h) -            c_user = h.history_modifier_id -            c_date = h.history_date -        nb_deleted[model.__name__] += len(to_delete) - -for item in to_delete: -    item.delete() -for m in nb_deleted: -    print "* %d deleted for %s" % (nb_deleted[m], m) diff --git a/scripts/import_from_csv.py b/scripts/import_from_csv.py deleted file mode 100755 index 9640f1851..000000000 --- a/scripts/import_from_csv.py +++ /dev/null @@ -1,68 +0,0 @@ -#!/usr/bin/python -# -*- coding: utf-8 -*- - -""" -Import departements and towns from csv file -""" - -DELIMITER = "," -QUOTECHAR = '"' - -import sys -import csv -sys.path.append('.') - -from django.core.management import setup_environ -import settings - -setup_environ(settings) - -from optparse import OptionParser - -from ishtar_common import models - -def insert_department(value): -    idx, label = value -    if models.Department.objects.filter(number=idx).count(): -        return -    models.Department(number=idx, label=label).save() -    print idx, label, u" inserted" - -def insert_town(value): -    idx, label = value -    if models.Town.objects.filter(numero_insee=idx).count(): -        return -    try: -        dpt = models.Department.objects.get(number=idx[:2]) -    except: -        return -    models.Town(numero_insee=idx, name=label, departement=dpt).save() -    print idx, label, u" inserted" - -tables = {u"department":insert_department, -          u"town":insert_town} - -usage = u"usage: %%prog csv_file.csv table_name\n\n"\ -        u"Table name must be in: %s." % u", ".join(tables.keys()) -parser = OptionParser(usage=usage) - -(options, args) = parser.parse_args() - -try: -    assert len(args) == 2 -except AssertionError: -    parser.error(u"You must provide one csv file and the table name.") - -try: -    assert args[1] in tables.keys() -except AssertionError: -    parser.error(u"Incorrect table name.") - -try: -    values = csv.reader(open(args[0], 'rb'), delimiter=DELIMITER, -                    quotechar=QUOTECHAR) -except (IOError): -    parser.error(u"Incorrect CSV file.") - -for value in values: -    tables[args[1]](value) | 
