[IMP] mail.group: kanban view improved; photo management and code udpated; now has a default photo
bzr revid: tde@openerp.com-20120329073209-doh665jwak2e12hk
This commit is contained in:
+37
-32
@@ -19,13 +19,16 @@
|
||||
#
|
||||
##############################################################################
|
||||
|
||||
import tools
|
||||
import datetime as DT
|
||||
import io
|
||||
import openerp
|
||||
import openerp.tools as tools
|
||||
from osv import osv
|
||||
from osv import fields
|
||||
from tools.translate import _
|
||||
|
||||
import io, StringIO
|
||||
from PIL import Image
|
||||
import StringIO
|
||||
import tools
|
||||
from tools.translate import _
|
||||
|
||||
class mail_group(osv.osv):
|
||||
"""
|
||||
@@ -43,28 +46,30 @@ class mail_group(osv.osv):
|
||||
def action_group_leave(self, cr, uid, ids, context={}):
|
||||
return self.message_unsubscribe(cr, uid, ids, context=context);
|
||||
|
||||
def onchange_photo_mini(self, cr, uid, ids, value, context=None):
|
||||
return {'value': {'photo': value, 'photo_mini': self._photo_resize(cr, uid, value) } }
|
||||
def onchange_photo(self, cr, uid, ids, value, context=None):
|
||||
if not value:
|
||||
return {'value': {'avatar_big': value, 'avatar': value} }
|
||||
return {'value': {'photo_big': value, 'photo': self._photo_resize(cr, uid, value) } }
|
||||
|
||||
def _set_photo_mini(self, cr, uid, id, name, value, args, context=None):
|
||||
self.write(cr, uid, [id], {'photo': value}, context=context)
|
||||
return True
|
||||
def _set_photo(self, cr, uid, id, name, value, args, context=None):
|
||||
if value:
|
||||
return self.write(cr, uid, [id], {'photo_big': value}, context=context)
|
||||
else:
|
||||
return self.write(cr, uid, [id], {'photo_big': value}, context=context)
|
||||
|
||||
def _photo_resize(self, cr, uid, photo, context=None):
|
||||
def _photo_resize(self, cr, uid, photo, width=128, height=128, context=None):
|
||||
image_stream = io.BytesIO(photo.decode('base64'))
|
||||
img = Image.open(image_stream)
|
||||
img.thumbnail((120, 100), Image.ANTIALIAS)
|
||||
img.thumbnail((width, height), Image.ANTIALIAS)
|
||||
img_stream = StringIO.StringIO()
|
||||
img.save(img_stream, "JPEG")
|
||||
return img_stream.getvalue().encode('base64')
|
||||
|
||||
def _get_photo_mini(self, cr, uid, ids, name, args, context=None):
|
||||
result = {}
|
||||
def _get_photo(self, cr, uid, ids, name, args, context=None):
|
||||
result = dict.fromkeys(ids, False)
|
||||
for group in self.browse(cr, uid, ids, context=context):
|
||||
if not group.photo:
|
||||
result[group.id] = False
|
||||
else:
|
||||
result[group.id] = self._photo_resize(cr, uid, group.photo, context=context)
|
||||
if group.photo_big:
|
||||
result[group.id] = self._photo_resize(cr, uid, group.photo_big, context=context)
|
||||
return result
|
||||
|
||||
def is_subscriber(self, cr, uid, ids, name, args, context=None):
|
||||
@@ -73,16 +78,12 @@ class mail_group(osv.osv):
|
||||
result[id] = self.message_is_subscriber(cr, uid, [id], context=context)
|
||||
return result
|
||||
|
||||
def get_messages_nbr(self, cr, uid, ids, name, args, context=None):
|
||||
def get_last_month_msg_nbr(self, cr, uid, ids, name, args, context=None):
|
||||
result = {}
|
||||
message_obj = self.pool.get('mail.message')
|
||||
for id in ids:
|
||||
result[id] = self.message_get_messages_nbr(cr, uid, [id], context=context)
|
||||
return result
|
||||
|
||||
def get_discussions_nbr(self, cr, uid, ids, name, args, context=None):
|
||||
result = {}
|
||||
for id in ids:
|
||||
result[id] = self.message_get_discussions_nbr(cr, uid, [id], context=context)
|
||||
lower_date = (DT.datetime.now() - DT.timedelta(days=30)).strftime(tools.DEFAULT_SERVER_DATE_FORMAT)
|
||||
result[id] = message_obj.search(cr, uid, ['&', '&', ('model', '=', self._name), ('res_id', 'in', ids), ('date', '>=', lower_date)], count=True, context=context)
|
||||
return result
|
||||
|
||||
def get_members_nbr(self, cr, uid, ids, name, args, context=None):
|
||||
@@ -90,27 +91,31 @@ class mail_group(osv.osv):
|
||||
for id in ids:
|
||||
result[id] = len(self.message_get_subscribers_ids(cr, uid, [id], context=context))
|
||||
return result
|
||||
|
||||
|
||||
def _get_default_photo(self, cr, uid, context=None):
|
||||
avatar_path = openerp.modules.get_module_resource('mail', 'static/src/img', 'groupdefault.png')
|
||||
return self._photo_resize(cr, uid, open(avatar_path, 'rb').read().encode('base64'), context=context)
|
||||
|
||||
_columns = {
|
||||
'name': fields.char('Name', size=64, required=True),
|
||||
'description': fields.text('Description'),
|
||||
'responsible_id': fields.many2one('res.users', string='Responsible',
|
||||
ondelete='set null', required=True, select=1),
|
||||
'public': fields.boolean('Public', help='This group is visible by non members'),
|
||||
'photo': fields.binary('Photo'),
|
||||
'photo_mini': fields.function(_get_photo_mini, fnct_inv=_set_photo_mini, string='Photo Mini', type="binary",
|
||||
'photo_big': fields.binary('Full-size photo', help='Field holding the full-sized PIL-supported and base64 encoded version of the group image. The photo field is used as an interface for this field.'),
|
||||
'photo': fields.function(_get_photo, fnct_inv=_set_photo, string='Photo', type="binary",
|
||||
store = {
|
||||
'mail.group': (lambda self, cr, uid, ids, c={}: ids, ['photo'], 10),
|
||||
}),
|
||||
'mail.group': (lambda self, cr, uid, ids, c={}: ids, ['photo_big'], 10),
|
||||
}, help='Field holding the automatically resized (128x128) PIL-supported and base64 encoded version of the group image.'),
|
||||
'joined': fields.function(is_subscriber, type='boolean', string='Joined'),
|
||||
'messages_nbr': fields.function(get_messages_nbr, type='integer', string='Messages count'),
|
||||
'discussions_nbr': fields.function(get_discussions_nbr, type='integer', string='Discussions count'),
|
||||
'last_month_msg_nbr': fields.function(get_last_month_msg_nbr, type='integer', string='Messages count for last month'),
|
||||
'members_nbr': fields.function(get_members_nbr, type='integer', string='Members count'),
|
||||
}
|
||||
|
||||
_defaults = {
|
||||
'public': True,
|
||||
'responsible_id': (lambda s, cr, uid, ctx: uid),
|
||||
'photo': _get_default_photo,
|
||||
}
|
||||
|
||||
mail_group()
|
||||
|
||||
@@ -26,15 +26,16 @@
|
||||
<span style="display: none;"><field name="joined"/></span>
|
||||
<ul>
|
||||
<li><field name="members_nbr"/> members</li>
|
||||
<li t-if="record.joined.raw_value"><b>Joined</b></li>
|
||||
<li t-if="! record.joined.raw_value"><a name="action_group_join" string="Join" type="object">Join</a></li>
|
||||
<li t-if="record.joined.raw_value"><a name="action_group_leave" string="Join" type="object">Leave</a></li>
|
||||
<li><field name="messages_nbr"/> messages in <field name="discussions_nbr"/> discussions</li>
|
||||
<li t-if="! record.joined.raw_value"><a name="action_group_join" string="Join" type="object" class="oe_group_join">Not following</a></li>
|
||||
<li t-if="record.joined.raw_value"><a name="action_group_leave" string="Join" type="object" class="oe_group_leave">Following</a></li>
|
||||
<li><field name="last_month_msg_nbr"/> messages last month</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
<script>
|
||||
$('.oe_group_photo').load(function() { if($(this).width() > $(this).height()) { $(this).addClass('oe_group_photo_wide') } });
|
||||
$('.oe_group_join').mouseover(function () { $(this).html('Follow'); }).mouseleave(function () { $(this).html('Not following'); });
|
||||
$('.oe_group_leave').mouseover(function () { $(this).html('Unfollow'); }).mouseleave(function () { $(this).html('Following'); });
|
||||
</script>
|
||||
</t>
|
||||
</templates>
|
||||
@@ -60,7 +61,7 @@
|
||||
</group>
|
||||
<group colspan="1" col="2">
|
||||
<separator string="Group image" colspan="2"/>
|
||||
<field name="photo_mini" widget='image' nolabel="1" on_change="onchange_photo_mini(photo_mini)"/>
|
||||
<field name="photo" widget='image' nolabel="1" on_change="onchange_photo(photo)"/>
|
||||
</group>
|
||||
<group colspan="1" col="2">
|
||||
<separator string="Privacy settings" colspan="2"/>
|
||||
|
||||
@@ -27,7 +27,7 @@
|
||||
.oe_group_photo {
|
||||
width: 100px;
|
||||
height: auto;
|
||||
clip: rect(10px, 100px, 110px, 0px);
|
||||
clip: rect(0px, 100px, 100px, 0px);
|
||||
}
|
||||
|
||||
.oe_group_photo_wide {
|
||||
@@ -44,6 +44,11 @@
|
||||
min-height: 120px;
|
||||
}
|
||||
|
||||
.oe_group_details a, .oe_group_details a:hover {
|
||||
font-weight: bold;
|
||||
color: #4c4c4c;
|
||||
}
|
||||
|
||||
.oe_group_details h4 {
|
||||
margin: 0;
|
||||
font-size: 13px;
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 19 KiB |
@@ -549,6 +549,7 @@ openerp.mail = function(session) {
|
||||
/* DataSets */
|
||||
this.ds_msg = new session.web.DataSet(this, 'mail.message');
|
||||
this.ds_thread = new session.web.DataSet(this, 'mail.thread');
|
||||
this.ds_groups = new session.web.DataSet(this, 'mail.group');
|
||||
this.ds_users = new session.web.DataSet(this, 'res.users');
|
||||
},
|
||||
|
||||
@@ -749,7 +750,8 @@ openerp.mail = function(session) {
|
||||
*/
|
||||
do_comment: function () {
|
||||
var body_text = this.$element.find('textarea.oe_mail_wall_action_textarea').val();
|
||||
return this.ds_users.call('message_append_note', [[this.session.uid], 'Tweet', body_text, false, 'comment']).then(this.init_comments());
|
||||
return this.ds_thread.call('message_append_note', [[], 'Tweet', body_text, false, 'comment']).then(this.init_comments());
|
||||
//return this.ds_users.call('message_append_note', [[this.session.uid], 'Tweet', body_text, false, 'comment']).then(this.init_comments());
|
||||
},
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user