<commit_before>from app.structures.models.user import *
from app.structures.models.course import *

def createUsername(firstName, lastName):
  firstName = firstName.lower()
  lastName = lastName.lower()
  #Try increasing the length of the first name to remove conflicts
  for i in range(1,len(firstName)+1):
    try:
      tryName = firstName[:i]+lastName
      u = User.objects.get(username=tryName)
    except User.DoesNotExist:
      return firstName[:i]+lastName

  #If we didn't get a successful name here append numbers
  conflictNumber = 1
  while True:
    try:
      tryName = firstName+lastName+str(conflictNumber)
      u = User.objects.get(username=tryName)
      conflictNumber += 1
    except:
      return firstName+lastName+str(conflictNumber)

def addUser(firstName, lastName, email=None, password="<PASSWORD>"):
  '''Creates a user with a distinct username'''
  #create the user
  u = User()
  u.username = createUsername(firstName, lastName)
  u.firstName = firstName
  u.lastName = lastName
  u.email = email
  u.setPassword(password)
  u.save()
  #return the user when we are done
  return u

def addOrGetUser(firstName, lastName, email=None, password="<PASSWORD>"):
  '''If we are given an email try to get an existing user otherwise create
  a new user'''
  if email != None:
    try:
      u = User.objects.get(firstName=firstName, lastName=lastName, email=email)
      return u
    except User.DoesNotExist:
      pass

  return addUser(firstName, lastName, email, password)

def addOrGetByUsername(username, firstName, lastName, email=None, password="<PASSWORD>"):
  try:
    u = User.objects.get(username=username)
    return u
  except User.DoesNotExist:
    u = User()
    u.username = username
    u.firstName = firstName<commit_msg>quick bug fix<commit_after>from app.structures.models.user import *
from app.structures.models.course import *

def createUsername(firstName, lastName):
  firstName = firstName.lower()
  lastName = lastName.lower()
  #Try increasing the length of the first name to remove conflicts
  for i in range(1,len(firstName)+1):
    try:
      tryName = firstName[:i]+lastName
      u = User.objects.get(username=tryName)
    except User.DoesNotExist:
      return firstName[:i]+lastName

  #If we didn't get a successful name here append numbers
  conflictNumber = 1
  while True:
    try:
      tryName = firstName+lastName+str(conflictNumber)
      u = User.objects.get(username=tryName)
      conflictNumber += 1
    except:
      return firstName+lastName+str(conflictNumber)

def addUser(firstName, lastName, email=None, password="<PASSWORD>"):
  '''Creates a user with a distinct username'''
  #create the user
  u = User()
  u.username = createUsername(firstName, lastName)
  u.firstName = firstName
  u.lastName = lastName
  u.email = email
  u.setPassword(password)
  u.save()
  #return the user when we are done
  return u

def addOrGetUser(firstName, lastName, email=None, password="<PASSWORD>"):
  '''If we are given an email try to get an existing user otherwise create
  a new user'''
  if email != None:
    try:
      u = User.objects.filter(firstName=firstName, lastName=lastName, email=email)
      return u[0]
    except User.DoesNotExist:
      pass

  return addUser(firstName, lastName, email, password)

def addOrGetByUsername(username, firstName, lastName, email=None, password="<PASSWORD>"):
  try:
    u = User.objects.get(username=username)
    return u
  except User.DoesNotExist:
    u = User()
    u.username = username
    u.firstName = firstName
{'fraction_non_alphanumeric': 0.10249150622876557, 'fraction_numerical': 0.002548131370328426, 'mean_word_length': 3.859697386519945, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '4402283', 'n_tokens_mistral': 1108, 'n_tokens_neox': 1097, 'n_words': 315}