def get_message(cls, participation=None, **kwargs): """Create a message.""" participation = participation if participation is not None \ else cls.get_participation() args = { "participation": participation, "subject": unique_unicode_id(), "text": unique_unicode_id(), "timestamp": (participation.contest.start + timedelta(0, unique_long_id())), } args.update(kwargs) message = Message(**args) return message
def post(self, dataset_id): dataset = self.safe_get_item(Dataset, dataset_id) task = dataset.task task.active_dataset = dataset if self.try_commit(): self.application.service.proxy_service.dataset_updated( task_id=task.id) # This kicks off judging of any submissions which were previously # unloved, but are now part of an autojudged taskset. self.application.service\ .evaluation_service.search_operations_not_done() self.application.service\ .scoring_service.search_operations_not_done() # Now send notifications to contestants. datetime = make_datetime() r = re.compile('notify_([0-9]+)$') count = 0 for k in self.request.arguments: m = r.match(k) if not m: continue participation = self.safe_get_item(Participation, m.group(1)) message = Message(datetime, self.get_argument("message_subject", ""), self.get_argument("message_text", ""), participation=participation) self.sql_session.add(message) count += 1 if self.try_commit(): self.application.service.add_notification( make_datetime(), "Messages sent to %d users." % count, "") self.redirect("/task/%s" % task.id)
def post(self, contest_id, user_id): user = self.safe_get_item(User, user_id) self.contest = self.safe_get_item(Contest, contest_id) participation = self.sql_session.query(Participation)\ .filter(Participation.contest == self.contest)\ .filter(Participation.user == user)\ .first() # check that the participation is valid if participation is None: raise tornado.web.HTTPError(404) message = Message(make_datetime(), self.get_argument("message_subject", ""), self.get_argument("message_text", ""), participation=participation) self.sql_session.add(message) if self.try_commit(): logger.info("Message submitted to user %s in contest %s.", user.username, self.contest.name) self.redirect("/contest/%s/user/%s" % (self.contest.id, user.id))