def notifications_job(request): data = None log = '' try: match_search = ItemsMatchView() pre_reg_items = PreRegisteredItem.objects.filter(lost=True) log += "<p>=========================</p>" log += "<p>======= START JOB =======</p>" for item in pre_reg_items: log += "<p>== Searching matches for item:</p>" log += "<p>______Title: " + item.title + "</p>" log += "<p>______Category: " + item.category + "</p>" log += "<p>______Created on: " + str(item.created_at) + "</p>" t = request.GET.copy() t.update({'q': string.replace(item.tags, ' ', '+')}) t.update({'category': item.category}) t.update({'unique_id': item.unique_id}) t.update({'start_date': str(item.created_at).split(' ')[0]}) request.GET = t match_results = match_search.get(request) for match in match_results: if not Notification.objects.filter(notification_type="MATCH", match=item, topic=match.object): log += "<p>== Creating notification for match:</p>" log += "<p>______Title: " + match.object.title + "</p>" log += "<p>______Category: " + match.object.category + "</p>" log += "<p>______Created on: " + str( match.object.date_field) + "</p>" notification = Notification() notification.receiver = item.owner notification.notification_type = "MATCH" notification.message = "This item matched your lost " notification.topic = match.object notification.match = item notification.save() log += "<p>== Notification Created</p>" log += "<p>=======================</p>" log += "<p><p>========= END JOB =======</p>" log += "<p>=========================</p>" except Exception, e: traceback.print_exc()
def notifications_job(request): data = None log ='' try: match_search = ItemsMatchView() pre_reg_items = PreRegisteredItem.objects.filter(lost=True) log += "<p>=========================</p>" log += "<p>======= START JOB =======</p>" for item in pre_reg_items: log+= "<p>== Searching matches for item:</p>" log+= "<p>______Title: "+item.title+"</p>" log+= "<p>______Category: "+item.category+"</p>" log+= "<p>______Created on: "+str(item.created_at)+"</p>" t= request.GET.copy() t.update({'q': string.replace(item.tags,' ','+')}) t.update({'category': item.category}) t.update({'unique_id': item.unique_id}) t.update({'start_date': str(item.created_at).split(' ')[0]}) request.GET = t match_results = match_search.get(request) for match in match_results: if not Notification.objects.filter(notification_type="MATCH", match=item, topic=match.object): log+= "<p>== Creating notification for match:</p>" log+= "<p>______Title: "+match.object.title+"</p>" log+= "<p>______Category: "+match.object.category+"</p>" log+= "<p>______Created on: "+str(match.object.date_field)+"</p>" notification = Notification() notification.receiver = item.owner notification.notification_type = "MATCH" notification.message = "This item matched your lost " notification.topic = match.object notification.match = item notification.save() log += "<p>== Notification Created</p>" log += "<p>=======================</p>" log += "<p><p>========= END JOB =======</p>" log += "<p>=========================</p>" except Exception, e: traceback.print_exc()