]> git.openstreetmap.org Git - osqa.git/blob - osqa/forum_modules/pgfulltext/management.py
487580ff6ef66d438aea3be9a0d90b9130c6d8a9
[osqa.git] / osqa / forum_modules / pgfulltext / management.py
1 import os
2
3 from django.db import connection, transaction
4 from django.conf import settings
5
6 import forum.models
7
8 if settings.DATABASE_ENGINE in ('postgresql_psycopg2', 'postgresql', ):
9     from django.db.models.signals import post_syncdb
10
11     def setup_pgfulltext(sender, **kwargs):
12         if sender == forum.models:
13            install_pg_fts()
14
15     post_syncdb.connect(setup_pgfulltext)
16
17 def install_pg_fts():
18     f = open(os.path.join(os.path.dirname(__file__), 'pg_fts_install.sql'), 'r')
19     
20     try:
21         cursor = connection.cursor()
22         cursor.execute(f.read())
23         transaction.commit_unless_managed()
24     except:
25         pass
26     finally:
27         cursor.close()
28
29     f.close()