示例#1
0
	def cb_tree_plug(self, tree, iter, id):
		"""plug object's childs in the tree"""
		from TreeMgmt import TreeRowMgmtSeparator
		if id == "cursus":
			from Cursus import Cursus
			from User import User
			def query(db, empty):
				q = db.session.query(Cursus)
				return q.order_by(Cursus.start.desc()).all()
			cursuslist = db.session_query(query, None,
			    'university, cursuslist : ' +
			    'query(Cursus).order_by(Cursus.start.desc()).all()')
			if cursuslist:
				for cursus in cursuslist:
					tree.plug(iter, cursus, self)
			tree.plug_action(iter, Cursus(), self,
			    Cursus.ADD_ACTION)
			tree.plug_group(iter, User(), self,
			    User.ADMINISTRATORS_GROUP)

		else:
			from Campus import Campus

			def query(db, empty):
				q = db.session.query(Campus)
				return q.order_by(Campus.name.desc()).all()

			campuslist = db.session_query(query, None,
			    'university, campuslist : ' +
			    'query(Campus).order_by(Campus.name.desc()).all()')
			for campus in campuslist:
				tree.plug(iter, campus, self)
			tree.plug_action(iter, Campus(), self,
			    Campus.ADD_ACTION)
示例#2
0
	def on_dialog_add(self, widget):
		"""call get_dialog_fields, and call db.session_query,
		 response gtk.RESPONSE_OK"""

		from Settings import Settings
		from Planning import Planning

		print "ON DIALOG ADD on : " + str(self.current_obj)
		if not self.current_obj:
			print "ERROR ON ADD"

		def query(db, obj):
			"""callback for db.session_query, this query
			 add obj to session and call db.session_try_commit"""

			db.session.add(obj.settings)
			db.session.add(obj.planning)
			db.session.add(obj)
			db.session_try_commit()
		obj = self.current_obj
		self.get_dialog_fields()
		obj.settings = Settings()
		obj.planning = Planning()
		obj.password = self.password(app.university.password_length)
		db.session_query(query, obj,
		    str("Insert user " + obj.login + "( name:" + obj.name +
		    ", firstname:" + obj.firstname + ", email:" + obj.email +
		    ") in db"))
		self.dialog.obj.response(gtk.RESPONSE_OK)
示例#3
0
    def on_dialog_add(self, widget):
        """call get_dialog_fields, and call db.session_query,
		 response gtk.RESPONSE_OK"""

        from Settings import Settings
        from Planning import Planning

        print "ON DIALOG ADD on : " + str(self.current_obj)
        if not self.current_obj:
            print "ERROR ON ADD"

        def query(db, obj):
            """callback for db.session_query, this query
			 add obj to session and call db.session_try_commit"""

            db.session.add(obj.settings)
            db.session.add(obj.planning)
            db.session.add(obj)
            db.session_try_commit()

        obj = self.current_obj
        self.get_dialog_fields()
        obj.settings = Settings()
        obj.planning = Planning()
        obj.password = self.password(app.university.password_length)
        db.session_query(
            query, obj,
            str("Insert user " + obj.login + "( name:" + obj.name +
                ", firstname:" + obj.firstname + ", email:" + obj.email +
                ") in db"))
        self.dialog.obj.response(gtk.RESPONSE_OK)
示例#4
0
    def on_valid_password_clicked(self, widget):
        """check the user's password, check if both new password
		are identicals, change the change_pass_status in error case"""

        passwd = self.old_password.get_text()
        login = app.user.login
        md5passwd = md5.new(passwd)

        def query(db, login):
            return db.session.query(User).filter(User.login == login).first()

        user = db.session_query(
            query, login, "auth : query(User).filter(User.login==login(" +
            str(login) + ").first()")
        if app.user.password != md5passwd.hexdigest():
            self.change_pass_status.set_markup(
                "Erreure: ancien mot de passe invalide")
            self.dialog_password.response(gtk.RESPONSE_OK)
        else:
            passwd1 = self.new_password1.get_text()
            passwd2 = self.new_password2.get_text()
            if passwd1 == passwd2:
                md5passwd = md5.new(passwd1)
                app.user.password = md5passwd.hexdigest()
                db.session_try_commit()
                self.dialog_password.response(gtk.RESPONSE_OK)
            else:
                self.change_pass_status.set_markup(
                    "Erreure: les nouveaux mots de passe ne sont pas identiques"
                )
示例#5
0
	def insert(self, obj):
		from ComboMgmt import ComboMgmt
		self.current_obj = obj
		def query(db, cursus):
			from copy import deepcopy
			if cursus:
				result = []
				for period in cursus.periods:
					result.append(period)
				return result
			return db.session.query(Period).all()
		if len(obj.classe.periods):
			cursus = obj.classe.periods[0].cursus
		else:
			cursus = None
		periodstore = db.session_query(query, cursus,
		    "period_insert : query(Period).all()")
		if len(obj.classe.periods):
			for period in obj.classe.periods:
				periodstore.remove(period)
		self.period_combo = ComboMgmt(self.periods, periodstore)
		if cursus:
			self.dialog_link.obj.set_title("Insertion d'une période du cursus " + cursus.name)
		else:
			self.dialog_link.obj.set_title("Insertion d'une période")
		result = self.dialog_link.obj.run()
		self.dialog_link.obj.hide()
		self.period_combo = None
		return result
