def markThread(uid, payload): mtype = int(payload["type"]) lid = int(payload["id_location"]) #comment_id = None if "comment_id" not in payload or payload["comment_id"] is None else int(payload["comment_id"]) comment_id = int(payload["comment_id"]) mark = M.ThreadMark.objects.filter(user__id=uid, type=mtype, location__id=lid, active=True) if mark.count()>0: # only allow one active threadmark of a given type per thread mark = mark[0] mh = M.ThreadMarkHistory() mh.active = mark.active mh.comment_id = mark.comment_id mh.ctime = mark.ctime mh.location_id = mark.location_id mh.user_id = mark.user_id mh.type = mark.type mh.save() mark.ctime = datetime.datetime.now() active_default = True if comment_id != mark.comment_id: #there was a real change of comment_id: don't update active default value active_default = mark.active else: #then probably just a toggle active_default = not mark.active mark.comment_id = comment_id mark.active = payload["active"] if "active" in payload else active_default # if no arg given, toggle else: mark = M.ThreadMark() mark.user_id = uid mark.location_id = lid mark.comment_id = comment_id mark.type = mtype mark.active = payload["active"] if "active" in payload else True mark.save() return UR.model2dict(mark)
def getLocation(id): """Returns an "enriched" location""" o = M.Comment.objects.select_related("location").filter(location__id=id, parent__id=None, deleted=False) loc_dict = UR.qs2dict(o, __NAMES["location_v_comment2"], "ID") h5l = None try: h5l = o[0].location.html5location if len(o) else None except M.HTML5Location.DoesNotExist: pass h5l_dict = UR.model2dict(h5l, __NAMES["html5location"], "ID") if h5l else {} return (loc_dict, h5l_dict)
def get_guestfileinfo(id_source): ownership = M.Ownership.objects.select_related("source", "ensemble", "folder").filter(source__id=id_source, deleted=False) o = { "files": UR.qs2dict(ownership, __NAMES["files2"] , "ID"), "ensembles": UR.qs2dict(ownership, __NAMES["ensembles2"] , "ID") , "folders": UR.qs2dict(ownership, __NAMES["folders2"] , "ID") , } if len(ownership)==1: if ownership[0].source.type == M.Source.TYPE_YOUTUBE: o["youtubeinfos"]= UR.model2dict(ownership[0].source.youtubeinfo, None, "id") return o
def getComment(id, uid): names = __NAMES["comment2"] comment = ( M.Comment.objects.select_related("location", "author") .extra( select={ "admin": "select cast(admin as integer) from base_membership, base_location where base_membership.user_id=base_comment.author_id and base_membership.ensemble_id = base_location.ensemble_id and base_location.id=base_comment.location_id" } ) .get(pk=id) ) return UR.model2dict(comment, names, "ID")
def set_grade_assignment(uid, P): id_user = P["id_user"] id_source = P["id_source"] record = None try: record = M.AssignmentGrade.objects.get(user__id=id_user, source__id=id_source) rh = M.AssignmentGradeHistory() rh.user_id = record.user_id rh.grade = record.grade rh.source_id = record.source_id rh.grader = record.grader rh.ctime = record.ctime rh.save() record.ctime = datetime.datetime.now() except M.AssignmentGrade.DoesNotExist: record = M.AssignmentGrade() record.user_id = id_user record.source_id = id_source record.grade = P["grade"] record.grader_id = uid record.save() return UR.model2dict(record, __NAMES["assignment_grade"], "id")
def getComment(id, uid): names = __NAMES["comment2"] comment = M.Comment.objects.select_related("location", "author").extra(select={"admin": 'select cast(admin as integer) from base_membership, base_location where base_membership.user_id=base_comment.author_id and base_membership.ensemble_id = base_location.ensemble_id and base_location.id=base_comment.location_id'}).get(pk=id) return UR.model2dict(comment, names, "ID")