allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From brond...@apache.org
Subject [49/50] git commit: [#3154] remove unused Artifact.tool_version and make tracker models less dependent on `c`
Date Wed, 21 Aug 2013 15:27:31 GMT
[#3154] remove unused Artifact.tool_version and make tracker models less dependent on `c`


Project: http://git-wip-us.apache.org/repos/asf/incubator-allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-allura/commit/272bd5c3
Tree: http://git-wip-us.apache.org/repos/asf/incubator-allura/tree/272bd5c3
Diff: http://git-wip-us.apache.org/repos/asf/incubator-allura/diff/272bd5c3

Branch: refs/heads/db/3154b
Commit: 272bd5c36a1e6617f07c8c86913772b80079d5a5
Parents: a598db5
Author: Dave Brondsema <dbrondsema@slashdotmedia.com>
Authored: Wed Aug 21 15:21:02 2013 +0000
Committer: Dave Brondsema <dbrondsema@slashdotmedia.com>
Committed: Wed Aug 21 15:26:27 2013 +0000

----------------------------------------------------------------------
 Allura/allura/controllers/project.py            |  7 +--
 Allura/allura/model/artifact.py                 |  6 +--
 Allura/allura/tests/test_globals.py             |  3 +-
 ForgeBlog/forgeblog/command/rssfeeds.py         |  1 -
 ForgeTracker/forgetracker/model/ticket.py       | 54 ++++++++++----------
 ForgeTracker/forgetracker/tests/test_app.py     |  6 ++-
 .../tests/unit/test_globals_model.py            | 22 ++++----
 scripts/project-import.py                       |  2 +-
 8 files changed, 50 insertions(+), 51 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/272bd5c3/Allura/allura/controllers/project.py
----------------------------------------------------------------------
diff --git a/Allura/allura/controllers/project.py b/Allura/allura/controllers/project.py
index d2b8510..5f293a6 100644
--- a/Allura/allura/controllers/project.py
+++ b/Allura/allura/controllers/project.py
@@ -778,9 +778,8 @@ class NeighborhoodAwardsController(object):
     def create(self, icon=None, short=None, full=None):
         require_access(self.neighborhood, 'admin')
         app_config_id = ObjectId()
-        tool_version = {'neighborhood': '0'}
         if short:
-            award = M.Award(app_config_id=app_config_id, tool_version=tool_version)
+            award = M.Award(app_config_id=app_config_id)
             award.short = short
             award.full = full
             award.created_by_neighborhood_id = self.neighborhood._id
@@ -802,9 +801,7 @@ class NeighborhoodAwardsController(object):
             deleted=False)).first()
         if grant_q and recipient_q:
             app_config_id = ObjectId()
-            tool_version = {'neighborhood': '0'}
-            award = M.AwardGrant(app_config_id=app_config_id,
-                                 tool_version=tool_version)
+            award = M.AwardGrant(app_config_id=app_config_id)
             award.award_id = grant_q._id
             award.granted_to_project_id = recipient_q._id
             award.granted_by_neighborhood_id = self.neighborhood._id

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/272bd5c3/Allura/allura/model/artifact.py
----------------------------------------------------------------------
diff --git a/Allura/allura/model/artifact.py b/Allura/allura/model/artifact.py
index b41b103..294c3d0 100644
--- a/Allura/allura/model/artifact.py
+++ b/Allura/allura/model/artifact.py
@@ -54,7 +54,6 @@ class Artifact(MappedClass):
     - Has a discussion thread that can have files attached to it
 
     :var mod_date: last-modified :class:`datetime`
-    :var tool_version: defaults to the parent Application's version
     :var acl: dict of permission name => [roles]
     :var labels: list of plain old strings
 
@@ -77,9 +76,7 @@ class Artifact(MappedClass):
     mod_date = FieldProperty(datetime, if_missing=datetime.utcnow)
     app_config_id = ForeignIdProperty('AppConfig', if_missing=lambda:c.app.config._id)
     plugin_verson = FieldProperty(S.Deprecated)