示例#6
0
    def insert(self, obj):
        from ComboMgmt import ComboMgmt
        self.current_obj = obj

        def query(db, cursus):
            from copy import deepcopy
            if cursus:
                result = []
                for period in cursus.periods:
                    result.append(period)
                return result
            return db.session.query(Period).all()

        if len(obj.classe.periods):
            cursus = obj.classe.periods[0].cursus
        else:
            cursus = None
        periodstore = db.session_query(query, cursus,
                                       "period_insert : query(Period).all()")
        if len(obj.classe.periods):
            for period in obj.classe.periods:
                periodstore.remove(period)
        self.period_combo = ComboMgmt(self.periods, periodstore)
        if cursus:
            self.dialog_link.obj.set_title(
                "Insertion d'une période du cursus " + cursus.name)
        else:
            self.dialog_link.obj.set_title("Insertion d'une période")
        result = self.dialog_link.obj.run()
        self.dialog_link.obj.hide()
        self.period_combo = None
        return result
示例#7
0
	def connect(self):
		from ContentMgmt import ContentMgmt
		import User
		User.init_graphics()
		from User import interface_user

		self.user = interface_user.connect()
		if self.user != None:
			from db import db
			from University import University
			print 'access granted'
			self.connected = True
			self.user.settings.load_settings()
			def query(db, empty):
				return db.session.query(University).get(1)
			self.university = db.session_query(query, None,
			    'Timetableasy init : query(University).get(1)')
			self.contentmgr = ContentMgmt()
			# XXX what to do with that ?
			#if db.status == False:
			#	self.contentmgr.status_bar.add_action('icon', 9)
			self.contentmgr.status_bar.add_action('icon', 2)
			self.contentmgr.status_bar.set_connection_status(1)
			self.contentmgr.status_bar.check_date_display()
			# XXX first load of rights
			if (not self.user.is_admin()):
				self.contentmgr.menubar.admin.hide()
			self.contentmgr.show()
		else:
			print 'access denied'
示例#8
0
    def connect(self):
        from ContentMgmt import ContentMgmt
        import User
        User.init_graphics()
        from User import interface_user

        self.user = interface_user.connect()
        if self.user != None:
            from db import db
            from University import University
            print 'access granted'
            self.connected = True
            self.user.settings.load_settings()

            def query(db, empty):
                return db.session.query(University).get(1)

            self.university = db.session_query(
                query, None, 'Timetableasy init : query(University).get(1)')
            self.contentmgr = ContentMgmt()
            # XXX what to do with that ?
            #if db.status == False:
            #	self.contentmgr.status_bar.add_action('icon', 9)
            self.contentmgr.status_bar.add_action('icon', 2)
            self.contentmgr.status_bar.set_connection_status(1)
            self.contentmgr.status_bar.check_date_display()
            # XXX first load of rights
            if (not self.user.is_admin()):
                self.contentmgr.menubar.admin.hide()
            self.contentmgr.show()
        else:
            print 'access denied'
示例#9
0
	def on_dialog_add(self, widget):
		"""call get_dialog_fields, and call db.session_query,
		 response gtk.RESPONSE_OK"""

		def query(db, obj):
			"""callback for db.session_query, this query
			 add obj to session and call db.session_try_commit"""

			from Planning import Planning
			obj.planning = Planning()
			db.session.add(obj)
			db.session_try_commit()
		obj = self.current_obj
		self.get_dialog_fields()
		db.session_query(query, obj,
		    str("insert period " + obj.name +
		    " (end:" + str(obj.end) + ") in db"))
		self.dialog.obj.response(gtk.RESPONSE_OK)
示例#10
0
    def on_dialog_add(self, widget):
        """call get_dialog_fields, and call db.session_query,
		 response gtk.RESPONSE_OK"""
        def query(db, obj):
            """callback for db.session_query, this query
			 add obj to session and call db.session_try_commit"""

            from Planning import Planning
            obj.planning = Planning()
            db.session.add(obj)
            db.session_try_commit()

        obj = self.current_obj
        self.get_dialog_fields()
        db.session_query(
            query, obj,
            str("insert period " + obj.name + " (end:" + str(obj.end) +
                ") in db"))
        self.dialog.obj.response(gtk.RESPONSE_OK)
示例#11
0
    def on_dialog_add(self, widget):
        """call get_dialog_fields, and call db.session_query,
		 response gtk.RESPONSE_OK"""
        def query(db, obj):
            """callback for db.session_query, this query
			 add obj to session and call db.session_try_commit"""

            db.session.add(obj)
            db.session_try_commit()

        obj = self.current_obj
        self.get_dialog_fields()
        db.session_query(
            query, obj,
            str("insert course " + obj.name + " (e-learning:" +
                str(obj.c_elearning) + " ,classroom:" + str(obj.c_classroom) +
                " ,practice:" + str(obj.c_practice) + " ,eval practice:" +
                str(obj.e_practice) + " ,exam:" + str(obj.e_exam) + " ,oral:" +
                str(obj.e_oral) + ") in db"))
        self.dialog.obj.response(gtk.RESPONSE_OK)
