#NEWLINE# def can_vote_in_poll( self , poll , user ) : #NEWLINE# #INDENT# '\n        Given a poll, checks whether the user can answer to it.\n        ' #NEWLINE# if poll . duration : #NEWLINE# #INDENT# poll_dtend = ( poll . created + dt . timedelta ( days = poll . duration ) ) #NEWLINE# if ( poll_dtend < now ( ) ) : #NEWLINE# #INDENT# return False #NEWLINE# #UNINDENT# #UNINDENT# can_vote = ( self . _perform_basic_permission_check ( poll . topic . forum , user , 'can_vote_in_polls' ) and ( not poll . topic . is_locked ) ) #NEWLINE# user_votes = TopicPollVote . objects . filter ( poll_option__poll = poll ) #NEWLINE# if user . is_anonymous ( ) : #NEWLINE# #INDENT# forum_key = get_anonymous_user_forum_key ( user ) #NEWLINE# if can_vote : #NEWLINE# #INDENT# user_votes = user_votes . filter ( anonymous_key = forum_key ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# user_votes = user_votes . none ( ) #NEWLINE# can_vote = False #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# user_votes = user_votes . filter ( voter = user ) #NEWLINE# #UNINDENT# if ( user_votes . exists ( ) and can_vote ) : #NEWLINE# #INDENT# can_vote = poll . user_changes #NEWLINE# #UNINDENT# return can_vote