예제 #1
0
    def save_plugin_data(self, request=None):
        """Save plugin data.

        We want to save the generated lorem ipsum text for later use.
        Thus, although we don't show it to the user, in case when
        ``generate_lipsum`` field is set to True, we silently generate the
        text and save it into the plugin data.
        """
        if self.cleaned_data.get('generate_lipsum', None):
            lipsum_language = self.cleaned_data.get('lipsum_language', None)
            try:
                if lipsum_language in LANGUAGE_CHOICES_KEYS:
                    if lipsum_language == 'en':
                        gen = Generator()
                    else:
                        gen = TranslipsumGenerator(
                            language_code=lipsum_language
                        )
                    text = gen.generate_paragraph()
                    truncator = Truncator(text)
                    self.cleaned_data['text'] = truncator.chars(
                        self.cleaned_data.get('lipsum_max_chars',
                                              DEFAULT_MAX_CHARS)
                    )
            except Exception as err:
                if DEBUG:
                    logger.debug(err)
    def offers(doc, categories):
        queryset = Product.objects.filter(is_visible=True, is_retail=True, quantity__gt=0, price__gt=0)
        doc.write('<offers>')
        for product in queryset:
            try:
                category_id = product.categories.filter(parent__isnull=False, id__in=categories).values_list('id', flat=True)[0]
            except IndexError:
                try:
                    category_id = product.categories.filter(parent__isnull=True, id__in=categories).values_list('id', flat=True)[0]
                except IndexError:
                    continue

            text = product.description.strip()
            if text:
                text = strip_tags(strip_spaces_between_tags(product.description)).strip()
                text = typograph(WHITESPACE_RE.sub(' ', text))
                truncator = Truncator(text)
                text = truncator.chars(512)

            doc.write('<offer>')
            doc.write('<url>http://tomat-podarky.ru{}</url>'.format(product.get_absolute_url()))
            doc.write('<price>{}</price>'.format(product.price))
            doc.write('<currencyId>RUR</currencyId>')
            doc.write('<categoryId>{}</categoryId>'.format(category_id))
            doc.write('<delivery>true</delivery>')
            doc.write('<name>')
            doc.write(_(typograph(product.title)))
            doc.write('</name>')
            if text:
                doc.write('<description>')
                doc.write(_(text))
                doc.write('</description>')
            doc.write('</offer>\n')
        doc.write('</offers>')
예제 #3
0
 def avoid_truncated_word(self, text): 
     """Truncate in a way that text will be shorter than max_length and won't be cut in the middle of a word""" 
     words = text.split()
     if not words:
         return text
     truncator = Truncator(text)
     last_word = text.split()[-1]
     text = truncator.chars(self.max_length, '')
     truncated_last_word = text.split()[-1]
     if truncated_last_word !=  last_word: 
         # last word is cut. So, remove it
         num_words = len(text.split())
         text = truncator.words(num_words - 1) 
     return text
예제 #4
0
def truncate_chars(data, maxlen):
    """
    Truncate string to at most ``maxlen``, including elipsis.
    * uses django.utils.text Truncator class.

    :param data: string to truncate
    :param maxlen: length to truncate to
    :returns: string (truncated if necessary)
    """
    from django.utils.text import Truncator

    if isinstance(data, six.text_type) and len(data) > maxlen:
        truncator = Truncator(data)
        data = truncator.chars(maxlen)
    return data
예제 #5
0
 def describe_operation(operation, backwards):
     """Return a string that describes a migration operation for --plan."""
     prefix = ''
     if hasattr(operation, 'code'):
         code = operation.reverse_code if backwards else operation.code
         action = code.__doc__ if code else ''
     elif hasattr(operation, 'sql'):
         action = operation.reverse_sql if backwards else operation.sql
     else:
         action = ''
         if backwards:
             prefix = 'Undo '
     if action is None:
         action = 'IRREVERSIBLE'
         is_error = True
     else:
         action = str(action).replace('\n', '')
         is_error = False
     if action:
         action = ' -> ' + action
     truncated = Truncator(action)
     return prefix + operation.describe() + truncated.chars(40), is_error
예제 #6
0
 def __str__(self):
     truncated_text = Truncator(self.text)
     return truncated_text.chars(30)
예제 #7
0
 def __str__(self):
     truncated_message = Truncator(self.message)
     # 将一个⻓字符串截取为 任意⻓度字符的简便方法(这里我们使用30个字符)
     return truncated_message.chars(30)
예제 #8
0
 def __str__(self):
     truncated_blog = Truncator(self.blog)
     return truncated_blog.chars(15)
