def prepareQuiz(user, quiz_list): for quiz in quiz_list: #quiz["titulo"] = str_limit(remove_html_tags(quiz["titulo"]), 200) #quiz["descricao"] = str_limit(remove_html_tags(quiz["descricao"]), 200) quiz["descricao"] = quiz["descricao"].replace("\n", "<br/>") # permissões para remover e alterar um quiz quiz["apagar"] = isAllowedToWriteObject(user, "quiz", quiz["registry_id"], quiz["_id"]) and not model.Quiz.quizIsAnswered(quiz["_id"]) quiz["alterar"] = isAllowedToWriteObject(user, "quiz", quiz["registry_id"], quiz["_id"]) # tipo do quiz em extenso quiz["tipo"] = TIPO_QUIZ[quiz["subtype"]] # datas formatadas quiz["data_fmt"] = short_datetime(quiz["data_cri"]) if "data_alt" in quiz and quiz["data_alt"]: quiz["data_alt"] = short_datetime(quiz["data_alt"]) # condição para permitir que o quiz seja respondido dentro_do_periodo = verificaIntervaloDMY(quiz["data_inicio"], quiz["data_fim"]) == 0 ja_respondeu = model.Quiz.getQuizAnswers(quiz["_id"], user) quiz["nao_pode_responder"] = (ja_respondeu and ja_respondeu["finalizado"]=="S") or \ not dentro_do_periodo or \ not isAllowedToReadObject(user, "quiz", quiz["registry_id"]) return sorted(quiz_list, key=itemgetter("data_cri"), reverse=True)
def prepareEvaluations(user, avals): aval_data = [] for aval in avals: dentroDoPeriodo = verificaIntervaloDMY(aval["data_inicio"], aval["data_encerramento"]) == 0 (registry_id, obj_name) = aval["_id"].split("/") aval_data.append((aval["_id"], \ aval["descricao"], \ aval["tipo"], \ aval["data_inicio"], \ aval["data_encerramento"], \ aval["jaAvaliou"] or not dentroDoPeriodo or not isAllowedToReadObject(user, "evaluation", registry_id, obj_name)\ )) return aval_data
def get(self, registry_id, form): user = self.get_current_user() form_id = "%s/%s" % (registry_id, form) formdata = _EMPTYREQUESTINVITEFORM() formdata.update(model.REQUESTINVITEFORM[form_id]) # verifica se está dentro do periodo de validade do formulário v = verificaIntervaloDMY(formdata["data_inicio"], formdata["data_encerramento"]) if v == 0: self.render("modules/invites/show-form-invite.html", REGISTRY_ID=user, \ MSG="", \ FORMDATA=formdata, \ NOMEPAG="convites") elif v == -1: self.render("home.html", REGISTRY_ID=user, MSG=u"Período de solicitação de convite ainda não iniciado.", \ NOMEPAG="convites") elif v == 1: self.render("home.html", REGISTRY_ID=user, MSG=u"Período de solicitação de convite encerrado.", \ NOMEPAG="convites")
def get(self, registry_id, aval): user = self.get_current_user() aval_id = '/'.join([registry_id,unquote(aval).decode("UTF-8")]) self._aval = model.Evaluation().retrieve(aval_id) if self._aval: #if verificaPeriodo(aval_data["data_inicio"], aval_data["data_encerramento"]): if verificaIntervaloDMY(self._aval.data_inicio, self._aval.data_encerramento) == 0: if self._aval.alreadyHasEvaluated(user): self.render("home.html", MSG=u"Você já realizou esta avaliação.", REGISTRY_ID=registry_id, \ NOMEPAG=u"Avaliações") else: self._aval.data_inicio = self._aval.data_inicio self._aval.data_encerramento = self._aval.data_encerramento self.render("modules/evaluation/evaluation-form.html", MSG="", \ AVALDATA=self._aval, AVAL_ID=aval_id, \ REGISTRY_ID=registry_id, \ NOMEPAG=u"Avaliações") else: self.render("home.html", MSG=u"Fora do período de avaliação.", REGISTRY_ID=registry_id, \ NOMEPAG=u"Avaliações") else: self.render("home.html", MSG=u"Avaliação inexistente.", REGISTRY_ID=registry_id, \ NOMEPAG=u"Avaliações")
def post(self, registry_id, aval): user = self.get_current_user() aval_id = '/'.join([registry_id,unquote(aval).decode("UTF-8")]) self._aval = model.Evaluation().retrieve(aval_id) if self._aval: #if verificaPeriodo(aval_data["data_inicio"], aval_data["data_encerramento"]): if verificaIntervaloDMY(self._aval.data_inicio, self._aval.data_encerramento) == 0: if self._aval.alreadyHasEvaluated(user): self.render("home.html", MSG=u"Você já realizou esta avaliação.", REGISTRY_ID=registry_id, \ NOMEPAG=u"Avaliações") else: # processa a avaliação realizada participantes = core.database.REGISTRY[registry_id]["participantes"] opcoes = [] for i in range(len(self._aval.pontuacao)): opcao = self.get_argument("opcao%d"%(i+1),"") if not opcao: self.render("modules/evaluation/evaluation-form.html", MSG=u"Alguma opção não foi selecionada.", \ AVALDATA=self._aval, PARTICIPANTES=participantes, AVAL_ID=aval_id, REGISTRY_ID=registry_id, \ NOMEPAG=u"Avaliações") return else: opcoes.append(opcao) if len(opcoes) != len(list(set(opcoes))): self.render("modules/evaluation/evaluation-form.html", MSG=u"Alguma opção foi selecionada mais de uma vez.", AVALDATA=self._aval, PARTICIPANTES=participantes, AVAL_ID=aval_id, REGISTRY_ID=registry_id, \ NOMEPAG=u"Avaliações") return # atualiza a lista de votos dados pelo usuário if user in self._aval.avaliacoes: self._aval.avaliacoes[user]["votos_dados"] = opcoes else: self._aval.avaliacoes[user] = { "votos_dados": opcoes, "votos_recebidos": 0 } # incrementa a pontuação de cada usuário votado pos=0 for op in opcoes: if op not in self._aval.avaliacoes: self._aval.avaliacoes[op] = { "votos_dados": [], "votos_recebidos": 0 } self._aval.avaliacoes[op]["votos_recebidos"] += int(self._aval.pontuacao[pos]) pos += 1 self._aval.save() log.model.log(user, u'realizou a avaliação', objeto=aval_id, tipo="evaluation") aval_data = prepareEvaluations(user, model.Evaluation.listEvaluations(user, registry_id)) links = [] if isOwner(user, registry_id): links.append((u"Nova avaliação de páginas", "/static/imagens/icones/wiki32.png", "/evaluation/new/"+registry_id+"/wiki")) links.append((u"Nova avaliação de participantes", "/static/imagens/icones/members32.png", "/evaluation/new/"+registry_id+"/member")) links.append(("Votos dos participantes", "/static/imagens/icones/vote32.png", "/evaluation/result/"+registry_id)) self.render("modules/evaluation/evaluation-list.html", EVALUATIONDATA=aval_data, \ MSG=u"Avaliação realizada com sucesso.", \ REGISTRY_ID=registry_id, PERMISSION=isOwner(user,registry_id), \ LINKS=links, \ NOMEPAG=u"Avaliações") else: self.render("home.html", MSG=u"Fora do período de avaliação.", REGISTRY_ID=registry_id, \ NOMEPAG=u"Avaliações") else: self.render("home.html", MSG=u"Avaliação inexistente.", REGISTRY_ID=registry_id, \ NOMEPAG=u"Avaliações")