def default_profile_settings(request: Request): access_token = request.headers.get('Access-Token') user_id = get_user_id_from_payload(access_token) profile_settings_obj = ProfileSettings.objects.get(id=user_id) avatar_obj = Avatar(name='default_img', url='/static/default_img.png/', id=profile_settings_obj) avatar_obj.save() data = {'url': avatar_obj.url} print(avatar_obj.url) return Response(data, status=status.HTTP_200_OK)
def add_comments(request: Request): video_id = request.data.get('id') access_token = request.headers.get('Access-Token') user_id = get_user_id_from_payload(access_token) comment = request.data.get('comment') username = ProfileSettings.objects.get(id=user_id).username video = Video.objects.get(video_id=video_id) comment_instance = VideoComments(video_id=video, username=username, comment=comment) comment_instance.save() return Response(status=status.HTTP_200_OK)
def get_video(request: Request): if request.method == 'POST': user_id = request.data.get('id') print('POST1') else: access_token = request.headers.get('Access-Token') user_id = get_user_id_from_payload(access_token) videos = Video.objects.all().filter(user_id=user_id) data = {} for i in range(videos.__len__()): video = {"url": videos[i].url, "id": videos[i].video_id} data[i] = video return Response(data=data, status=status.HTTP_200_OK)
def avatar(request): access_token = request.headers.get('Access-Token') user_id = get_user_id_from_payload(access_token) profile_settings = ProfileSettings.objects.get(id=user_id) avatar_img = request.data.get('avatar') data = { 'url': '/static/{}/'.format(avatar_img), } avatar = Avatar(name=avatar_img, url=data.get('url'), id=profile_settings) avatar.save() path = default_storage.save( os.path.join(settings.BASE_DIR) + '/static/{}/'.format(avatar_img), ContentFile(avatar_img.read())) return Response(data, status=status.HTTP_200_OK)
def security(request): access_token = request.headers.get('Access-Token') security = request.data.get('security') serializer_security = SecuritySerializer(data=security) user_id = get_user_id_from_payload(access_token) if serializer_security.is_valid(): data = { 'two_step_verification': serializer_security.data.get('two_step_verification'), 'your_devices': serializer_security.data.get('your_devices'), } security = Security.objects.get(id=user_id) saved_security = serializer_security.update(security, data) return Response(status=status.HTTP_200_OK)
def add_video(request: Request): access_token = request.headers.get('Access-Token') user_id = get_user_id_from_payload(access_token) audio_data = { 'name': request.data.get('audio_name'), 'author_name': request.data.get('author_name') } print(audio_data) audio = Audio(name=audio_data.get('name'), author_name=audio_data.get('author_name')) audio.save() video = request.data.get('video') path = os.path.join(settings.BASE_DIR) + '/static/video/{}/'.format(video) # if not os.path.isfile(path): default_storage.save( os.path.join(settings.BASE_DIR) + '/static/video/{}/'.format(video), ContentFile(video.read())) video_data = { 'url': '/static/video/{}/'.format(video), 'user_id': User.objects.get(id=user_id), 'description': request.data.get('video_description'), 'audio_id': audio, } video = Video(url=video_data.get('url'), uri=video_data.get('url'), user_id=video_data.get('user_id'), description=video_data.get('description'), audio_id=video_data.get('audio_id')) video.save() video = VideoStatistics.objects.get(id=video.video_id) hashtags_array = request.data.get('hashtags').split(' ') print(hashtags_array) for i in hashtags_array: hashtag = Hashtags(hashtag=i) hashtag.save() hashtags_on_video = HashtagsOnVideo(video_id=video, hashtag=hashtag) hashtags_on_video.save() print(video_data) return Response('LOL', status=status.HTTP_200_OK)
def profile_settings(request: Request): access_token = request.headers.get('Access-Token') profile_settings = request.data.get('profile-settings') user_id = get_user_id_from_payload(access_token) serializer_profile_settings = ProfileSettingsSerializer( data=profile_settings) if serializer_profile_settings.is_valid(): data = { 'push_notifications': serializer_profile_settings.data.get('push_notifications') } profile_settings = ProfileSettings.objects.get(id=user_id) if serializer_profile_settings.data.get('username') is not None: print(1) data['username'] = serializer_profile_settings.data.get('username') print(data) saved_profile_settings = serializer_profile_settings.update( profile_settings, data) return Response(status=status.HTTP_200_OK)
def confidentiality(request): access_token = request.headers.get('Access-Token') user_id = get_user_id_from_payload(access_token) confidentiality = request.data.get('confidentiality') serializer_confidentiality = ConfidentialitySerializer( data=confidentiality) if serializer_confidentiality.is_valid(): data = { 'private_account': serializer_confidentiality.data.get('private_account'), 'allow_download_video': serializer_confidentiality.data.get('allow_download_video'), 'comments_filter': serializer_confidentiality.data.get('comments_filter'), 'allow_private_message': serializer_confidentiality.data.get('allow_private_message'), 'allow_likes_list_looking': serializer_confidentiality.data.get('allow_likes_list_looking'), } confidentiality = Confidentiality.objects.get(id=user_id) saved_confidentiality = serializer_confidentiality.update( confidentiality, data) return Response(status=status.HTTP_200_OK)