예제 #9
0
파일: models.py 프로젝트: tempo3306/tx_web
 def save(self, *args, **kwargs):
     truncated = Truncator(self.message)
     self.slug = slugify(truncated.chars(10))
     super(Post, self).save(*args, **kwargs)
예제 #10
0
 def __str__(self):
     truncated_titulo = Truncator(self.titulo)
     return "{} - {}".format(self.numero_unidad, truncated_titulo.chars(30))
예제 #11
0
 def __str__(self):
   # このメソッドで30字に切り詰めた文字列をリターンする
   truncated_message = Truncator(self.message)
   return truncated_message.chars(30)
예제 #12
0
 def __str__(self):
     truncated_message = Truncator(self.message)
     return truncated_message.chars(30)
예제 #13
0
파일: post.py 프로젝트: zhqingit/qforum
 def __str__(self):
     truncated_content = Truncator(self.content)
     return truncated_content.chars(30)
예제 #14
0
 def __str__(self):
     # Truncator 将长字符串截断为任意字符串大小的便捷方法(此处使用30)
     truncated_message = Truncator(self.message)
     return truncated_message.chars(30)
예제 #15
0
 def __str__(self):
     truncated_name = Truncator(self.name)
     return truncated_name.chars(30)
예제 #16
0
파일: models.py 프로젝트: lethanhtupk/Forum
 def __str__(self):
     truncated_title = Truncator(self.title)
     return truncated_title.chars(30)
예제 #17
0
파일: models.py 프로젝트: tempo3306/tx_web
 def save(self, *args, **kwargs):
     truncated = Truncator(self.subject)
     self.slug = slugify('{0}{1}'.format(self.id, truncated.chars(10)))
     super(Topic, self).save(*args, **kwargs)
예제 #18
0
파일: models.py 프로젝트: tempo3306/tx_web
 def save(self, *args, **kwargs):
     truncated = Truncator(self.name)
     self.slug = slugify('{0}{1}'.format(self.id, truncated.chars(10)))
     super(Board,self).save(*args, **kwargs)
예제 #19
0
파일: models.py 프로젝트: j-millan/todo-app
 def get_truncated_task(self):
     truncated_message = Truncator(self.task)
     return truncated_message.chars(25)
예제 #20
0
 def __str__(self):
     truncated_intro = Truncator(self.intro)
     return truncated_intro.chars(30)
예제 #21
0
 def __str__(self):
     truncated_message = Truncator(self.text)
     return truncated_message.chars(20)
예제 #22
0
 def __str__(self):
     #Truncator 工具类,这是将一个长字符串截取为任意长度字符的简便方法
     truncated_message = Truncator(self.message)
     return truncated_message.chars(30)
예제 #23
0
 def __unicode__(self):
     truncator = Truncator(self.message)
     return u'%s: %s' % (self.id, truncator.chars(20))
예제 #24
0
 def __str__(self):
     truncated_message = Truncator(self.message)
     return truncated_message.chars(30)
예제 #25
0
 def __str__(self):
     truncated_message = Truncator(self.message)
     return truncated_message.chars(30) + " TS: " + str(self.time_stamp)
예제 #26
0
 def __str__(self):
     truncated_entry = Truncator(self.body)
     return str(truncated_entry.chars(30))
예제 #27
0
 def __str__(self):
     trunc_msg = Truncator(self.message)
     return trunc_msg.chars(30)
예제 #28
0
 def __str__(self):
     truncated_description = Truncator(self.description)
     return "{} - {}".format(self.codigo, truncated_description.chars(110))
 def __str__(self):
     truncated_body = Truncator(self.body)
     return truncated_body.chars(50)
예제 #30
0
 def __str__(self):
     truncated_message = Truncator(self.message)
     # 将一个长字符串截取为任意长度字符的简便方法
     return truncated_message.chars(30)
예제 #31
0
	def __str__(self):
		truncated_message = Truncator(self.message)
		return truncated_message.chars(30) + " TS: " + str(self.time_stamp)
예제 #32
0
def markup(text, truncate=None):
    if truncate is not None:
        t = Truncator(text)
        text = t.chars(truncate)

    return markdown(text, safe_mode=False)
예제 #33
0
파일: utils.py 프로젝트: ianmintz/pourover
def ellipse_text(text, max_chars):
    truncate = Truncator(text)

    return truncate.chars(max_chars, u"\u2026")
예제 #34
0
 def device_short_notes(self, obj):  # pylint: disable=no-self-use
     truncator = Truncator(obj.notes)
     return format_html(truncator.chars(50, truncate='...'))