def post(self, request, *args, **kw): # first we get the email parameter fingerprint_id = request.POST.get('fingerprint_id', '') question_id = request.POST.get('question', '') comment = request.POST.get('comment', '') if request.user.is_authenticated(): try: fingerprint = Fingerprint.objects.get( fingerprint_hash=fingerprint_id) question = Question.objects.get(id=question_id) ansrequest = None try: ansrequest = AnswerRequest.objects.get( fingerprint=fingerprint, question=question, requester=request.user, removed=False) # If this user already request this answer, just update request time ansrequest.comment = comment ansrequest.save() # otherwise we must create the request as a new one except: ansrequest = AnswerRequest(fingerprint=fingerprint, question=question, requester=request.user, comment=comment) ansrequest.save() if ansrequest != None: message = str( ansrequest.requester.get_full_name() ) + " requested you to answer some unanswered questions on database " + str( fingerprint.findName()) + "." sendNotification( timedelta(hours=12), fingerprint.owner, ansrequest.requester, "dbEdit/" + fingerprint.fingerprint_hash + "/" + str(fingerprint.questionnaire.id), message) result = { 'fingerprint_id': fingerprint_id, 'question_id': question_id, 'success': True } return Response(result, status=status.HTTP_200_OK) except Fingerprint.DoesNotExist: pass except Question.DoesNotExist: pass return Response({'success': False}, status=status.HTTP_400_BAD_REQUEST)
def markAnswerRequests(user, fingerprint, question, answer_requests): this_requests = answer_requests.filter(question=question) for req in this_requests: # We set the request as fullfilled req.removed = True req.save() message = "User "+str(fingerprint.owner.get_full_name())+" answered some questions you requested on database "+str(fingerprint.findName())+"." sendNotification(timedelta(hours=12), req.requester, fingerprint.owner, "fingerprint/"+fingerprint.fingerprint_hash+"/1/", message)
def post(self, request, *args, **kw): # first we get the email parameter fingerprint_id = request.POST.get('fingerprint_id', '') question_id = request.POST.get('question', '') comment = request.POST.get('comment', '') if request.user.is_authenticated(): try: fingerprint = Fingerprint.objects.get(fingerprint_hash=fingerprint_id) question = Question.objects.get(id=question_id) ansrequest = None try: ansrequest = AnswerRequest.objects.get( fingerprint=fingerprint, question=question, requester=request.user, removed = False) # If this user already request this answer, just update request time ansrequest.comment=comment ansrequest.save() # otherwise we must create the request as a new one except: ansrequest = AnswerRequest(fingerprint=fingerprint, question=question, requester=request.user, comment=comment) ansrequest.save() if ansrequest != None: message = str(ansrequest.requester.get_full_name())+" requested you to answer some unanswered questions on database "+str(fingerprint.findName())+"." sendNotification(timedelta(hours=12), fingerprint.owner, ansrequest.requester, "dbEdit/"+fingerprint.fingerprint_hash+"/"+str(fingerprint.questionnaire.id), message) result = { 'fingerprint_id': fingerprint_id, 'question_id': question_id, 'success': True } return Response(result, status=status.HTTP_200_OK) except Fingerprint.DoesNotExist: pass except Question.DoesNotExist: pass return Response({'success': False }, status=status.HTTP_400_BAD_REQUEST)
def post(self, request, *args, **kw): if request.user.is_authenticated(): # first we get the email parameter fingerprint_id = request.POST.get('fingerprint_id', '') fingerprint_name = request.POST.get('fingerprint_name', '') owner = request.POST.get('owner', '') comment = request.POST.get('comment', '') user_commented = request.POST.get('user_commented', '') if fingerprint_id != '' and owner != '' and comment != '' and user_commented != '': try: this_user = User.objects.get(username__exact=owner) user_fullname = None if (this_user.first_name != '' and this_user.last_name != ''): user_fullname = this_user.first_name + ' ' + this_user.last_name else: user_fullname = this_user.username notification_message = "%s has new comments." % ( str(fingerprint_name)) sendNotification( timedelta(hours=1), this_user, request.user, "fingerprint/" + fingerprint_id + "/1/discussion/", notification_message, custom_mail_message= ('Emif Catalogue: There\'s a new comment on one of your databases', render_to_string( 'emails/new_db_comment.html', { 'fingerprint_id': fingerprint_id, 'fingerprint_name': fingerprint_name, 'owner': user_fullname, 'comment': comment, 'base_url': settings.BASE_URL, 'user_commented': user_commented }))) return Response({}, status=status.HTTP_200_OK) except User.DoesNotExist: print "Tried to send email to invalid user " + str(owner) pass return Response({}, status=status.HTTP_400_BAD_REQUEST)
def post(self, request, *args, **kw): if request.user.is_authenticated(): # first we get the email parameter fingerprint_id = request.POST.get('fingerprint_id', '') fingerprint_name = request.POST.get('fingerprint_name', '') owner = request.POST.get('owner', '') comment = request.POST.get('comment', '') user_commented = request.POST.get('user_commented', '') if fingerprint_id != '' and owner != '' and comment != '' and user_commented != '': try: this_user = User.objects.get(username__exact=owner) user_fullname = None if(this_user.first_name != '' and this_user.last_name != ''): user_fullname = this_user.first_name + ' ' + this_user.last_name else: user_fullname = this_user.username notification_message = "%s has new comments." % (str(fingerprint_name)) sendNotification(timedelta(hours=1), this_user, request.user, "fingerprint/"+fingerprint_id+"/1/discussion/", notification_message, custom_mail_message=('Emif Catalogue: There\'s a new comment on one of your databases', render_to_string('emails/new_db_comment.html', { 'fingerprint_id': fingerprint_id, 'fingerprint_name': fingerprint_name, 'owner': user_fullname, 'comment': comment, 'base_url': settings.BASE_URL, 'user_commented': user_commented }) ) ) return Response({}, status=status.HTTP_200_OK) except User.DoesNotExist: print "Tried to send email to invalid user "+str(owner) pass return Response({}, status=status.HTTP_400_BAD_REQUEST)
def post(self, request, *args, **kw): id = request.POST.get('id', -1) hash = request.POST.get('hash') valid = False # Verify if it is a valid email if id != None and id != -1 and hash != None: try: finger = Fingerprint.objects.get(fingerprint_hash=hash) if finger.owner == request.user or request.user.is_staff: username = finger.shared.get(id=id) old_owner = finger.owner finger.owner = username finger.shared.add(old_owner) finger.shared.remove(username) finger.save() finger.indexFingerprint() new_owner_mess = "%s passed you ownership of database %s" % ( old_owner.get_full_name(), finger.findName()) sendNotification( timedelta(hours=1), username, old_owner, "fingerprint/%s/1/" % (finger.fingerprint_hash), new_owner_mess) return Response({'success': True}, status=status.HTTP_200_OK) except Fingerprint.DoesNotExist: pass return Response({'success': False}, status=403)
def post(self, request, *args, **kw): id = request.POST.get('id', -1) hash = request.POST.get('hash') valid = False # Verify if it is a valid email if id != None and id != -1 and hash != None: try: finger = Fingerprint.objects.get(fingerprint_hash=hash) if finger.owner == request.user or request.user.is_staff: username = finger.shared.get(id=id) old_owner = finger.owner finger.owner = username finger.shared.add(old_owner) finger.shared.remove(username) finger.save() finger.indexFingerprint() new_owner_mess = "%s passed you ownership of database %s" % (old_owner.get_full_name(), finger.findName()) sendNotification(timedelta(hours=1), username, old_owner, "fingerprint/%s/1/"%(finger.fingerprint_hash), new_owner_mess) return Response({'success': True}, status=status.HTTP_200_OK) except Fingerprint.DoesNotExist: pass return Response({'success': False}, status=403)