コード例 #1
0
ファイル: one2many.py プロジェクト: rhythmus/rinohtype
    def test(self):
        for country_name, cities in self.data:
            new_country = country(name=country_name)

            self.ds.insert(new_country)

            for city_name in cities:
                new_country.cities.append(city(name=city_name))

        new_country.cities.append(city(name="Bremen"))

        # But Bremen is not an English town, is it?
        result = self.ds.select(
            city, sql.where("name=", sql.string_literal("Bremen")))
        bremen = result.next()

        result = self.ds.select(
            country, sql.where("name=", sql.string_literal("Germany")))
        germany = result.next()

        # this will update the foreign key in the city table
        bremen.country_id = germany.id
        self.ds.flush_updates()

        german_cities = germany.cities.select(sql.order_by("name"))
        names = map(lambda c: c.name, list(german_cities))
        self.assertEqual(
            names, [u"Berlin", u"Bremen", u"Hamburg", u"München", u"Witten"])

        bremen_where = sql.where("name='Bremen'")
        self.assertEqual(len(germany.cities), 5)
        self.assertEqual(germany.cities.len(bremen_where), 1)

        bremen = germany.cities.select(bremen_where).next()
        self.assertEqual(bremen.name, u"Bremen")
コード例 #2
0
ファイル: one2many.py プロジェクト: dvorberg/t4
    def test(self):
        for country_name, cities in self.data:
            new_country = country(name=country_name)

            self.ds.insert(new_country)

            for city_name in cities:
                new_country.cities.append(city(name=city_name))

        new_country.cities.append(city(name="Bremen"))

        # But Bremen is not an English town, is it?
        result = self.ds.select(city, sql.where("name=", sql.string_literal("Bremen")))
        bremen = result.next()

        result = self.ds.select(country, sql.where("name=", sql.string_literal("Germany")))
        germany = result.next()

        # this will update the foreign key in the city table
        bremen.country_id = germany.id
        self.ds.commit(bremen, germany)

        german_cities = germany.cities.select(sql.order_by("name"))
        names = map(lambda c: c.name, list(german_cities))
        self.assertEqual(names, [u"Berlin", u"Bremen", u"Hamburg", u"München", u"Witten"])

        bremen_where = sql.where("name='Bremen'")
        self.assertEqual(len(germany.cities), 5)
        self.assertEqual(germany.cities.len(bremen_where), 1)

        bremen = germany.cities.select(bremen_where).next()
        self.assertEqual(bremen.name, u"Bremen")
コード例 #3
0
 def select_with_where_and_order_by(self):
     result = self.ds.select(person,
                             sql.where("height IS NOT NULL"),
                             sql.order_by("height"))
     
     firstnames = map(lambda p: p.firstname, list(result))
     self.assertEqual(firstnames, [u"Annette", u"Marie-Luise",
                                   u"Diedrich", ])
コード例 #4
0
    def select_with_where_and_order_by(self):
        result = self.ds.select(person, sql.where("height IS NOT NULL"),
                                sql.order_by("height"))

        firstnames = map(lambda p: p.firstname, list(result))
        self.assertEqual(firstnames, [
            u"Annette",
            u"Marie-Luise",
            u"Diedrich",
        ])
コード例 #5
0
    def test(self):
        for fqdn, emails in self.data:
            dom, tld = split(fqdn, ".")
            new_domain = domain(domain=dom, tld=tld)
            self.ds.insert(new_domain)

            for addr in emails:
                new_domain.emails.append(
                    email(remote_part_domain=dom,
                          remote_part_tld=tld,
                          local_part=addr))

        # Let's check...
        tux4web = self.ds.select_one(domain, sql.where("domain='tux4web'"))
        self.assertEqual(len(tux4web.emails), 4)

        apple = self.ds.select_by_primary_key(domain, (
            "apple",
            "com",
        ))
        self.assertEqual(len(apple.emails), 3)

        result = apple.emails.select(sql.where("local_part = 'steve'"))
        steve = result.next()

        self.assertEqual(steve.local_part, "steve")
        self.assertEqual(steve.remote_part_domain, "apple")

        # The other way 'round
        emails = self.ds.select(email)

        # This will yield one select statement for each email.
        # This effect can be prevented by using SQL joins.
        # This is being worked on.
        for a in emails:
            self.assertEqual(a.remote_part_domain, a.domain.domain)

        new_email = email(local_part="dv")
        tux4web.emails.append(new_email)
        self.assertEqual(len(tux4web.emails), 5)

        result = tux4web.emails.select(sql.order_by("local_part"))
        result = list(result)
        last = result[-1]
        self.assertEqual(last.local_part, "support")
コード例 #6
0
    def test(self):
        for fqdn, emails in self.data:
            dom, tld = split(fqdn, ".")
            new_domain = domain(domain=dom, tld=tld)
            self.ds.insert(new_domain)

            for addr in emails:
                new_domain.emails.append(
                    email(remote_part_domain=dom, remote_part_tld=tld,
                          local_part=addr))
                
        # Let's check...
        tux4web = self.ds.select_one(domain, sql.where("domain='tux4web'"))
        self.assertEqual(len(tux4web.emails), 4)

        apple = self.ds.select_by_primary_key(domain, ("apple", "com",))
        self.assertEqual(len(apple.emails), 3)

        result = apple.emails.select(sql.where("local_part = 'steve'"))
        steve = result.next()

        self.assertEqual(steve.local_part, "steve")
        self.assertEqual(steve.remote_part_domain, "apple")

        # The other way 'round
        emails = self.ds.select(email)

        # This will yield one select statement for each email.
        # This effect can be prevented by using SQL joins.
        # This is being worked on.
        for a in emails:
            self.assertEqual(a.remote_part_domain, a.domain.domain)


        new_email = email(local_part="dv")
        tux4web.emails.append(new_email)
        self.assertEqual(len(tux4web.emails), 5)
        
        result = tux4web.emails.select(sql.order_by("local_part"))
        result = list(result)
        last = result[-1]
        self.assertEqual(last.local_part, "support")
