def model_run(self, model_context): from camelot.view.action_steps import UpdateProgress, SelectRestore label, storage = yield SelectRestore(self.backup_mechanism) yield UpdateProgress(text=_('Restore in progress')) backup_mechanism = self.backup_mechanism(label, storage) for completed, total, description in backup_mechanism.restore(): yield UpdateProgress(completed, total, text=description)
def model_run(self, model_context): from camelot.view.action_steps import UpdateProgress, SelectBackup label, storage = yield SelectBackup(self.backup_mechanism) yield UpdateProgress(text=_('Backup in progress')) backup_mechanism = self.backup_mechanism(label, storage) backup_iterator = backup_mechanism.backup(settings.ENGINE()) for completed, total, description in backup_iterator: yield UpdateProgress(completed, total, text=description)
def model_run(self, model_context): from camelot.view.action_steps import UpdateProgress, SelectRestore label, storage = yield SelectRestore(self.backup_mechanism) yield UpdateProgress(text=_('Restore in progress')) backup_mechanism = self.backup_mechanism(label, storage) restore_iterator = backup_mechanism.restore(settings.ENGINE()) for completed, total, description in restore_iterator: yield UpdateProgress(completed, total, text=description) for step in super(Restore, self).model_run(model_context): yield step
def model_run( self, model_context ): from camelot.view.action_steps import ( SelectFile, UpdateProgress, Refresh, FlushSession ) select_image_files = SelectFile( 'Image Files (*.png *.jpg);;All Files (*)' ) select_image_files.single = False file_names = yield select_image_files file_count = len( file_names ) # end select files # begin create movies import os from sqlalchemy import orm from camelot.core.orm import Session from camelot_example.model import Movie movie_mapper = orm.class_mapper( Movie ) cover_property = movie_mapper.get_property( 'cover' ) storage = cover_property.columns[0].type.storage session = Session() for i, file_name in enumerate(file_names): yield UpdateProgress( i, file_count ) title = os.path.splitext( os.path.basename( file_name ) )[0] stored_file = storage.checkin( six.text_type( file_name ) ) movie = Movie( title = six.text_type( title ) ) movie.cover = stored_file yield FlushSession( session ) # end create movies # begin refresh yield Refresh()
def model_run(self, model_context): from camelot.view.action_steps import (SelectFile, UpdateProgress, Refresh, FlushSession) select_files = SelectFile('Txt Files (*.txt *.csv);;All Files (*)') select_files.single = False file_names = yield select_files file_count = len(file_names) import os from camelot.core.orm import Session from rms.Model.Orar import Orar session = Session() for i, file_name in enumerate(file_names): yield UpdateProgress(i, file_count) title = os.path.splitext(os.path.basename(file_name))[0] print(file_name) for line in open(file_name): vals = line.split(';')[:-1] if len(vals) != 8: raise ImportException("Fisierul nu e dat bine") if vals[2] not in ['0', '1', '2']: raise ImportException("Frecventa nu e data bine") print(vals) orar = Orar(*vals) print(orar) session.add(orar) yield FlushSession(session) # begin refresh yield Refresh()
def model_run(self, model_context): from camelot.view.action_steps import (UpdateProgress, FlushSession, UpdateObject) step = max(1, model_context.selection_count / 100) for i, obj in enumerate(model_context.get_selection()): if i % step == 0: yield UpdateProgress(i, model_context.selection_count) self.method(obj) # the object might have changed without the need to be flushed # to the database yield UpdateObject(obj) yield FlushSession(model_context.session)
def model_run( self, model_context ): # # the model_run generator method yields various ActionSteps # options = Options() yield ChangeObject( options ) if options.only_selected: iterator = model_context.get_selection() else: iterator = model_context.get_collection() for movie in iterator: yield UpdateProgress( text = u'Change %s'%unicode( movie ) ) movie.rating = min( 5, max( 0, (movie.rating or 0 ) + options.change ) ) # # FlushSession will write the changes to the database and inform # the GUI # yield FlushSession( model_context.session )
def model_run(self, model_context): from camelot.view.action_steps import (SelectFile, UpdateProgress, Refresh, FlushSession) select_files = SelectFile('Txt Files (*.txt *.csv);;All Files (*)') select_files.single = False file_names = yield select_files file_count = len(file_names) import os from camelot.core.orm import Session from rms.Model.ResurseUmane import ResurseUmane from rms.Model.Discipline import Discipline from rms.Model.OreSuplimentare import OreSuplimentare session = Session() for i, file_name in enumerate(file_names): yield UpdateProgress(i, file_count) print(file_name) f = open(file_name) info_prof = f.readline().split(";")[:-1] print(info_prof) prof = Profesor(*info_prof) session.add(prof) for line in f: if line[-1] == ';': vals = line[:-1].split(',') else: vals = line[:-2].split(',') print(vals) try: vals[0] = int(vals[0]) oresup = OreSuplimentare(*vals) oresup.profesor = prof session.add(oresup) except ValueError: disc = Discipline(*vals) disc.profesor = prof session.add(disc) yield FlushSession(session) # begin refresh yield Refresh()
def model_run(self, model_context): # Buscar todos aquellos creditos que estan activos y corresponden al barrio obj = model_context.get_object() from sqlalchemy.sql import select tbl_credito = Credito.mapper.mapped_table tbl_benef = Beneficiaria.mapper.mapped_table tbl_barrio = Barrio.mapper.mapped_table stmt = select( [ tbl_credito.c.id.label('credito_id'), ], from_obj=tbl_credito.join(tbl_benef).join(tbl_barrio), whereclause=and_(tbl_credito.c.fecha_finalizacion == None, obj.barrio_id == tbl_barrio.c.id), ) res = model_context.session.execute(stmt) for row in res: pc = PagoCredito() pc.planilla_pagos = obj pc.credito = Credito.query.filter_by(id=row["credito_id"]).one() yield UpdateProgress() yield FlushSession(PagoCredito.query.session) yield FlushSession(model_context.session)