Skip to content

Instantly share code, notes, and snippets.

@averrin
Created March 14, 2011 13:23
Show Gist options
  • Save averrin/be6d30f90757c9654b0f to your computer and use it in GitHub Desktop.
Save averrin/be6d30f90757c9654b0f to your computer and use it in GitHub Desktop.
@render_to('sro2/journal/journal.html')
def journal_ng_obj(request,ctype,obj_id,start_date='',end_date=''):
if start_date and end_date:
#если даты переданы, то созадаем из них объекты datetime
day,mounth,year = start_date.split('.')
eday,emounth,eyear = end_date.split('.')
sd=date(int(year), int(mounth), int(day))
ed=date(int(eyear), int(emounth), int(eday)+1)
else:
#а не переданы, делаем период, охватывающий последние сутки
ed=datetime.today()
sd=date(2009,1,1)
links={
OrgSro:[
'org',
'currperm',
'obj.org.orgstuff_set.all()',
'obj.stagelist_set.instance_of(Permit).all()',
'obj.stagelist_set.instance_of(Statement).all()',
'obj.orginsurance_set.all()',
'OrgLicense.objects.filter(orgsro=obj)',
'Phone.objects.filter(id__in=obj.org.contactphone_set.all().values_list("phone__id"))',
'WWW.objects.filter(id__in=obj.org.contactwww_set.all().values_list("www__id"))',
'Email.objects.filter(id__in=obj.org.contactemail_set.all().values_list("email__id"))',
],
Person:[
'obj.orgstuff_set.all()',
'obj.personskill_set.all()'
],
Permit:[
'Permit.objects.filter(no=obj.no,status__gt=0)'
]
}
ct=ctype
ctype=ContentType.objects.get(model=ctype)
obj=ctype.model_class().objects.get(pk=obj_id)
obj.ctype=ct
logs = LogEntry.objects.filter(content_type=ctype,object_id=obj_id).filter(action_time__gte=sd).filter(action_time__lte=ed)
t=[]
for log in logs:
t.append(log)
logs=t[:]
if ctype.model_class() in links and links[ctype.model_class()]:
for subobj_str in links[ctype.model_class()]:
sublogs = []
try:
subobj=getattr(obj,subobj_str)
sublogs = LogEntry.objects.filter(content_type=ContentType.objects.get_for_model(subobj.__class__),object_id=subobj.id).filter(action_time__gte=sd).filter(action_time__lte=ed)
except:
eval_string=subobj_str
try:
subset=eval(eval_string)
if subset.count():
ctype=ContentType.objects.get_for_model(subset[0].__class__)
for item in subset:
subsublogs = LogEntry.objects.filter(content_type=ctype,object_id=item.id).filter(action_time__gte=sd).filter(action_time__lte=ed)
for log in subsublogs:
sublogs.append(log)
except:
pass
if sublogs != []:
t=[]
for log in sublogs:
t.append(log)
logs.extend(t)
logs=sorted(process_logs(logs),key=gt,reverse=True)
return {
'logs':logs,
'object':obj
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment