def notify(request): if request.method == 'POST': try: item = Item.objects.filter(pk=request.POST.get('item_id'))[0] sender = request.user receiver = item.found_by_user response_data = {} method = request.POST.get('method') message = request.POST.get('message') if (method == 'IBF'): notification = Notification() notification.sender = sender notification.receiver = receiver notification.message = message notification.topic = item notification.notification_type = 'CLAIM' notification.save() item.status = 'CLAIMED' item.lost_by_user = sender item.save() response_data['result'] = 'OK' elif (method == 'email'): email_subject = 'IBF: Claimed Item' email_body = "Hey %s, someone is claiming one of the items you found. Here's his email address so you can get in touchL %s" % ( receiver.username, sender.email) send_mail(email_subject, email_body, '*****@*****.**', [receiver.email], fail_silently=False) item.status = 'CLAIMED' item.lost_by_user = sender item.save() response_data['result'] = 'OK' elif (method == 'phone'): item.status = 'CLAIMED' item.lost_by_user = sender item.save() response_data['result'] = 'OK' if (method == 'leave_message'): notification = Notification() notification.sender = sender notification.receiver = receiver notification.message = message notification.topic = item notification.notification_type = 'CLAIM' notification.save() response_data['result'] = 'OK' except Exception, e: traceback.print_exc() response_data['result'] = 'ERROR'
def notify(request): if request.method=='POST': try: item = Item.objects.filter(pk=request.POST.get('item_id'))[0] sender = request.user receiver = item.found_by_user response_data = {} method = request.POST.get('method') message = request.POST.get('message') if (method == 'IBF'): notification = Notification() notification.sender = sender notification.receiver = receiver notification.message = message notification.topic = item notification.notification_type = 'CLAIM' notification.save() item.status = 'CLAIMED' item.lost_by_user = sender item.save() response_data['result'] = 'OK' elif (method == 'email'): email_subject = 'IBF: Claimed Item' email_body = "Hey %s, someone is claiming one of the items you found. Here's his email address so you can get in touchL %s" % (receiver.username, sender.email) send_mail(email_subject, email_body, '*****@*****.**', [receiver.email], fail_silently=False) item.status = 'CLAIMED' item.lost_by_user = sender item.save() response_data['result'] = 'OK' elif (method == 'phone'): item.status = 'CLAIMED' item.lost_by_user = sender item.save() response_data['result'] = 'OK' if (method == 'leave_message'): notification = Notification() notification.sender = sender notification.receiver = receiver notification.message = message notification.topic = item notification.notification_type = 'CLAIM' notification.save() response_data['result'] = 'OK' except Exception, e: traceback.print_exc() response_data['result'] = 'ERROR'
def reply_to_notification(request): if request.method == 'POST': try: old_notification = Notification.objects.filter( pk=request.POST.get('notification_pk'))[0] sender = request.user if old_notification.sender == sender: receiver = old_notification.receiver else: receiver = old_notification.sender response_data = {} message = request.POST.get('message') notification = Notification() notification.sender = sender notification.receiver = receiver notification.notification_type = "CLAIM" notification.message = message notification.topic = old_notification.topic notification.save() response_data['result'] = 'OK' except Exception, e: traceback.print_exc() response_data['result'] = 'ERROR'
def repatriate_item(request): response_data = {} if request.method=='POST': try: item_id = request.POST.get('item_id') item = Item.objects.filter(pk=item_id)[0] item.status = "PREREPATRIATED" item.save() notification = Notification() notification.sender = item.found_by_user notification.receiver = item.lost_by_user notification.message = item.found_by_user.username + ' wants to mark this item (subject of this conversation) as "Repatriated". If you agreed with the finder on a metting, then please accept his request.' notification.topic = item notification.notification_type = 'ACCEPT' notification.save() response_data['result'] = 'OK' except Exception, e: traceback.print_exc() response_data['result'] = 'ERROR'
def repatriate_item(request): response_data = {} if request.method == 'POST': try: item_id = request.POST.get('item_id') item = Item.objects.filter(pk=item_id)[0] item.status = "PREREPATRIATED" item.save() notification = Notification() notification.sender = item.found_by_user notification.receiver = item.lost_by_user notification.message = item.found_by_user.username + ' wants to mark this item (subject of this conversation) as "Repatriated". If you agreed with the finder on a metting, then please accept his request.' notification.topic = item notification.notification_type = 'ACCEPT' notification.save() response_data['result'] = 'OK' except Exception, e: traceback.print_exc() response_data['result'] = 'ERROR'
def respond_to_repatriation(request): response_data = {} if request.method == 'POST': try: notification = Notification.objects.filter( pk=request.POST.get('notification_id'))[0] response = request.POST.get('response') notification = Notification.objects.filter( pk=request.POST.get('notification_id'))[0] item = Item.objects.filter(pk=notification.topic.pk)[0] notification.notification_type = "CLAIM" new_notification = Notification() new_notification.sender = request.user new_notification.receiver = notification.sender if response == 'true': new_notification.message = "Congratulations!! " + notification.topic.title + " has been repatriated." new_notification.notification_type = 'CLAIM' item.status = "REPATRIATED" item.save() else: new_notification.message = request.user.username + " and you have to agree how the repatriation will occur. Once this is done, you can request a 'Repatriated' status change on " + notification.topic.title new_notification.notification_type = 'CLAIM' item.status = "CLAIMED" item.save() new_notification.topic = item new_notification.notification_type = 'CLAIM' new_notification.save() response_data['message'] = new_notification.message notification.save() response_data['result'] = 'OK' except Exception, e: traceback.print_exc() response_data['result'] = 'ERROR'
def reply_to_notification(request): if request.method=='POST': try: old_notification = Notification.objects.filter(pk=request.POST.get('notification_pk'))[0] sender = request.user if old_notification.sender == sender: receiver = old_notification.receiver else: receiver = old_notification.sender response_data = {} message = request.POST.get('message') notification = Notification() notification.sender = sender notification.receiver = receiver notification.notification_type = "CLAIM" notification.message = message notification.topic = old_notification.topic notification.save() response_data['result'] = 'OK' except Exception, e: traceback.print_exc() response_data['result'] = 'ERROR'
def respond_to_repatriation(request): response_data = {} if request.method=='POST': try: notification = Notification.objects.filter(pk=request.POST.get('notification_id'))[0] response = request.POST.get('response') notification = Notification.objects.filter(pk=request.POST.get('notification_id'))[0] item = Item.objects.filter(pk=notification.topic.pk)[0] notification.notification_type = "CLAIM" new_notification = Notification() new_notification.sender = request.user new_notification.receiver = notification.sender if response == 'true': new_notification.message = "Congratulations!! "+notification.topic.title + " has been repatriated." new_notification.notification_type = 'CLAIM' item.status = "REPATRIATED" item.save() else: new_notification.message = request.user.username + " and you have to agree how the repatriation will occur. Once this is done, you can request a 'Repatriated' status change on "+notification.topic.title new_notification.notification_type = 'CLAIM' item.status = "CLAIMED" item.save() new_notification.topic = item new_notification.notification_type = 'CLAIM' new_notification.save() response_data['message'] = new_notification.message notification.save() response_data['result'] = 'OK' except Exception, e: traceback.print_exc() response_data['result'] = 'ERROR'