def index2(self, custom1=None, member=None, queue=None, date=None, hour=None): ''' List records ''' log.debug('index2: custom1=%s (%s), member=%s (%s), queue=%s (%s), date=%s (%s), hour=%s (%s).' % ( custom1, type(custom1), member, type(member), queue, type(queue), date, type(date), hour, type(hour))) session['custom1'] = custom1 if custom1 is not None and custom1!='' else None session['member'] = member if member is not None and member!=-1 else None session['queue'] = queue if queue is not None and queue!=-1 else None session['date'] = date if date is not None else None session['hour'] = hour if hour is not None and hour!='' else None session.save() # User must be admin or queue supervisor sv = ['admin'] for q in Globals.asterisk.queues: sv.append('SV ' + q) if not in_any_group(*sv): tmpl_context.grid = None flash(u'Accès interdit !', 'error') else: tmpl_context.grid = grid tmpl_context.form = search_form # Use tabs ui_tabs_js.inject() return dict( title=u"Liste des enregistrements", debug='', values={'custom1': custom1, 'member': member, 'queue': queue, 'date': date, 'hour': hour})
def index(self, **kw): log.debug('index') if Globals.manager is None: flash(u'Vérifier la connexion Asterisk', 'error') else: Globals.manager.send_action({'Action': 'QueueStatus'}) for k in ('custom1', 'member', 'queue', 'date', 'hour'): if k in session.keys(): del(session[k]) session.save() # User must be admin or queue supervisor sv = ['admin'] for q in Globals.asterisk.queues: sv.append('SV ' + q) if not in_any_group(*sv): tmpl_context.grid = None flash(u'Accès interdit !', 'error') else: tmpl_context.grid = grid tmpl_context.form = search_form # Use tabs ui_tabs_js.inject() return dict(title=u"Liste des enregistrements", debug='', values={})
def index2(self, number=None, in_out=None, date=None, hour=None): cdrs = check_access() filter = [] if number: number = str(number) filter.append(u'numéro contient ' + number) cdrs = cdrs.filter((CDR.src.like('%' + number + '%')) | (CDR.dst.like('%' + number + '%'))) if in_out=='in': filter.append(u'type entrant') #cdrs = cdrs.filter('''NOT (dstchannel ~ E'Dahdi/1?\\\\d-1' OR dstchannel LIKE 'IAX2/teliax%')''') #cdrs = cdrs.filter(sqlalchemy.not_(CDR.lastdata.ilike('Dahdi/g0/%'))) cdrs = cdrs.filter(CDR.channel.ilike('SIP/TOICSB%')) elif in_out=='out': filter.append(u'type sortant') #cdrs = cdrs.filter(''' (dstchannel ~ E'Dahdi/1?\\\\d-1' OR dstchannel LIKE 'IAX2/teliax%')''') #cdrs = cdrs.filter(CDR.lastdata.ilike('Dahdi/g0/%')) cdrs = cdrs.filter(CDR.dstchannel.ilike('SIP/TOICSB%')) if date: filter.append(date.strftime('date %d/%m/%Y')) if db_engine=='oracle': cdrs = cdrs.filter(sqlalchemy.func.trunc(CDR.calldate, 'J')==date) else: # PostgreSql cdrs = cdrs.filter(sqlalchemy.sql.cast(CDR.calldate, sqlalchemy.types.DATE)==date) if hour: filter.append(u'heure approximative %dh%02d' % (hour[0], hour[1])) if db_engine=='oracle': if hour[1]>=30: hour1 = '%02d:%02d' % (hour[0], hour[1]-30) hour2 = '%02d:%02d' % (hour[0]+1, hour[1]-30) else: hour1 = '%02d:%02d' % (hour[0]-1, hour[1]+30) hour2 = '%02d:%02d' % (hour[0], hour[1]+30) cdrs = cdrs.filter(hour1<=sqlalchemy.func.to_char(CDR.calldate, 'HH24:MI')) cdrs = cdrs.filter(sqlalchemy.func.to_char(CDR.calldate, 'HH24:MI')<=hour2) else: # PostgreSql hour = '%d:%02d' % (hour[0], hour[1]) cdrs = cdrs.filter("'" + hour + "' - '" + interval + "'::interval <= calldate::time AND calldate::time <= '" + hour + "' + '" + interval + "'::interval") if len(filter): if len(filter)>1: m = u'Critères: ' else: m = u'Critere: ' flash( m + ', et '.join(filter) + '.') global filtered_cdrs filtered_cdrs = cdrs tmpl_context.form = search_form tmpl_context.grid = cdr_grid values = {'in_out': in_out, 'date': date, 'number': number, 'hour': hour} # Use tabs ui_tabs_js.inject() return dict( title=u'Journal des appels', debug='', values=values)
def new(self, **kw): ''' Display new phone form ''' tmpl_context.ip_form = ip_form tmpl_context.form = new_phone_form from tw.uitheme import uilightness_css uilightness_css.inject() from tw.jquery.ui import ui_tabs_js ui_tabs_js.inject() return dict(title = u'Nouveau téléphone', debug='', values='')
def index(self, selected=None, daily=None): if not in_any_group('admin','STATS'): flash(u'Accès interdit !', 'error') redirect('/') if daily: log.info('stats_type <- %s' % daily) self.stats_type = daily (m,d,y) = daily.split('/') title = u'Statistiques quotidiennes de %s %s' % (month_name[int(m)-1], y) flot_label = u'Appels quotidiens (%s %s)' % (month_name[int(m)-1], y) last_day = monthrange(int(y),int(m))[1] row_list = [last_day, 15, 10, 5] else: self.stats_type = None title = u'Statistiques mensuelles' flot_label = u'Appels mensuels' row_list = [12, 18, 24, 30, 36, 48, 60, 120] # Data grid tmpl_context.data_grid = MyJqGrid( id='data_grid', url='/stats/fetch', caption=u"Valeurs", sortname='name', sortorder='desc', colNames = [u'Jour' if daily else u'Mois', u'Appels', u'Durée'], colModel = [ { 'name': 'date', 'width': 60, 'sortable': True}, { 'name': 'calls', 'width': 40, 'align': 'right', 'sortable': True}, { 'name': 'billsec', 'width': 40, 'align': 'right', 'sortable': True} ], navbuttons_options = {'view': False, 'edit': False, 'add': False, 'del': False, 'search': False, 'refresh': True, }, loadComplete = js_callback('load_complete'), rowNum = row_list[0], rowList = row_list, ) # Hidden form for daily stats tmpl_context.form = Form( name = 'stats_form', submit_text = None, hover_help = True, fields = [ HiddenField(name='daily',default=self.stats_type), ] ) log.info('stats_type -> %s' % self.stats_type) # Plot: data are gathered from the grid, through javscript, cf. stats.html tmpl_context.data_flot = FlotWidget( data = [ { 'data': [], 'label': u'Appels mensuels' }, ], options = { 'grid': { 'backgroundColor': '#fffaff', 'clickable': True, 'hoverable': True}, 'xaxis': { 'ticks': []} }, height = '300px', width = '600px', label = flot_label, id='data_flot' ) # Hourly grid tmpl_context.hourly_grid = MyJqGrid( id='hourly_grid', url='/stats/fetch_hourly', caption=u'Valeurs horaires', sortname='name', sortorder='desc', colNames = [u'Tranche horaire', u'Appels', u'Durée'], colModel = [ { 'name': 'date', 'width': 60, 'sortable': False}, { 'name': 'calls', 'width': 40, 'align': 'right', 'sortable': False}, { 'name': 'billsec', 'width': 40, 'align': 'right', 'sortable': False} ], navbuttons_options = {'view': False, 'edit': False, 'add': False, 'del': False, 'search': False, 'refresh': True, }, loadComplete = js_callback('load_hourly_complete'), rowNum = 24, rowList = [12,24], ) # Plot: data are gathered from the grid, through javscript, cf. stats.html tmpl_context.hourly_flot = FlotWidget( data = [ { 'data': [], 'label': u'Distribution horaire' }, ], options = { 'grid': { 'backgroundColor': '#fffaff', 'clickable': True, 'hoverable': True}, 'xaxis': { 'ticks': []} }, height = '300px', width = '600px', label = flot_label, id='hourly_flot' ) # Inject javascript for tabs from tw.jquery.ui import ui_tabs_js ui_tabs_js.inject() return dict( title=title, debug=False, values={})