from util import render_tile, BaseTile

from pylons import request, response, session, tmpl_context as c
from pylons.i18n import _ 

from webhelpers.text import truncate

import adhocracy.model as model
from .. import helpers as h
from .. import text

class UserTile(BaseTile):
    
    def __init__(self, user):
        self.user = user
        self.__instance_group = None
   
    def _bio(self):       
        if self.user.bio:
            return text.render(self.user.bio)
        return ""
    
    bio = property(_bio)
    
    def _num_proposals(self):
        pred = lambda d: isinstance(d, model.Proposal) and \
                         d.instance==c.instance and \
                         not d.is_deleted()
        return len(filter(pred, self.user.delegateables))
    
    num_proposals = property(_num_proposals)
    
    def _num_comments(self):
        pred = lambda cm: cm.topic.instance == c.instance and \
                          not cm.is_deleted()
        return len(filter(pred, self.user.comments))
    
    num_comments = property(_num_comments)
    
    def _num_instances(self):
        return len([i for i in self.user.instances if i.is_shown()])
    
    num_instances = property(_num_instances)
    
    def _instance_group(self):
        if c.instance and not self.__instance_group:     
            m = self.user.instance_membership(c.instance)
            self.__instance_group = m.group if m else None
        return self.__instance_group
        
    instance_group = property(_instance_group)

def row(user):
    return render_tile('/user/tiles.html', 'row', UserTile(user), 
                       user=user, instance=c.instance, cached=True)   

def header(user, tile=None, active='activity'):
    if tile is None:
        tile = UserTile(user)
    return render_tile('/user/tiles.html', 'header', tile, 
                       user=user, active=active)
@@ -2,89 +2,21 @@
 rom 
-util import render_tile, BaseTile%0A%0Afrom pylons import request, response, session,
+pylons import
  tmp
@@ -34,32 +34,31 @@
 s c%0A
+%0A
 from 
-pylons.i18n
+adhocracy
  import 
 _ %0A%0A
@@ -57,129 +57,104 @@
 ort 
-_ %0A
+model
 %0Afrom 
-webhelpers.text import truncate%0A%0Aimport adhocracy.model as model%0Afrom .. import helpers as h%0Afrom .. import text
+adhocracy.lib import text%0Afrom adhocracy.lib.tiles.util import render_tile, BaseTile%0A
 %0A%0Acl
@@ -177,20 +177,16 @@
 eTile):%0A
-    
 %0A    def
@@ -270,19 +270,16 @@
  = None%0A
-   
 %0A    def
@@ -290,23 +290,16 @@
 o(self):
-       
 %0A       
@@ -381,20 +381,16 @@
 turn %22%22%0A
-    
 %0A    bio
@@ -407,20 +407,16 @@
 y(_bio)%0A
-    
 %0A    def
@@ -534,18 +534,20 @@
 instance
+ 
 ==
+ 
 c.instan
@@ -653,28 +653,24 @@
 gateables))%0A
-    
 %0A    num_pro
@@ -703,20 +703,16 @@
 posals)%0A
-    
 %0A    def
@@ -896,20 +896,16 @@
 ments))%0A
-    
 %0A    num
@@ -940,20 +940,16 @@
 mments)%0A
-    
 %0A    def
@@ -1040,20 +1040,16 @@
 own()%5D)%0A
-    
 %0A    num
@@ -1086,20 +1086,16 @@
 tances)%0A
-    
 %0A    def
@@ -1170,21 +1170,16 @@
 e_group:
-     
 %0A       
@@ -1325,24 +1325,16 @@
 e_group%0A
-        
 %0A    ins
@@ -1374,16 +1374,17 @@
 group)%0A%0A
+%0A
 def row(
@@ -1455,17 +1455,16 @@
 e(user),
- 
 %0A       
@@ -1523,19 +1523,17 @@
 ed=True)
-   
+%0A
 %0A%0Adef he
@@ -1683,17 +1683,16 @@
 ', tile,
- 
 %0A       
@@ -1732,8 +1732,9 @@
 =active)
+%0A

remove unused imports, cleanup