def post(self, request): code_lag = check_lan(request) date = request.data serializer = Create_SongExceptionSerializer(data=date) if serializer.is_valid(): serializer.save() return json_resp(code=200, msg='OK') return json_resp(code=499, msg=code_lag['499'])
def post(self, request): code_lag = check_lan(request) data = request.data data['case_user'] = request.user.id serializer = Create_ExceptionCaseSerializer(data=data) if serializer.is_valid(): serializer.save() return json_resp(code=200, msg='ok') return json_resp(code=499, msg=code_lag['499'])
def get(self, request, pk): code_lag = check_lan(request) music = self.get_object(pk) if music: ser_data = AllSongMusic_html5_Serializer(music) data = ser_data.data return json_resp(code=200, msg='ok', data=data) else: return json_resp(code=479, msg=code_lag['479'])
def get(self, request, pk): code_lag=check_lan(request) up_all_click_count(pk) # update_hour_click(pk, "allmusic") redis_db = read_from_cache(pk, 'allmusic') music = self.get_object(pk) if music: pass else: return json_resp(code=479,msg=code_lag['479']) owner_id = request.user.id if p(owner_id).is_loveing(pk): is_praise = True else: is_praise = False share_count = get_all_share_count(pk) praise_redis_count = p(pk).lovedby_count() praise_count=music.praise+praise_redis_count click_count = get_all_click_count(pk) comment_count = music.all_music_comment.count() if redis_db: redis_db["is_praise"] = is_praise redis_db['share_count'] = share_count redis_db['praise_count'] = praise_count redis_db['view_count'] = click_count redis_db['comment_count'] = comment_count return json_resp(code=200, msg='ok', data=redis_db) else: if music: if music.is_delete: return json_resp(code=479, msg=code_lag['479']) else: serializer = AllSongMusicDetailSerializer(music) data = serializer.data data['is_praise'] = is_praise data['share_count'] = share_count data['praise_count'] = praise_count data['view_count'] = click_count data['comment_count'] = comment_count write_to_cache(pk, 'allmusic', data) return json_resp(code=200, msg='ok', data=data) else: return json_resp(code=479, msg=code_lag['479'])
def authenticate_credentials(self, key): # Search token in cache cache_user = cache_token.get(key) if cache_user: return (cache_user, key) model = self.get_model() try: token = model.objects.select_related('user').get(key=key) except model.DoesNotExist: raise exceptions.AuthenticationFailed(_('Invalid token.')) if not token.user.is_active: raise exceptions.AuthenticationFailed(_('User inactive or deleted.')) utc_now = datetime.datetime.utcnow().replace(tzinfo=utc) if EXPIRE_HOURS>0: if token.created < utc_now - datetime.timedelta(hours=EXPIRE_HOURS): token.delete() return json_resp(code=400,msg='Token has expired then delete.') # raise exceptions.AuthenticationFailed(_('Token has expired then delete.')) if token: # Cache token cache_token.set(key, token.user, EXPIRE_HOURS*60*60) else: if token: cache_token.set(key, token.user, timeout=0) return (token.user, token)
def get(self, request, pk): code_lag=check_lan(request) try: all_post = AllSongMusic.objects.filter(all_music_auth=pk, is_enable=True, is_delete=False) return js_resp_paging(all_post, request, AllSongMusic_Popular_Serializer) except User.DoesNotExist: return json_resp(code=499, msg=code_lag['499'])
def post(self, request): code_lag = check_lan(request) try: music_id = request.data.get('musicid') except: return json_resp(code=499, msg=code_lag['499']) if music_id: try: music = MusicProfiel.objects.get(id=music_id) music.view_count += 1 music.save() return json_resp(code=200, msg="ok") except: return json_resp(code=499, msg=code_lag['499']) else: return json_resp(code=499, msg=code_lag['499'])
def put(self, request, pk): code_lag = check_lan(request) music = self.get_object(pk) if music: auth = music.all_music_auth if request.user == auth: data_copy = request.data.copy() data_copy['is_delete'] = True data_copy['deleted_at'] = datetime.datetime.now() serializer = CreateAllSongMusicSerializer(music, data=data_copy, partial=True) if serializer.is_valid(): serializer.save() return json_resp(code=200, msg='ok') return json_resp(code=499, msg=code_lag['499']) else: return json_resp(code=480, msg=code_lag['480']) else: return json_resp(code=479, msg=code_lag['479'])
def post(self, request, pk): code_lag=check_lan(request) music = self.get_object(pk) user = request.user data = request.data data['user'] = user.id data['music'] = pk if music: to_user = music.all_music_auth else: return json_resp(code=479, msg=code_lag['479']) serializer = ALLCommentSerializers(data=request.data) if serializer.is_valid(): serializer.save(owner=user, music=music) # up_notifactions_count(music.all_music_auth.id) comment_msg(request.user.id, to_user.id, music.id) return json_resp(code=200, msg="ok") else: return json_resp(code=484, msg=code_lag['484'])
def post(self, request): code_lag = check_lan(request) slug = self.request.data.get('slug', '') word = self.request.data.get('word', "") if word: if slug == 'song': music = self.get_queryset_music(word) singer = self.get_queryset_singer(word=word) if singer: type = 0 else: type = 1 return api_paging(singer=singer, song=music, Serializer_singer=SingerSerializer, Serializer_song=MusicProfileSearchSer, request=request, type=type, return_count=10) elif slug == 'people': users = self.get_queryset_users(word=word) return js_resp_paging(objs=users, request=request, serializer_obj=AccountSerializer, pages=20) else: return json_resp(code=499, msg=code_lag['499']) else: return json_resp(code=486, msg=code_lag['486'])
def put(self, request, pk): code_lag=check_lan(request) music = self.get_object(pk) if not music: return json_resp(code=479, msg=code_lag['479']) else: owner_id = request.user.id if p(owner_id).is_loveing(pk): p(owner_id).unpraise(pk) return json_resp(code=200, msg=code_lag['200']) else: p(owner_id).praise(pk) to_user_id = music.all_music_auth.id from_user = owner_id praise_msg.delay(from_user, to_user_id, music.id) return json_resp(code=200, msg=code_lag['200'])
def get(self, request): from dao.models.music import PartSongMusic, MusicProfiel part_music = PartSongMusic.objects.select_related().all() part_list = [] for part in part_music: music_id = part.music_info.id part_list.append(music_id) new_list = list(set(part_list)) if new_list: for new in new_list: music_new = PartSongMusic.objects.filter(music_info__id=new) count = music_new.count() change_music = MusicProfiel.objects.get(id=new) change_music.view_count = count change_music.save() return json_resp(code=200, msg='ok')
def complete(request, *args, **kwargs): user = request.user token = Token.objects.get(user_id=user).key return json_resp(code=200, msg='ok', data={"token": token})
def get(self, request): user_id = self.request.user.id count = get_notifactions_count(user_id) return json_resp(code=200, msg='ok', data={"count": count})