示例#12
0
	def on_dialog_add(self, widget):
		"""call get_dialog_fields, and call db.session_query,
		 response gtk.RESPONSE_OK"""

		def query(db, obj):
			"""callback for db.session_query, this query
			 add obj to session and call db.session_try_commit"""

			db.session.add(obj)
			db.session_try_commit()
		obj = self.current_obj
		self.get_dialog_fields()
		db.session_query(query, obj,
		    str("insert course " + obj.name +
		    " (e-learning:" + str(obj.c_elearning) +
		    " ,classroom:" + str(obj.c_classroom) +
		    " ,practice:" + str(obj.c_practice) +
		    " ,eval practice:" + str(obj.e_practice) +
		    " ,exam:" + str(obj.e_exam) +
		    " ,oral:" + str(obj.e_oral) + ") in db"))
		self.dialog.obj.response(gtk.RESPONSE_OK)
示例#13
0
def auth(login, passwd):
	"""check if the login and password combination is valid"""

	from db import db
	db.session_init()
	md5passwd = md5.new(passwd)
	print "login : %s, passwd : %s, md5passwd : %s" % (login, passwd, md5passwd.hexdigest())
	def query(db, login):
		return db.session.query(User).filter(User.login==login).first()
	user = db.session_query(query, login,
	    "auth : query(User).filter(User.login==login(" + str(login) + ").first()")
	if user == None or user.password != md5passwd.hexdigest():
		return None
	else:
		return user
示例#14
0
def auth(login, passwd):
    """check if the login and password combination is valid"""

    from db import db
    db.session_init()
    md5passwd = md5.new(passwd)
    print "login : %s, passwd : %s, md5passwd : %s" % (login, passwd,
                                                       md5passwd.hexdigest())

    def query(db, login):
        return db.session.query(User).filter(User.login == login).first()

    user = db.session_query(
        query, login, "auth : query(User).filter(User.login==login(" +
        str(login) + ").first()")
    if user == None or user.password != md5passwd.hexdigest():
        return None
    else:
        return user
示例#15
0
	def on_valid_password_clicked(self, widget):
		"""check the user's password, check if both new password
		are identicals, change the change_pass_status in error case"""

		passwd = self.old_password.get_text()
		login = app.user.login
		md5passwd = md5.new(passwd)
		def query(db, login):
			return db.session.query(User).filter(User.login==login).first()
		user = db.session_query(query, login,
		    "auth : query(User).filter(User.login==login(" + str(login) + ").first()")
		if app.user.password != md5passwd.hexdigest():
			self.change_pass_status.set_markup("Erreure: ancien mot de passe invalide")
			self.dialog_password.response(gtk.RESPONSE_OK)
		else:
			passwd1 = self.new_password1.get_text()
			passwd2 = self.new_password2.get_text()
			if passwd1 == passwd2:
				md5passwd = md5.new(passwd1)
				app.user.password = md5passwd.hexdigest()
				db.session_try_commit()
				self.dialog_password.response(gtk.RESPONSE_OK)
			else:
				self.change_pass_status.set_markup("Erreure: les nouveaux mots de passe ne sont pas identiques")
示例#16
0
	def cb_tree_tooltip_text(self, tree, id):
		"""return the tooltip text for the tree"""
		if self.row[id].action == self.ADD_STUDENT_ACTION:
			return "Double cliquer pour ajouter un étudiant"
		elif (self.row[id].action == self.ADD_CLASS_MANAGER_ACTION or
		    self.row[id].action == self.ADD_CAMPUS_MANAGER_ACTION or
		    self.row[id].action == self.ADD_CURSUS_MANAGER_ACTION):
			return "Double cliquer pour ajouter un manager"
		elif self.row[id].action == self.ADD_ADMINISTRATOR_ACTION:
			return "Double cliquer pour ajouter un administrateur"
		elif self.row[id].action == self.ADD_CAMPUS_TEACHER_ACTION:
			return "Double cliquer pour ajouter un enseignant"
		elif self.row[id].action == self.ADMINISTRATORS_GROUP:
			def query(db, empty):
				from User import User
				q = db.session.query(User)
				return q.filter(User.type == "admin").count()
			nb_admin = db.session_query(query, None,
			    'user: nb_admin = ' +
			    'query(User).filter(User.type == "admin").count()')
			return str("Administrateurs de " +
			    str(self.row[id].obj_parent.name) + ", " +
			    str(nb_admin) + " membre" +
			    str(["", "s"][nb_admin > 1]))
		elif self.row[id].action == self.CURSUS_MANAGERS_GROUP:
			parent = self.row[id].obj_parent
			return str("Managers du cursus " +
			    str(parent.name) + ", " +
			    str(len(parent.managers)) + " membre" +
			    str(["", "s"][len(parent.managers) > 1]))
		elif self.row[id].action == self.CAMPUS_MANAGERS_GROUP:
			parent = self.row[id].obj_parent
			return str("Managers du campus " +
			    str(parent.name) + ", " +
			    str(len(parent.managers)) + " membre" +
			    str(["", "s"][len(parent.managers) > 1]))
		elif self.row[id].action == self.CAMPUS_TEACHERS_GROUP:
			parent = self.row[id].obj_parent
			return str("Enseignants du campus " +
			    str(parent.name) + ", " +
			    str(len(parent.teachers)) + " membre" +
			    str(["", "s"][len(parent.teachers) > 1]))
		elif self.row[id].action == self.CLASS_MANAGERS_GROUP:
			parent = self.row[id].obj_parent
			return str("Managers de la classe " +
			    str(parent.name) + ", " +
			    str(len(parent.managers)) + " membre" +
			    str(["", "s"][len(parent.managers) > 1]))
		elif self.row[id].action == self.CLASS_STUDENTS_GROUP:
			parent = self.row[id].obj_parent
			return str("Etudiants de la classe " +
			    str(parent.name) + ", " +
			    str(len(parent.students)) + " membre" +
			    str(["", "s"][len(parent.students) > 1]))
		elif self.row[id].action == self.CLASS_TEACHERS_GROUP:
			parent = self.row[id].obj_parent
			def query(db, parent):
				from User import User
				from Event import Event
				from Planning import Planning
				q = db.session.query(User).join(Event)
				q = q.join(Planning)
				q = q.filter(Planning.id == parent.id_planning)
				return q.count()
			nb_teachers = db.session_query(query, parent,
			    'user: nb_teachers = ' +
			    'query(User).join(Event).join(Planning)' +
			    '.filter(Planning.id == ' +
			    str(parent.id_planning) + ').count()')
			return str("Enseignants de la classe " +
			    str(parent.name) + ", " +
			    str(nb_teachers) + " membre" +
			    str(["", "s"][nb_teachers > 1]))

		if self.type == 'admin':
			desc = "Administrateur "
		elif self.type == 'manager':
			desc = "Manager "
		elif self.type == 'teacher':
			desc = "Enseignent "
		elif self.type == 'student':
			desc = "Etudiant "
		else:
			desc = "Utilisateur "
		desc += self.name + " " + self.firstname + " " + self.email
		if TreeMgmt.parent_action(self, id) == self.CAMPUS_TEACHERS_GROUP:
			# XXX complete tooltip : <nb_cours> <volume horaire_tt>
			pass
		elif TreeMgmt.parent_action(self, id) == self.CLASS_TEACHERS_GROUP:
			# XXX complete tooltip : list(<cours> <volume horaire>)
			pass
		return desc
