def meta_competence_edit_view(context, request): if IMetaCompetence.providedBy(context): add_form = False meta_competence = context context = meta_competence.__parent__ else: meta_competence = MetaCompetence() add_form = True errors = {} defaults = {} if 'form.submitted' in request.POST: try: # FormEncode validation defaults = dict(request.POST) form_result = meta_competence_schema.to_python(request.POST) except formencode.validators.Invalid, why: errors=why.error_dict else: # Apply schema fields to the project object field_names = [ p.key for p in class_mapper(MetaCompetence).iterate_properties ] changed = False for field_name in field_names: if field_name in form_result.keys(): if form_result[field_name] != getattr(meta_competence, field_name): setattr(meta_competence, field_name, form_result[field_name]) changed = True # Add onjective if this is the add form if add_form: session = DBSession() session.add(meta_competence) return HTTPFound(location = model_url(context, request))
def _add_meta_competence(self, title=u'Meta competence', description=u'Meta competence'): from eportfolio.models.meta_competence import MetaCompetence from eportfolio.models import DBSession session = DBSession() meta_competence = MetaCompetence(title=title, description=description) session.add(meta_competence) session.flush() return meta_competence
def _populate_db(self): session = DBSession() # Add a teacher ############### Change user name and email here ############### if not session.query(Teacher).filter(Teacher.email == u"*****@*****.**").all(): admin = Teacher(first_name=u'Admin', last_name=u'User', email=u"*****@*****.**", password=u'password') session.add(admin)
def _add_competence(self, title=u'Competence', description=u'Competence', meta_competence=None): from eportfolio.models.competence import Competence from eportfolio.models import DBSession if not meta_competence: meta_competence = self._add_meta_competence() session = DBSession() competence = Competence(title=title, description=description, meta_competence=meta_competence) session.add(competence) session.flush() return competence
def _add_objective(self, title=u'Objective', description=u'Objective', project=None): from eportfolio.models.objective import Objective from eportfolio.models import DBSession if not project: project = self._add_project() session = DBSession() objective = Objective(title=title, description=description, project=project) session.add(objective) session.flush() return objective
def _add_indicator(self, title=u'Indicator', description=u'Indicator', indicator_set=None): from eportfolio.models.indicator import Indicator from eportfolio.models import DBSession if not indicator_set: indicator_set = self._add_indicator_set() session = DBSession() indicator = Indicator(title=title, description=description, indicator_set=indicator_set) session.add(indicator) session.flush() return indicator
def _add_indicator_set(self, title=u'Indicator set', description=u'Indicator set', competence=None): from eportfolio.models.indicator_set import IndicatorSet from eportfolio.models import DBSession if not competence: competence = self._add_competence() session = DBSession() indicator_set = IndicatorSet(title=title, description=description, competence=competence) session.add(indicator_set) session.flush() return indicator_set
def _add_student(self, first_name=u"Buck", last_name=u"Mulligan", email=u"*****@*****.**", password=u'123456'): from eportfolio.models.student import Student from eportfolio.models import DBSession session = DBSession() student = Student() student.first_name = first_name student.last_name = last_name student.email = email student.password = u'{SHA}%s' % sha.new(password).hexdigest() session.add(student) session.flush() return student
def _populate_db(self): session = DBSession() # Add a teacher ############### Change user name and email here ############### if not session.query(Teacher).filter( Teacher.email == u"*****@*****.**").all(): admin = Teacher(first_name=u'Admin', last_name=u'User', email=u"*****@*****.**", password=u'password') session.add(admin)
def _add_teacher(self, first_name=u'Leopold', last_name=u'Bloom', email=u'*****@*****.**', password=u'12345'): from eportfolio.models.teacher import Teacher from eportfolio.models import DBSession session = DBSession() teacher = Teacher() teacher.first_name = first_name teacher.last_name = last_name teacher.email = email teacher.password = u'{SHA}%s' % sha.new(password).hexdigest() session.add(teacher) session.flush() return teacher
def _add_project(self, title=u"Project", start_date=None, end_date=None): from eportfolio.models.project import Project from eportfolio.models import DBSession if not start_date: start_date = datetime.date.today() - datetime.timedelta(days=10) if not end_date: end_date = datetime.date.today() + datetime.timedelta(days=10) session = DBSession() project = Project() project.title = title project.start_date = start_date project.end_date = end_date session.add(project) session.flush() return project
def objective_edit_view(context, request): session = DBSession() competences = session.query(Competence).all() if IObjective.providedBy(context): add_form = False objective = context project = context.project context = objective.__parent__ else: objective = Objective() add_form = True project = context.__parent__ errors = {} defaults = {} if 'form.submitted' in request.POST: try: # FormEncode validation defaults = dict(request.POST) form_result = objective_schema.to_python(request.POST) except formencode.validators.Invalid, why: errors = why.error_dict else: # Apply schema fields to the project object changed = False competences = [] for competence_id in form_result['competences']: competence = session.query(Competence).filter_by( id=competence_id).first() if competence: competences.append(competence) form_result['competences'] = competences for field_name in objective_schema.fields.keys(): if form_result[field_name] != getattr(objective, field_name): setattr(objective, field_name, form_result[field_name]) changed = True # Add onjective if this is the add form if add_form: objective.project = project session.add(objective) return HTTPFound(location=model_url(context, request))
def indicator_edit_view(context, request): if IIndicator.providedBy(context): indicator = context indicator_set = indicator.indicator_set add_form = False else: indicator = Indicator() indicator_set = context.__parent__ add_form = True competences_container = find_interface(context, ICompetences) errors = {} defaults = {} if 'form.submitted' in request.POST: try: # FormEncode validation defaults = dict(request.POST) form_result = indicator_schema.to_python(request.POST) except formencode.validators.Invalid, why: errors = why.error_dict else: # Apply schema fields to the project object field_names = [ p.key for p in class_mapper(Indicator).iterate_properties ] changed = False for field_name in field_names: if field_name in form_result.keys(): if form_result[field_name] != getattr( indicator, field_name): setattr(indicator, field_name, form_result[field_name]) changed = True # Add project if this is the add form if add_form: session = DBSession() indicator.indicator_set = indicator_set indicator.index = indicator_set.indicators.count() - 1 session.add(indicator) return HTTPFound( location=model_url(competences_container, request))
def objective_edit_view(context, request): session = DBSession() competences = session.query(Competence).all() if IObjective.providedBy(context): add_form = False objective = context project = context.project context = objective.__parent__ else: objective = Objective() add_form = True project = context.__parent__ errors = {} defaults = {} if 'form.submitted' in request.POST: try: # FormEncode validation defaults = dict(request.POST) form_result = objective_schema.to_python(request.POST) except formencode.validators.Invalid, why: errors=why.error_dict else: # Apply schema fields to the project object changed = False competences = [] for competence_id in form_result['competences']: competence = session.query(Competence).filter_by(id=competence_id).first() if competence: competences.append(competence) form_result['competences'] = competences for field_name in objective_schema.fields.keys(): if form_result[field_name] != getattr(objective, field_name): setattr(objective, field_name, form_result[field_name]) changed = True # Add onjective if this is the add form if add_form: objective.project = project session.add(objective) return HTTPFound(location = model_url(context, request))
def competence_edit_view(context, request): session = DBSession() meta_competences = session.query(MetaCompetence).all() if ICompetence.providedBy(context): competence = context context = competence.__parent__ add_form = False else: competence = Competence() add_form = True errors = {} defaults = {} if 'form.submitted' in request.POST: try: # FormEncode validation defaults = dict(request.POST) form_result = competence_schema.to_python(request.POST) except formencode.validators.Invalid, why: errors = why.error_dict else: # Apply schema fields to the project object field_names = [ p.key for p in class_mapper(Competence).iterate_properties ] changed = False for field_name in field_names: if field_name in form_result.keys(): if form_result[field_name] != getattr( competence, field_name): setattr(competence, field_name, form_result[field_name]) changed = True # Add project if this is the add form if add_form: session.add(competence) return HTTPFound(location=model_url(context, request))
def indicator_edit_view(context, request): if IIndicator.providedBy(context): indicator = context indicator_set = indicator.indicator_set add_form = False else: indicator = Indicator() indicator_set = context.__parent__ add_form = True competences_container = find_interface(context, ICompetences) errors = {} defaults = {} if 'form.submitted' in request.POST: try: # FormEncode validation defaults = dict(request.POST) form_result = indicator_schema.to_python(request.POST) except formencode.validators.Invalid, why: errors=why.error_dict else: # Apply schema fields to the project object field_names = [ p.key for p in class_mapper(Indicator).iterate_properties ] changed = False for field_name in field_names: if field_name in form_result.keys(): if form_result[field_name] != getattr(indicator, field_name): setattr(indicator, field_name, form_result[field_name]) changed = True # Add project if this is the add form if add_form: session = DBSession() indicator.indicator_set = indicator_set indicator.index = indicator_set.indicators.count() - 1 session.add(indicator) return HTTPFound(location = model_url(competences_container, request))
def project_edit_view(context, request): if IProject.providedBy(context): project = context context = project.__parent__ add_form = False else: project = Project() add_form = True errors = {} defaults = {} if 'form.submitted' in request.POST: try: # FormEncode validation defaults = dict(request.POST) form_result = project_schema.to_python(request.POST) except formencode.validators.Invalid, why: errors=why.error_dict else: # Apply schema fields to the project object changed = False for field_name in project_schema.fields.keys(): if form_result[field_name] != getattr(project, field_name): setattr(project, field_name, form_result[field_name]) changed = True # Add project if this is the add form if add_form: session = DBSession() # Add the teacher that created the project to the project. user = authenticated_user(request) if ITeacher.providedBy(user): project.teachers.append(user) session.add(project) return HTTPFound(location = model_url(context, request))
def project_edit_view(context, request): if IProject.providedBy(context): project = context context = project.__parent__ add_form = False else: project = Project() add_form = True errors = {} defaults = {} if 'form.submitted' in request.POST: try: # FormEncode validation defaults = dict(request.POST) form_result = project_schema.to_python(request.POST) except formencode.validators.Invalid, why: errors = why.error_dict else: # Apply schema fields to the project object changed = False for field_name in project_schema.fields.keys(): if form_result[field_name] != getattr(project, field_name): setattr(project, field_name, form_result[field_name]) changed = True # Add project if this is the add form if add_form: session = DBSession() # Add the teacher that created the project to the project. user = authenticated_user(request) if ITeacher.providedBy(user): project.teachers.append(user) session.add(project) return HTTPFound(location=model_url(context, request))
def teacher_edit_view(context, request): if ITeacher.providedBy(context): teacher = context context = teacher.__parent__ add_form = False else: teacher = Teacher(id=uuid.uuid4()) add_form = True errors = {} defaults = {} if "form.submitted" in request.POST: try: # FormEncode validation defaults = dict(request.POST) state = FormencodeState() state.user_id = teacher.user_name if add_form: form_result = teacher_add_schema.to_python(request.POST, state) else: form_result = teacher_schema.to_python(request.POST, state) except formencode.validators.Invalid, why: errors = why.error_dict else: changed = False # Convert password to SHA hash if form_result.get("password", None): form_result["password"] = "******" % sha.new(form_result["password"]).hexdigest() changed = True # Handle portrait upload if form_result["portrait"] is not None: # Scale image and convert to JPEG im = Image.open(form_result["portrait"].file) im.thumbnail((128, 128), Image.ANTIALIAS) # Convert to RGB if neccessary if im.mode != "RGB": im = im.convert("RGB") outfile = StringIO() im.save(outfile, "JPEG") outfile.seek(0) teacher.portrait = File("portrait.jpg", outfile.read()) changed = True del form_result["portrait"] # Apply schema fields to the student object field_names = [p.key for p in class_mapper(Teacher).iterate_properties] for field_name in field_names: if field_name in form_result.keys(): if form_result[field_name] != getattr(teacher, field_name): setattr(teacher, field_name, form_result[field_name]) changed = True # Add student if this is the add form if add_form: session = DBSession() session.add(teacher) if not form_result["password"]: reset_url = model_url(get_root(request), request, "retrieve_password.html") teacher.send_password_reset(reset_url) return HTTPFound(location=model_url(context, request))
def teacher_edit_view(context, request): if ITeacher.providedBy(context): teacher = context context = teacher.__parent__ add_form = False else: teacher = Teacher(id=uuid.uuid4()) add_form = True errors = {} defaults = {} if 'form.submitted' in request.POST: try: # FormEncode validation defaults = dict(request.POST) state = FormencodeState() state.user_id = teacher.user_name if add_form: form_result = teacher_add_schema.to_python(request.POST, state) else: form_result = teacher_schema.to_python(request.POST, state) except formencode.validators.Invalid, why: errors=why.error_dict else: changed = False # Convert password to SHA hash if form_result.get('password', None): form_result['password'] = '******' % sha.new(form_result['password']).hexdigest() changed = True # Handle portrait upload if form_result['portrait'] is not None: # Scale image and convert to JPEG im = Image.open(form_result['portrait'].file) im.thumbnail((128, 128),Image.ANTIALIAS) # Convert to RGB if neccessary if im.mode != "RGB": im = im.convert("RGB") outfile = StringIO() im.save(outfile, "JPEG") outfile.seek(0) teacher.portrait = File('portrait.jpg', outfile.read()) changed = True del form_result['portrait'] # Apply schema fields to the student object field_names = [ p.key for p in class_mapper(Teacher).iterate_properties ] for field_name in field_names: if field_name in form_result.keys(): if form_result[field_name] != getattr(teacher, field_name): setattr(teacher, field_name, form_result[field_name]) changed = True # Add student if this is the add form if add_form: session = DBSession() session.add(teacher) if not form_result['password']: reset_url = model_url(get_root(request), request, 'retrieve_password.html') teacher.send_password_reset(reset_url) return HTTPFound(location = model_url(context, request))