def get(self, request, format=None): paginator = PageNumberPagination() paginator.page_size = 10 # retrieve hidden activity_hidden = ActivityControl.objects.filter( auth_user=request.user).filter( Q(is_hidden=True) | Q(is_reported=True)).values('activity_id') # TODO get connection posts Friends or Company friends = Friend.objects.friends(request.user) friends.append(request.user) # Get company post profile_session = ProfileSession(request) company = profile_session.get_company() if company: company = company[1] if company: print("is company") activity_data = Activity.objects.filter(company=company, blocked=False) \ .exclude(pk__in=[activity_hidden]).prefetch_related('activity_attachment') else: activity_data = Activity.objects.filter(auth_user__in=[user for user in friends], blocked=False) \ .exclude(pk__in=[activity_hidden]).prefetch_related('activity_attachment') if activity_data: result_page = paginator.paginate_queryset(activity_data, request) data = ActivitySerializer(instance=result_page, many=True, context={ 'request': request }).data return paginator.get_paginated_response(data) else: raise DataNotFoundException return Response(status=HTTP_500_INTERNAL_SERVER_ERROR)
def get(self, request, slug, formate=None): paginator = PageNumberPagination() paginator.page_size = 10 profile = get_object_or_404(UsersProfile, slug=slug) attachment = ActivityAttachment.objects.filter( auth_user=profile.auth_user, type='AUDIO') # retrieve hidden activity_hidden = ActivityControl.objects.filter( auth_user=request.user).filter( Q(is_hidden=True) | Q(is_reported=True)).values('activity_id') activity_data = Activity.objects.filter(pk__in=[activity.activity.pk for activity in attachment]) \ .exclude(pk__in=[activity_hidden]) if activity_data: result_page = paginator.paginate_queryset(activity_data, request) data = ActivitySerializer(instance=result_page, many=True, context={ 'request': request }).data return paginator.get_paginated_response(data) else: raise DataNotFoundException return Response(status=HTTP_500_INTERNAL_SERVER_ERROR)
def get(self, request, pk, formate=None): activity = Activity.objects.get(pk=pk) if activity: return Response(data=ActivitySerializer(instance=activity, context={ 'request': request }).data, status=HTTP_200_OK) raise DataNotFoundException
def post(self, request): activity = ActivitySerializer(data=request.data, context={'request': request}) activity.is_valid(raise_exception=True) profile_session = ProfileSession(request) company = profile_session.get_company() if company and company[0]: activity.save(auth_user=request.user, company=Company.objects.get(id=company[1].pk)) else: activity.save(auth_user=request.user) if activity and 'mentions' in request.data: activity_mention = ActivityMentionSerializer( data=request.data['mentions'], many=True) activity_mention.is_valid(raise_exception=True) activity_mention.save(activity=activity.instance) return Response(data=activity.data, status=HTTP_201_CREATED)
def put(self, request, slug, pk, formate=None): get_object_or_404(UsersProfile, auth_user=request.user) activity = get_object_or_404(Activity, pk=pk, is_active=False) activity.is_active = True activity.content = request.data['content'] activity.save() if 'album_id' in request.data: attachment = ActivityAttachment.objects.get(activity=activity) attachment.album_id = request.data['album_id'] attachment.save() return Response(data=ActivitySerializer(instance=activity, context={ 'request': request }).data, status=HTTP_201_CREATED)
def post(self, request, slug, formate=None): activity = Activity(content=None, auth_user=request.user) activity.save() file = request.FILES['file'] file_type = check_file_type(file) data = cloudinary.uploader.upload_large(request.FILES['file'], resource_type="video") # TODO need more enhancement attachment = activity.activity_attachment.create( path=data['secure_url'], type=file_type, auth_user=request.user) return Response(data=ActivitySerializer(instance=attachment.activity, context={ 'request': request }).data, status=HTTP_201_CREATED)
def post(self, request, pk, formate=None): activity = get_object_or_404(Activity, pk=pk) ActivitySocialAction.objects.get_or_create(auth_user=request.user, activity_id=pk, has_share=True) shared_activity = Activity.objects.create( auth_user=request.user, original_activity_id=activity.pk, content='', action='shared %s post' if activity.auth_user == request.user else "shared a %s") shared_activity = ActivitySerializer(instance=shared_activity, context={ 'request': request }).data return Response(data=shared_activity, status=HTTP_201_CREATED)
def get(self, request, slug, formate=None): paginator = PageNumberPagination() paginator.page_size = 10 profile = get_object_or_404(UsersProfile, slug=slug) activity_data = Activity.objects.filter( auth_user=profile.auth_user).prefetch_related( 'activity_attachment') if activity_data: result_page = paginator.paginate_queryset(activity_data, request) data = ActivitySerializer(instance=result_page, many=True, context={ 'request': request }).data return paginator.get_paginated_response(data) else: raise DataNotFoundException return Response(status=HTTP_500_INTERNAL_SERVER_ERROR)
def post(self, request, slug, formate=None): profile = get_object_or_404(UsersProfile, auth_user=request.user) file = request.FILES['file'] is_image(file) album, created = Albums.objects.get_or_create( album_name=settings.UNTITLED_ALBUM, user_profile=profile) activity = Activity(auth_user=request.user, content='', is_active=False) activity.save() data = cloudinary.uploader.upload(request.FILES['file'], folder=settings.AVATAR, crop='limit', use_filename=True, eager=[{ 'width': 200, 'height': 200, 'crop': 'thumb', 'gravity': 'face', 'radius': 'max', 'effect': 'sepia' }, { 'width': 100, 'height': 150, 'crop': 'fit', 'format': 'png' }]) activity.activity_attachment.create(path=data['secure_url'], type='IMG', auth_user=request.user, album=album) return Response(data=ActivitySerializer(instance=activity, context={ 'request': request }).data, status=HTTP_201_CREATED)
def get(self, request, slug, pk, formate=None): profile = get_object_or_404(UsersProfile, slug=slug) album = get_object_or_404(Albums, pk=pk, user_profile=profile) activity_hidden = ActivityControl.objects.filter( auth_user=request.user).filter( Q(is_hidden=True) | Q(is_reported=True)).values('activity_id') activity_attachement_list = get_list_or_404( ActivityAttachment, ~Q(pk__in=[activity_hidden]), album=album) activity_list = get_list_or_404( Activity, pk__in=[ attachment.activity.pk for attachment in activity_attachement_list ]) return Response(data=ActivitySerializer(instance=activity_list, many=True, context={ 'request': request }).data, status=HTTP_200_OK)
def get(self, request, slug, formate=None): paginator = PageNumberPagination() paginator.page_size = 10 profile = get_object_or_404(UsersProfile, slug=slug) bookmarked_activity = ActivityControl.objects.filter( auth_user=profile.auth_user, is_saved=True).values('activity_id') bookmarked_activity.exclude(is_hidden=True) bookmarked_activity.exclude(is_reported=False) bookmarked_activity = bookmarked_activity.values('activity_id') activity_data = Activity.objects.filter( pk__in=[bookmarked_activity]).prefetch_related( 'activity_attachment') if activity_data: result_page = paginator.paginate_queryset(activity_data, request) data = ActivitySerializer(instance=result_page, many=True, context={ 'request': request }).data return paginator.get_paginated_response(data) else: raise DataNotFoundException return Response(status=HTTP_500_INTERNAL_SERVER_ERROR)
def get(self, request, format=None): paginator = PageNumberPagination() paginator.page_size = 10 activityControlQueryset = ActivityControl.objects.filter( is_saved=True, auth_user=request.user) activity_data = Activity.objects.filter( pk__in=[x.activity.pk for x in activityControlQueryset ]).prefetch_related('activity_attachment') if 'search' in request.GET: activity_data = activity_data.filter( content__contains=request.GET.get('search', None)) if activity_data: result_page = paginator.paginate_queryset(activity_data, request) data = ActivitySerializer(instance=result_page, many=True, context={ 'request': request }).data return paginator.get_paginated_response(data) else: raise DataNotFoundException return Response(status=HTTP_500_INTERNAL_SERVER_ERROR)