コード例 #7
0
ファイル: conditions.py プロジェクト: MariusCC/rinohtype
def my_document(ds):
    document = dsc_document()

    dir = dirname(__file__)

    if dir == "": dir = "."

    print("Loading background", file=debug)
    background = eps_image(document, open(dir + "/conditions_background.eps", 'rb'))


    print("Loading fonts", file=debug)
    italic  = type1(open(pjoin(dir, "italic.pfb"), 'rb'),
                    open(pjoin(dir, "italic.afm"), 'rb'))

    bold    = type1(open(pjoin(dir, "bold.pfb"), 'rb'),
                    open(pjoin(dir, "bold.afm"), 'rb'))

    bolditalic = type1(open(pjoin(dir, "bolditalic.pfb"), 'rb'),
                       open(pjoin(dir, "bolditalic.afm"), 'rb'))

    # Define the relevant styles.
    h1 = style(font=bolditalic, font_size=9.2,
               color="0.98 0 0.48 0.63 setcmykcolor",
               margin_top=mm(2))

    h2 = style(font=bolditalic, font_size=8, color="0 setgray",
               margin_top=mm(2))

    description = style(font=italic, font_size=7, color="0 setgray",
               padding_top=2, padding_bottom=1, text_align="justify")

    tabelle_dunkel = style(font=italic, font_size=7, color="0 setgray",
                           background_color="1 0.24 sub setgray",
                           padding_top=2, padding_bottom=1,
                           padding_right=2)
    tabelle_hell   = style(font=italic, font_size=7, color="0 setgray",
                           background_color="1 0.12 sub setgray",
                           padding_top=2, padding_bottom=1,
                           padding_right=2)

    # Create the divs

    print("Making db requests", file=debug)
    divs = []
    pages = ds.select(schema.page, sql.order_by("rank"))
    tabcounter = 0

    for page in pages:
        ds = []
        ds.append(div(page.name, h1))

        entries = page.entries.select(sql.order_by("rank"))

        for entry in entries:
            if entry.type == "caption":
                if entry.value1 is not None and entry.value1.strip() != "":
                    ds.append(div(entry.value1, h2))

                if entry.value2 is not None and entry.value2.strip() != "":
                    ds.append(div(entry.value2, description))

            elif entry.type == "info":
                if entry.value2 is None or entry.value2.strip() == "":
                    ds.append(div(entry.value1, description))
                else:
                    cls = ( tabelle_dunkel, tabelle_hell, )[tabcounter%2]
                    tabcounter += 1
                    ds.append(lr_div(entry.value1, entry.value2, cls))

        divs.append(div_div(ds))

    # layout
    print("Starting layout process", file=debug)
    layout(divs, new_page(document, background, italic))

    return document
コード例 #8
0
def my_document(ds):
    document = dsc_document()

    dir = dirname(__file__)

    if dir == "": dir = "."

    print("Loading background", file=debug)
    background = eps_image(document,
                           open(dir + "/conditions_background.eps", 'rb'))

    print("Loading fonts", file=debug)
    italic = type1(open(pjoin(dir, "italic.pfb"), 'rb'),
                   open(pjoin(dir, "italic.afm"), 'rb'))

    bold = type1(open(pjoin(dir, "bold.pfb"), 'rb'),
                 open(pjoin(dir, "bold.afm"), 'rb'))

    bolditalic = type1(open(pjoin(dir, "bolditalic.pfb"), 'rb'),
                       open(pjoin(dir, "bolditalic.afm"), 'rb'))

    # Define the relevant styles.
    h1 = style(font=bolditalic,
               font_size=9.2,
               color="0.98 0 0.48 0.63 setcmykcolor",
               margin_top=mm(2))

    h2 = style(font=bolditalic,
               font_size=8,
               color="0 setgray",
               margin_top=mm(2))

    description = style(font=italic,
                        font_size=7,
                        color="0 setgray",
                        padding_top=2,
                        padding_bottom=1,
                        text_align="justify")

    tabelle_dunkel = style(font=italic,
                           font_size=7,
                           color="0 setgray",
                           background_color="1 0.24 sub setgray",
                           padding_top=2,
                           padding_bottom=1,
                           padding_right=2)
    tabelle_hell = style(font=italic,
                         font_size=7,
                         color="0 setgray",
                         background_color="1 0.12 sub setgray",
                         padding_top=2,
                         padding_bottom=1,
                         padding_right=2)

    # Create the divs

    print("Making db requests", file=debug)
    divs = []
    pages = ds.select(schema.page, sql.order_by("rank"))
    tabcounter = 0

    for page in pages:
        ds = []
        ds.append(div(page.name, h1))

        entries = page.entries.select(sql.order_by("rank"))

        for entry in entries:
            if entry.type == "caption":
                if entry.value1 is not None and entry.value1.strip() != "":
                    ds.append(div(entry.value1, h2))

                if entry.value2 is not None and entry.value2.strip() != "":
                    ds.append(div(entry.value2, description))

            elif entry.type == "info":
                if entry.value2 is None or entry.value2.strip() == "":
                    ds.append(div(entry.value1, description))
                else:
                    cls = (
                        tabelle_dunkel,
                        tabelle_hell,
                    )[tabcounter % 2]
                    tabcounter += 1
                    ds.append(lr_div(entry.value1, entry.value2, cls))

        divs.append(div_div(ds))

    # layout
    print("Starting layout process", file=debug)
    layout(divs, new_page(document, background, italic))

    return document