You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@bloodhound.apache.org by ma...@apache.org on 2013/02/22 09:56:12 UTC
svn commit: r1448946 - in
/incubator/bloodhound/branches/bep_0003_multiproduct:
bloodhound_multiproduct/multiproduct/ bloodhound_theme/bhtheme/templates/
Author: matevz
Date: Fri Feb 22 08:56:11 2013
New Revision: 1448946
URL: http://svn.apache.org/r1448946
Log:
#404 - Populate default schema on product addition (initial implementation)
Added:
incubator/bloodhound/branches/bep_0003_multiproduct/bloodhound_multiproduct/multiproduct/util.py
Modified:
incubator/bloodhound/branches/bep_0003_multiproduct/bloodhound_multiproduct/multiproduct/api.py
incubator/bloodhound/branches/bep_0003_multiproduct/bloodhound_multiproduct/multiproduct/product_admin.py
incubator/bloodhound/branches/bep_0003_multiproduct/bloodhound_multiproduct/multiproduct/web_ui.py
incubator/bloodhound/branches/bep_0003_multiproduct/bloodhound_theme/bhtheme/templates/bh_product_view.html
Modified: incubator/bloodhound/branches/bep_0003_multiproduct/bloodhound_multiproduct/multiproduct/api.py
URL: http://svn.apache.org/viewvc/incubator/bloodhound/branches/bep_0003_multiproduct/bloodhound_multiproduct/multiproduct/api.py?rev=1448946&r1=1448945&r2=1448946&view=diff
==============================================================================
--- incubator/bloodhound/branches/bep_0003_multiproduct/bloodhound_multiproduct/multiproduct/api.py (original)
+++ incubator/bloodhound/branches/bep_0003_multiproduct/bloodhound_multiproduct/multiproduct/api.py Fri Feb 22 08:56:11 2013
@@ -68,6 +68,10 @@ class MultiProductSystem(Component):
SCHEMA = [mcls._get_schema() \
for mcls in (Product, ProductResourceMap)]
+ # Tables which should be migrated (extended with 'product' column)
+ MIGRATE_TABLES = ['enum', 'component', 'milestone', 'version', 'permission', 'wiki']
+
+
def get_version(self):
"""Finds the current version of the bloodhound database schema"""
rows = self.env.db_query("""
@@ -136,10 +140,8 @@ class MultiProductSystem(Component):
DEFAULT_PRODUCT = 'default'
- migrate_tables = ['enum', 'component', 'milestone', 'version', 'permission', 'wiki']
-
# extend trac default schema by adding product column and extending key with product
- table_defs = [copy.deepcopy(t) for t in trac.db_default.schema if t.name in migrate_tables]
+ table_defs = [copy.deepcopy(t) for t in trac.db_default.schema if t.name in self.MIGRATE_TABLES]
for t in table_defs:
t.columns.append(Column('product'))
if isinstance(t.key, list):
@@ -170,7 +172,7 @@ class MultiProductSystem(Component):
WHERE product=''""" % DEFAULT_PRODUCT)
self.log.info("Migrating tables to a new schema")
- for table in migrate_tables:
+ for table in self.MIGRATE_TABLES:
cols = ','.join(table_columns[table])
self.log.info("Migrating table '%s' to a new schema", table)
db("CREATE TABLE %s_temp AS SELECT %s FROM %s" %
Modified: incubator/bloodhound/branches/bep_0003_multiproduct/bloodhound_multiproduct/multiproduct/product_admin.py
URL: http://svn.apache.org/viewvc/incubator/bloodhound/branches/bep_0003_multiproduct/bloodhound_multiproduct/multiproduct/product_admin.py?rev=1448946&r1=1448945&r2=1448946&view=diff
==============================================================================
--- incubator/bloodhound/branches/bep_0003_multiproduct/bloodhound_multiproduct/multiproduct/product_admin.py (original)
+++ incubator/bloodhound/branches/bep_0003_multiproduct/bloodhound_multiproduct/multiproduct/product_admin.py Fri Feb 22 08:56:11 2013
@@ -27,6 +27,8 @@ from trac.resource import ResourceNotFou
from model import Product
from trac.util.translation import _, N_, gettext
from trac.web.chrome import Chrome, add_notice, add_warning
+from multiproduct.util import ProductDelegate
+
class ProductAdminPanel(TicketAdminPanel):
"""The Product Admin Panel"""
@@ -74,11 +76,10 @@ class ProductAdminPanel(TicketAdminPanel
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))
+ ProductDelegate.add_product(self.env, prod, keys, field_data)
+ 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:
@@ -88,19 +89,7 @@ class ProductAdminPanel(TicketAdminPanel
# Remove product
elif req.args.get('remove'):
- req.perm.require('PRODUCT_DELETE')
- sel = req.args.get('sel')
- if not sel:
- raise TracError(_('No product selected'))
- if not isinstance(sel, list):
- sel = [sel]
- with self.env.db_transaction:
- for prefix in sel:
- prod = Product(self.env, {'prefix':prefix})
- prod.delete()
- add_notice(req, _("The selected products have been "
- "removed."))
- req.redirect(req.href.admin(cat, page))
+ raise TracError(_('Product removal is not allowed!'))
# Set default product
elif req.args.get('apply'):
Added: incubator/bloodhound/branches/bep_0003_multiproduct/bloodhound_multiproduct/multiproduct/util.py
URL: http://svn.apache.org/viewvc/incubator/bloodhound/branches/bep_0003_multiproduct/bloodhound_multiproduct/multiproduct/util.py?rev=1448946&view=auto
==============================================================================
--- incubator/bloodhound/branches/bep_0003_multiproduct/bloodhound_multiproduct/multiproduct/util.py (added)
+++ incubator/bloodhound/branches/bep_0003_multiproduct/bloodhound_multiproduct/multiproduct/util.py Fri Feb 22 08:56:11 2013
@@ -0,0 +1,44 @@
+
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+"""Bloodhound multiproduct utility APIs"""
+
+from trac import db_default
+from multiproduct.api import MultiProductSystem
+
+class ProductDelegate(object):
+ @staticmethod
+ def add_product(env, product, keys, field_data):
+ product.update_field_dict(keys)
+ product.update_field_dict(field_data)
+ product.insert()
+
+ env.log.debug("Adding product info (%s) to tables:" % product.prefix)
+ with env.db_direct_transaction as db:
+ for table in db_default.get_data(db):
+ if not table[0] in MultiProductSystem.MIGRATE_TABLES:
+ continue
+
+ env.log.debug(" -> %s" % table[0])
+ cols = table[1] + ('product', )
+ rows = [p + (product.prefix, ) for p in table[2]]
+ db.executemany(
+ "INSERT INTO %s (%s) VALUES (%s)" %
+ (table[0], ','.join(cols), ','.join(['%s' for c in cols])),
+ rows)
+
Modified: incubator/bloodhound/branches/bep_0003_multiproduct/bloodhound_multiproduct/multiproduct/web_ui.py
URL: http://svn.apache.org/viewvc/incubator/bloodhound/branches/bep_0003_multiproduct/bloodhound_multiproduct/multiproduct/web_ui.py?rev=1448946&r1=1448945&r2=1448946&view=diff
==============================================================================
--- incubator/bloodhound/branches/bep_0003_multiproduct/bloodhound_multiproduct/multiproduct/web_ui.py (original)
+++ incubator/bloodhound/branches/bep_0003_multiproduct/bloodhound_multiproduct/multiproduct/web_ui.py Fri Feb 22 08:56:11 2013
@@ -34,6 +34,8 @@ from trac.web.chrome import (add_link, a
from trac.web.main import RequestDispatcher
from multiproduct.model import Product
+from multiproduct.util import ProductDelegate
+
PRODUCT_RE = re.compile(r'^/products/(?P<pid>[^/]*)(?P<pathinfo>.*)')
@@ -161,18 +163,11 @@ class ProductModule(Component):
elif action == 'edit':
return self._do_save(req, product)
elif action == 'delete':
- req.perm(product.resource).require('PRODUCT_DELETE')
- retarget_to = req.args.get('retarget', None)
- name = product.name
- product.delete(resources_to=retarget_to)
- add_notice(req, _('The product "%(n)s" has been deleted.',
- n = name))
- req.redirect(req.href.products())
+ raise TracError(_('Product removal is not allowed!'))
elif action in ('new', 'edit'):
return self._render_editor(req, product)
elif action == 'delete':
- req.perm(product.resource).require('PRODUCT_DELETE')
- return 'product_delete.html', data, None
+ raise TracError(_('Product removal is not allowed!'))
if pid is None:
data = {'products': products,
@@ -258,12 +253,10 @@ class ProductModule(Component):
'choose a different name.', name=name))
if not warnings:
- prod = Product(self.env)
- prod.update_field_dict(keys)
- prod.update_field_dict(field_data)
- prod.insert()
+ ProductDelegate.add_product(self.env, product, keys, field_data)
add_notice(req, _('The product "%(id)s" has been added.',
- id=prefix))
+ id=prefix))
+
if warnings:
product.update_field_dict(keys)
product.update_field_dict(field_data)
Modified: incubator/bloodhound/branches/bep_0003_multiproduct/bloodhound_theme/bhtheme/templates/bh_product_view.html
URL: http://svn.apache.org/viewvc/incubator/bloodhound/branches/bep_0003_multiproduct/bloodhound_theme/bhtheme/templates/bh_product_view.html?rev=1448946&r1=1448945&r2=1448946&view=diff
==============================================================================
--- incubator/bloodhound/branches/bep_0003_multiproduct/bloodhound_theme/bhtheme/templates/bh_product_view.html (original)
+++ incubator/bloodhound/branches/bep_0003_multiproduct/bloodhound_theme/bhtheme/templates/bh_product_view.html Fri Feb 22 08:56:11 2013
@@ -47,7 +47,7 @@
<py:def function="product_buttons()">
<div py:if="'PRODUCT_MODIFY' in perm(product.resource) or
'PRODUCT_DELETE' in perm(product.resource) or
- attachments.can_create"
+ (attachments and attachments.can_create)"
class="buttons">
<form py:if="'PRODUCT_MODIFY' in perm(product.resource)"
method="get" action="" id="editproduct"