Exemplo n.º 1
0
 def test_cut(self):
     self.assertEqual(cut('a string to be mangled', 'a'),
                       ' string to be mngled')
     self.assertEqual(cut('a string to be mangled', 'ng'),
                       'a stri to be maled')
     self.assertEqual(cut('a string to be mangled', 'strings'),
                       'a string to be mangled')
Exemplo n.º 2
0
 def test_cut(self):
     self.assertEqual(cut('a string to be mangled', 'a'),
                      ' string to be mngled')
     self.assertEqual(cut('a string to be mangled', 'ng'),
                      'a stri to be maled')
     self.assertEqual(cut('a string to be mangled', 'strings'),
                      'a string to be mangled')
Exemplo n.º 3
0
def grammar(value, arg):

    "Removes all | separators, creates line breaks and adds grammar description"

    separator = '|'
    subvalue = cut(value, separator)

    event_type_object = arg
    grammar_text = event_type_object.text_field.split(separator)
    grammar_text_len = grammar_text.__len__()

    # check whether a event type is given
    # also check whether user requested to not add grammar descriptions
    if (grammar_text[0] != "None") and (grammar_text[0] !=
                                        "none") and (arg is not None):
        x = ''
        y = 0
        for i in subvalue.splitlines():
            if y < grammar_text_len:
                strg = ' ' + '(' + grammar_text[y] + ')'
            else:
                strg = ''

            x += i + strg + ' \r\n'
            y += 1

        subvalue = x

    value = urlize(subvalue)
    value = linebreaks(value)

    return value
Exemplo n.º 4
0
 def format_result(self, request, item):
     context = RequestContext(request)
     return {
         'id': item.id,
         'title': item.title,
         'desc': cut(truncatewords(striptags(item.description), 15), '&nbsp;')
     }
Exemplo n.º 5
0
Arquivo: views.py Projeto: brob/trucks
def getZip(latlng):
	# grab some lat/long coords from wherever. For this example,
	# I just opened a javascript console in the browser and ran:
	#
	# navigator.geolocation.getCurrentPosition(function(p) {
	# console.log(p);
	# })
	#
	latLngVar = defaultfilters.cut(latlng, " ")

	# Did the geocoding request comes from a device with a
	# location sensor? Must be either true or false.
	sensor = 'true'

	# Hit Google's reverse geocoder directly
	# NOTE: I *think* their terms state that you're supposed to
	# use google maps if you use their api for anything.
	base = "http://maps.googleapis.com/maps/api/geocode/json?"
	params = "latlng={latlng}&sensor={sen}".format(
		latlng = latLngVar,
		sen = "true"
	)
	url = "{base}{params}".format(base=base, params=params)
	response = requests.get(url)
	jsonObj = json.loads(response.content)
	fullAddress = jsonObj['results'][0]['formatted_address']
	return str(fullAddress)
Exemplo n.º 6
0
 def test_non_string_input(self):
     # Filters shouldn't break if passed non-strings
     self.assertEqual(addslashes(123), '123')
     self.assertEqual(linenumbers(123), '1. 123')
     self.assertEqual(lower(123), '123')
     self.assertEqual(make_list(123), ['1', '2', '3'])
     self.assertEqual(slugify(123), '123')
     self.assertEqual(title(123), '123')
     self.assertEqual(truncatewords(123, 2), '123')
     self.assertEqual(upper(123), '123')
     self.assertEqual(urlencode(123), '123')
     self.assertEqual(urlize(123), '123')
     self.assertEqual(urlizetrunc(123, 1), '123')
     self.assertEqual(wordcount(123), 1)
     self.assertEqual(wordwrap(123, 2), '123')
     self.assertEqual(ljust('123', 4), '123 ')
     self.assertEqual(rjust('123', 4), ' 123')
     self.assertEqual(center('123', 5), ' 123 ')
     self.assertEqual(center('123', 6), ' 123  ')
     self.assertEqual(cut(123, '2'), '13')
     self.assertEqual(escape(123), '123')
     self.assertEqual(linebreaks_filter(123), '<p>123</p>')
     self.assertEqual(linebreaksbr(123), '123')
     self.assertEqual(removetags(123, 'a'), '123')
     self.assertEqual(striptags(123), '123')
Exemplo n.º 7
0
 def test_non_string_input(self):
     # Filters shouldn't break if passed non-strings
     self.assertEqual(addslashes(123), '123')
     self.assertEqual(linenumbers(123), '1. 123')
     self.assertEqual(lower(123), '123')
     self.assertEqual(make_list(123), ['1', '2', '3'])
     self.assertEqual(slugify(123), '123')
     self.assertEqual(title(123), '123')
     self.assertEqual(truncatewords(123, 2), '123')
     self.assertEqual(upper(123), '123')
     self.assertEqual(urlencode(123), '123')
     self.assertEqual(urlize(123), '123')
     self.assertEqual(urlizetrunc(123, 1), '123')
     self.assertEqual(wordcount(123), 1)
     self.assertEqual(wordwrap(123, 2), '123')
     self.assertEqual(ljust('123', 4), '123 ')
     self.assertEqual(rjust('123', 4), ' 123')
     self.assertEqual(center('123', 5), ' 123 ')
     self.assertEqual(center('123', 6), ' 123  ')
     self.assertEqual(cut(123, '2'), '13')
     self.assertEqual(escape(123), '123')
     self.assertEqual(linebreaks_filter(123), '<p>123</p>')
     self.assertEqual(linebreaksbr(123), '123')
     self.assertEqual(removetags(123, 'a'), '123')
     self.assertEqual(striptags(123), '123')
Exemplo n.º 8
0
def fix_json_string(string):
    """
    Marks a string as not requiring further HTML escaping prior to output.
    """
    string = safe(string)
    string = string.replace('"\\"',"'").replace('\\"\"', "'") # fix quotes
    string = cut(string,"\"") # keep fixing
    string = safe(string)  # keep fixing
    return string
Exemplo n.º 9
0
 def test_non_string_input(self):
     self.assertEqual(cut(123, '2'), '13')
Exemplo n.º 10
0
 def test_non_string_input(self):
     self.assertEqual(cut(123, "2"), "13")
Exemplo n.º 11
0
 def test_non_matching_string(self):
     self.assertEqual(
         cut("a string to be mangled", "strings"), "a string to be mangled"
     )
Exemplo n.º 12
0
 def test_non_string_input(self):
     self.assertEqual(cut(123, '2'), '13')
Exemplo n.º 13
0
 def test_character(self):
     self.assertEqual(cut('a string to be mangled', 'a'), ' string to be mngled')
Exemplo n.º 14
0
 def test_non_matching_string(self):
     self.assertEqual(cut('a string to be mangled', 'strings'),
                      'a string to be mangled')
Exemplo n.º 15
0
 def test_characters(self):
     self.assertEqual(cut('a string to be mangled', 'ng'),
                      'a stri to be maled')
Exemplo n.º 16
0
 def test_characters(self):
     self.assertEqual(cut("a string to be mangled", "ng"), "a stri to be maled")
Exemplo n.º 17
0
 def test_characters(self):
     self.assertEqual(cut('a string to be mangled', 'ng'), 'a stri to be maled')
Exemplo n.º 18
0
 def test_non_matching_string(self):
     self.assertEqual(cut('a string to be mangled', 'strings'), 'a string to be mangled')
Exemplo n.º 19
0
 def test_character(self):
     self.assertEqual(cut('a string to be mangled', 'a'),
                      ' string to be mngled')
Exemplo n.º 20
0
 def test_character(self):
     self.assertEqual(cut("a string to be mangled", "a"), " string to be mngled")