示例#17
0
	def cb_tree_plug(self, tree, iter, id):
		"""plug object's childs in the tree"""
		if self.row[id].action == self.ADMINISTRATORS_GROUP:
			def query(db, empty):
				q = db.session.query(User)
				return q.filter(User.type == "admin").all()
			administratorlist = db.session_query(query, None,
			    'user: administratorlist = ' +
			    'query(User).filter(User.type == "admin").all()')
			for admin in administratorlist:
				tree.plug(iter, admin, self)
			tree.plug_action(iter, User(), self,
			    self.ADD_ADMINISTRATOR_ACTION, self)
		elif self.row[id].action == self.CURSUS_MANAGERS_GROUP:
			parent = self.row[id].obj_parent
			for manager in parent.managers:
				tree.plug(iter, manager, parent, self)
			tree.plug_action(iter, User(), parent,
			    self.ADD_CURSUS_MANAGER_ACTION, self)
		elif self.row[id].action == self.CAMPUS_MANAGERS_GROUP:
			parent = self.row[id].obj_parent
			for manager in parent.managers:
				tree.plug(iter, manager, parent, self)
			tree.plug_action(iter, User(), parent,
			    self.ADD_CAMPUS_MANAGER_ACTION, self)
		elif self.row[id].action == self.CAMPUS_TEACHERS_GROUP:
			parent = self.row[id].obj_parent
			for teacher in parent.teachers:
				tree.plug(iter, teacher, parent, self)
			tree.plug_action(iter, User(), parent,
			    self.ADD_CAMPUS_TEACHER_ACTION, self)
		elif self.row[id].action == self.CLASS_MANAGERS_GROUP:
			parent = self.row[id].obj_parent
			for manager in parent.managers:
				tree.plug(iter, manager, parent, self)
			tree.plug_action(iter, User(), parent,
			    self.ADD_CLASS_MANAGER_ACTION, self)
		elif self.row[id].action == self.CLASS_STUDENTS_GROUP:
			parent = self.row[id].obj_parent
			for student in parent.students:
				tree.plug(iter, student, parent, self)
			tree.plug_action(iter, User(), parent,
			    self.ADD_STUDENT_ACTION, self)
		elif self.row[id].action == self.CLASS_TEACHERS_GROUP:
			parent = self.row[id].obj_parent
			def query(db, parent):
				from User import User
				from Event import Event
				from Planning import Planning
				from Course import Course
				q = db.session.query(User).join(Event)
				q = q.join(Planning)
				q = q.filter(Planning.id == parent.id_planning)
				return q.all()
			teachers = db.session_query(query, parent,
			    'user: teachers = ' +
			    'query(User).join(Event).join(Planning)' +
			    '.filter(Planning.id == ' +
			    str(parent.id_planning) + ').execute()')
			if teachers:
				for teacher in teachers:
					tree.plug(iter, teacher, parent, self)
