Merge lp:~mvo/software-center/display-price-property into lp:software-center

Proposed by Michael Vogt
Status: Merged
Merged at revision: 3110
Proposed branch: lp:~mvo/software-center/display-price-property
Merge into: lp:software-center
Diff against target: 167 lines (+72/-21)
6 files modified
softwarecenter/db/application.py (+24/-4)
softwarecenter/ui/gtk3/models/appstore2.py (+2/-5)
softwarecenter/ui/gtk3/views/appdetailsview.py (+1/-8)
softwarecenter/ui/gtk3/widgets/cellrenderers.py (+1/-2)
tests/gtk3/test_appdetailsview.py (+2/-2)
tests/test_application.py (+42/-0)
To merge this branch: bzr merge lp:~mvo/software-center/display-price-property
Reviewer Review Type Date Requested Status
Gary Lasker (community) Approve
Review via email: mp+120083@code.launchpad.net

Description of the change

This is another branch for the unity people, it will include the currency
in the "price" property. In addition there is a new "raw_price" property
that can be used as a sort key and that will not include currency data.

To post a comment you must log in.
Revision history for this message
Gary Lasker (gary-lasker) wrote :

This looks fine. Thanks for the unit test!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'softwarecenter/db/application.py'
--- softwarecenter/db/application.py 2012-08-15 14:11:19 +0000
+++ softwarecenter/db/application.py 2012-08-17 09:01:23 +0000
@@ -531,7 +531,7 @@
531 u"current software sources.")) % utf8(self.pkgname)531 u"current software sources.")) % utf8(self.pkgname)
532 return PkgStates.NOT_FOUND532 return PkgStates.NOT_FOUND
533 else:533 else:
534 if self.price:534 if self.raw_price:
535 return PkgStates.NEEDS_PURCHASE535 return PkgStates.NEEDS_PURCHASE
536 if (self.purchase_date and536 if (self.purchase_date and
537 self._doc.get_value(XapianValues.ARCHIVE_DEB_LINE)):537 self._doc.get_value(XapianValues.ARCHIVE_DEB_LINE)):
@@ -568,15 +568,35 @@
568568
569 @property569 @property
570 def currency(self):570 def currency(self):
571 if self.price:571 """ Get the currency for the price """
572 if self.raw_price:
572 # this is hardcoded to US dollar for now, but if the server573 # this is hardcoded to US dollar for now, but if the server
573 # ever changes that we are prepared574 # ever changes that we are prepared
574 return "US$"575 return "US$"
575576
576 @property577 @property
578 def raw_price(self):
579 """ The raw price, useful for e.g. sort-by """
580 if self._doc:
581 return self._doc.get_value(XapianValues.PRICE)
582
583 @property
577 def price(self):584 def price(self):
578 if self._doc:585 """ The price and the currency ready to display to the user """
579 return self._doc.get_value(XapianValues.PRICE)586 raw_price = self.raw_price
587 currency = self.currency
588 if raw_price and currency:
589 # FIXME: need to determine the currency dynamically once we can
590 # get that info from the software-center-agent/payments
591 # service.
592 # NOTE: the currency string for this label is purposely not
593 # translatable when hardcoded, since it (currently)
594 # won't vary based on locale and as such we don't want
595 # it translated
596 # FIXME: if we support different currencies eventually we need
597 # to format them here differently too, e.g.
598 # "US$ 1" but "1EUR"
599 return "%s %s" % (currency, raw_price)
580600
581 @property601 @property
582 def supported_distros(self):602 def supported_distros(self):
583603
=== modified file 'softwarecenter/ui/gtk3/models/appstore2.py'
--- softwarecenter/ui/gtk3/models/appstore2.py 2012-08-15 14:11:19 +0000
+++ softwarecenter/ui/gtk3/models/appstore2.py 2012-08-17 09:01:23 +0000
@@ -213,13 +213,10 @@
213 GObject.markup_escape_text(appname),213 GObject.markup_escape_text(appname),
214 GObject.markup_escape_text(summary))214 GObject.markup_escape_text(summary))
215215
216 def get_price(self, doc):216 def get_display_price(self, doc):
217 return doc.get_value(XapianValues.PRICE)
218
219 def get_currency(self, doc):
220 app = self.db.get_application(doc)217 app = self.db.get_application(doc)
221 details = app.get_details(self.db)218 details = app.get_details(self.db)
222 return details.currency219 return details.price
223220
224 def get_icon(self, doc):221 def get_icon(self, doc):
225 try:222 try:
226223
=== modified file 'softwarecenter/ui/gtk3/views/appdetailsview.py'
--- softwarecenter/ui/gtk3/views/appdetailsview.py 2012-08-16 14:44:29 +0000
+++ softwarecenter/ui/gtk3/views/appdetailsview.py 2012-08-17 09:01:23 +0000
@@ -365,14 +365,7 @@
365 elif state == PkgStates.INSTALLED:365 elif state == PkgStates.INSTALLED:
366 self.set_button_label(_('Remove'))366 self.set_button_label(_('Remove'))
367 elif state == PkgStates.NEEDS_PURCHASE:367 elif state == PkgStates.NEEDS_PURCHASE:
368 # FIXME: need to determine the currency dynamically once we can368 self.set_label("%s" % (app_details.price))
369 # get that info from the software-center-agent/payments
370 # service.
371 # NOTE: the currency string for this label is purposely not
372 # translatable when hardcoded, since it (currently)
373 # won't vary based on locale and as such we don't want
374 # it translated
375 self.set_label("%s %s" % (app_details.currency, app_details.price))
376 if (app_details.hardware_requirements_satisfied and369 if (app_details.hardware_requirements_satisfied and
377 app_details.region_requirements_satisfied):370 app_details.region_requirements_satisfied):
378 self.set_button_label(_(u'Buy\u2026'))371 self.set_button_label(_(u'Buy\u2026'))
379372
=== modified file 'softwarecenter/ui/gtk3/widgets/cellrenderers.py'
--- softwarecenter/ui/gtk3/widgets/cellrenderers.py 2012-08-15 14:11:19 +0000
+++ softwarecenter/ui/gtk3/widgets/cellrenderers.py 2012-08-17 09:01:23 +0000
@@ -123,8 +123,7 @@
123123
124 def _render_price(self, context, cr, app, layout, cell_area, xpad, ypad,124 def _render_price(self, context, cr, app, layout, cell_area, xpad, ypad,
125 is_rtl):125 is_rtl):
126 layout.set_markup("%s %s" % (126 layout.set_markup("%s" % self.model.get_display_price(app))
127 self.model.get_currency(app), self.model.get_price(app)), -1)
128127
129 if is_rtl:128 if is_rtl:
130 x = cell_area.x + xpad129 x = cell_area.x + xpad
131130
=== modified file 'tests/gtk3/test_appdetailsview.py'
--- tests/gtk3/test_appdetailsview.py 2012-08-17 08:06:50 +0000
+++ tests/gtk3/test_appdetailsview.py 2012-08-17 09:01:23 +0000
@@ -82,8 +82,8 @@
82 # create mock app82 # create mock app
83 self.set_mock_app_and_details(83 self.set_mock_app_and_details(
84 app_name="abiword", purchase_date="2011-11-20 17:45:01",84 app_name="abiword", purchase_date="2011-11-20 17:45:01",
85 _error_not_found="error not found", price="1.00",85 _error_not_found="error not found", price="US$ 1.00",
86 currency="US$", pkgname="abiword", error="error-text")86 pkgname="abiword", error="error-text")
87 mock_app = self.view.app87 mock_app = self.view.app
88 mock_details = self.view.app_details88 mock_details = self.view.app_details
8989
9090
=== added file 'tests/test_application.py'
--- tests/test_application.py 1970-01-01 00:00:00 +0000
+++ tests/test_application.py 2012-08-17 09:01:23 +0000
@@ -0,0 +1,42 @@
1import unittest
2
3from mock import (
4 patch,
5 Mock,
6 )
7
8from tests.utils import (
9 setup_test_env,
10 get_test_db,
11)
12setup_test_env()
13from softwarecenter.db.application import (
14 Application,
15 AppDetails,
16 )
17
18
19# FIXME: move application/appdetails tests from test_database.py
20# into this file for better structure
21class ApplicationTestCase(unittest.TestCase):
22
23 def test_application_name(self):
24 app1 = Application(appname="The AppName", pkgname="pkgapp")
25 self.assertEqual(app1.name, "The AppName")
26 app2 = Application(appname="", pkgname="pkgapp2")
27 self.assertEqual(app2.name, "pkgapp2")
28
29 def test_appdetails(self):
30 app = Application("Foo app", "dpkg")
31 db = get_test_db()
32 appdetails = app.get_details(db)
33 # patching properties is a bit cumbersome
34 with patch.object(AppDetails, "raw_price") as mock_price:
35 with patch.object(AppDetails, "currency") as mock_currency:
36 mock_price.__get__ = Mock(return_value="2.99")
37 mock_currency.__get__ = Mock(return_value="USD")
38 self.assertEqual("USD 2.99", appdetails.price)
39
40
41if __name__ == "__main__":
42 unittest.main()

Subscribers

People subscribed via source and target branches