<commit_before>from model import Membership
from datetime import datetime
from re import compile
from i18n import _

class UrlBuilder:
    def __init__(self, webrequest):
        p = compile("[^:]*://[^/]*")
        m = p.match(webrequest.url)
        self.baseUrl = m.group()

    # without trailing /
    def getBaseUrl(self):
        return self.baseUrl
    
    def buildUrl(self, url):
        if url[0] != '/':
            url = "/%s" % url
        return "%s%s" % (self.getBaseUrl(), url)

# Returns all memberships of the given user, in no
# particular order
def membershipsOfUser(user):
    memberships = Membership.gql("WHERE user = :1", user)
    return memberships.fetch(10000)

# Returns a date formatted nicely, comparing it to the current date.
def niceDate(t, lang):
    now = datetime.now()
    if now.year == t.year:
        if now.month == t.month and now.day == t.day:
            return t.strftime(str(_('Today at %H:%S', lang)))
        return t.strftime(str(_('On %b %d', lang)))
    else:
        return t.strftime(str(_('On %D', lang)))
    
# Returns a membership amongst the given ones, where the user
# is the given one. Return None if no one is found.
def findMembershipForUser(memberships, user):
    for membership in memberships:
        if membership.user == user:
            return membership
    return None

# Returns the description of a transaction according to
# a users's point of view. This does not include the date
# of the transaction.<commit_msg>Intento de poner el locale al del usuario, cuando se formatean fechas.<commit_after>from model import Membership
from datetime import datetime
from re import compile
from i18n import _
import locale

class UrlBuilder:
    def __init__(self, webrequest):
        p = compile("[^:]*://[^/]*")
        m = p.match(webrequest.url)
        self.baseUrl = m.group()

    # without trailing /
    def getBaseUrl(self):
        return self.baseUrl
    
    def buildUrl(self, url):
        if url[0] != '/':
            url = "/%s" % url
        return "%s%s" % (self.getBaseUrl(), url)

# Returns all memberships of the given user, in no
# particular order
def membershipsOfUser(user):
    memberships = Membership.gql("WHERE user = :1", user)
    return memberships.fetch(10000)

# Returns a date formatted nicely, comparing it to the current date.
def niceDate(t, lang):
	try:
		locale.setlocale(locale.LC_ALL, lang)
	except:
		localeNotSupported = True
	
	now = datetime.now()
	if now.year == t.year:
	    if now.month == t.month and now.day == t.day:
	        return t.strftime(str(_('Today at %H:%S', lang)))
	    return t.strftime(str(_('On %b %d', lang)))
	else:
		return t.strftime(str(_('On %D', lang)))
    
# Returns a membership amongst the given ones, where the user
# is the given one. Return None if no one is found.
def findMembershipForUser(memberships, user):
    for membership in memberships:
        if membership.user == user:
            return membership
    return None

# Returns the description of a transaction according to
# a users's point of view. This does not include the date
# of the transaction.
{'fraction_non_alphanumeric': 0.11296534017971759, 'fraction_numerical': 0.005776636713735558, 'mean_word_length': 2.9455696202531647, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1472529', 'n_tokens_mistral': 964, 'n_tokens_neox': 926, 'n_words': 340}