示例#18
0
    def cb_tree_tooltip_text(self, tree, id):
        """return the tooltip text for the tree"""
        if self.row[id].action == self.ADD_STUDENT_ACTION:
            return "Double cliquer pour ajouter un étudiant"
        elif (self.row[id].action == self.ADD_CLASS_MANAGER_ACTION
              or self.row[id].action == self.ADD_CAMPUS_MANAGER_ACTION
              or self.row[id].action == self.ADD_CURSUS_MANAGER_ACTION):
            return "Double cliquer pour ajouter un manager"
        elif self.row[id].action == self.ADD_ADMINISTRATOR_ACTION:
            return "Double cliquer pour ajouter un administrateur"
        elif self.row[id].action == self.ADD_CAMPUS_TEACHER_ACTION:
            return "Double cliquer pour ajouter un enseignant"
        elif self.row[id].action == self.ADMINISTRATORS_GROUP:

            def query(db, empty):
                from User import User
                q = db.session.query(User)
                return q.filter(User.type == "admin").count()

            nb_admin = db.session_query(
                query, None, 'user: nb_admin = ' +
                'query(User).filter(User.type == "admin").count()')
            return str("Administrateurs de " +
                       str(self.row[id].obj_parent.name) + ", " +
                       str(nb_admin) + " membre" +
                       str(["", "s"][nb_admin > 1]))
        elif self.row[id].action == self.CURSUS_MANAGERS_GROUP:
            parent = self.row[id].obj_parent
            return str("Managers du cursus " + str(parent.name) + ", " +
                       str(len(parent.managers)) + " membre" +
                       str(["", "s"][len(parent.managers) > 1]))
        elif self.row[id].action == self.CAMPUS_MANAGERS_GROUP:
            parent = self.row[id].obj_parent
            return str("Managers du campus " + str(parent.name) + ", " +
                       str(len(parent.managers)) + " membre" +
                       str(["", "s"][len(parent.managers) > 1]))
        elif self.row[id].action == self.CAMPUS_TEACHERS_GROUP:
            parent = self.row[id].obj_parent
            return str("Enseignants du campus " + str(parent.name) + ", " +
                       str(len(parent.teachers)) + " membre" +
                       str(["", "s"][len(parent.teachers) > 1]))
        elif self.row[id].action == self.CLASS_MANAGERS_GROUP:
            parent = self.row[id].obj_parent
            return str("Managers de la classe " + str(parent.name) + ", " +
                       str(len(parent.managers)) + " membre" +
                       str(["", "s"][len(parent.managers) > 1]))
        elif self.row[id].action == self.CLASS_STUDENTS_GROUP:
            parent = self.row[id].obj_parent
            return str("Etudiants de la classe " + str(parent.name) + ", " +
                       str(len(parent.students)) + " membre" +
                       str(["", "s"][len(parent.students) > 1]))
        elif self.row[id].action == self.CLASS_TEACHERS_GROUP:
            parent = self.row[id].obj_parent

            def query(db, parent):
                from User import User
                from Event import Event
                from Planning import Planning
                q = db.session.query(User).join(Event)
                q = q.join(Planning)
                q = q.filter(Planning.id == parent.id_planning)
                return q.count()

            nb_teachers = db.session_query(
                query, parent, 'user: nb_teachers = ' +
                'query(User).join(Event).join(Planning)' +
                '.filter(Planning.id == ' + str(parent.id_planning) +
                ').count()')
            return str("Enseignants de la classe " + str(parent.name) + ", " +
                       str(nb_teachers) + " membre" +
                       str(["", "s"][nb_teachers > 1]))

        if self.type == 'admin':
            desc = "Administrateur "
        elif self.type == 'manager':
            desc = "Manager "
        elif self.type == 'teacher':
            desc = "Enseignent "
        elif self.type == 'student':
            desc = "Etudiant "
        else:
            desc = "Utilisateur "
        desc += self.name + " " + self.firstname + " " + self.email
        if TreeMgmt.parent_action(self, id) == self.CAMPUS_TEACHERS_GROUP:
            # XXX complete tooltip : <nb_cours> <volume horaire_tt>
            pass
        elif TreeMgmt.parent_action(self, id) == self.CLASS_TEACHERS_GROUP:
            # XXX complete tooltip : list(<cours> <volume horaire>)
            pass
        return desc