-    tool_version = FieldProperty(
-        { str: str },
-        if_missing=lambda:{c.app.config.tool_name:c.app.__version__})
+    tool_version = FieldProperty(S.Deprecated)
     acl = FieldProperty(ACL)
     tags = FieldProperty(S.Deprecated)
     labels = FieldProperty([str])
@@ -368,6 +365,7 @@ class Artifact(MappedClass):
         if t is None:
             idx = self.index()
             t = Thread.new(
+                app_config_id=self.app_config_id,
                 discussion_id=self.app_config.discussion_id,
                 ref_id=idx['id'],
                 subject='%s discussion' % h.get_first(idx, 'title'))

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/272bd5c3/Allura/allura/tests/test_globals.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/test_globals.py b/Allura/allura/tests/test_globals.py
index 526af04..437021b 100644
--- a/Allura/allura/tests/test_globals.py
+++ b/Allura/allura/tests/test_globals.py
@@ -504,8 +504,7 @@ def test_hideawards_macro():
     p_nbhd = M.Neighborhood.query.get(name='Projects')
 
     app_config_id = ObjectId()
-    tool_version = {'neighborhood': '0'}
-    award = M.Award(app_config_id=app_config_id, tool_version=tool_version)
+    award = M.Award(app_config_id=app_config_id)
     award.short = u'Award short'
     award.full = u'Award full'
     award.created_by_neighborhood_id = p_nbhd._id

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/272bd5c3/ForgeBlog/forgeblog/command/rssfeeds.py
----------------------------------------------------------------------
diff --git a/ForgeBlog/forgeblog/command/rssfeeds.py b/ForgeBlog/forgeblog/command/rssfeeds.py
index 305bc5a..aefacdb 100644
--- a/ForgeBlog/forgeblog/command/rssfeeds.py
+++ b/ForgeBlog/forgeblog/command/rssfeeds.py
@@ -169,7 +169,6 @@ class RssFeedsCommand(base.BlogCommand):
         if b_count == 0:
             post = BM.BlogPost(title=title, text=content, timestamp=updated,
                             app_config_id=appid,
-                            tool_version={'blog': version.__version__},
                             state='published')
             post.neighborhood_id=c.project.neighborhood_id
             post.make_slug()

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/272bd5c3/ForgeTracker/forgetracker/model/ticket.py
----------------------------------------------------------------------
diff --git a/ForgeTracker/forgetracker/model/ticket.py b/ForgeTracker/forgetracker/model/ticket.py
index 0536f71..d16039e 100644
--- a/ForgeTracker/forgetracker/model/ticket.py
+++ b/ForgeTracker/forgetracker/model/ticket.py
@@ -73,7 +73,8 @@ class Globals(MappedClass):
 
     type_s = 'Globals'
     _id = FieldProperty(schema.ObjectId)
-    app_config_id = ForeignIdProperty('AppConfig', if_missing=lambda:c.app.config._id)
+    app_config_id = ForeignIdProperty(AppConfig, if_missing=lambda:c.app.config._id)
+    app_config = RelationProperty(AppConfig, via='app_config_id')
     last_ticket_num = FieldProperty(int)
     status_names = FieldProperty(str)
     open_status_names = FieldProperty(str)
@@ -97,13 +98,12 @@ class Globals(MappedClass):
                                                             'labels': False,
                                                             })
 
-    @classmethod
-    def next_ticket_num(cls):
-        gbl = cls.query.find_and_modify(
-            query=dict(app_config_id=c.app.config._id),
+    def next_ticket_num(self):
+        gbl = Globals.query.find_and_modify(
+            query=dict(app_config_id=self.app_config_id),
             update={'$inc': { 'last_ticket_num': 1}},
             new=True)
-        session(cls).expunge(gbl)
+        session(gbl).expunge(gbl)
         return gbl.last_ticket_num
 
     @property
@@ -189,11 +189,11 @@ class Globals(MappedClass):
             return d
         mongo_query = {'custom_fields.%s' % fld_name: m_name}
         r = Ticket.query.find(dict(
-            mongo_query, app_config_id=c.app.config._id, deleted=False))
+            mongo_query, app_config_id=self.app_config_id, deleted=False))
         tickets = [t for t in r if security.has_access(t, 'read')]
         d['hits'] = len(tickets)
         d['closed'] = sum(1 for t in tickets
-                          if t.status in c.app.globals.set_of_closed_status_names)
+                          if t.status in self.set_of_closed_status_names)
         return d
 
     def invalidate_bin_counts(self):
