119 | | if settings_dict['NAME'] == '': |
120 | | from django.core.exceptions import ImproperlyConfigured |
121 | | raise ImproperlyConfigured("You need to specify NAME in your Django settings file.") |
122 | | conn_params = { |
123 | | 'database': settings_dict['NAME'], |
124 | | } |
125 | | conn_params.update(settings_dict['OPTIONS']) |
126 | | if 'autocommit' in conn_params: |
127 | | del conn_params['autocommit'] |
128 | | if settings_dict['USER']: |
129 | | conn_params['user'] = settings_dict['USER'] |
130 | | if settings_dict['PASSWORD']: |
131 | | conn_params['password'] = settings_dict['PASSWORD'] |
132 | | if settings_dict['HOST']: |
133 | | conn_params['host'] = settings_dict['HOST'] |
134 | | if settings_dict['PORT']: |
135 | | conn_params['port'] = settings_dict['PORT'] |
136 | | self.connection = Database.connect(**conn_params) |
| 119 | |
| 120 | if 'SERVICE' in settings_dict and settings_dict['SERVICE']: |
| 121 | # The service name exists and is of greater than zero length |
| 122 | self.connection = Database.connect('service=%s' % settings_dict['SERVICE']) |
| 123 | else: |
| 124 | # Connect the normal way |
| 125 | if settings_dict['NAME'] == '': |
| 126 | from django.core.exceptions import ImproperlyConfigured |
| 127 | raise ImproperlyConfigured("You need to specify NAME in your Django settings file.") |
| 128 | conn_params = { |
| 129 | 'database': settings_dict['NAME'], |
| 130 | } |
| 131 | conn_params.update(settings_dict['OPTIONS']) |
| 132 | if 'autocommit' in conn_params: |
| 133 | del conn_params['autocommit'] |
| 134 | if settings_dict['USER']: |
| 135 | conn_params['user'] = settings_dict['USER'] |
| 136 | if settings_dict['PASSWORD']: |
| 137 | conn_params['password'] = settings_dict['PASSWORD'] |
| 138 | if settings_dict['HOST']: |
| 139 | conn_params['host'] = settings_dict['HOST'] |
| 140 | if settings_dict['PORT']: |
| 141 | conn_params['port'] = settings_dict['PORT'] |
| 142 | self.connection = Database.connect(**conn_params) |
| 143 | |
| 144 | # Now that the connection is created, finish up. |