def addSection(): form = AddSection() if form.validate_on_submit(): if form.img_file.data: imgfile = save_picture(form.img_file.data, False) sect = Section(name=form.name.data, img_alt=form.img_alt.data, img_file=imgfile) else: sect = Section(name=form.name.data, img_alt=form.img_alt.data) db.session.add(sect) db.session.commit() flash(f'Section {form.name.data} created', 'success') return render_template('admin/addSection.html', form=form)
def frontend_urls(request): """ Our javascript needs a global dictionary of url templates like: FRONTEND_URLS = { 'reorder_section_node': '/casebooks/_CASEBOOK_ID/sections/_SECTION_ORDINALS/reorder/_CHILD_ORDINALS/' } These can't be generated directly from reverse() because reverse('reorder_section_node', args=['_CASEBOOK_ID', ...]) doesn't resolve -- we need to pass in args as ints or ordinals or Casebook instances or whatever. This function calls reverse() with valid inputs for each url template we need, and then replaces the strings in the resulting url with the desired placeholders. """ global _frontend_urls if not _frontend_urls: urls_in = { # key: [url_name, reverse_args, strings, placeholders] 'reorder_section_node': [ 'reorder_node', [1, "2", "3"], ["1", "2", "3"], ['_CASEBOOK_ID', '_SECTION_ORDINALS', '_CHILD_ORDINALS'] ], 'reorder_casebook_node': [ 'reorder_node', [1, "2"], ["1", "2"], ['_CASEBOOK_ID', '_CHILD_ORDINALS'] ], 'new_section_or_resource': ['new_section_or_resource', [1], ["1"], ['$CASEBOOK_ID']], 'search': ['search', [], [], []], 'new_casebook': ['new_casebook', [], [], []], 'section': ['section', [1, "2"], ["1", "2"], ['CASEBOOK_ID', 'SECTION_ID']], 'casebook': ['casebook', [1], ["1"], ['_ID']], 'export_casebook': [ 'export', [Casebook(id=1), "docx"], ["1", "docx"], ['_ID', '_FORMAT'] ], 'export_section': [ 'export', [Section(id=1), "docx"], ["1", "docx"], ['_ID', '_FORMAT'] ], 'export_resource': [ 'export', [Resource(id=1), "docx"], ["1", "docx"], ['_ID', '_FORMAT'] ], } urls_out = {} for key, [url_name, reverse_args, strings, placeholders] in urls_in.items(): url = reverse(url_name, args=reverse_args) for string, placeholder in zip(strings, placeholders): url = url.replace(str(string), placeholder, 1) urls_out[key] = url _frontend_urls = mark_safe(json.dumps(urls_out)) return {'frontend_urls': _frontend_urls}
def add_section(request): name=request.POST.get('section_name') title=request.POST.get('section_title') language=str(request.LANGUAGE_CODE) next_index=int(request.POST.get('section_index')) new_section=Section(section_name=name, section_title=title, section_lang=language, section_author=request.user, section_index=next_index) new_section.save() new_content=Content(section_id=new_section, text="No se ha definido contenido para esta sección") new_content.save() return HttpResponseRedirect("/")
def add_section(exam_in_db, section_dict): # add simple properties properties_to_add = [ "name", "info", "comment", "postinfo", "allowed_attempts", "show_correct_answer", "show_solution", "max_questions_to_attempt" ] section = Section() for key in properties_to_add: if key in section_dict and hasattr(section, key): setattr(section, key, section_dict[key]) section.exam = exam_in_db # add compound properties if "marking_scheme" in section_dict: subdict = section_dict["marking_scheme"] if "correct" in subdict: section.correct_marks = subdict["correct"] if "wrong" in subdict: section.wrong_marks = subdict["wrong"] if "na" in subdict: section.na_marks = subdict["na"] if "hint_deduction" in subdict: section.hint_deduction = subdict["hint_deduction"] if "unlock" in section_dict: subdict = section_dict["unlock"] if "marks" in subdict: section.unlock_marks = subdict["marks"] if "questions" in subdict: section.unlock_questions = subdict["questions"] if "both_needed" in subdict: section.unlock_both_needed = subdict["both_needed"] if "shuffle" in section_dict: subdict = section_dict["shuffle"] if "questions" in subdict: section.shuffle_questions = subdict["questions"] if "options" in subdict: section.shuffle_options = subdict["options"] section.save() # add tags if "tags" in section_dict: for tagname in section_dict["tags"]: section.add_tag(tagname) # add questions for question_dict in section_dict["questions"]: add_question(section, question_dict)
def AddSection(course_id, instructor_id, quarter, section, instructor_title, ratings): try: q = quarter[:2].upper() y = quarter[2:] #print course_id #print "%s %s"%(q, y) r = AddRating(ratings) i = Section(quarter=q, year=y, idinstructor=instructor_id, idcourse=course_id, idrating=r, instructortitle=instructor_title, section=section) i.save() return i.id except Exception, e: print "exception: ", e return None
def sections(self): for section in self.field_sections: yield Section(section, self)