@@ -229,13 +229,13 @@ class Globals(MappedClass):
 
     def has_deleted_tickets(self):
         return Ticket.query.find(dict(
-            app_config_id=c.app.config._id, deleted=True)).count() > 0
+            app_config_id=self.app_config_id, deleted=True)).count() > 0
 
     def move_tickets(self, ticket_ids, destination_tracker_id):
         tracker = AppConfig.query.get(_id=destination_tracker_id)
         tickets = Ticket.query.find(dict(
             _id={'$in': [ObjectId(id) for id in ticket_ids]},
-            app_config_id=c.app.config._id)).sort('ticket_num').all()
+            app_config_id=self.app_config_id)).sort('ticket_num').all()
         filtered = self.filtered_by_subscription({t._id: t for t in tickets})
         original_ticket_nums = {t._id: t.ticket_num for t in tickets}
         users = User.query.find({'_id': {'$in': filtered.keys()}}).all()
@@ -247,13 +247,13 @@ class Globals(MappedClass):
             fromaddr = str(c.user.email_address_header()),
             reply_to = str(c.user.email_address_header()),
             subject = '[%s:%s] Mass ticket moving by %s' % (c.project.shortname,
-                                                          c.app.config.options.mount_point,
+                                                          self.app_config.options.mount_point,
                                                           c.user.display_name))
         tmpl = g.jinja2_env.get_template('forgetracker:data/mass_move_report.html')
 
         tmpl_context = {
             'original_tracker': '%s:%s' % (c.project.shortname,
-                                           c.app.config.options.mount_point),
+                                           self.app_config.options.mount_point),
             'destination_tracker': '%s:%s' % (tracker.project.shortname,
                                               tracker.options.mount_point),
             'tickets': [],
@@ -270,16 +270,16 @@ class Globals(MappedClass):
                 destinations = [str(user._id)]))
             mail_tasks.sendmail.post(**mail)
 
-        if c.app.config.options.get('TicketMonitoringType') in (
+        if self.app_config.options.get('TicketMonitoringType') in (
                 'AllTicketChanges', 'AllPublicTicketChanges'):
-            monitoring_email = c.app.config.options.get('TicketMonitoringEmail')
+            monitoring_email = self.app_config.options.get('TicketMonitoringEmail')
             tmpl_context['tickets'] = [{
                     'original_num': original_ticket_nums[_id],
                     'destination_num': moved_tickets[_id].ticket_num,
                     'summary': moved_tickets[_id].summary
                 } for _id, t in moved_tickets.iteritems()
                   if (not t.private or
-                      c.app.config.options.get('TicketMonitoringType') ==
+                      self.app_config.options.get('TicketMonitoringType') ==
                       'AllTicketChanges')]
             if len(tmpl_context['tickets']) > 0:
                 mail.update(dict(
@@ -288,7 +288,7 @@ class Globals(MappedClass):
                     destinations = [monitoring_email]))
                 mail_tasks.sendmail.post(**mail)
 
-        moved_from = '%s/%s' % (c.project.shortname, c.app.config.options.mount_point)
+        moved_from = '%s/%s' % (c.project.shortname, self.app_config.options.mount_point)
         moved_to = '%s/%s' % (tracker.project.shortname, tracker.options.mount_point)
         text = 'Tickets moved from %s to %s' % (moved_from, moved_to)
         Notification.post_user(c.user, None, 'flash', text=text)
@@ -297,7 +297,7 @@ class Globals(MappedClass):
         from forgetracker.tracker_main import get_change_text, get_label
         tickets = Ticket.query.find(dict(
                 _id={'$in':[ObjectId(id) for id in aslist(post_data['__ticket_ids'])]},
-                app_config_id=c.app.config._id)).all()
+                app_config_id=self.app_config_id)).all()
 
         fields = set(['status'])
         values = {}
