def clean_up():
    # Clean up old database records
    cursor = db.cursor()
    cursor.execute("DELETE FROM %s WHERE %s < NOW()" % \
        (db.quote_name('core_sessions'), db.quote_name('expire_date')))
    cursor.execute("DELETE FROM %s WHERE %s < NOW() - INTERVAL '1 week'" % \
        (db.quote_name('registration_challenges'), db.quote_name('request_date')))
    db.commit()
示例#2
0
def get_sql_indexes(mod):
    "Returns a list of the CREATE INDEX SQL statements for the given module."
    from django.core.db import db
    output = []
    for klass in mod._MODELS:
        for f in klass._meta.fields:
            if f.db_index:
                unique = f.unique and "UNIQUE " or ""
                output.append("CREATE %sINDEX %s_%s ON %s (%s);" % \
                    (unique, klass._meta.db_table, f.column,
                    db.quote_name(klass._meta.db_table), db.quote_name(f.column)))
    return output
示例#3
0
def _get_contenttype_insert(opts):
    from django.core.db import db
    return "INSERT INTO %s (%s, %s, %s) VALUES ('%s', '%s', '%s');" % \
        (db.quote_name('content_types'), db.quote_name('name'), db.quote_name('package'),
        db.quote_name('python_module_name'), opts.verbose_name, opts.app_label, opts.module_name)
示例#4
0
def _get_permission_insert(name, codename, opts):
    from django.core.db import db
    return "INSERT INTO %s (%s, %s, %s) VALUES ('%s', '%s', '%s');" % \
        (db.quote_name('auth_permissions'), db.quote_name('name'), db.quote_name('package'),
        db.quote_name('codename'), name.replace("'", "''"), opts.app_label, codename)
示例#5
0
def _get_packages_insert(app_label):
    from django.core.db import db
    return "INSERT INTO %s (%s, %s) VALUES ('%s', '%s');" % \
        (db.quote_name('packages'), db.quote_name('label'), db.quote_name('name'),
        app_label, app_label)