예제 #1
0
class CountriesZones(OrderedTable):

    class_id = 'countries-zones'
    class_title = MSG(u'Countries Zones')
    class_handler = BaseCountriesZones
    class_views = ['view', 'add_record']
    class_version = '20090923'

    view = CountriesZones_View()
    add_record = Table_AddRecord(title=MSG(u'Add a new zone'))

    form = [
        TextWidget('title', title=MSG(u'Country title')),
        BooleanRadio('has_tax', title=MSG(u'Has TAX ?'))
    ]

    @staticmethod
    def _make_resource(cls, folder, name, *args, **kw):
        OrderedTable._make_resource(cls, folder, name)
        table = BaseCountriesZones()
        zones = []
        csv = ro_database.get_handler(get_abspath('data/countries.csv'),
                                      CSVFile)
        for line in csv.get_rows():
            zone = unicode(line[1], 'utf-8')
            if zone not in zones:
                zones.append(zone)
                table.add_record({'title': Property(zone, language='fr')})
        folder.set_handler(name, table)
예제 #2
0
class Countries(Table):

    class_id = 'countries'
    class_title = MSG(u'Countries')
    class_handler = BaseCountries
    class_views = ['view', 'add_record']

    view = Countries_View()
    add_record = Table_AddRecord(title=MSG(u'Add a new country'))

    form = [
        TextWidget('title', title=MSG(u'Country title')),
        SelectWidget('zone', title=MSG(u'Zone')),
        BooleanRadio('enabled', title=MSG(u'Enabled')),
    ]

    # XXX Enabled means its enabled for delivery not for registration
    # People from south africa can register on website but not to be delivered
    # This distinction must be explicit

    @staticmethod
    def _make_resource(cls, folder, name, *args, **kw):
        Table._make_resource(cls, folder, name)
        # Import CSV with list of countries
        zones = []
        table = BaseCountries()
        csv = ro_database.get_handler(get_abspath('data/countries.csv'),
                                      CSVFile)
        for line in csv.get_rows():
            country = unicode(line[0], 'utf-8')
            zone = unicode(line[1], 'utf-8')
            if zone not in zones:
                zones.append(zone)
            table.add_record({
                'title': Property(country, language='fr'),
                'zone': str(zones.index(zone)),
                'enabled': True
            })
        folder.set_handler(name, table)