@@ -314,7 +314,7 @@ class Globals(MappedClass):
 
         custom_values = {}
         custom_fields = {}
-        for cf in c.app.globals.custom_fields or []:
+        for cf in self.custom_fields or []:
             v = post_data.get(cf.name)
             if v:
                 custom_values[cf.name] = v
@@ -369,7 +369,7 @@ class Globals(MappedClass):
             fromaddr = str(c.user._id),
             reply_to = str(c.user._id),
             subject = '[%s:%s] Mass edit changes by %s' % (c.project.shortname,
-                                                           c.app.config.options.mount_point,
+                                                           self.app_config.options.mount_point,
                                                            c.user.display_name),
         )
         tmpl = g.jinja2_env.get_template('forgetracker:data/mass_report.html')
@@ -394,13 +394,13 @@ class Globals(MappedClass):
                 destinations = [str(user._id)]))
             mail_tasks.sendmail.post(**mail)
 
-        if c.app.config.options.get('TicketMonitoringType') in (
+        if self.app_config.options.get('TicketMonitoringType') in (
                 'AllTicketChanges', 'AllPublicTicketChanges'):
-            monitoring_email = c.app.config.options.get('TicketMonitoringEmail')
+            monitoring_email = self.app_config.options.get('TicketMonitoringEmail')
             visible_changes = []
             for t_id, t in changed_tickets.items():
                 if (not t.private or
-                        c.app.config.options.get('TicketMonitoringType') ==
+                        self.app_config.options.get('TicketMonitoringType') ==
                         'AllTicketChanges'):
                     visible_changes.append(
                             (changed_tickets[t_id], jinja2.Markup(changes[t_id])))
@@ -412,16 +412,16 @@ class Globals(MappedClass):
                     destinations = [monitoring_email]))
                 mail_tasks.sendmail.post(**mail)
 
-        c.app.globals.invalidate_bin_counts()
+        self.invalidate_bin_counts()
         ThreadLocalORMSession.flush_all()
-        app = '%s/%s' % (c.project.shortname, c.app.config.options.mount_point)
+        app = '%s/%s' % (c.project.shortname, self.app_config.options.mount_point)
         count = len(tickets)
         text = 'Updated {} ticket{} in {}'.format(count, 's' if count != 1 else '', app)
         Notification.post_user(c.user, None, 'flash', text=text)
 
     def filtered_by_subscription(self, tickets, project_id=None, app_config_id=None):
         p_id = project_id if project_id else c.project._id
