You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@bloodhound.apache.org by rj...@apache.org on 2014/03/03 08:07:53 UTC

svn commit: r1573459 - in /bloodhound/trunk/bloodhound_theme/bhtheme: htdocs/bloodhound.css templates/bloodhound_theme.html theme.py

Author: rjollos
Date: Mon Mar  3 07:07:53 2014
New Revision: 1573459

URL: http://svn.apache.org/r1573459
Log:
0.8dev: Fixed regression in r1570616: the product at scope is no longer the default selection. Refs #727.

The code in `theme.py` was also refactored to simplify preparation of the `options` dictionary.

Modified:
    bloodhound/trunk/bloodhound_theme/bhtheme/htdocs/bloodhound.css
    bloodhound/trunk/bloodhound_theme/bhtheme/templates/bloodhound_theme.html
    bloodhound/trunk/bloodhound_theme/bhtheme/theme.py

Modified: bloodhound/trunk/bloodhound_theme/bhtheme/htdocs/bloodhound.css
URL: http://svn.apache.org/viewvc/bloodhound/trunk/bloodhound_theme/bhtheme/htdocs/bloodhound.css?rev=1573459&r1=1573458&r2=1573459&view=diff
==============================================================================
--- bloodhound/trunk/bloodhound_theme/bhtheme/htdocs/bloodhound.css (original)
+++ bloodhound/trunk/bloodhound_theme/bhtheme/htdocs/bloodhound.css Mon Mar  3 07:07:53 2014
@@ -343,7 +343,7 @@ ol.arabic     { list-style-type: decimal
  margin-bottom: 5px;
 }
 #qct-more {
-    visibility: hidden;
+ visibility: hidden;
 }
 
 /*

Modified: bloodhound/trunk/bloodhound_theme/bhtheme/templates/bloodhound_theme.html
URL: http://svn.apache.org/viewvc/bloodhound/trunk/bloodhound_theme/bhtheme/templates/bloodhound_theme.html?rev=1573459&r1=1573458&r2=1573459&view=diff
==============================================================================
--- bloodhound/trunk/bloodhound_theme/bhtheme/templates/bloodhound_theme.html (original)
+++ bloodhound/trunk/bloodhound_theme/bhtheme/templates/bloodhound_theme.html Mon Mar  3 07:07:53 2014
@@ -117,13 +117,15 @@
               <!--! create ticket button + dropdown -->
               <py:def function="field_select(field)">
                 <select id="field-${field.name}" name="field_${field.name}"
-                    class="input-block-level" data-field="${field.name}" data-optional="${'true' if field.optional else 'false'}">
+                        class="input-block-level" data-field="${field.name}"
+                        data-optional="${'true' if field.optional else 'false'}">
                   <option value="">${'' if field.optional else 'Choose...'}</option>
-                  <option py:for="idx,option in enumerate(field.options)"
-                          py:with="description = field.options_desc[idx] if field.options_desc else option"
-                          selected="${field.value == option or None}"
-                          value = "${option.value}"
-                          data-product-new-ticket-url = "${option.product_new_ticket_url}"
+                  <option py:for="option in field.options"
+                          py:with="description = option.description or option;
+                                   value = option.value or option"
+                          selected="${field.value == value or None}"
+                          value = "$value"
+                          data-product-new-ticket-url = "$option.new_ticket_url"
                           py:content="description"></option>
                   <optgroup py:for="optgroup in field.optgroups"
                             py:if="optgroup.options"

Modified: bloodhound/trunk/bloodhound_theme/bhtheme/theme.py
URL: http://svn.apache.org/viewvc/bloodhound/trunk/bloodhound_theme/bhtheme/theme.py?rev=1573459&r1=1573458&r2=1573459&view=diff
==============================================================================
--- bloodhound/trunk/bloodhound_theme/bhtheme/theme.py (original)
+++ bloodhound/trunk/bloodhound_theme/bhtheme/theme.py Mon Mar  3 07:07:53 2014
@@ -47,7 +47,6 @@ from bhdashboard.web_ui import Dashboard
 from bhdashboard import wiki
 
 from multiproduct.env import ProductEnvironment
-from multiproduct.model import Product
 from multiproduct.web_ui import PRODUCT_RE, ProductModule
 from bhtheme.translation import _, add_domain
 
@@ -532,7 +531,7 @@ class QuickCreateTicketDialog(Component)
         locale_dir = pkg_resources.resource_filename(__name__, 'locale')
         add_domain(self.env.path, locale_dir)
         super(QuickCreateTicketDialog, self).__init__(*args, **kwargs)
-        
+
     # IRequestFilter(Interface):
 
     def pre_process_request(self, req, handler):
@@ -556,26 +555,31 @@ class QuickCreateTicketDialog(Component)
             dum_req.perm = req.perm
             ticket = Ticket(self.env)
             tm._populate(dum_req, ticket, False)
-            all_fields = dict([f['name'], self.add_prod_new_ticket_url(dum_req, f)]
+            all_fields = dict([f['name'], f]
                               for f in tm._prepare_fields(dum_req, ticket)
                               if f['type'] == 'select')
 
             product_field = all_fields.get('product')
             if product_field:
-                # Filter out products for which user doesn't have TICKET_CREATE
-                product_field['options'] = \
-                    [prefix for prefix in product_field['options']
-                     if req.perm.has_permission('TICKET_CREATE',
-                                                Neighborhood('product', prefix['value'])
-                                                    .child(None, None))]
-
+                # When at product scope, set the default selection to the
+                # product at current scope. When at global scope the default
+                # selection is determined by [ticket] default_product
                 if self.env.product and \
                         self.env.product.prefix in product_field['options']:
                     product_field['value'] = self.env.product.prefix
-                product_field['options_desc'] = [
-                    ProductEnvironment.lookup_env(self.env, p['value']).product.name
-                        for p in product_field['options']
-                ]
+                # Transform the options field to dictionary of product
+                # attributes and filter out products for which user doesn't
+                #  have TICKET_CREATE permission
+                product_field['options'] = [
+                    dict(value=p,
+                         new_ticket_url=dum_req.href.products(p, 'newticket'),
+                         description=ProductEnvironment.lookup_env(self.env, p)
+                                                       .product.name
+                    )
+                for p in product_field['options']
+                    if req.perm.has_permission('TICKET_CREATE',
+                                               Neighborhood('product', p)
+                                               .child(None, None))]
             else:
                 msg = _("Missing ticket field '%(field)s'.", field='product')
                 if ProductTicketModule is not None and \
@@ -666,17 +670,5 @@ class QuickCreateTicketDialog(Component)
                                    "of ticket #%s: %s" % (t.id, e))
         return t['product'], t.id
 
-    def add_prod_new_ticket_url(self, req, fields):
-        if fields.get('name') == 'product':
-            options_with_attrs = []
-            for option in fields.get('options', []):
-                options_with_attrs.append({
-                    'value': option,
-                    'product_new_ticket_url': \
-                            req.href.products(option, 'newticket')
-                })
-            fields['options'] = options_with_attrs
-        return fields
-
 from pkg_resources import get_distribution
 application_version = get_distribution('BloodhoundTheme').version