示例#19
0
    def init_graphics(self):
        from ComboMgmt import ComboMgmt
        from GtkMapper import GtkMapper

        from User import User
        from Course import Course

        GtkMapper('graphics/dialog_event.glade', self, app.debug)

        def query_user(db, empty_data):
            return db.session.query(User).all()

        def query_classroom(db, empty_data):
            return db.session.query(ClassRoom).all()

        def query_course(db, empty_data):
            return db.session.query(Course).all()

        self.dialog.valid_event.set_sensitive(False)

        userstore = []
        classroomstore = []
        if self.planning.type_campus:
            self.dialog.line_private_event.obj.hide()
            self.dialog.line_modality.obj.hide()
            self.dialog.line_course.obj.hide()
            classroomstore = db.session_query(
                query_classroom, None, "events : query(ClassRoom).all()")
            self.allow_classroom = True
            userstore = db.session_query(query_user, None,
                                         "events : query(User).all()")
            self.classroom_combo = ComboMgmt(
                self.dialog.line_classroom.classroom, classroomstore,
                self.classroom, None)
            self.teacher_combo = ComboMgmt(
                self.dialog.line_teacher_name.teacher_name, userstore,
                self.teacher, self.teacher_name)

        if self.planning.type_class:
            self.dialog.line_private_event.obj.hide()
            classroomstore = db.session_query(
                query_classroom, None, "events : query(ClassRoom).all()")
            self.allow_classroom = True
            userstore = db.session_query(query_user, None,
                                         "events : query(User).all()")
            courses = db.session_query(query_course, None,
                                       "events : query(Course).all()")
            '''course_store = gtk.ListStore(str, object)
			for course in courses:
				course_store.append([course.name, course])
			self.dialog.line_course.course.set_model(course_store)'''
            self.course_combo = ComboMgmt(self.dialog.line_course.course,
                                          courses, self.course, None)
            self.classroom_combo = ComboMgmt(
                self.dialog.line_classroom.classroom, classroomstore,
                self.classroom, None)
            self.teacher_combo = ComboMgmt(
                self.dialog.line_teacher_name.teacher_name, userstore,
                self.teacher, self.teacher_name)

        if self.planning.type_period:
            self.dialog.line_classroom.obj.hide()
            self.dialog.line_private_event.obj.hide()
            courses = db.session_query(query_course, None,
                                       "events : query(Course).all()")
            userstore = db.session_query(query_user, None,
                                         "events : query(User).all()")
            self.course_combo = ComboMgmt(self.dialog.line_course.course,
                                          courses, self.course, None)
            self.teacher_combo = ComboMgmt(
                self.dialog.line_teacher_name.teacher_name, userstore,
                self.teacher, self.teacher_name)

        if self.planning.type_user:
            self.dialog.line_private_event.private_event.set_active(1)
            self.dialog.line_required_event.obj.hide()
            self.dialog.line_teacher_name.obj.hide()
            self.dialog.line_modality.obj.hide()
            self.dialog.line_classroom.obj.hide()
            self.dialog.line_course.obj.hide()

        self.dialog_confirmation = gtk.MessageDialog(
            None, gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT,
            gtk.MESSAGE_QUESTION, gtk.BUTTONS_OK_CANCEL, None)
        return
示例#20
0
    def title_changed(self, view, frame, title):
        """manage action on planning view, resize event, right
		click, drop and click event... """

        from Event import Event

        def query(db, id):
            """callback for db.session_query, this query
			 event in terms of this id"""

            return db.session.query(Event).get(id)

        print "title change : %s" % title
        if title == "none":
            return
        # list event
        data = re.search('/signal/events/.*\?.*start=(.*)&end=(.*).*', title)
        if data:
            start = data.group(1)
            end = data.group(2)
            events = "$('#events').text('%s')" % \
                self.events2json(start, end).replace("'", "\\'")
            self.browser.execute_script(events)
        # create event
        data = re.search('/signal/events-create/.*\?.*start=(.*)&end=(.*).*',
                         title)
        if data:
            start = data.group(1)
            end = data.group(2)
            # XXX create event
            self.refresh_events()
        # resize event
        data = re.search('/signal/event-resize/.*\?.*minutedelta=(.*)&id=(.*)',
                         title)
        if data:
            minutedelta = data.group(1)
            id = data.group(2)
            event = db.session_query(
                query, id, "planning : query(Event).get(" + str(id) + ")")
            event.time_length += int(minutedelta) / 60
            db.session_try_commit()
        # drop event
        data = re.search(
            '/signal/event-drop/.*\?.*daydelta=(.*)&minutedelta=(.*)&id=(.*)',
            title)
        if data:
            daydelta = data.group(1)
            minutedelta = data.group(2)
            id = data.group(3)
            event = db.session_query(
                query, id, "planning : query(Event).get(" + str(id) + ")")
            delta = relativedelta(days=int(daydelta), minutes=int(minutedelta))
            event.datetime += delta
            db.session_try_commit()
        # click event
        data = re.search('/signal/event-click/.*\?.*id=(.*)', title)
        if data:
            id = data.group(1)
            event = db.session_query(
                query, id, "planning : query(Event).get(" + str(id) + ")")
            editable_event = False
            if event.planning.type_user and self.check_rights(
                    "user", event.id_planning) == True:
                editable_event = True
            elif event.planning.type_class and self.check_rights(
                    "class", (event.planning.type_class.campus.id,
                              event.planning.type_class.id)) == True:
                editable_event = True
            elif event.planning.type_campus and self.check_rights(
                    "campus", event.planning.type_campus.id) == True:
                editable_event = True
            elif event.planning.type_period and self.check_rights(
                    "period") == True:
                editable_event = True
            elif self.check_rights("univ") == True:
                editable_event = True
            if editable_event:
                if event.change_event() == gtk.RESPONSE_OK:
                    self.refresh_events()
        # right click event
        data = re.search('/signal/event-right-click/.*\?.*id=(.*)', title)
        if data:
            id = data.group(1)
            self.clicked_event = db.session_query(
                query, id, "planning : query(Event).get(" + str(id) + ")")
            duplicate_event = False
            if self.clicked_event.planning.type_user and self.check_rights(
                    "user", self.clicked_event.id_planning) == True:
                duplicate_event = True
            elif self.clicked_event.planning.type_class and self.check_rights(
                    "class",
                (self.clicked_event.planning.type_class.campus.id,
                 self.clicked_event.planning.type_class.id)) == True:
                duplicate_event = True
            elif self.clicked_event.planning.type_campus and self.check_rights(
                    "campus",
                    self.clicked_event.planning.type_campus.id) == True:
                duplicate_event = True
            elif self.clicked_event.planning.type_period and self.check_rights(
                    "period") == True:
                duplicate_event = True
            elif self.check_rights("univ") == True:
                duplicate_event = True
            print 'right clic event'
            self.menu_context_popup(self.last_event, duplicate_event)
        # right click day
        data = re.search('/signal/day-right-click/.*\?.*date=(.*)', title)
        if data:
            date = data.group(1)
            print 'right clic day' + date
            self.menu_context_popup(self.last_event)
