Exemple #1
0
def handle_find(entry,values):
  rack = values.get('rack')
  patt = values.get('patt')

  # See if it's a special case (cookie)
  matches = special_case(rack, patt)
  if matches is None:
    # See if it's a multiple word case
    if patt:
      patts = []
      parts = patt.replace(',','/').split('/')
      if len(parts) > 1:
	for part in parts:
	  patts.append(format_patt(part, True))
      if len(patts) > 1:
	matches = search.search2(rack, patts)
  if matches is None:
    matches = search.search(rack, format_patt(patt))

  def compare(a,b):
    d = len(a)-len(b)
    if d:
      return -d
    if a < b:
      return -1
    elif a > b:
      return +1
    return 0

  entries = []

  if matches:
    matches.sort(cmp=compare)

    words = []
    last_len = 0
    for match in matches:
      l = len(match)
      if l != last_len and len(words):
        entries.append({'len': last_len, 'words': ', '.join(words)})
        words = []
      last_len = l
      words.append(match)
    if len(words):
      entries.append({'len': last_len, 'words': ', '.join(words)})

  return {
    'rack':    rack,
    'patt':    patt,
    'entries': entries
  }
Exemple #2
0
def handle_matches(entry,values):
  MAX_MATCHES = 100

  id               = entry[COL_ID]
  location         = entry[COL_LOCATION]
  country          = GazCountry(location)
  x                = entry[COL_X]
  y                = entry[COL_Y]
  tz               = entry[COL_TZ]
  gender           = entry[COL_GENDER]
  age              = Age(entry[COL_DOB])
  ethnicity        = entry[COL_ETHNICITY]
  height           = entry[COL_HEIGHT]
  weight           = entry[COL_WEIGHT]
  gender_choice    = entry[COL_GENDER_CHOICE]
  age_min          = entry[COL_AGE_MIN]
  age_max          = entry[COL_AGE_MAX]
  ethnicity_choice = entry[COL_ETHNICITY_CHOICE]
  height_min       = entry[COL_HEIGHT_MIN]
  height_max       = entry[COL_HEIGHT_MAX]
  weight_choice    = entry[COL_WEIGHT_CHOICE]

  ids = search.search2(300,'distance',id,x,y,tz,gender,age,ethnicity,height,weight,gender_choice,age_min,age_max,ethnicity_choice,height_min,height_max,weight_choice)[:MAX_MATCHES]

  # Remove blocked members
  ids = filter(lambda x:not BlockedMutually(id,x), ids)

  SaveResults(id, ids)

  SetLocale(country)

  unit_distance, unit_height = Units(country)

  criteria = []
  if gender_choice:
    criteria.append('%s' % (GenderList(gender_choice)))
  if age_min or age_max:
    criteria.append('%s years old' % (Range(age_min, age_max)))
  if height_min or height_max:
    criteria.append('%s tall' % (Range(Height(height_min,unit_height,2), Height(height_max,unit_height,2))))
  if ethnicity_choice:
    criteria.append('%s' % (EthnicityList(ethnicity_choice)))

  dict = {}
  dict['action']   = 'member'
  dict['type']     = 'short'
  dict['criteria'] = ', '.join(criteria)
  dict['entries']  = ListMembers(ids,None,location,x,y,tz,unit_distance)

  return dict
  y                = entry[COL_Y]
  tz               = entry[COL_TZ]
  gender           = entry[COL_GENDER]
  age              = Age(entry[COL_DOB])
  ethnicity        = entry[COL_ETHNICITY]
  height           = entry[COL_HEIGHT]
  weight           = entry[COL_WEIGHT]
  gender_choice    = entry[COL_GENDER_CHOICE]
  age_min          = entry[COL_AGE_MIN]
  age_max          = entry[COL_AGE_MAX]
  ethnicity_choice = entry[COL_ETHNICITY_CHOICE]
  height_min       = entry[COL_HEIGHT_MIN]
  height_max       = entry[COL_HEIGHT_MAX]
  weight_choice    = entry[COL_WEIGHT_CHOICE]

  ids = search.search2(50,'distance',id,x,y,tz,gender,age,ethnicity,height,weight,gender_choice,age_min,age_max,ethnicity_choice,height_min,height_max,weight_choice)

  # Remove blocked members
  ids = filter(lambda x:not BlockedMutually(id,x), ids)

  for i in ids:
    if i not in results:
      results[i] = []
    results[i].append(id)

