Example #1
0
def objects():

    #~ slot = Instantiator('courses.Slot','name start_time end_time').build
    #~
    #~ kw = dict(monday=True,tuesday=True,wednesday=False,thursday=True,friday=True)
    #~ yield slot("Erste Stunde","16:00","17:00",**kw)
    #~ yield slot("Zweite Stunde","17:00","18:00",**kw)
    #~ yield slot("Dritte Stunde","18:00","19:00",**kw)
    #~
    #~ kw = dict(wednesday=True)
    #~ yield slot("Mittwochs 13 Uhr","13:00","14:00",**kw)
    #~ yield slot("Mittwochs 14 Uhr","14:00","15:00",**kw)
    #~ yield slot("Mittwochs 15 Uhr","15:00","16:00",**kw)
    #~ yield slot("Mittwochs 16 Uhr","16:00","17:00",**kw)
    #~ yield slot("Mittwochs 17 Uhr","17:00","18:00",**kw)
    #~ yield slot("Mittwochs 18 Uhr","18:00","19:00",**kw)

    courses = dd.resolve_app('courses')

    yield courses.Line(**babelkw('name',
                                 de=u"Deutsch Anfänger",
                                 fr=u"Allemand débutants",
                                 en=u"German beginners",
                                 ))
    yield courses.Line(**babelkw('name',
                                 de=u"Französisch Anfänger",
                                 fr=u"Français débutants",
                                 en=u"French beginners",
                                 ))
Example #2
0
def O(fr,en,de,de_BE):
    return Expression(**babelkw('name',de=de,de_BE=de_BE,en=en,fr=fr))
Example #3
0
    def test01(self):
        """
        Tests some basic funtionality.
        """
        #~ self.assertEqual(settings.MIDDLEWARE_CLASSES,1)
        self.assertEqual(1+1, 2)

        Person = dd.resolve_model("contacts.Person")
        # person = Instantiator(Person).build
        # company = Instantiator("contacts.Company").build

        ee = create_and_get('countries.Country',
                            isocode='EE', **babelkw('name',
                                                    de="Estland",
                                                    fr='Estonie',
                                                    en="Estonia",
                                                    nl='Estland',
                                                    et='Eesti',
                                                    ))
        be = create_and_get('countries.Country',
                            isocode='BE', **babelkw('name',
                                                    de="Belgien",
                                                    fr='Belgique',
                                                    en="Belgium",
                                                    nl='Belgie',
                                                    et='Belgia',
                                                    ))

        eupen = create_and_get(
            'countries.Place', name=u'Eupen', country=be, zip_code='4700')

        vigala = create_and_get('countries.Place', name=u'Vigala', country=ee)

        luc = create_and_get(Person,
                             first_name='Luc', last_name='Saffre',
                             gender=Genders.male,
                             country=ee, street='Uus', street_no='1',
                             addr2=u'Vana-Vigala küla',
                             city=vigala, zip_code='78003')

        settings.SITE.uppercase_last_name = True

        """If the following tests raise a "DoesNotExist: Company matching
        query does not exist" then this may come because
        Site._site_config has been filled before the database switched
        from the real db to test db.  and not properly reset.

        """

        if settings.SITE.get_language_info('en'):
            with translation.override('en'):
                self.assertEquals(luc.address, u'''\
Mr Luc SAFFRE
Uus 1
Vana-Vigala küla
78003 Vigala
Estonia''')

        if settings.SITE.get_language_info('de'):
            with translation.override('de'):
                self.assertEquals(luc.address, u'''\
Herrn Luc SAFFRE
Uus 1
Vana-Vigala küla
78003 Vigala
Estland''')
                self.assertEquals(luc.address_html, '''\
<p>Herrn Luc SAFFRE<br />Uus 1<br />Vana-Vigala k&#252;la<br />78003 Vigala<br />Estland</p>''')

        u = create_and_get(settings.SITE.user_model,
                           username='******', language='', profile=dd.UserProfiles.admin)

        """
        disable SITE.is_imported_partner() otherwise 
        disabled_fields may contain more than just the 'id' field.
        """
        save_iip = settings.SITE.is_imported_partner

        def f(obj):
            return False
        settings.SITE.is_imported_partner = f

        """
        Note that we must specify the language both in the user 
        and in HTTP_ACCEPT_LANGUAGE because...
        """

        luc = Person.objects.get(name__exact="Saffre Luc")
        self.assertEqual(luc.pk, contacts.PARTNER_NUMBERS_START_AT)

        url = settings.SITE.build_admin_url(
            'api', 'contacts', 'Person',
            '%d?query=&an=detail&fmt=json' % luc.pk)
        #~ url = '/api/contacts/Person/%d?query=&an=detail&fmt=json' % luc.pk
        if settings.SITE.get_language_info('en'):
            u.language = 'en'
            u.save()
            response = self.client.get(
                url, REMOTE_USER='******', HTTP_ACCEPT_LANGUAGE='en')
            result = self.check_json_result(
                response, 'navinfo disable_delete data id title')
            self.assertEqual(result['data']['country'], "Estonia")
            self.assertEqual(result['data']['gender'], "Male")

        if settings.SITE.get_language_info('de'):
            u.language = 'de'
            u.save()
            response = self.client.get(
                url, REMOTE_USER='******', HTTP_ACCEPT_LANGUAGE='de')
            result = self.check_json_result(
                response,
                'navinfo disable_delete data id title')
            self.assertEqual(result['data']['country'], "Estland")
            self.assertEqual(result['data']['gender'], u"Männlich")
            #~ self.assertEqual(result['data']['disabled_fields'],['contact_ptr_id','id'])
            #~ self.assertEqual(result['data']['disabled_fields'],['id'])
            df = result['data']['disabled_fields']
            self.assertEqual(df['id'], True)

        if settings.SITE.get_language_info('fr'):
            u.language = 'fr'
            u.save()
            response = self.client.get(
                url, REMOTE_USER='******', HTTP_ACCEPT_LANGUAGE='fr')
            result = self.check_json_result(
                response, 'navinfo disable_delete data id title')
            self.assertEqual(result['data']['country'], "Estonie")
            self.assertEqual(result['data']['gender'], u"Masculin")

        #~ u.language = lang
        #~ u.save()
        # restore is_imported_partner method
        settings.SITE.is_imported_partner = save_iip

        #~ def test03(self):
        """
        Test the following situation:
        
        - User 1 opens the :menuselection:`Configure --> System--> System Parameters` dialog
        - User 2 creates a new Person (which increases next_partner_id)
        - User 1 clicks on `Save`.
        
        `next_partner_id` may not get overwritten 
        
        """
        # User 1
        SiteConfigs = settings.SITE.modules.system.SiteConfigs
        elem = SiteConfigs.get_row_by_pk(None, settings.SITE.config_id)
        self.assertEqual(elem.next_partner_id,
                         contacts.PARTNER_NUMBERS_START_AT + 1)

        elem.next_partner_id = 12345
        elem.full_clean()
        elem.save()
        #~ print "saved"
        self.assertEqual(settings.SITE.site_config.next_partner_id, 12345)
        john = create_and_get(Person, first_name='John', last_name='Smith')
        self.assertEqual(john.pk, 12345)
        self.assertEqual(elem.next_partner_id, 12346)
        self.assertEqual(settings.SITE.site_config.next_partner_id, 12346)