Author: rjollos
Date: Tue Mar  4 20:50:32 2014
New Revision: 1574195

URL: http://svn.apache.org/r1574195
Log:
0.8dev: When attempting to add a product, preserve form data when a warning is 
raised. Refs #661.

The warning messages were also made more specific.

Modified:
    bloodhound/trunk/bloodhound_multiproduct/multiproduct/product_admin.py
    
bloodhound/trunk/bloodhound_multiproduct/multiproduct/templates/admin_products.html
    bloodhound/trunk/bloodhound_theme/bhtheme/templates/bh_admin_products.html

Modified: bloodhound/trunk/bloodhound_multiproduct/multiproduct/product_admin.py
URL: 
http://svn.apache.org/viewvc/bloodhound/trunk/bloodhound_multiproduct/multiproduct/product_admin.py?rev=1574195&r1=1574194&r2=1574195&view=diff
==============================================================================
--- bloodhound/trunk/bloodhound_multiproduct/multiproduct/product_admin.py 
(original)
+++ bloodhound/trunk/bloodhound_multiproduct/multiproduct/product_admin.py Tue 
Mar  4 20:50:32 2014
@@ -85,6 +85,7 @@ class ProductAdminPanel(TicketAdminPanel
                       'description':description,
                       'owner':owner,
                       }
+        data = {}
 
         # Detail view?
         if product:
@@ -105,27 +106,38 @@ class ProductAdminPanel(TicketAdminPanel
             default = self.config.get('ticket', 'default_product')
             if req.method == 'POST':
                 # Add Product
-                if req.args.get('add') and req.args.get('prefix'):
+                if req.args.get('add'):
                     req.perm.require('PRODUCT_CREATE')
-                    if not owner:
-                        add_warning(req, _('All fields are required!'))
-                        req.redirect(req.href.admin(cat, page))
-
-                    try:
-                        prod = Product(self.env, keys)
-                    except ResourceNotFound:
-                        prod = Product(self.env)
-                        prod.update_field_dict(keys)
-                        prod.update_field_dict(field_data)
-                        prod.insert()
-                        add_notice(req, _('The product "%(id)s" has been 
added.',
-                                          id=prefix))
-                        req.redirect(req.href.admin(cat, page))
+                    if not (prefix and name and owner):
+                        if not prefix:
+                            add_warning(req, _("You must provide a prefix "
+                                               "for the product."))
+                        if not name:
+                            add_warning(req, _("You must provide a name "
+                                               "for the product."))
+                        if not owner:
+                            add_warning(req, _("You must provide an owner "
+                                               "for the product."))
+                        data['prefix'] = prefix
+                        data['name'] = name
+                        data['owner'] = owner
+                        print data
                     else:
-                        if prod.prefix is None:
-                            raise TracError(_('Invalid product id.'))
-                        raise TracError(_("Product %(id)s already exists.",
-                                          id=prefix))
+                        try:
+                            prod = Product(self.env, keys)
+                        except ResourceNotFound:
+                            prod = Product(self.env)
+                            prod.update_field_dict(keys)
+                            prod.update_field_dict(field_data)
+                            prod.insert()
+                            add_notice(req, _('The product "%(id)s" has been '
+                                              'added.', id=prefix))
+                            req.redirect(req.href.admin(cat, page))
+                        else:
+                            if prod.prefix is None:
+                                raise TracError(_('Invalid product id.'))
+                            raise TracError(_("Product %(id)s already exists.",
+                                              id=prefix))
 
                 # Remove product
                 elif req.args.get('remove'):
@@ -149,10 +161,9 @@ class ProductAdminPanel(TicketAdminPanel
                     _save_config(self.config, req, self.log)
                     req.redirect(req.href.admin(cat, page))
 
-            products = Product.select(self.env)
-            data = {'view': 'list',
-                    'products': products,
-                    'default': default}
+            data['view'] = 'list'
+            data['products'] = Product.select(self.env)
+            data['default'] = default
         if self.config.getbool('ticket', 'restrict_owner'):
             perm = PermissionSystem(self.env)
             def valid_owner(username):

Modified: 
bloodhound/trunk/bloodhound_multiproduct/multiproduct/templates/admin_products.html
URL: 
http://svn.apache.org/viewvc/bloodhound/trunk/bloodhound_multiproduct/multiproduct/templates/admin_products.html?rev=1574195&r1=1574194&r2=1574195&view=diff
==============================================================================
--- 
bloodhound/trunk/bloodhound_multiproduct/multiproduct/templates/admin_products.html
 (original)
+++ 
bloodhound/trunk/bloodhound_multiproduct/multiproduct/templates/admin_products.html
 Tue Mar  4 20:50:32 2014
@@ -86,12 +86,12 @@ $product.description</textarea>
           <fieldset>
             <legend>Add Product:</legend>
             <div class="field">
-              <label>Prefix:<br /><input type="text" name="prefix" /></label>
+              <label>Prefix:<br /><input type="text" name="prefix" 
value="$prefix" /></label>
             </div>
             <div class="field">
-              <label>Name:<br /><input type="text" name="name" /></label>
+              <label>Name:<br /><input type="text" name="name" value="$name" 
/></label>
             </div>
-            ${owner_field()}
+            ${owner_field(owner)}
             <div class="buttons">
               <input type="submit" name="add" value="${_('Add')}"/>
             </div>

Modified: 
bloodhound/trunk/bloodhound_theme/bhtheme/templates/bh_admin_products.html
URL: 
http://svn.apache.org/viewvc/bloodhound/trunk/bloodhound_theme/bhtheme/templates/bh_admin_products.html?rev=1574195&r1=1574194&r2=1574195&view=diff
==============================================================================
--- bloodhound/trunk/bloodhound_theme/bhtheme/templates/bh_admin_products.html 
(original)
+++ bloodhound/trunk/bloodhound_theme/bhtheme/templates/bh_admin_products.html 
Tue Mar  4 20:50:32 2014
@@ -105,16 +105,17 @@
                   <label class="control-label" for="prefix">Prefix:</label>
                   <div class="controls">
                     <input type="text" id="prefix" class="input-large"
-                           name="prefix" />
+                           name="prefix" value="$prefix" />
                   </div>
                 </div>
                 <div class="control-group">
                   <label class="control-label" for="name">Name:</label>
                   <div class="controls">
-                    <input type="text" id="name" class="input-large" 
name="name" />
+                    <input type="text" id="name" class="input-large"
+                           name="name" value="$name" />
                   </div>
                 </div>
-                ${owner_field()}
+                ${owner_field(owner)}
                 <div class="control-group">
                   <input type="submit" class="btn" name="add"
                          value="${_('Add')}" />


Reply via email to