|
| 1 | +# Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
| 2 | +# All rights reserved. Contact: Pasi Eronen <pasi.eronen@nokia.com> |
| 3 | +# |
| 4 | +# Redistribution and use in source and binary forms, with or without |
| 5 | +# modification, are permitted provided that the following conditions |
| 6 | +# are met: |
| 7 | +# |
| 8 | +# * Redistributions of source code must retain the above copyright |
| 9 | +# notice, this list of conditions and the following disclaimer. |
| 10 | +# |
| 11 | +# * Redistributions in binary form must reproduce the above |
| 12 | +# copyright notice, this list of conditions and the following |
| 13 | +# disclaimer in the documentation and/or other materials provided |
| 14 | +# with the distribution. |
| 15 | +# |
| 16 | +# * Neither the name of the Nokia Corporation and/or its |
| 17 | +# subsidiary(-ies) nor the names of its contributors may be used |
| 18 | +# to endorse or promote products derived from this software |
| 19 | +# without specific prior written permission. |
| 20 | +# |
| 21 | +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 22 | +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 23 | +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 24 | +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 25 | +# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 26 | +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 27 | +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 28 | +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 29 | +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 30 | +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 31 | +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 32 | + |
| 33 | +from ietf import settings |
| 34 | +from django.core import management |
| 35 | +management.setup_environ(settings) |
| 36 | + |
| 37 | +from django.db.models.fields import CharField, TextField |
| 38 | +from django import db |
| 39 | +from django.db import models |
| 40 | + |
| 41 | +cursor = db.connection.cursor() |
| 42 | + |
| 43 | +def check_non_ascii(model, field): |
| 44 | + #print " Checking", field.column |
| 45 | + sql = "SELECT src.%s,src.%s FROM %s AS src WHERE src.%s RLIKE '[^\\t-~]+'" % (model._meta.pk.column, field.column, model._meta.db_table, field.column) |
| 46 | + #print sql |
| 47 | + cursor.execute(sql) |
| 48 | + rows = cursor.fetchall() |
| 49 | + if len(rows) > 0: |
| 50 | + print " NON-ASCII: %s.%s (%d rows)" % (model._meta.db_table,field.column, len(rows)) |
| 51 | + #for row in rows[0:20]: |
| 52 | + # print " ", row |
| 53 | + #print " Use the following SQL to debug:" |
| 54 | + #print sql |
| 55 | + |
| 56 | +APPS = ['announcements', 'idrfc','idtracker','iesg','ietfauth','ipr','liaisons','proceedings','redirects'] |
| 57 | +all_models = [] |
| 58 | +for app_label in APPS: |
| 59 | + all_models.extend(models.get_models(models.get_app(app_label))) |
| 60 | + |
| 61 | +for model in all_models: |
| 62 | + print "\nChecking %s (table %s)" % (model._meta.object_name, model._meta.db_table) |
| 63 | + for f in model._meta.fields: |
| 64 | + if isinstance(f, CharField) or isinstance(f, TextField): |
| 65 | + check_non_ascii(model,f) |
0 commit comments