def test_created_timestamp(self): self._generate() r = self.client.get(urlparams(self.url, sort='created')) items = pq(r.content)('.primary .item') for idx, c in enumerate(r.context['pager'].object_list): eq_(strip_whitespace(items.eq(idx).find('.modified').text()), 'Added %s' % strip_whitespace(datetime_filter(c.created)))
def test_updated_timestamp(self): self._generate() r = self.client.get(urlparams(self.url, sort='updated')) items = pq(r.content)('.primary .item') for idx, c in enumerate(r.context['pager'].object_list): eq_(strip_whitespace(items.eq(idx).find('.modified').text()), 'Updated %s' % strip_whitespace(datetime_filter(c.modified)))
def tweak_message(message): """We piggyback on jinja2's babel_extract() (really, Babel's extract_* functions) but they don't support some things we need so this function will tweak the message. Specifically: 1) We strip whitespace from the msgid. Jinja2 will only strip whitespace from the ends of a string so linebreaks show up in your .po files still. 2) Babel doesn't support context (msgctxt). We hack that in ourselves here. """ if isinstance(message, basestring): message = strip_whitespace(message) elif isinstance(message, tuple): # A tuple of 2 has context, 3 is plural, 4 is plural with context if len(message) == 2: message = add_context(message[1], message[0]) elif len(message) == 3: singular, plural, num = message message = (strip_whitespace(singular), strip_whitespace(plural), num) elif len(message) == 4: singular, plural, num, ctxt = message message = (add_context(ctxt, strip_whitespace(singular)), add_context(ctxt, strip_whitespace(plural)), num) return message
def test_updated_timestamp(self): self._generate() r = self.client.get(urlparams(self.url, sort="updated")) items = pq(r.content)(".primary .item") for idx, c in enumerate(r.context["pager"].object_list): eq_( strip_whitespace(items.eq(idx).find(".modified").text()), "Updated %s" % strip_whitespace(datetime_filter(c.modified)), )
def handle(self, *args, **options): try: apps = settings.DB_LOCALIZE except AttributeError: raise CommandError('DB_LOCALIZE setting is not defined!') strings = [] for app, models in apps.items(): for model, params in models.items(): model_class = get_model(app, model) attrs = params['attrs'] qs = model_class.objects.all().values_list(*attrs).distinct() for item in qs: for i in range(len(attrs)): msg = { 'id': strip_whitespace(item[i]), 'context': 'DB: %s.%s.%s' % (app, model, attrs[i]), 'comments': params.get('comments')} strings.append(msg) py_file = os.path.expanduser(options.get('outputfile')) py_file = os.path.abspath(py_file) print 'Outputting db strings to: {filename}'.format(filename=py_file) with open(py_file, 'w+') as f: f.write(HEADER) f.write('from tower import ugettext as _\n\n') for s in strings: comments = s['comments'] if comments: for c in comments: f.write(u'# {comment}\n'.format(comment=c).encode('utf8')) f.write(u'_("""{id}""", "{context}")\n'.format(id=s['id'], context=s['context']) .encode('utf8'))
def test_updated_date(self): doc = pq(self.client.get(urlparams(self.url, sort='updated')).content) for item in doc('.items .item'): item = pq(item) addon_id = item('.install').attr('data-addon') ts = Addon.objects.get(id=addon_id).last_updated eq_(item('.updated').text(), 'Updated %s' % strip_whitespace(datetime_filter(ts)))
def test_created_not_updated(self): """Don't display the updated date but the created date for themes.""" r = self.client.get(self.url) doc = pq(r.content) details = doc('.addon-info li') # There's no "Last Updated" entry. assert not any('Last Updated' in node.text_content() for node in details) # But there's a "Created" entry. for detail in details: if detail.find('h3').text_content() == 'Created': created = detail.find('p').text_content() eq_(created, strip_whitespace(datetime_filter(self.addon.created))) break # Needed, or we go in the "else" clause. else: assert False, 'No "Created" entry found.'
def handle(self, *args, **options): try: apps = settings.DB_LOCALIZE except AttributeError: raise CommandError('DB_LOCALIZE setting is not defined!') strings = [] for app, models in apps.items(): for model, params in models.items(): model_class = get_model(app, model) attrs = params['attrs'] qs = model_class.objects.all().values_list(*attrs).distinct() for item in qs: for i in range(len(attrs)): msg = { 'id': strip_whitespace(item[i]), 'context': 'DB: %s.%s.%s' % (app, model, attrs[i]), 'comments': params.get('comments') } strings.append(msg) py_file = os.path.expanduser(options.get('outputfile')) py_file = os.path.abspath(py_file) print 'Outputting db strings to: {filename}'.format(filename=py_file) with open(py_file, 'w+') as f: f.write('#################################################\n') f.write('### File generated by ./manage.py extract_db. ###\n') f.write('#################################################\n') f.write('from tower import ugettext as _\n\n') for s in strings: comments = s['comments'] if comments: for c in comments: f.write( u'# {comment}\n'.format(comment=c).encode('utf8')) f.write(u'_("""{id}""", "{context}")\n'.format( id=s['id'], context=s['context']).encode('utf8'))
def get_clean(selection): return strip_whitespace(str(selection))
def loc(s): """A noop function for strings that are not ready to be localized.""" return strip_whitespace(s)
def render_token_list(self, tokens): """Strip whitespace from msgid before letting gettext touch it.""" rendered = super(ShoehornedBlockTranslateNode, self).render_token_list(tokens) return strip_whitespace(rendered[0]), rendered[1]
def _parse_block(self, parser, allow_pluralize): ref, buffer = super(I18nExtension, self)._parse_block(parser, allow_pluralize) return ref, strip_whitespace(buffer)
def render_token_list(self, tokens): """Strip whitespace from msgid before letting gettext touch it.""" rendered = super(ShoehornedBlockTranslateNode, self).render_token_list( tokens) return strip_whitespace(rendered[0]), rendered[1]
def _parse_block(self, parser, allow_pluralize): parse_block = InternationalizationExtension._parse_block ref, buffer = parse_block(self, parser, allow_pluralize) return ref, strip_whitespace(buffer)