for id in results.keys():
  db.execute('SELECT * FROM profiles WHERE id=%d LIMIT 1' % (id))
  entry = db.fetchone()
  if not entry:
    continue
  email         = entry[COL_EMAIL]
Exemple #4
0
def handle_results(entry,values):
  MAX_MATCHES = 200

  id               = entry[COL_ID]
  location         = entry[COL_LOCATION]
  country          = GazCountry(location)
  x                = entry[COL_X]
  y                = entry[COL_Y]
  tz               = entry[COL_TZ]
  gender           = entry[COL_GENDER]
  age              = Age(entry[COL_DOB])
  ethnicity        = entry[COL_ETHNICITY]
  height           = entry[COL_HEIGHT]
  weight           = entry[COL_WEIGHT]
  gender_choice    = entry[COL_GENDER_CHOICE]
  age_min          = entry[COL_AGE_MIN]
  age_max          = entry[COL_AGE_MAX]
  ethnicity_choice = entry[COL_ETHNICITY_CHOICE]
  height_min       = entry[COL_HEIGHT_MIN]
  height_max       = entry[COL_HEIGHT_MAX]
  weight_choice    = entry[COL_WEIGHT_CHOICE]

  ParseAge(values, 'age_min')
  ParseAge(values, 'age_max')
  ParseRange(values, 'age_min', 'age_max')
  ParseHeight(values, 'height_min')
  ParseHeight(values, 'height_max')
  ParseRange(values, 'height_min', 'height_max')

  distance = None
  if values.get('distance'):
    distance = int(values['distance'])
    search_location = location
    if values.get('location'):
      tuple = GazLocation(values['location'])
      if tuple:
        search_location = values['location']
        x = tuple[0]
        y = tuple[1]
  if values.get('age_min'):
    age_min = int(values['age_min'])
  if values.get('age_max'):
    age_max = int(values['age_max'])
  if values.get('ethnicity_choice'):
    ethnicity_choice = eval(values['ethnicity_choice'])
  if values.get('height_min'):
    height_min = int(values['height_min'])
  if values.get('height_max'):
    height_max = int(values['height_max'])
  if values.get('weight_choice'):
    weight_choice = eval(values['weight_choice'])
  order = None
  if values.get('order'):
    order = values['order']

  ids = search.search2(distance,order,id,x,y,tz,gender,age,ethnicity,height,weight,gender_choice,age_min,age_max,ethnicity_choice,height_min,height_max,weight_choice)[:MAX_MATCHES]

  # Remove blocked members
  ids = filter(lambda x:not BlockedMutually(id,x), ids)

  SaveResults(id, ids)

  SetLocale(country)

  unit_distance, unit_height = Units(country)

  criteria = []
  if gender_choice:
    criteria.append('%s' % (GenderList(gender_choice)))
  if age_min or age_max:
    criteria.append('%s years old' % (Range(age_min, age_max)))
  if height_min or height_max:
    criteria.append('%s tall' % (Range(Height(height_min,unit_height,2), Height(height_max,unit_height,2))))
  if ethnicity_choice:
    criteria.append('%s' % (EthnicityList(ethnicity_choice)))

  dict = {}
  dict['action']   = 'member'
  dict['type']     = 'short'
  dict['around']   = Distance(distance,unit_distance) + ' around ' + GazPlacename(search_location, location) if distance else 'Worldwide'
  dict['criteria'] = ', '.join(criteria)
  dict['entries']  = ListMembers(ids,None,location,x,y,tz,unit_distance)
  dict['nav']      = 'search'

  return dict