ensure teams have a slug

pull/83/head
Thibault Duplessis 2012-12-18 01:06:38 +01:00
parent f2be5e79c2
commit 808ef19c5d
3 changed files with 6 additions and 2 deletions

View File

@ -3,6 +3,7 @@ package team
import user.User
import ornicar.scalalib.Random
import org.joda.time.DateTime
import com.novus.salat.annotations.Key
import java.text.Normalizer
@ -44,5 +45,7 @@ object Team {
createdAt = DateTime.now,
createdBy = createdBy.id)
def nameToId(name: String) = templating.StringHelper slugify name
def nameToId(name: String) = (templating.StringHelper slugify name) |> { slug
slug.isEmpty.fold(Random nextString 8, slug)
}
}

View File

@ -12,7 +12,7 @@ object StringHelper extends StringHelper
trait StringHelper {
def slugify(input: String) = {
val nowhitespace = input.replace(" ", "-")
val nowhitespace = input.trim.replace(" ", "-")
val normalized = Normalizer.normalize(nowhitespace, Normalizer.Form.NFD)
val slug = """[^\w-]""".r.replaceAllIn(normalized, "")
slug.toLowerCase

1
todo
View File

@ -49,3 +49,4 @@ show all join requests
show join requests in teams list
kick someone out of a team
team search
team forum recent posts is broken