示例#21
0
	def init_graphics(self):
		from ComboMgmt import ComboMgmt
		from GtkMapper import GtkMapper

		from User import User
		from Course import Course

		GtkMapper('graphics/dialog_event.glade', self, app.debug)

		def query_user(db, empty_data):
			return db.session.query(User).all()

		def query_classroom(db, empty_data):
			return db.session.query(ClassRoom).all()

		def query_course(db, empty_data):
			return db.session.query(Course).all()

		self.dialog.valid_event.set_sensitive(False)

		userstore = []
		classroomstore = []
		if self.planning.type_campus:
			self.dialog.line_private_event.obj.hide()
			self.dialog.line_modality.obj.hide()
			self.dialog.line_course.obj.hide()
			classroomstore = db.session_query(query_classroom, None,
			    "events : query(ClassRoom).all()")
			self.allow_classroom = True
			userstore = db.session_query(query_user, None,
			    "events : query(User).all()")
			self.classroom_combo = ComboMgmt(self.dialog.line_classroom.classroom, classroomstore, self.classroom, None)
			self.teacher_combo = ComboMgmt(self.dialog.line_teacher_name.teacher_name, userstore, self.teacher, self.teacher_name)

		if self.planning.type_class:
			self.dialog.line_private_event.obj.hide()
			classroomstore = db.session_query(query_classroom, None,
			    "events : query(ClassRoom).all()")
			self.allow_classroom = True
			userstore = db.session_query(query_user, None,
			    "events : query(User).all()")
			courses = db.session_query(query_course, None,
			    "events : query(Course).all()")
			'''course_store = gtk.ListStore(str, object)
			for course in courses:
				course_store.append([course.name, course])
			self.dialog.line_course.course.set_model(course_store)'''
			self.course_combo = ComboMgmt(self.dialog.line_course.course, courses, self.course, None)
			self.classroom_combo = ComboMgmt(self.dialog.line_classroom.classroom, classroomstore, self.classroom, None)
			self.teacher_combo = ComboMgmt(self.dialog.line_teacher_name.teacher_name, userstore, self.teacher, self.teacher_name)

		if self.planning.type_period:
			self.dialog.line_classroom.obj.hide()
			self.dialog.line_private_event.obj.hide()
			courses = db.session_query(query_course, None,
			    "events : query(Course).all()")
			userstore = db.session_query(query_user, None,
			    "events : query(User).all()")
			self.course_combo = ComboMgmt(self.dialog.line_course.course, courses, self.course, None)
			self.teacher_combo = ComboMgmt(self.dialog.line_teacher_name.teacher_name, userstore, self.teacher, self.teacher_name)

		if self.planning.type_user:
			self.dialog.line_private_event.private_event.set_active(1)
			self.dialog.line_required_event.obj.hide()
			self.dialog.line_teacher_name.obj.hide()
			self.dialog.line_modality.obj.hide()
			self.dialog.line_classroom.obj.hide()
			self.dialog.line_course.obj.hide()

		self.dialog_confirmation = gtk.MessageDialog(None,
		    gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT,
		    gtk.MESSAGE_QUESTION,
		    gtk.BUTTONS_OK_CANCEL,
		    None)
		return
示例#22
0
    def cb_tree_plug(self, tree, iter, id):
        """plug object's childs in the tree"""
        if self.row[id].action == self.ADMINISTRATORS_GROUP:

            def query(db, empty):
                q = db.session.query(User)
                return q.filter(User.type == "admin").all()

            administratorlist = db.session_query(
                query, None, 'user: administratorlist = ' +
                'query(User).filter(User.type == "admin").all()')
            for admin in administratorlist:
                tree.plug(iter, admin, self)
            tree.plug_action(iter, User(), self, self.ADD_ADMINISTRATOR_ACTION,
                             self)
        elif self.row[id].action == self.CURSUS_MANAGERS_GROUP:
            parent = self.row[id].obj_parent
            for manager in parent.managers:
                tree.plug(iter, manager, parent, self)
            tree.plug_action(iter, User(), parent,
                             self.ADD_CURSUS_MANAGER_ACTION, self)
        elif self.row[id].action == self.CAMPUS_MANAGERS_GROUP:
            parent = self.row[id].obj_parent
            for manager in parent.managers:
                tree.plug(iter, manager, parent, self)
            tree.plug_action(iter, User(), parent,
                             self.ADD_CAMPUS_MANAGER_ACTION, self)
        elif self.row[id].action == self.CAMPUS_TEACHERS_GROUP:
            parent = self.row[id].obj_parent
            for teacher in parent.teachers:
                tree.plug(iter, teacher, parent, self)
            tree.plug_action(iter, User(), parent,
                             self.ADD_CAMPUS_TEACHER_ACTION, self)
        elif self.row[id].action == self.CLASS_MANAGERS_GROUP:
            parent = self.row[id].obj_parent
            for manager in parent.managers:
                tree.plug(iter, manager, parent, self)
            tree.plug_action(iter, User(), parent,
                             self.ADD_CLASS_MANAGER_ACTION, self)
        elif self.row[id].action == self.CLASS_STUDENTS_GROUP:
            parent = self.row[id].obj_parent
            for student in parent.students:
                tree.plug(iter, student, parent, self)
            tree.plug_action(iter, User(), parent, self.ADD_STUDENT_ACTION,
                             self)
        elif self.row[id].action == self.CLASS_TEACHERS_GROUP:
            parent = self.row[id].obj_parent

            def query(db, parent):
                from User import User
                from Event import Event
                from Planning import Planning
                from Course import Course
                q = db.session.query(User).join(Event)
                q = q.join(Planning)
                q = q.filter(Planning.id == parent.id_planning)
                return q.all()

            teachers = db.session_query(
                query, parent, 'user: teachers = ' +
                'query(User).join(Event).join(Planning)' +
                '.filter(Planning.id == ' + str(parent.id_planning) +
                ').execute()')
            if teachers:
                for teacher in teachers:
                    tree.plug(iter, teacher, parent, self)