-        ac_id = app_config_id if app_config_id else c.app.config._id
+        ac_id = app_config_id if app_config_id else self.app_config_id
         ticket_ids = tickets.keys()
         tickets_index_id = {ticket.index_id(): t_id for t_id, ticket in tickets.iteritems()}
         subscriptions = Mailbox.query.find({
@@ -678,11 +678,11 @@ class Ticket(VersionedArtifact, ActivityObject, VotableArtifact):
 
     @property
     def monitoring_email(self):
-        return c.app.config.options.get('TicketMonitoringEmail')
+        return self.app_config.options.get('TicketMonitoringEmail')
 
     @property
     def notify_post(self):
-        monitoring_type = c.app.config.options.get('TicketMonitoringType')
+        monitoring_type = self.app_config.options.get('TicketMonitoringType')
         return monitoring_type == 'AllTicketChanges' or (
                 monitoring_type == 'AllPublicTicketChanges' and
                 not self.private)

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/272bd5c3/ForgeTracker/forgetracker/tests/test_app.py
----------------------------------------------------------------------
diff --git a/ForgeTracker/forgetracker/tests/test_app.py b/ForgeTracker/forgetracker/tests/test_app.py
index b92a72f..e6e74b8 100644
--- a/ForgeTracker/forgetracker/tests/test_app.py
+++ b/ForgeTracker/forgetracker/tests/test_app.py
@@ -15,12 +15,12 @@
 #       specific language governing permissions and limitations
 #       under the License.
 
-import datetime
 import tempfile
 import json
 import operator
 
 from nose.tools import assert_equal, assert_true
+from pylons import tmpl_context as c
 
 from allura import model as M
 from allura.tests import decorators as td
@@ -40,6 +40,10 @@ class TestBulkExport(TrackerTestController):
         ticket.discussion_thread.add_post(text='silly comment')
 
     def test_bulk_export(self):
+        # Clear out some context vars, to properly simulate how this is run from the export
task
+        # Besides, core functionality shouldn't need the c context vars
+        c.app = c.project = None
+
         f = tempfile.TemporaryFile()
         self.tracker.bulk_export(f)
         f.seek(0)

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/272bd5c3/ForgeTracker/forgetracker/tests/unit/test_globals_model.py
----------------------------------------------------------------------
diff --git a/ForgeTracker/forgetracker/tests/unit/test_globals_model.py b/ForgeTracker/forgetracker/tests/unit/test_globals_model.py
index 357caec..c3c0c30 100644
--- a/ForgeTracker/forgetracker/tests/unit/test_globals_model.py
+++ b/ForgeTracker/forgetracker/tests/unit/test_globals_model.py
@@ -15,18 +15,19 @@
 #       specific language governing permissions and limitations
 #       under the License.
 
+from datetime import datetime, timedelta
+
 import mock
 from nose.tools import assert_equal
-from datetime import datetime, timedelta
+from pylons import tmpl_context as c
+from ming.orm.ormsession import ThreadLocalORMSession
+from bson import ObjectId
 
 import forgetracker
 from forgetracker.model import Globals
 from forgetracker.tests.unit import TrackerTestWithModel
-from pylons import tmpl_context as c
 from allura.lib import helpers as h
 
-from ming.orm.ormsession import ThreadLocalORMSession
-
 
 class TestGlobalsModel(TrackerTestWithModel):
     def setUp(self):
@@ -41,13 +42,15 @@ class TestGlobalsModel(TrackerTestWithModel):
         assert c.app.globals != bugs_globals
 
     def test_next_ticket_number_increments(self):
-        assert Globals.next_ticket_num() == 1
-        assert Globals.next_ticket_num() == 2
+        gl = Globals()
+        assert_equal(gl.next_ticket_num(), 1)
+        assert_equal(gl.next_ticket_num(), 2)
 
     def test_ticket_numbers_are_independent(self):
-        assert Globals.next_ticket_num() == 1
-        h.set_context('test', 'doc-bugs', neighborhood='Projects')
-        assert Globals.next_ticket_num() == 1
+        with h.push_context('test', 'doc-bugs', neighborhood='Projects'):
+            assert_equal(c.app.globals.next_ticket_num(), 1)
+        with h.push_context('test', 'bugs', neighborhood='Projects'):
+            assert_equal(c.app.globals.next_ticket_num(), 1)
 
     @mock.patch('forgetracker.model.ticket.datetime')
     def test_bin_count(self, mock_dt):
@@ -133,4 +136,3 @@ def globals_with_custom_fields(custom_fields):
     c.app.globals.custom_fields = custom_fields
     ThreadLocalORMSession.flush_all()
     return c.app.globals
-

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/272bd5c3/scripts/project-import.py
----------------------------------------------------------------------
diff --git a/scripts/project-import.py b/scripts/project-import.py
index 5855da6..f4ba62f 100644
--- a/scripts/project-import.py
+++ b/scripts/project-import.py
@@ -240,7 +240,7 @@ def create_project(p, nbhd, user, options):
 
     for a in p.awards:
         M.AwardGrant(app_config_id=bson.ObjectId(),
-                tool_version=dict(neighborhood='0'), award_id=a._id,
+                award_id=a._id,
                 granted_to_project_id=project._id,
                 granted_by_neighborhood_id=nbhd._id)
     project.notifications_disabled = False


Mime
View raw message