def test_slug_with_symbols(self):
        slug = slugify("aaa ?? aaa")

        self.assertEqual(slug, "aaa-aaa", msg="Slugify must remove symbols")
Exemple #2
0
	def post(self, request, params):
		user = who_is_logged(self.session)
		if user is None:
			return HttpResponseFound(redirect_to=("/user/login/"))
			
		bm = get_book_manager()
				
		if ('title' in request.data and 'author' in request.data and 
			not_empty(request.data["title"].value) and
			not_empty(request.data["author"].value)):			



			book = bm.createBook({
				"title":request.data["title"].value,
				"author":request.data["author"].value,
				"slug":slugify(request.data["title"].value),
			})
			
			# Exist this book?
			exist_book = bm.findOneBook({"slug":book["slug"]})
			
			if exist_book is None:
				
				# Si el libro no existía guardamos la imagen
				config = ConfigRunner()
				media_root = config.media_root
				media_url = config.media_url
				
				#Si existe, guardamos imagen.
				if "cover" in request.data:
					file_name_server = book["slug"] + "." + request.data["cover"].filename.split(".")[-1]
					file = open(media_root + file_name_server, "wb")
					urlfile = media_url + file_name_server 
					for line in request.data["cover"].file:
						file.write(line)
					
					file.close()
					book["urlfile"] = urlfile
				
				
				id_book = bm.insertBook(book)
				
				if id_book is not None:
					return {
						"book":book,
						"msg":"Creado de forma satisfactoria.",
					}
					
				else:
					return {
						"msg":"Algo falló, inténtelo de nuevo.",
					}
					
			else:
				return {
						"msg":"Ya existe un libro con el título '%s'." % request.data["title"].value,
				}
		
		else:
			return {
				"msg":"Falta alguno de los campos.",
			}
    def test_simple_slug(self):
        slug = slugify("Á b c y ótras")

        self.assertEqual(slug, "a-b-c-y-otras", msg="Slugify must create a slug without spaces, tildes...")