示例#23
0
    def get_event(self, start=None, end=None, all=False):
        """use for get all events link to this planning and
		 the linked planning for merge"""

        from Event import Event
        from Timetableasy import app

        def query(db, id):
            """callback for db.session_query, this query
			 event in plannings unless private = True"""

            if type(id) is tuple:
                return db.session.query(Event).filter(
                    Event.id_planning.in_(
                        id[0])).filter(Event.private_event == 0).filter(
                            Event.datetime >= id[1]).filter(
                                Event.datetime <= id[2]).all()
            else:
                return db.session.query(Event).filter(
                    Event.id_planning.in_(id)).filter(
                        Event.private_event == 0).all()

        def query_planning_user(db, id):
            """callback for db.session_query, this query
			 event in user's planning"""

            if type(id) is tuple:
                return db.session.query(Event).filter(
                    Event.id_planning == id[0]).filter(
                        Event.datetime >= id[1]).filter(
                            Event.datetime <= id[2]).all()
            else:
                return db.session.query(Event).filter(
                    Event.id_planning == id).all()

        def query_required(db, id):
            """callback for db.session_query, this query
			 event in plannings  where required  = True
			 unless private = True"""

            if type(id) is tuple:
                return db.session.query(Event).filter(
                    Event.id_planning.in_(
                        id[0])).filter(Event.private_event == 0).filter(
                            Event.required_event == 1).filter(
                                Event.datetime >= id[1]).filter(
                                    Event.datetime <= id[2]).all()
            else:
                return db.session.query(Event).filter(
                    Event.id_planning.in_(id)).filter(
                        Event.private_event == 0).filter(
                            Event.required_event == 1).all()

        events = []
        for i in self.planning_parent:
            change_list = []
            if type(self.planning_parent[i][0]) is list:
                change_list = self.planning_parent[i][0]
            else:
                change_list.append(self.planning_parent[i][0])
            if self.planning_parent[i][0] and self.planning_parent[i][
                    0] == app.user.id_planning:
                if start != None and end != None:
                    events.append(
                        db.session_query(
                            query_planning_user,
                            (self.planning_parent[i][0], start, end),
                            str("execute query to get Event "
                                "filter on Event.id_planning== " +
                                str(self.planning_parent[i][0]) +
                                ").filter(Event.datetime>=id[1]).filter(Event.datetime<=id[2]).all()"
                                )))
                else:
                    events.append(
                        db.session_query(
                            query_planning_user, self.planning_parent[i][0],
                            str("execute query to get Event "
                                "filter on Event.id_planning== " +
                                str(self.planning_parent[i][0]) + ").all()")))
            elif self.planning_parent[i][0] and (self.planning_parent[i][1]
                                                 or all == True):
                if start != None and end != None:
                    events.append(
                        db.session_query(
                            query, (change_list, start, end),
                            str("execute query to get Event filter " +
                                "on Event.id_planning.in_" +
                                str(self.planning_parent[i][0]) +
                                ").filter(Event.private_event==0).filter(Event.datetime>=id[1]).filter(Event.datetime<=id[2]).all()"
                                )))
                else:
                    events.append(
                        db.session_query(
                            query, change_list,
                            str("execute query to get Event filter " +
                                "on Event.id_planning.in_" +
                                str(self.planning_parent[i][0]) +
                                ").filter(Event.private_event==0).all()")))
            elif self.planning_parent[i][0]:
                if start != None and end != None:
                    events.append(
                        db.session_query(
                            query_required, (change_list, start, end),
                            str("execute query to get Event filter " +
                                "on Event.id_planning.in_" +
                                str(self.planning_parent[i][0]) +
                                ").filter(Event.private_event==0).filter(Event.required_event==1).filter(Event.datetime>=id[1]).filter(Event.datetime<=id[2]).all()"
                                )))
                else:
                    events.append(
                        db.session_query(
                            query_required, change_list,
                            str("execute query to get Event filter " +
                                "on Event.id_planning.in_(" +
                                str(self.planning_parent[i][0]) +
                                ").filter(Event.private_event==0).filter(Event.required_event==1).all()"
                                )))
        return events