本文整理汇总了Python中models.Course.query方法的典型用法代码示例。如果您正苦于以下问题:Python Course.query方法的具体用法?Python Course.query怎么用?Python Course.query使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Course
的用法示例。
在下文中一共展示了Course.query方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get
# 需要导入模块: from models import Course [as 别名]
# 或者: from models.Course import query [as 别名]
def get(self):
logging.info("Starting to clean the datastore")
courses = Course.query()
for key in courses.iter(keys_only=True):
files = File.query(ancestor=key)
if files.get() is None:
key.delete()
logging.info("Deleting: " + key.string_id())
logging.info("Done cleaning the datastore")
示例2: get
# 需要导入模块: from models import Course [as 别名]
# 或者: from models.Course import query [as 别名]
def get(self):
# self.addcourses()
s = Source.query()
if s.count(limit=1) == 0:
self.redirect('/addsource')
else:
c = Course.query()
context = {'courses': c, 'sources': s}
self.render('classes.html', context)
示例3: post
# 需要导入模块: from models import Course [as 别名]
# 或者: from models.Course import query [as 别名]
def post(self):
fields = ['source', 'number', 'dept', 'name', 'level', 'description']
p = self.get_params_dict(fields)
s = Source.query()
c = Course.query()
errors, p, kn = self.prepare_course(p, fields)
context = {'errors': errors, 'sources': s, 'courses': c}
if not errors:
Course.get_or_insert(kn, **p)
self.redirect('/')
else:
self.render('classes.html', context)
示例4: export_courses
# 需要导入模块: from models import Course [as 别名]
# 或者: from models.Course import query [as 别名]
def export_courses():
"""
export_courses
get all courses from the database
return all courses as a dictionary of course dictionaries
"""
courses = Course.query().fetch()
dictionary = {}
for course in courses:
dictionary[course.department + "" + course.number] = course.to_dict()
return dictionary
示例5: check_db
# 需要导入模块: from models import Course [as 别名]
# 或者: from models.Course import query [as 别名]
def check_db():
"""
check_db
Compares the database entries with the entire list of courses
Returns a list of courses that failed to insert into the database
"""
with open("courses_2016.json") as data:
data = data.read()
courses = json.loads(data)
course_keys_in_db = Course.query().fetch(keys_only=True)
db_list = []
failures = []
for course in course_keys_in_db:
db_list.append(course.id())
failures = [i for i in courses if i.replace(" ","") not in db_list]
return failures
示例6: get
# 需要导入模块: from models import Course [as 别名]
# 或者: from models.Course import query [as 别名]
def get(self, dept):
template = main.jinja_env.get_template("templates/main.html")
values = {"departments": models.DEPARTMENT_NAMES, "types": models.FILE_TYPES}
values["dept"] = dept
termcodes = []
this_year = date.today().year + 1
this_month = date.today().month
for year in range(this_year, this_year - 3, -1):
yearcode = year * 100
for quarter, value in [('Spring', 30), ("Winter", 20), ("Fall", 10)]:
termcodes.append({"term":quarter + " " + str(year - 1) + "-" + str(year) ,"code":yearcode + value})
values["termcodes"] = termcodes
if 1 <= this_month <= 2:
# Winter Quarter
values["termcodes"] = termcodes[4:]
elif 3 <= this_month <= 6:
# Spring Quarter
values["termcodes"] = termcodes[3:]
elif 7 <= this_month <= 8:
# Summer
pass
elif 9 <= this_month <= 11:
# Fall Quarter
values["termcodes"] = termcodes[2:]
elif this_month == 12:
# Winter Quarter
values["termcodes"] = termcodes[1:]
course_keys = Course.query(Course.department == dept)
courses = []
files = {}
for course_key in course_keys.iter(keys_only=True):
courses.append(course_key.string_id())
files[course_key.string_id()] = File.query(ancestor=course_key)
courses.sort()
values["courses"] = courses
values["files"] = files
self.response.out.write(template.render(values))