Ejemplo n.º 1
0
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'
Ejemplo n.º 2
0
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'
Ejemplo n.º 3
0
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'
Ejemplo n.º 4
0
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()
Ejemplo n.º 5
0
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()
Ejemplo n.º 6
0
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'
Ejemplo n.º 7
0
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'
Ejemplo n.º 8
0
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'
Ejemplo n.º 9
0
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'
Ejemplo n.º 10
0
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'