<s> from datetime import datetime <EOL> from elixir import using_options <EOL> from elixir import ManyToOne , OneToMany <EOL> from elixir import Field , Unicode , Integer , Boolean <EOL> from sqlalchemy . ext . orderinglist import ordering_list <EOL> from nagare . database import session <EOL> from kansha . card . models import DataCard <EOL> from kansha . models import Entity <EOL> class DataColumn ( Entity ) : <EOL> """<STR_LIT>""" <EOL> using_options ( tablename = '<STR_LIT>' ) <EOL> title = Field ( Unicode ( <NUM_LIT:200> ) ) <EOL> index = Field ( Integer ) <EOL> nb_max_cards = Field ( Integer ) <EOL> archive = Field ( Boolean , default = False ) <EOL> cards = OneToMany ( '<STR_LIT>' , order_by = '<STR_LIT:index>' , <EOL> collection_class = ordering_list ( '<STR_LIT:index>' ) ) <EOL> board = ManyToOne ( '<STR_LIT>' , colname = '<STR_LIT>' ) <EOL> def update ( self , other ) : <EOL> self . title = other . title <EOL> self . index = other . index <EOL> self . nb_max_cards = other . nb_max_cards <EOL> session . flush ( ) <EOL> @ classmethod <EOL> def create_column ( cls , board , index , title , nb_cards = None , archive = False ) : <EOL> """<STR_LIT>""" <EOL> q = cls . query <EOL> q = q . filter ( cls . index >= index ) <EOL> q = q . filter ( cls . board == board ) <EOL> q . update ( { '<STR_LIT:index>' : cls . index + <NUM_LIT:1> } ) <EOL> col = cls ( title = title , index = index , board = board , nb_max_cards = nb_cards , archive = archive ) <EOL> session . flush ( ) <EOL> return col <EOL> def create_card ( self , title , user ) : <EOL> card = DataCard ( title = title , creation_date = datetime . now ( ) ) <EOL> self . cards . append ( card ) <EOL> session . flush ( ) <EOL> return card <EOL> def remove_card ( self , card ) : <EOL> if card in self . cards : <EOL> self . cards . remove ( card ) <EOL> def insert_card ( self , index , card ) : <EOL> self . cards . insert ( index , card ) <EOL> def delete_card ( self , card ) : <EOL> self . remove_card ( card ) <EOL> card . delete ( ) <EOL> def purge_cards ( self ) : <EOL> for card in self . cards : <EOL> card . delete ( ) <EOL> def append_card ( self , card ) : <EOL> card . index = None <EOL> self . cards . append ( card ) <EOL> @ classmethod <EOL> def delete_column ( cls , column ) : <EOL> """<STR_LIT>""" <EOL> index = column . index <EOL> board = column . board <EOL> column . delete ( ) <EOL> session . flush ( ) <EOL> q = cls . query <EOL> q = q . filter ( cls . index >= index ) <EOL> q = q . filter ( cls . board == board ) <EOL> q . update ( { '<STR_LIT:index>' : cls . index - <NUM_LIT:1> } ) <EOL> def get_cards_count ( self ) : <EOL> q = DataCard . query . filter ( DataCard . column_id == self . id ) <EOL> return q . count ( ) </s>
