本文整理汇总了Python中models.Course类的典型用法代码示例。如果您正苦于以下问题:Python Course类的具体用法?Python Course怎么用?Python Course使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Course类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: parse_schedule
def parse_schedule():
html = open("switcher/schedule.txt")
counter = 0
department = ""
for line in html:
print counter
counter += 1
if re.findall(r'\S+', line) == []:
continue
x = re.findall('([A-Z]+[\s,/&]*?[A-Z]+)\s\s+([0-9A-Z]+)\s+([\s\S]+[\S])', line)
if x == []:
department = line.strip()
#print department
#"""
d = Department()
d.init(department)
d.save()
#"""
else:
#print x
code = x[0][0] + "." + x[0][1] + ".Spring.2014"
#"""
c = Course()
c.init(code, d)
c.save()
示例2: get
def get(self):
from models import *
from google.appengine.ext import db
db.delete(Course.all())
db.delete(Offerings.all())
import re
rx_department = re.compile(r'[A-Z]+')
import csv
reader = csv.DictReader(open('resources/dump.csv'))
try:
for course in reader:
name = course['name']
number = course['number']
description = course['description'][:500]
match = rx_department.match(number)
department = number
if match:
department = match.group(0)
entry = Course(name=name, number=number, description=description, department=department)
entry.put()
for item in ['winter', 'spring', 'fall', 'summer']:
if 1 < len(course[item]):
offering = Offerings(course=entry, offered=item)
offering.put()
except KeyError, e:
pass
示例3: _course_exists
def _course_exists(request):
form = CourseInitialForm(request.POST, request.FILES)
if form.is_valid():
section_number = ""
if request.user.get_profile().school.title == "James Madison University":
section_number = request.POST['course_id'].zfill(4)
else:
section_number = request.POST['course_id']
try:
course = Course.objects.get(
number__iexact=request.POST['course_number'],
course_id__iexact=section_number,
institution__iexact=request.user.get_profile().school.title)
return (True, course)
except Course.DoesNotExist:
wall = ConvoWall(wall_type=3)
wall.save()
course = Course(
wall=wall,
number=request.POST['course_number'],
course_id=section_number,
institution=request.user.get_profile().school.title)
course.save()
return (False, course)
return (False, None)
示例4: setUp
def setUp(self):
self.testbed = testbed.Testbed()
self.testbed.activate()
self.testbed.init_datastore_v3_stub()
# should all return None, because this is simply creating data and is all meant to be correct
self.assertIsNone(User.register(None, '[email protected]', 'pwd', 'pwd', 'teacher', 't'))
self.assertIsNone(User.register(None, '[email protected]', 'pwd', 'pwd', 'teachertwo', 'ttwo'))
self.assertIsNone(User.register(None, '[email protected]', 'pwd', 'pwd', 'student', 's'))
self.teacher = User.all().filter('email =', '[email protected]').get()
self.teacher2 = User.all().filter('email =', '[email protected]').get()
self.student = User.all().filter('email =', '[email protected]' ).get()
self.assertIsNotNone(self.teacher)
self.assertIsNone(self.teacher.make_teacher())
self.assertIsNotNone(self.teacher2)
self.assertIsNone(self.teacher2.make_teacher())
self.assertIsNone(Course.create(self.teacher, 'public', ''))
self.public = Course.all().filter('name =', 'Public').get()
self.assertIsNotNone(self.public)
self.assertIsNone(Course.create(self.teacher, 'private', 'on'))
self.private = Course.all().filter('name =', 'Private').get()
self.assertIsNotNone(self.private)
示例5: insert_course
def insert_course(dept, num, text):
""" Regexes for extracting class properties; results go into capture group 1 """
# Course Title
m = re.search("[\d\w]{5} - ([\w ]*)", text)
title = m.group(1) if m else "nomatch"
# Course Description
m = re.search("\.\s(.*)\sTypically",text)
des = m.group(1) if m else "nomatch"
# Credit hours aren't fixed for every course
# Credit Hours: 2.00
# Credit Hours: 2.00 or 3.00.
# Credit Hours: 1.00 to 18.00.
m = re.search("Credit Hours: (\d+\.\d+)",text, flags=re.IGNORECASE)
m = re.search("(\d+\.\d+)(.*?)Credit hours",text, flags=re.IGNORECASE) if not m else m
cr = m.group(1) if m else "-1"
# Semesters Offered
m = re.search("Typically offered (.*?)\.", text)
sem = m.group(1).split() if m else ["nomatch"]
# Course Type: Lecture, Recitation, Lab, Seminar, etc.
m = re.search("Schedule Types:\s((?:[\w ]+)(?:,[\w ]+)*) \s+", text)
form = m.group(1).split(", ") if m else ["nomatch"]
# Learning objectives will not necessarily follow campuses
m = re.search("campuses:(\s+([\w\s])+\n)", text)
campus = m.group(1).strip().split("\n\n") if m else ["nomatch"]
campus = [camp.strip() for camp in campus]
# prereq regex and decomosition of prereqs into lists of AND conditions (works for most classes, not 477 and similar)
# re.DOTALL matches all characters, including "\n"
idx = text.find("campuses:")
m = re.search("Prerequisites:(.*)",text[idx:],flags=re.DOTALL)
if m:
allReqs = []
prereqText = m.group(1).strip()
prereqText = prereqText.encode('ascii', 'ignore')
for i in PrereqParser.parseprereq(prereqText):
reqArr = []
for j in i.split():
if j.find("-C") != -1:
j = j.replace("-C","")
reqArr.append(Requisite(course=j,reqType=False))
else:
reqArr.append(Requisite(course=j,reqType=True))
allReqs.append(RequisiteList(courses=reqArr))
else:
allReqs = []
# create course entity
course = Course(number=num, title=title, department=dept, form=form,
description=des, credits=float(cr), semesters=sem,
campuses=campus,requisites=allReqs, id=dept + num)
# store course
course.put()
示例6: test_create_course
def test_create_course(self):
c = Course(title = 'Some Course',
start_time='09:00',
slots=20)
c.save()
self.assertQuerysetEqual(Course.objects.all(),
['<Course: Some Course>'])
示例7: test_course_insert
def test_course_insert(self):
print "in test_course_insert"
setup(self)
self.assertEqual(Course.objects.count(), 2)
course3 = Course(teacher=Teacher.objects.get(pk=1), name="Grad3", position=3)
course3.save()
self.assertEqual(Course.objects.count(), 3)
示例8: populate
def populate(line):
overall = line.split('#')
forCourses = overall[0].strip().split(',')
y = [y.strip() for y in overall[1].strip().split('$')]
c = Course(course_name=forCourses[0], course_ID=forCourses[1], course_acronym=forCourses[2], course_credits=int(forCourses[3]))
c.save()
c = Course.objects.get(pk=c.pk)
for x in y:
temp = [e.strip() for e in x.split(',')]
c.offered_set.create(class_day=temp[0],start_time=str(1+TIME_CHOICES.index(temp[1])),end_time=str(1+TIME_CHOICES.index(temp[2])))
示例9: test_day
def test_day(self):
course = Course(
slug='day-course',
days=[
('Mondays', '7:00', '8:00pm'), ('Tuesdays', '3:00', '4:00pm')
]
)
self.assertEqual(course.day('mondays'), course.days[0])
self.assertEqual(course.day('Tuesdays'), course.days[1])
self.assertRaises(KeyError, lambda: course.day('Saturdays'))
示例10: addcourses
def addcourses(self):
fields = ['name', 'short_desc', 'dept', 'number', 'level']
parent = Key(Source, 'Udacity')
for course in cdata:
opt = dict(zip(fields, course))
opt['source'] = parent
kn = self.centid('Udacity', opt['dept'], opt['number'])
opt['number'] = int(opt['number'])
Course.get_or_insert(kn, **opt)
示例11: create_course
def create_course(request, name, description, price, discount, init_date, end_date):
s = Session.objects.get(session_key=request.session["auth_token"])
user = User.objects.get(login=s.get_decoded()['login'])
if user.user_type != 'Creator':
return HttpResponseBadRequest('User is not Creator')
init_date_parsed = dateutil.parser.parse(init_date)
end_date_parsed = dateutil.parser.parse(end_date)
course = Course(creator=user, name=name, description=description, price=price, discount=discount,
init_date=init_date_parsed, end_date=end_date_parsed)
course.save()
return HttpResponse('Course created successful')
示例12: post
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)
示例13: create_sample_courses
def create_sample_courses():
for y in range(2009,2012):
create_semester('Fall', y, 9, 1, 12, 31)
create_semester('Spring', y, 1, 1, 5, 30)
semesters = Semester.objects.all()
for co,nm in [("CS 101", "Fundamentals of Computer Science"),
("CS 102", "Programming I"),
("CS 117", "Programming II"),
("CS 150", "Operating Systems"),
("CS 164", "Software Engineering"),
("CS 130", "Algorithms & Data Structures")]:
for sem in random.sample(semesters, 3):
tag = co.replace(' ', '').lower() + sem.tag
grp = Group(name=tag)
grp.save()
key = '%x' % random.getrandbits(24)
c = Course(tag=tag, name=nm, code=co, semester=sem,
group=grp, key=key,
is_active=_flip())
c.save()
us = random.sample(User.objects.all(), random.randrange(4,8))
num_instructors = random.choice([1,2])
instrs = us[:num_instructors]
studs = us[num_instructors:]
for u in us:
e = Enrollment(course=c, user=u,
kind = 'I' if u in instrs
else random.choice(['A', 'G']),
notify_on_commit = _flip(),
notify_new_grades = _flip())
e.save()
ln = CourseLink(course=c, kind='H',
url='http://liucs.net/%s/' % tag)
ln.save()
if _flip():
ln = CourseLink(course=c, kind='T',
url='http://amazon.com/%s' % nm)
ln.save()
if _flip():
fmt = random.choice(['http://liucs.net/svn/%s/',
'http://github.com/league/%s'])
ln = CourseLink(course=c, kind='R', url=fmt % tag)
ln.save()
示例14: _get_or_create_course
def _get_or_create_course(self, course, department, instructors, attributes, restrictions, section):
course_record = Course.query.filter_by(name=course.course_name).first()
if not course_record:
course_record = Course(name=course.course_name, subject=course.subject, subject_level=course.course_number)
#print "Adding Course: \"%s-%s\"" % (course.subject, course.course_number)
self.num_new_courses += 1
if course.course_name not in self.course_names:
self.num_courses += 1
self.course_names[course.course_name] = True
course_record.department = department
course_record.attributes = attributes
course_record.restrictions = restrictions
course_record.sections.append(section)
db.session.add(course_record)
#db.session.commit()
return course_record
示例15: updateSummary
def updateSummary():
logging.info("UPDATING SUMMARY")
query = Summary.all()
db.delete(query)
courses = Course.all()
items = []
for course in courses:
item = {}
item['name'] = course.name
item['id'] = course.cid
item['hasSept'] = course.hasSeptemberResults
item['hasFebr'] = course.hasFebruaryResults
item['hasJune'] = course.hasJuneResults
item['recent'] = course.nTimesUpdated
item['addedJune'] = str(course.added_june)
item['addedSept'] = str(course.added_sept)
item['addedFebr'] = str(course.added_febr)
items.append(item)
summary = Summary()
summary.courses = simplejson.dumps(items)
summary.put()
logging.info("FINISHED UPDATING SUMMARY")