[IMP]Refactore.

bzr revid: vme@tinyerp.com-20140325122327-9lqr308hz01q25p7
This commit is contained in:
Vidhin Mehta (OpenERP) 2014-03-25 17:53:27 +05:30
parent 458991e011
commit 0881710694
2 changed files with 42 additions and 45 deletions

View File

@ -204,10 +204,6 @@ class event_track(osv.osv):
_group_by_full = {
'stage_id': _read_group_stage_ids,
}
def _fetch_record(self, cr, uid, event_id, context=None):
return self.search(cr, uid, [('event_id','=',event_id),('date','!=',False),('duration','!=',False),('duration','!=',0)], context=context)
def _get_value(self, cr, uid, event, context=None):
keys_for_table = {}
format_date = []
@ -216,13 +212,23 @@ class event_track(osv.osv):
rooms = []
talks = {}
skip_td = {}
domain = [('event_id','=',event.id),('date','!=',False),('duration','!=',False),('duration','!=',0)]
fields = ['id', 'duration', 'location_id', 'name', 'date', 'color', 'speaker_ids', 'website_published']
location_object = self.pool.get('event.track.location')
event_track_ids = self._fetch_record(cr, uid, event.id, context=context)
res_partner = self.pool.get('res.partner')
local_tz = pytz.timezone(event.timezone_of_event)
event_tracks = self.search_read(cr, uid, domain, fields, context=context)
def get_speaker_name(ids):
speaker_names = res_partner.name_get(cr, uid, ids, context=context)
string = "By "
for name in speaker_names:
string = string + name[1]
if(speaker_names[-1:][0][0] != name[0]):string = string + ", "
return string
def set_value(key, val):
sort_tracks[key][val]=[]
for track in self.read(cr, uid, event_track_ids, ['date','duration'],context=context):
for track in event_tracks:
start_time, end_time, key = CONVERT_TIME(track['date'], track['duration'], local_tz)
if not keys_for_table.has_key(key):
keys_for_table[key] = []
@ -233,9 +239,9 @@ class event_track(osv.osv):
[set_value(key, value[0].strftime('%H:%M')+" - "+value[1].strftime('%H:%M')) for key in keys_for_table.keys() for value in keys_for_table[key]]
for track in self.browse(cr, uid, event_track_ids, context=context):
if(track.location_id):room_list.append(track.location_id.id)
start_time, end_time, key = CONVERT_TIME(track.date, track.duration, local_tz)
for track in event_tracks:
if(track['location_id']):room_list.append(track['location_id'][0])
start_time, end_time, key = CONVERT_TIME(track['date'], track['duration'], local_tz)
secret_key = None
row_span = 0
for index, value in enumerate(keys_for_table[key]):
@ -246,7 +252,9 @@ class event_track(osv.osv):
if value[1] == end_time and secret_key:
if not index == row_span:
row_span = row_span - 1
sort_tracks[key][secret_key].append({'object':track,'row_span': index - row_span, 'location':track.location_id.id})
track['row_span'] = index - row_span
track['speaker_ids'] = get_speaker_name(track['speaker_ids']) if len(track['speaker_ids'])else ""
sort_tracks[key][secret_key].append(track)
for room in list(set(room_list)):
if room:rooms.append([room, location_object.browse(cr, uid, room).name])
@ -257,14 +265,14 @@ class event_track(osv.osv):
format_date.append((datetime.datetime.strptime(track, '%m-%d-%y')).strftime("%d %B, %Y"))
key1 = sort_tracks[track].keys()
for tra in sort_tracks[track].keys():
sort_tracks[track][tra] = sorted(sort_tracks[track][tra], key=lambda x: x['location'])
sort_tracks[track][tra] = sorted(sort_tracks[track][tra], key=lambda x: x['location_id'])
for i in sort_tracks[track][tra]:
if i['row_span']:
skip_time = key1[key1.index(tra)+1: key1.index(tra)+i['row_span']]
if not skip_td[track].has_key(i['location']):
skip_td[track] [i['location']] = []
skip_td[track][i['location']] = skip_td[track] [i['location']] + skip_time
if not skip_td[track].has_key(i['location_id'][0]):
skip_td[track] [i['location_id'][0]] = []
skip_td[track][i['location_id'][0]] = skip_td[track] [i['location_id'][0]] + skip_time
return {
'event': event,
'main_object': event,

View File

@ -86,39 +86,28 @@
</t>
<t t-if="len(days[day][slot])">
<t t-set="record" t-value="days[day][slot][index]" />
<t t-if="not record['object'].location_id and for_all" >
<t t-if="not record['location_id'] and for_all" >
<t t-set="for_all" t-value="False"/>
<td t-if="sid" id="seach_enable" t-att-colspan="len(room_list)" t-attf-class="event_color_#{record['object'].color} text-center">
<img t-if="not record['object'].website_published" title="Not Published" style="width:10px; height:10px" src="/web/static/src/img/icons/gtk-no.png" />
<a t-attf-href="/event/#{ slug(event) }/track/#{ slug([record['object'].id, record['object'].name]) }"> <t t-esc="record['object'].name" /> </a>
<t t-foreach="record['object'].speaker_ids" t-as="speaker">
<small class="text-muted">
<t t-if="speaker == record['object'].speaker_ids[:1][0]"><br/>By </t>
<t t-esc="speaker.name"/>
<t t-if=" speaker.id !=record['object'].speaker_ids[:1][0].id">,</t>
</small>
</t>
<td t-if="sid" id="seach_enable" t-att-colspan="len(room_list)" t-attf-class="event_color_#{record['color']} text-center">
<img t-if="not record['website_published']" title="Not Published" style="width:10px; height:10px" src="/web/static/src/img/icons/gtk-no.png" />
<a t-attf-href="/event/#{ slug(event) }/track/#{ slug([record['id'], record['name']]) }"> <t t-esc="record['name']" /> </a>
<br/><small class="text-muted"> <t t-esc="record['speaker_ids']" /></small>
</td>
</t>
<t t-if="record['object'].location_id.id != room[0] and for_all" >
<td t-attf-style="width: #{td_width}px;">
</td>
</t>
<t t-if="record['object'].location_id.id == room[0]" >
<td t-att-rowspan="record['row_span']" t-attf-style="width: #{td_width}px;"
t-attf-class="event_color_#{record['object'].color}" id="seach_enable">
<img t-if="not record['object'].website_published" title="Not Published" style="width:10px; height:10px" src="/web/static/src/img/icons/gtk-no.png" />
<a t-attf-href="/event/#{ slug(event) }/track/#{ slug([record['object'].id, record['object'].name]) }"> <t t-esc="record['object'].name" /> </a>
<t t-foreach="record['object'].speaker_ids" t-as="speaker">
<small class="text-muted">
<t t-if="speaker == record['object'].speaker_ids[:1][0]"><br/>By </t>
<t t-esc="speaker.name"/>
<t t-if=" speaker.id !=record['object'].speaker_ids[:1][0].id">,</t>
</small>
<t t-if="record['location_id']">
<t t-if="record['location_id'][0] != room[0] and for_all" >
<td t-attf-style="width: #{td_width}px;">
</td>
</t>
<t t-if="record['location_id'][0] == room[0]" >
<td t-att-rowspan="record['row_span']" t-attf-style="width: #{td_width}px;" t-attf-class="event_color_#{record['color']}" id="seach_enable">
<img t-if="not record['website_published']" title="Not Published" style="width:10px; height:10px" src="/web/static/src/img/icons/gtk-no.png" />
<a t-attf-href="/event/#{ slug(event) }/track/#{ slug([record['id'], record['name']]) }"> <t t-esc="record['name']" /> </a>
<br/><small class="text-muted"> <t t-esc="record['speaker_ids']" /></small>
</td>
<t t-if="record['id'] != days[day][slot][-1]['id']" >
<t t-set="index" t-value="index + 1"/>
</t>
</td>
<t t-if="record['object'].id != days[day][slot][-1]['object'].id" >
<t t-set="index" t-value="index + 1"/>
</t>
</t>
</t>