def hangup_signal_handler(signum, frame): """called after the hangup signal is received.""" global globals4signal dsh_utils.db_print2('dsh_failed.signal_handler: entered...', 116) time.sleep(1) calleeDshUid = globals4signal['callee_dsh_uid'] if is_triggered_by_dial_now(calleeDshUid): sys.exit(0) callee = dsh_django_utils.get_foreign_key(Person, calleeDshUid) if not callee: message = 'dsh_failed: no such callee found: ' + calleeDshUid dsh_utils.give_bad_news(message, logging.error) dsh_agi.report_event(message, reportLevel = 'ERR', sessionID=get_session()) sys.exit(1) else: dsh_utils.db_print('dsh_failed: found callee: ' + repr(callee), 116) event = Event( owner=callee, phone_number=callee.phone_number, action='NOPU', etype='INF', description='.call not picked up. re-arming.', session=get_session()) event.save() dsh_django_utils.check_auto_timed_calls_for_person( callee, sessionID=get_session()) calleeInfo = dsh_django_utils.callee_info(callee) dsh_utils.give_news('dsh_failed.signal_handler: rearming callee: '+\ calleeInfo, logging.info)
def get_foreign_key(whatKind, dshUid): """called by load_one(). locate a foreign key object.""" return dsh_django_utils.get_foreign_key(whatKind, dshUid)
def demographics(request, dshUid, personTable): """ 10/03/13: called by views.demographics(). """ if dsh_django_request.deny_it(request): return views.please_log_in() response = views.page_header('demographics', includeMp3Player=True) person = dsh_django_utils.get_foreign_key(personTable, dshUid) if not person: message = 'dsh_common_views.demographics: no person found: ' + dshUid response += dsh_utils.red_error_break_msg(message) dsh_django_utils.error_event(message, errorLevel='ERR') response += page_footer() return HttpResponse(response) personEditUrl = dsh_django_config.lookup('PERSON_DETAIL_URL') + \ str(person.id) thumb = dsh_django_utils.thumbnail( person, person.mugshot, noCenter=True) url = '<a href=%s title="edit person details">%s</a>' % \ (personEditUrl, thumb) response += url response += '<BR><BR>' response += '<TABLE BORDER=1>' name = person.__unicode__() if name: response += '<TR><TD>name</TD><TD>%s</TD></TR>' % (name,) if person.spoken_name: spokenName = person.spoken_name_display_field() if spokenName: response += '<TR><TD>spoken name</TD><TD>%s</TD></TR>' % \ (spokenName) response += '<TR><TD>dsh uid</TD><TD>%s</TD></TR>' % (person.dsh_uid,) if person.phone_number: response += '<TR><TD>phone</TD><TD>%s</TD></TR>' % \ (person.phone_number,) if person.organization and person.organization.alias: response += '<TR><TD>org.</TD><TD>%s</TD></TR>' % \ (person.organization.alias,) if person.ptype: response += '<TR><TD>type</TD><TD>%s</TD></TR>' % (person.ptype,) if person.gender: response += '<TR><TD>gender</TD><TD>%s</TD></TR>' % (person.gender,) if person.date_birth: if person.birth_date_approximate: dateStr = str(person.date_birth.year) else: dateStr = person.date_birth.isoformat() response += '<TR><TD>birth date</TD><TD>%s</TD></TR>' % (dateStr,) if person.birth_date_approximate: response += '<TR><TD>birth date approximate</TD><TD>True</TD></TR>' if person.date_birth: years = dsh_common_db.calculate_age(person) if years: response += '<TR><TD>age</TD><TD>%s</TD></TR>' % (str(years),) if person.modify_datetime: timeStr = person.modify_datetime.strftime( '%#Y-%#m-%#d %#H:%#M:%#S') response += '<TR><TD>modify time</TD><TD>%s</TD></TR>' % (timeStr,) response += '</TABLE>' response += views.mp3_widget_control() response += views.page_footer() return HttpResponse(response)
def keyword_select(dshUid, keyWordTable, itemTable, action='select'): """ 10/03/14: called by dsh_common_views.keyword_select(). add the keyworded items to the current selection. returns (success, response) """ response = '' keyword = dsh_django_utils.get_foreign_key(keyWordTable, dshUid) if not keyword: message = 'dsh_common_selection.keyword_select: no such dsh_uid: ' +\ dshUid response += dsh_utils.red_error_break_msg(message) dsh_django_utils.error_event(message, errorLevel='ERR') return (False, response) response += dsh_utils.black_break_msg( 'The key word is: "' + keyword.key_word + '".') items = itemTable.objects.filter(key_words__dsh_uid__exact=dshUid) if not items: message = 'dsh_common_selection.keyword_select: ' +\ 'no messages with this key word.' response += dsh_utils.red_error_break_msg(message) return (False, response) response += dsh_utils.black_break_msg( 'Number of messages with this key word: ' + str(len(items)) + '.') # # the stuff below is copied from dsh_selection.keyword_select_starred(). # count = 0 for item in items: if action == 'deselect': if not item.u17: continue item.u17 = False else: if item.u17: continue item.u17 = True try: item.save(noLogging=True) count += 1 except: message = 'dsh_common_selection.keyword_select: failed to save: '+\ item.dsh_uid dsh_django_utils.error_event(message, errorLevel='CRT') response += dsh_utils.red_error_break_msg(message) return (False, response) if action == 'deselect': message = 'Items removed from the selection: ' else: message = 'Items added to the selection: ' message += str(count) + '.' response += dsh_utils.black_break_msg(message) dsh_agi.report_event(message) return (True, response)
def add_person_key_word(personTable, keyWordTable, dshUid, action='set'): """ 10/03/22: copied from dsh_selection.keyword_add_del() called by dsh_common_view.add_person_keyword()""" errorMsg = '' keyWord = dsh_django_utils.get_foreign_key(keyWordTable, dshUid) if not keyWord: message = 'dsh_common_selection.add_person_key_word: ' +\ 'bad key word dshUid: ' + repr(dshUid) dsh_django_utils.error_event(message, errorLevel='ERR') errorMsg += dsh_utils.red_error_break_msg(message) return errorMsg selectedPersons = personTable.objects.filter(u17=True) if not selectedPersons: errorMsg += dsh_utils.red_error_break_msg( 'no person selected currently.') return errorMsg count = 0 for person in selectedPersons: kwList = person.person_key_words.all() if action == 'set': if keyWord in kwList: continue try: person.person_key_words.add(keyWord) person.save(noLogging=True) count += 1 except: message = 'dsh_common_selection.add_person_key_word: ' +\ 'key word add ' +\ 'failed: ' + repr(dshUid) dsh_django_utils.error_event(message, errorLevel='CRT') errorMsg += dsh_utils.red_error_break_msg(message) return errorMsg elif action == 'clear': if not (keyWord in kwList): continue try: person.person_key_words.remove(keyWord) person.save(noLogging=True) count += 1 except: message = 'dsh_common_selection.add_person_key_word: ' +\ 'key word del ' +\ 'failed: ' + repr(dshUid) dsh_django_utils.error_event(message, errorLevel='CRT') errorMsg += dsh_utils.red_error_break_msg(message) return errorMsg else: return dsh_utils.red_error_break_msg('bad action: ' + action) if action == 'set': actDone = 'added to' logAction = 'KADD' elif action == 'clear': actDone = 'removed from' logAction = 'KDEL' else: return dsh_utils.red_error_break_msg('bad action: ' + action) keyStr = keyWord.key_word message = 'key word "%s" %s %s persons.' % (keyStr, actDone, str(count)) errorMsg += dsh_utils.black_break_msg(message) dsh_agi.report_event( message, action=logAction, item=keyWord) return errorMsg
def select_keyed_persons(personTable, keyWordTable, dshUid, action='set'): """ 10/03/22: modeled after keyword_select(). could've combined them but I'm lazy. called by dsh_common_views.select_keyed_persons(). add the keyworded persons to the current selection. returns (success, response) """ response = '' keyword = dsh_django_utils.get_foreign_key(keyWordTable, dshUid) if not keyword: message = 'dsh_common_selection.select_keyed_persons: ' +\ 'no such dsh_uid: ' + dshUid response += dsh_utils.red_error_break_msg(message) dsh_django_utils.error_event(message, errorLevel='ERR') return (False, response) response += dsh_utils.black_break_msg( 'The key word is: "' + keyword.key_word + '".') persons = personTable.objects.filter( person_key_words__dsh_uid__exact=dshUid) if not persons: message = 'dsh_common_selection.select_keyed_persons: ' +\ 'no person with this key word.' response += dsh_utils.red_error_break_msg(message) return (False, response) response += dsh_utils.black_break_msg( 'Number of persons with this key word: ' + str(len(persons)) + '.') # # the stuff below is copied from dsh_selection.keyword_select_starred(). # count = 0 for person in persons: if action == 'clear': if not person.u17: continue person.u17 = False else: if person.u17: continue person.u17 = True try: person.save(noLogging=True) count += 1 except: message = 'dsh_common_selection.select_keyed_persons: ' +\ 'failed to save: '+ item.dsh_uid dsh_django_utils.error_event(message, errorLevel='CRT') response += dsh_utils.red_error_break_msg(message) return (False, response) if action == 'clear': message = 'Items removed from the selection: ' else: message = 'Items added to the selection: ' message += str(count) + '.' response += dsh_utils.black_break_msg(message) dsh_agi.report_event(message) return (True, response)