<s> from nagare import security <EOL> from peak . rules import when <EOL> from nagare . security import common <EOL> from kansha . card import Card <EOL> from kansha . cardextension import CardExtension <EOL> from kansha . board import VOTES_PUBLIC , VOTES_MEMBERS <EOL> from . models import DataVote <EOL> class Votes ( CardExtension ) : <EOL> '''<STR_LIT>''' <EOL> LOAD_PRIORITY = <NUM_LIT> <EOL> @ property <EOL> def allowed ( self ) : <EOL> return self . configurator . votes_allowed <EOL> def count_votes ( self ) : <EOL> '''<STR_LIT>''' <EOL> return DataVote . count_votes ( self . card . data ) <EOL> def toggle ( self ) : <EOL> '''<STR_LIT>''' <EOL> security . check_permissions ( '<STR_LIT>' , self ) <EOL> user = security . get_user ( ) <EOL> if self . has_voted ( ) : <EOL> DataVote . get_vote ( self . card . data , user . data ) . delete ( ) <EOL> else : <EOL> DataVote ( card = self . card . data , user = user . data ) <EOL> def has_voted ( self ) : <EOL> '''<STR_LIT>''' <EOL> user = security . get_user ( ) <EOL> return DataVote . has_voted ( self . card . data , user . data ) <EOL> @ when ( common . Rules . has_permission , "<STR_LIT>" ) <EOL> def has_permission_Card_vote ( self , user , perm , votes ) : <EOL> return ( ( security . has_permissions ( '<STR_LIT>' , votes . card ) and votes . allowed == VOTES_MEMBERS ) or <EOL> ( votes . allowed == VOTES_PUBLIC and user ) ) </s>
