def on_enable(self): """ on enable we set order to the last one """ order = TaskMention.get_next_order() self.context.order = order self.request.dbsession.merge(self.context)
def __call__(self): return dict( business_types=BusinessType.query().all(), mentions=TaskMention.query().all(), items=self._collect_items(), breadcrumb=self.breadcrumb, back_link=self.back_link, help_message=self.help_message, )
def mention(dbsession): from autonomie.models.task.mentions import TaskMention mention = TaskMention( title=u"TaskMention tet", full_text=u"blabla", label=u"bla", ) dbsession.add(mention) dbsession.flush() return mention
def migrate_datas(): from autonomie.models.project.types import BusinessType from autonomie.models.config import Config from autonomie.models.task.mentions import TaskMention from autonomie.models.project.mentions import BusinessTypeTaskMention from autonomie_base.models.base import DBSESSION from alembic.context import get_bind session = DBSESSION() conn = get_bind() # Collect business type ids business_type_ids = [b[0] for b in session.query(BusinessType.id)] # for each fixed config key we now use mentions for index, (doctype, key, label, title) in enumerate((( 'estimation', 'coop_estimationfooter', u"Informations sur l'acceptation des devis", u"Acceptation du devis", ), ( "invoice", "coop_invoicepayment", u"Informations de paiement pour les factures", u"Mode de paiement", ), ( "invoice", "coop_invoicelate", u"Informations sur les retards de paiement", u"Retard de paiement", ))): # We retrieve the configurated value value = Config.get_value(key, "") mention = TaskMention( order=index, label=label, title=title, full_text=value.replace('%IBAN%', "{IBAN}").replace( '%RIB%', "{RIB}").replace('%ENTREPRENEUR%', '{name}')) session.add(mention) session.flush() for btype_id in business_type_ids: rel = BusinessTypeTaskMention( task_mention_id=mention.id, business_type_id=btype_id, doctype=doctype, mandatory=True, ) session.add(rel) session.flush() op.execute( u"INSERT INTO mandatory_task_mention_rel (task_id, mention_id) \ SELECT task.id, {mention_id} from task join node on task.id=node.id where \ node.type_='{type_}'".format(mention_id=mention.id, type_=doctype))
def _an_task_mentions(self): from autonomie.models.task.mentions import TaskMention for mention in TaskMention.query(): mention.full_text = self.faker.paragraph(nb_sentences=3) self.session.merge(mention)
def __init__(self, *args, **kwargs): AdminCrudListView.__init__(self, *args, **kwargs) self.max_order = TaskMention.get_next_order() - 1