# -*- coding: utf-8 -*-
from logical.models import Database
from django.core.exceptions import ObjectDoesNotExist
from system.models import Configuration


def database_name_evironment_constraint(database_name, environment_name):
    try:
        database = Database.objects.get(name=database_name)
    except ObjectDoesNotExist:
        return False
    else:
        dev_envs = Configuration.get_by_name_as_list('dev_envs')
        new_db_env_is_not_dev = environment_name not in dev_envs

        prod_envs = Configuration.get_by_name_as_list('prod_envs')
        db_env_is_prod = database.environment.name in prod_envs

        if new_db_env_is_not_dev and db_env_is_prod:
            return True

@@ -21,98 +21,8 @@
 -*-%0A
-from logical.models import Database%0Afrom django.core.exceptions import ObjectDoesNotExist%0A
 from
@@ -141,17 +141,45 @@
     
-try:%0A    
+from logical.models import Database%0A%0A
     
@@ -186,16 +186,17 @@
 database
+s
  = Datab
@@ -207,19 +207,22 @@
 objects.
-get
+filter
 (name=da
@@ -242,33 +242,24 @@
     
-except ObjectDoesNotExist
+if not databases
 :%0A  
@@ -281,22 +281,9 @@
 lse%0A
-    else:%0A    
+%0A
     
@@ -347,35 +347,10 @@
     
-    new_db_env_is_not_dev =
+if
  env
@@ -363,20 +363,16 @@
 nt_name 
-not 
 in dev_e
@@ -370,30 +370,48 @@
  in dev_envs
-%0A%0A
+:%0A 
     
+   return False%0A%0A
     prod_env
@@ -469,28 +469,28 @@
     
-    db_env_is_prod =
+return any((%0A       
  dat
@@ -525,25 +525,24 @@
 od_envs%0A
-%0A
         
 if new_d
@@ -537,73 +537,32 @@
     
-if new_db_env_is_not_dev and db_env_is_prod:%0A            return True
+for database in databases))
 %0A

improve database validator