def person2obj(person, kind=None): if not kind: kind='full' dat={'id': person.id, 'gender':person.gender, 'reflexive':False, 'left': True, 'right': False, 'name': person.short_name(), 'created': person.created.strftime(DATE_DASH_REV), 'last_purchase': Purchase.objects.filter(who_with=person).exists() and Purchase.objects.filter(who_with=person).order_by('-created')[0].created.strftime(DATE_DASH_REV_DAY) or '2011-01-01', 'purchases_together': Purchase.objects.filter(who_with=person).count(), 'weight': 1, 'spent_together': Purchase.objects.filter(who_with=person).exists() and Purchase.objects.filter(who_with=person).aggregate(Sum('cost'))['cost__sum'] or 0,} if kind=='supporting': dat['name']=person.initial() elif kind=='anon': dat['name']='' dat['gender']=1 elif kind=='initials': dat['name']=person.initial() elif kind=='extended': dat['name']=unicode(person) elif kind=='short name': #the default. pass else: from util import ipdb;ipdb() return dat
def ipdb(): import inspect try: par = inspect.stack()[1] desc = '%s line:%s' % (par[1], [par[2]]) except: log.error('failed to inspect stack.') from util import ipdb;ipdb() desc='failed to inspect stack.' if settings.LOCAL: log.error('missed ipdb call. %s', desc) import ipdb;ipdb.set_trace() else: log.error('missed ipdb call. %s', desc)
def logout(request): from django.contrib.auth import logout from utils import ipdb;ipdb() logout(request)
def people_connections(request, exclude_disabled=False, since=None, until=None, detail_level=None, data_only=False): if type(until) is datetime.datetime: until=until.date() if not detail_level: detail_level='short name' vals = {} people = Person.objects.all() if exclude_disabled: people = people.exclude(disabled=True) edges = [] nodes = {} linked_ids = set() #the ones who really should be highlighted here. supporting_linked_ids=set() #just linkers, included because there was action in ppl they introduced me to. ID=45299 newly_created=set() purch_existed=set() for person in people: if person.id==ID: from util import ipdb;ipdb() #include them if they've got purch in the last year, or they introduced me to sb in the last year. if since and person.created>since and ((not until) or person.created<=until): #at some point should also include them if they're in a new phototag. newly_created.add(person.id) if since: if until: if person.purchases.filter(created__gt=since).filter(created__lte=until).exists(): purch_existed.add(person.id) else: if person.purchases.filter(created__gt=since).exists(): purch_existed.add(person.id) else: purch_existed.add(person.id) #also add the person who introduced me. for person in people: if person.id in newly_created or person.id in purch_existed: for from_person in person.met_through.all(): if from_person.id==ID: from util import ipdb;ipdb() supporting_linked_ids.add(from_person.id) for person in people: if person.id==ID: from util import ipdb;ipdb() #ordering matters. default is supporting, then is purch existed #then is newly created in green. if person.id in supporting_linked_ids: nodes[person.id]=person2obj(person,kind=detail_level) nodes[person.id]['newly_created']=False nodes[person.id]['supporting']=True #make edges for these. if person.id in purch_existed or person.id in newly_created: for from_person in person.met_through.all(): #only include edges where both poeple are mentioned. edges.append({'target': from_person.id, 'source': person.id, 'value': 1,}) if person.id in purch_existed: #and (not person.purchases.exists()) nodes[person.id] = person2obj(person,kind=detail_level) nodes[person.id]['newly_created']=False nodes[person.id]['supporting']=False if person.id in newly_created: #and (not person.purchases.exists()) nodes[person.id] = person2obj(person,kind=detail_level) nodes[person.id]['newly_created']=True nodes[person.id]['supporting']=False if not since: nodes[person.id]['newly_created']=False nodes[person.id]['supporting']=True vals['nodes'] = nodes vals['edges'] = edges if data_only: return vals return r2r('jinja2/people_connections.html', request, vals)