Exemplo n.º 1
0
    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()
Exemplo n.º 2
0
 def get_or_create( cls, username ):
     session = Session()
     authentication = session.query( cls ).filter_by( username = username ).first()
     if not authentication:
         authentication = cls( username = username )
         session.add( authentication )
         session.flush()
     return authentication
Exemplo n.º 3
0
 def get_or_create( cls, username ):
     session = Session()
     authentication = session.query( cls ).filter_by( username = username ).first()
     if not authentication:
         authentication = cls( username = username )
         session.add( authentication )
         session.flush()
     return authentication
Exemplo n.º 4
0
    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)
                disc = session.query(Discipline).filter(Discipline.disc==orar.disc).first()
                if disc:
                    orar.disciplina = disc
                    session.flush()

        yield FlushSession(session)
        # begin refresh
        yield Refresh()
        # end refresh
Exemplo n.º 5
0
    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)
            f = open(file_name)
            info_prof = f.readline().split(";")[:-1]
            if session.query(Profesor).filter(Profesor.username == info_prof[0]).first() != None:
                raise UserException("Exista deja profesorul "+info_prof[2])
            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.titular = prof
                    session.add(disc)
        yield FlushSession(session)
        # begin refresh
        yield Refresh()
        # end refresh
Exemplo n.º 6
0
    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()
Exemplo n.º 7
0
from gradebook.model import (Course,
        Student, StudentContactInfo)
course, = session.query(Course).all()

import csv
with open('class-list.csv', 'rb') as csvfile:
    reader = csv.DictReader(csvfile, delimiter=";")
    for row in reader:
        print row
        ln = row["Last"]
        fn = row["First"]
        student = Student(first_name=unicode(fn.strip()),
                last_name=unicode(ln.strip()),
                user_name=unicode(row["NetID"]),
                course=course)

        session.add(student)
        session.add(StudentContactInfo(
            student=student,
            kind="email",
            value=row["NetID"]+"@illinois.edu",
            ))

        print unicode(student)

#from gradebook.model import Course
#for name in session.query(Course.name):
    #print name

session.flush()