本文整理汇总了Python中models.Submission类的典型用法代码示例。如果您正苦于以下问题:Python Submission类的具体用法?Python Submission怎么用?Python Submission使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Submission类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
def main() :
POST_LIMIT = 10
STREAMING_SUBS = ['mlbstreams', 'nbastreams', 'soccerstreams'] #, 'nflstreams', 'nhlstreams', 'cfbstreams', 'ncaabballstreams', 'boxingstreams', 'mmastreams']
db = DB.initialize(rebuild = False);
# Connect to Reddit
reddit_obj = Reddit.connect()
# Create submissions and comments
for sub in STREAMING_SUBS:
submissions_with_comments = Reddit.scrape_posts(reddit_obj, sub, POST_LIMIT)
Submission.create_with_comments(submissions_with_comments, db)
# Parse comments for streams
comment_data = Comment.get_all(db)
stream_list = Reddit.parse_comments_for_streams(comment_data, db)
# Create streams
for stream in stream_list:
Stream.create(stream, db)
# Print the matches table from SQLite
Submission.print_all(db)
# Close the DB connection
DB.close(db)
示例2: evaluate
def evaluate(source_code_name, user_id, task, contest):
extension = get_extension(source_code_name)
command = get_command(extension)
contest_id = contest.contest_id
os.system(command.format(DEST_FOLDER.format(contest_id) + source_code_name, DEST_FOLDER.format(contest_id) + remove_extension(source_code_name)))
source_code_name = remove_extension(source_code_name)
task_id = task.task_id
status = True
for input_file in os.listdir(INPUT_FOLDER.format(contest_id, task_id)):
if get_extension(input_file) == 'zip': continue
user_output = subprocess.check_output(DEST_FOLDER.format(contest_id) + source_code_name + "< " + INPUT_FOLDER.format(contest_id, task_id) + input_file, shell=True)
user_output = re.sub('[\s+]\\n', '\n', user_output)
user_output = user_output.strip()
input_num = input_file.split('_')[1].split('.')[0]
with open(OUTPUT_FOLDER.format(contest_id, task_id) + 'out_' + input_num + '.out') as f:
output = f.read().strip()
print 'worker'
print 'output\n {} \n user_output\n {}'.format(output, user_output)
status = user_output == output
accepted = 'Accepted' if status else 'Wrong Answer'
submission = Submission(accepted, extension, datetime.utcnow(), task.name, user_id, task.task_id, contest.contest_id)
submission.save()
示例3: submit
def submit(request):
team = get_team(request.user)
params = dict()
if request.method == 'POST':
form = forms.UploadSubmissionForm(request.POST, request.FILES)
params['form'] = form
if form.is_valid():
submission = Submission(
team=team,
package=request.FILES['file'],
command=request.POST['command'],
)
submission.save()
error = utils.unzip(submission.package.path)
if error:
submission.delete()
params['error'] = error
return render_submit(request, params)
try:
execute_tester(submission)
except Exception as error:
print u'ERROR: Blad wewnetrzny testerki:', error
return my_results(
request, message=_(u'Rozwiązanie zostało wysłane.'))
return render_submit(request, params)
示例4: put_submission
def put_submission(self, problem_name, level, score, answer):
submission = Submission(student_magic_number = self.magic,
problem_id = self.problem_id, answer = answer,
score = score, type = problem_name, level = level)
# logging.warn("submit: %s %s %s %s %s %s" % (self.magic, self.problem_id, answer, score, problem_name, level))
submission.put()
self.increment_number_of_attempts(self.magic, self.level, self.problem_id, problem_name)
self.best_score(self.magic, self.level, self.problem_id, problem_name, score)
示例5: new_submission
def new_submission(assignment_id):
assignment = Assignment.query.get(assignment_id)
if request.method == 'POST' and 'file' in request.files:
filename = submissions.save(request.files['file'])
rec = Submission(
filename=filename,
is_official=False,
assignment_id=assignment_id,
user_id=g.user.id)
rec.save()
rec.officialize()
return redirect(url_for('view_assignment', assignment_id=assignment_id))
示例6: post
def post(self):
format = self.request.get('format', 'json').lower()
id = self.request.get('level_id', None)
if id is None:
res = {"response": {"error": "no level id with submission"}}
else:
level = Level.get_by_id(long(id))
user_name = self.request.get('user')
user = User.all().filter('name =', user_name).get()
if user is None:
user = User(name = user_name)
user.put()
score = self.request.get('score', 0)
words_found = self.request.get('words_found').split(",")
submission = Submission()
submission.user = user
submission.level = level
submission.score = score
submission.words_found = words_found
submission.time = datetime.datetime.now()
submission.put()
res = {"response": {"status" : "OK"}}
if format == "json":
self.response.out.write(simplejson.dumps(res))
elif format == "xml":
self.response.out.write(dict2xml(res).to_string())
示例7: save
def save(request):
form = request.POST
sub = Submission(
user=form["user"],
date=time.strftime("%Y-%m-%d %H:%M:%S"),
language=form["language"],
code=form["code"],
input=form["input"],
)
try:
sub["memory"] = form["memory"]
sub["time"] = form["time"]
finally:
sub.save()
return HttpResponse("OK")
示例8: get
def get(self, test):
"""Retrieve submissions for the current user."""
self.response.content_type = "application/json"
gplus_id = self.session.get("gplus_id")
if gplus_id is None:
self.response.status = 401
self.response.out.write(utils.createError(401, "Current user not connected."))
return
if test is not None:
user = ndb.Key("TestUser", gplus_id).get()
else:
user = ndb.Key("User", gplus_id).get()
if user is None:
self.response.status = 401
self.response.out.write(utils.createError(401, "Current user not connected."))
return
items = []
submissions = Submission.query(ancestor=user.key).order(-Submission.date).fetch(50)
for submission in submissions:
items.append({
"id": submission.key.id(),
"colour": submission.colour,
"url": submission.url,
"date": submission.date.strftime("%Y-%m-%dT%H:%M:%S.%f")
})
self.response.out.write(json.dumps({"items": items}))
示例9: get_level_stats
def get_level_stats(self, format, delta = datetime.timedelta(), page = 0, limit = 100):
level = get_current_level()
if level is not None:
submissions = Submission.all().filter("time >", level.time - delta).order('time').order('-score').fetch(limit, page * limit)
i = 1
ranks = []
for submission in submissions:
obj = {"rank" : i,
"user" : submission.user.name,
"score" : submission.score}
if format == "json":
ranks.append(obj)
elif format == "xml":
ranks.append({"ranking": obj})
i = i + 1
res = {"response": ranks}
else :
res = {"response": {"error": "could not get the level"}}
if format == "json":
return simplejson.dumps(res)
elif format == "xml":
return dict2xml(res).to_string()
示例10: upload_file
def upload_file():
title = request.form['song']
artist = request.form['artist']
picture_file = request.files['file']
photo = Photo()
photo.file.put(picture_file)
photo.save()
track = Track.get_from_spotify(artist, title)
if track is None:
return "No track found!"
track.save()
submission = Submission(photo=photo, track=track)
submission.save()
return redirect('/submissions')
示例11: get_all_attempts
def get_all_attempts(self, magic, level, problemid, prob_type):
return (
Submission.all()
.filter("student_magic_number =", str(magic))
.filter("type =", str(prob_type))
.filter("level =", level)
.filter("problem_id =", problemid)
)
示例12: _save_submission
def _save_submission(self,request):
def get_type(request):
try:
return FacilityType.objects.get(name=request.POST['type'])
except KeyError:
return None
submit_args = {
'submitter':request.user,
'raw':repr(request.POST),
'name':request.POST.get('name',None),
'address':request.POST.get('address',None),
'type':get_type(request),
'location':get_location(request.POST)
}
submission = Submission(**submit_args)
submission.save()
return submission
示例13: get
def get(self):
magic = self.request.get('student')
submissions = Submission.all().filter('student_magic_number =', str(magic))
submissions_objects = []
for submission in submissions:
utc = int(time.mktime(submission.answered_on.timetuple()))
submissions_objects.append({"type":submission.type, "level":submission.level, "id":submission.problem_id, "score":submission.score, "answered_on":utc, "answer":submission.answer})
blob = json.dumps(submissions_objects)
self.response.out.write(blob)
示例14: update_group
def update_group(self, key):
if not auth.logged_in():
return self.redirect('/groups')
user = auth.current_user()
group = Group.get(key)
if group.owner.user_id() != user.user_id() and not auth.user_is_admin():
Messages.add('Only the owner of the group owner may modify it')
return self.redirect('/groups')
name = self.request.get('name')
public = self.request.get('public') == 'public'
abandon = self.request.get('abandon-project')
sub_text = self.request.get('submission-text')
sub_url = self.request.get('submission-url')
remove_submission = self.request.get_all('remove-submission')
remove = self.request.get_all('remove')
owner = self.request.get('owner')
delete = self.request.get('delete')
if delete:
group.delete()
return self.redirect('/groups')
group.name = name
group.public = public
if abandon:
group.project = None
if sub_text and sub_url:
Submission(text=sub_text, url=sub_url, group=group).put()
for sub in Submission.get(remove_submission):
sub.delete()
pending = list(group.pending_users)
for user in pending:
approve = self.request.get("approve-%s" % user)
if approve == "approve":
group.members.append(user)
group.pending_users.remove(user)
elif approve == "refuse":
group.pending_users.remove(user)
group.owner = auth.user_from_email(owner)
for user in remove:
if auth.user_from_email(user) == group.owner:
Messages.add('Cannot remove the group owner')
return self.redirect('/groups/%s/edit' % key)
else:
group.members.remove(auth.user_from_email(user))
group.put()
return self.redirect('/groups/%s' % key)
示例15: get
def get(self):
submissions = []
#subs= Submission.gql("WHERE pid=:1", 11)
for submission in Submission.all().order('-post_time'):
submissions.append({
'name': submission.name,
'pid': submission.pid,
'image_url': submission.image_url,
})
self.response.out.write(json.dumps(submissions))