def get_consensus_meta(self, citation): context = self.context _context_fields = context.get('hyp_dcs_get_consensus_meta', {}) votes = citation.votes user = get_user_from_request(context) user_vote = None try: if user and not user.is_anonymous: user_vote = votes.get(created_by=user) serializer = DynamicVoteSerializer( user_vote, context=context, **_context_fields ) except Vote.DoesNotExist: pass return ( { 'down_count': votes.filter(vote_type=Vote.DOWNVOTE).count(), 'neutral_count': votes.filter(vote_type=Vote.NEUTRAL).count(), 'total_count': votes.count(), 'up_count': votes.filter(vote_type=Vote.UPVOTE).count(), 'user_vote': ( serializer.data if user_vote is not None else None ) } )
def get_user_vote(self, obj): user = get_user_from_request(self.context) if user and not user.is_anonymous: vote = obj.votes.filter(created_by=user) if vote.exists(): return VoteSerializer(vote.last()).data return False return False
def get_user_endorsement(self, obj): user = get_user_from_request(self.context) if user: try: return EndorsementSerializer( obj.endorsements.get(created_by=user.id)).data except Endorsement.DoesNotExist: return None
def get_user_vote(self, obj): vote = None user = get_user_from_request(self.context) try: if user and not user.is_anonymous: vote = obj.votes.get(created_by=user) vote = VoteSerializer(vote).data return vote except Vote.DoesNotExist: return None
def get_user_vote(self, obj): user = get_user_from_request(self.context) _context_fields = self.context.get('dis_dcs_get_user_vote', {}) if user and not user.is_anonymous: vote = obj.votes.filter(created_by=user) if vote.exists(): return DynamicVoteSerializer( vote.last(), context=self.context, **_context_fields, ).data return False return False
def get_user_vote(self, post): vote = None user = get_user_from_request(self.context) _context_fields = self.context.get('doc_dps_get_user_vote', {}) try: if user and not user.is_anonymous: vote = post.votes.get(created_by=user) vote = DynamicVoteSerializer( vote, context=self.context, **_context_fields, ).data return vote except Vote.DoesNotExist: return None
def get_user_flag(self, obj): flag = None user = get_user_from_request(self.context) if user: try: flag_created_by = obj.flag_created_by if len(flag_created_by) == 0: return None flag = FlagSerializer(flag_created_by).data except AttributeError: try: flag = obj.flags.get(created_by=user.id) flag = FlagSerializer(flag).data except Flag.DoesNotExist: pass return flag
def get_user_vote(self, paper): vote = None user = get_user_from_request(self.context) if user: try: vote_created_by = paper.vote_created_by if len(vote_created_by) == 0: return None vote = PaperVoteSerializer(vote_created_by).data except AttributeError: try: vote = paper.votes.get(created_by=user.id) vote = PaperVoteSerializer(vote).data except Vote.DoesNotExist: pass return vote
def get_user_vote(self, paper): vote = None user = get_user_from_request(self.context) context = self.context _context_fields = context.get("pap_dps_get_user_vote", {}) if user: try: vote = paper.votes.get(created_by=user.id) vote = DynamicPaperVoteSerializer( vote, context=self.context, **_context_fields, ).data except Vote.DoesNotExist: pass return vote
def get_user_flag(self, paper): if self.context.get("purchase_minimal_serialization", False): return None flag = None user = get_user_from_request(self.context) if user: try: flag_created_by = paper.flag_created_by if len(flag_created_by) == 0: return None flag = FlagSerializer(flag_created_by).data except AttributeError: try: flag = paper.flags.get(created_by=user.id) flag = FlagSerializer(flag).data except Flag.DoesNotExist: pass return flag