cssutils #For a new MyMart feature, we're allowing our members to customise the look of parts of the site.They can choose custom colours with a palette widget. The values they give us are used to generate a CSS stylesheet which alters the rendering of certain page items.
I wanted to write test cases to ensure that the CSS is being generated correctly, so I used Christof Hoecke's cssutils module to parse and then inspect the CSS.
cssutils parses a stylesheet into a hierarchy of DOM Level 2 objects. A stylesheet is typically made up of several CSSStyleRules which are broken down into a list of Selector objects and a CSSStyleDeclaration object which can be interrogated for the actual values we're looking for.
First pull the CSS text into a variable, load it from file, enter it by hand, what ever is appropriate.
>>> pagecsstext = """div.data-key { color:#333333; }"""
Once we have the CSS in hand, parse it using cssutils'
parseString method.
>>> from cssutils import parseString
>>> pagecss = parseString(pagecsstext)
>>> pagecss.cssRules
[<cssutils.css.cssstylerule.CSSStyleRule object at 0x1480230>]
For the tests, I then need to search out and evaluate specific rules and values. cssutils doesn't make this as easy as we might like, my hope here was that I would be able to say something like pagecss.get_rule_for_selector("div.data-key") or something similar. There are problems with this for the implementor, I might request .data-key which should match in some situations. However, it would be nice to see a naive implementation added to the module. Here's one I made earlier:
def get_rule_for_selector(stylesheet, selector):
for rule in stylesheet.cssRules:
if hasattr(rule, "selectorList") and selector in [s.selectorText for s in rule.selectorList]:
return rule
We can then write expressions to get to the values of the stylesheet as follows.
>>> div_data_key = get_rule_for_selector(pagecss, "div.data-key")
>>> div_data_key = div_data_key.style.getPropertyValue("color") u'#333333'
Bringing it all together, here is my first test case. The page is served by Django, so I use their Client object to make a request.
class ShopTests(MyMartTestCase):
def test_shop_css(self):
c = Client()
r = c.get("/somebody/screen.css")
self.assertEqual(r.headers["Content-Type"], "text/css; charset=utf-8")
rcss = parseString(r.content)
tc_h2 = get_rule_for_selector(rcss, "table#content h2")
self.assertEqual(tc_h2.style.getPropertyValue("background-color"),
"#ff99cc")
self.assertEqual(tc_h2.style.getPropertyValue("color"),
"#000000")
tc_body = get_rule_for_selector(rcss, "table#content div.block-body")
self.assertEqual(tc_body.style.getPropertyValue("background-color"),
"#ffccdd")
self.assertEqual(tc_body.style.getPropertyValue("color"),
"#333333")
The Chiho Aoshima exhibition at Gloucester Road is the highlight of my daily commute. Sometimes during that commute my city way of life seems to be madness, but Aoshima always makes me think of the opportunities for warmth, happiness and friendship here, as much as the fresh air and new life to be found in the country. My girlfriend currently lives in Mexico and the range from country to city parallels the distance between us, but also makes me feel like it's not that far. Japanese characters like these have childlike joy in spades, and that's not so far from how our relationship works either.
In a recent revision of Django (not exactly sure which) my patches for my tickets #3160 and #3162 were added to the trunk.
After all these years of hanging around open source, I have finally made a code contribution which has made it into a release. The contributions are very small, but I hope they will be my first baby steps.
Yay!
Yesterday I met Scott Keiller of Starbucks to discuss his company's role in the Ethiopian government's attempts to trademark the names of several premium types of coffee. We met in a Starbucks store on Fulham Palace Road in London and chatted for 40 minutes. Scott covered off quite a few of the things Starbucks does to try to reach out to the people of the areas in which it has stores and talked about coffee production and buying, Oxfam and other organisations and Starbucks' take on this specific case. Scott disputed the allegations made by Oxfam and said "Starbucks believes that Ethiopian farmers have a right to their regional coffee names and that [they] do not claim any ownership rights to Ethiopia's coffee names."
In part 1, we learned how, after I received a card from Oxfam urging me to protest Starbucks opposition to the trademarking of the names Sidamo, Harar and Yirgacheffe by the Ethiopian government on behalf of farmers in that country, I walked into Starbucks' London head office unannounced and asked to meet their MD. As he was absent, Scott Keiller, head of CSR, stepped in and offered to meet at a later date.
Previously Oxfam and Starbucks had been friends. In 2004 they worked together on a rural development project[1]. For Starbucks' Cathy Heseltine "the ultimate test is whether we make a difference to these coffee growing communities."
I didn't want to open the conversation with an accusation. Scott was always going to be better armed with facts than I, it's his job. My plan was to learn a bit more about Scott and his role, discuss some of the good things Starbucks does and then try to learn why Oxfam, once a best friend, was now making negative statements about the company. I hoped that Scott would be frank and open.
Starbucks' employers are "partners," they share in the company's success through schemes including offering share options to all ("Bean Stock"). They also provide the basis for a series of community schemes of which Scott was very proud. These include looking after the environment, attempting to reduce carbon, and trying to help improve the lives of people in their communities, including encouraging literacy as directly as arranging father and son book readings in stores.
Starbucks buys coffee above the market rate, at $3.12/kg instead of $2.28/kg[2]. It has direct relationships with it's farmers and 97% of it's supply agreements are operated transparently, through things like contract disclosure. Conservation International has been involved in verifying a large proportion of the supply chain. Starbucks created a microfinance fund with $8.5m investment. While much of this data comes via Scott rather than through any kind of rigourous journalism, Phil Bloomer, head of Oxfam's Make Trade Fair campaign, speaking in 2004, said Starbucks "was taking the lead in the responsible purchasing of coffee, by paying premium prices and making long-term contracts with farmers."[3]
Why then is Starbucks blocking attempts by the Ethiopian government to trademark coffee names? Scott did not accept that this was the case, and I clarified, stating that their application had been made through the National Coffee Association in the US, of which Starbucks has a 20% voting block. Scott did not seem to feel as though Starbucks was placing roadblocks to the Ethiopian application as he reminded me subsequently by email: "we do not claim any ownership rights to Ethiopia's coffee names." And yet in 2007 Oxfam's David Taylor reports that the USPTO stated clearly that it was the NCA's opposition that lead to the failure of the application and the Robert Nelson, the NCA's president, in turn pointed the finger at Starbucks[4].
In his clarification of Starbucks previous application, Scott explained that Starbucks sell a coffee named "Shirkina Sun-Dried Sidamo," which they developed in partnership with the growers. They sought to trademark only the Shirkina part of the name, a word which means partnership in Ethiopian. If this is the case, it's difficult to see how this alone could prejudice the USPTO's judgement.
I find this situation troubling, but the clearest thing is that I lack the time and ability to bring it to a sensible conclusion. Even reporting back on a single simple interaction is fraught with questions of bias, accurate sourcing and politics.
I'd like to thank Scott for his time. He was very diligent in educating me about Starbucks caring sharing side, he even gave me a copy of their Corporate Social Responsibility Fiscal 2005 Annual Report and sheaf of clippings. But he was also a consummate politician, reminiscent of Thank You For Smoking's Nick Naylor, carefully worded answers ready to go.
It is overlooked that charities, especially those like Oxfam with sophisticated PR and marketing operations, often push the boundaries of truth in their effort to acheive greater goals. This is unfortunate.
My personal final opinion is that, in this particular case, Starbucks still looks like a villain. The NCA comments are undeniable. While Oxfam may misrepresent organisations from time to time, I believe in and support their work (I didn't tour 450km through Cambodia for nothing). I feel that continuing to support them as they work to change minds at Starbucks' is the best course.
Choose another page: 1, 2, 3, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113 or return to the most recent entries.
Last updated at 11:32, Wednesday June 18th, 2008. All times are shown in 24-hour clock format and are BST.
Rate my journal on bloghop.com: