def upload(request): """ The method uploads the image files to the S3 bucket :param request: request here is for Post :return: returns a Httpresponse of file upload successfull """ try: userdata = Util.Getuser() uid = userdata['id'] if request.method == "POST": image = request.FILES.get('IMAGE') if image: if imghdr.what(image): print('-------->') s3 = S3Upload picture = s3.transfer(request, image) print("s2 pic url returned", picture) user = User.objects.get(pk=uid) print("user get", user) user.profile_pic = picture user.save() logger.info("file upload success") if user: return HttpResponse('File uploaded to s3') else: raise UserSerializers.errors else: logger.warning("only image file allowed") HttpResponse('File other than image are not allowed') else: logger.warning("not a image file") raise ValueError except ValueError: return Response({'error': 'no image detected'}, status=400)
def get(self, request, *args, **kwargs): """ :param request: request for data :return: returns the response """ try: userdata = Util.Getuser() uid = userdata['id'] noted = Notes.objects.filter( user=uid, is_Trash=False, is_archive=False).order_by('-created_at') if noted: print("in header", request.META['HTTP_AUTHORIZATION']) notedata = NoteSerializers(noted, many=True) obj = pickle.dumps(notedata.data) redisCache.set('note', obj) logger.info('All your Notes') return Response(notedata.data, status=200) else: logger.warning("note is not present") raise ValueError except ValueError: return Response({'error': 'no such notes'}, status=404)
def get(self, request, *args, **kwargs): """ :param request: request for data :return: returns the response """ try: userdata = Util.Getuser() uid = userdata['id'] noted = Label.objects.filter(user=uid) if noted: notedata = LabelSerializers(noted, many=True) return Response(notedata.data, status=200) else: raise ValueError except ValueError: return Response({'error': 'no such label'}, status=404)
def get(self, request, *args, **kwargs): """ :param request: request for data :return: returns the response """ try: userdata = Util.Getuser() uid = userdata['id'] note_archive = Notes.objects.filter(user=uid, is_archive=True) note = NoteSerializers(note_archive, many=True) if note: return Response(note.data, status=200) else: logger.warning("no such note present in db") raise ValueError except ValueError: return Response({'message': 'no archives found'}, status=400)
def get(self, request, *args, **kwargs): """ :param request: request for data :return: returns the response """ try: userdata = Util.Getuser() uid = userdata['id'] reminder = Notes.objects.filter(user=uid, reminder__isnull=False) notes = NoteSerializers(reminder, many=True) print(datetime.date) # reminder = datetime.datetime.now() - datetime.timedelta(days=90) if notes: return Response(notes.data, status=200) else: logger.warning("no such note present in db") raise ValueError except ValueError: return Response({'message': 'reminder not set'}, status=400)
def labelNote(request, labelname, *args, **kwargs): """ :param request: request for data :param labelname: label name passed as params :param args: arguements :param kwargs: keyword arguements :return: note with label """ try: userdata = Util.Getuser() uid = userdata['id'] labels = Label.objects.get(user=uid, name=labelname) print("labeldata******", labels) if labels: notedata = labels.notes_set.all() print("--------", notedata) noteser = NoteSerializers(notedata, many=True) return Response({'data': noteser.data}, status=200) else: raise ValueError except ValueError: return Response({'error': 'no such label'}, status=404)