[copr] master: Update the logic (0de746e)

bkabrda at fedoraproject.org bkabrda at fedoraproject.org
Mon Jan 28 09:30:04 UTC 2013


Repository : http://git.fedorahosted.org/cgit/copr.git

On branch  : master

>---------------------------------------------------------------

commit 0de746efc3b5fa66a522fc76ee7ff90fd7e94214
Author: Pierre-Yves Chibon <pingou at pingoured.fr>
Date:   Mon Jan 28 09:06:23 2013 +0100

    Update the logic
    
    - The check_for_duplicates should be a parameter since the logic can be called from
    the API where the form validation is different
    
    - When raising an error, give an error message, this way when the API calls the function
    and catch the error, it can make something of it.


>---------------------------------------------------------------

 coprs_frontend/coprs/config.py            |    1 +
 coprs_frontend/coprs/logic/coprs_logic.py |   15 +++++++++------
 2 files changed, 10 insertions(+), 6 deletions(-)

diff --git a/coprs_frontend/coprs/config.py b/coprs_frontend/coprs/config.py
index 6218ea9..3ab0410 100644
--- a/coprs_frontend/coprs/config.py
+++ b/coprs_frontend/coprs/config.py
@@ -24,6 +24,7 @@ class Config(object):
 
 class ProductionConfig(Config):
     DEBUG = False
+    SQLALCHEMY_DATABASE_URI = 'postgresql+psycopg2://bkabrda:pass@/copr'
 
 class DevelopmentConfig(Config):
     DEBUG = True
diff --git a/coprs_frontend/coprs/logic/coprs_logic.py b/coprs_frontend/coprs/logic/coprs_logic.py
index a862055..a27668e 100644
--- a/coprs_frontend/coprs/logic/coprs_logic.py
+++ b/coprs_frontend/coprs/logic/coprs_logic.py
@@ -47,7 +47,8 @@ class CoprsLogic(object):
         return query
 
     @classmethod
-    def add(cls, user, name, repos, selected_chroots, description, instructions):
+    def add(cls, user, name, repos, selected_chroots, description,
+        instructions, check_for_duplicates=False):
         copr = models.Copr(name=name,
                            repos=repos,
                            owner=user,
@@ -55,21 +56,23 @@ class CoprsLogic(object):
                            instructions=instructions,
                            created_on=int(time.time()))
         CoprsLogic.new(user, copr,
-            check_for_duplicates=False) # form validation checks for duplicates
+            check_for_duplicates=check_for_duplicates) # form validation checks for duplicates
         CoprChrootsLogic.new_from_names(user, copr,
             selected_chroots)
         return copr
 
     @classmethod
     def new(cls, user, copr, check_for_duplicates = True):
-        if check_for_duplicates and cls.exists_for_current_user(user, copr.name):
-            raise exceptions.DuplicateCoprNameException
+        if check_for_duplicates and cls.exists_for_current_user(user, copr.name).all():
+            raise exceptions.DuplicateCoprNameException(
+                'Copr: "{0}" already exists'.format(copr.name))
         db.session.add(copr)
 
     @classmethod
     def update(cls, user, copr, check_for_duplicates = True):
-        if check_for_duplicates and cls.exists_for_current_user(user, copr.name):
-            raise exceptions.DuplicateCoprNameException
+        if check_for_duplicates and cls.exists_for_current_user(user, copr.name).all():
+            raise exceptions.DuplicateCoprNameException(
+                'Copr: "{0}" already exists'.format(copr.name))
         db.session.add(copr)
 
     @classmethod



More information about the copr-devel mailing list