Changeset 188

Show
Ignore:
Timestamp:
01/22/09 13:19:03 (10 months ago)
Author:
gallardj
Message:

Fixes #2929. Uses a smart truncate function to clip the project description to around 35 characters for easy viewing on the browse page.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • management/bs-admin/trunk/cache_and_sync.py

    r184 r188  
    195195 
    196196 
     197def smart_truncate(content, length=35, suffix='...'): 
     198  if len(content) <= length: 
     199    return content 
     200  else: 
     201    return ' '.join(content[:length+1].split(' ')[0:-1]) + suffix 
     202 
    197203def sync_project_profiles(): 
    198204  # Create Social DB 
     
    321327          conn.commit() 
    322328         
     329        sql = "SELECT value FROM elgg_profile_data WHERE owner='%s' AND name='minibio'" % (project_id) 
     330        cursor.execute(sql) 
     331        value = cursor.fetchall() 
     332        if value: 
     333          sql = "UPDATE elgg_profile_data SET value=%s WHERE owner=%s AND name='minibio'" 
     334          cursor.execute(sql, (smart_truncate(descr), project_id)) 
     335          conn.commit() 
     336        else: 
     337          sql = "INSERT INTO elgg_profile_data VALUES (DEFAULT, %s, 'LOGGED_IN', 'minibio', %s)" 
     338          cursor.execute(sql, (project_id, smart_truncate(descr))) 
     339          conn.commit() 
     340         
    323341        sql = "SELECT value FROM elgg_profile_data WHERE owner='%s' AND name='workweb'" % (project_id) 
    324342        cursor.execute(sql)