Esempio n. 1
0
File: admin.py Progetto: Tydus/tsp
    def post(self):

        subject=self.get_argument('subject')
        student=self.get_argument('student')

        s=Subject.objects(id=ObjectId(subject)).first()
        if not s:
            return self.write({'err':'课题不存在'})
        if s.applied_to:
            return self.write({'err':'课题已被分配给'+s.applied_to.realname.encode('utf-8')})

        u=Student.objects(username=student).first()
        if not u:
            return self.write({'err':'学生不存在'})
        if u.applied_to:
            return self.write({'err':'学生已被分配'+u.applied_to.name.encode('utf-8')+'课题'})

        # Match Straightly
        s.selected_by=[]
        s.applied_to=u
        u.selected=None
        u.applied_to=s

        s.save()
        u.save()

        self.write({})
Esempio n. 2
0
    def post(self):

        subject=self.get_argument('subject')
        student=self.get_argument('student',default="")

        s=Subject.objects(id=ObjectId(subject)).first()
        if not s:
            return self.write({'err':'课题不存在'})

        if s.professor.username!=self.current_user.username:
            return self.write({'err':'不是你的课题'})

        if s.selected_by==[]:
            return self.write({'err':'不可改选上阶段选好的课题'})

        # Clear previous approvement
        if s.applied_to:
            u=Student.objects(username=s.applied_to.username).first()
            u.applied_to=None
            u.save()
            s.applied_to=None

        if student:
            for u_embedded in s.selected_by:
                u=Student.objects(username=u_embedded.username).first()
                if u.username==student:
                    # You are the one!
                    s.applied_to=u
                    u.applied_to=s
                u.save()

        s.save()

        self.write({})
Esempio n. 3
0
    def post(self):
        u=self.current_user

        subject=self.get_argument('id')
        s=Subject.objects(id=ObjectId(subject)).first()
        if not s:
            return self.write({'err':'课题不存在'})

        if s.professor.username!=self.current_user.username:
            return self.write({'err':'不是你的课题'})

        s.delete()

        self.write({})
Esempio n. 4
0
File: student.py Progetto: Tydus/tsp
    def post(self):
        subject=self.get_argument('subject',"")

        u=self.current_user
        if u.excluded:
            return self.write({'err':'你被从选课中排除'})
        if u.applied_to:
            return self.write({'err':'你已被'+u.applied_to.name.encode('utf-8')+'课题选中'})

        if not subject:
            # Clear Currently Selected
            if u.selected:
                old_s=u.selected
                #u.selected=None
                old_s.selected_by=[i for i in old_s.selected_by if i.id!=u.id]
                old_s.save()
                u.save()

	else:
            s=Subject.objects(id=ObjectId(subject)).first()
            if not s:
                return self.write({'err':'课题不存在'})
            if s.applied_to:
                return self.write({'err':'课题已被'+s.applied_to.realname.encode('utf-8')+'选中'})

            # Clear Currently Selected
            if u.selected:
                old_s=u.selected
                #u.selected=None
                old_s.selected_by=[i for i in old_s.selected_by if i.id!=u.id]
                old_s.save()

            # Beware if old_s==s
            s.reload()

            # Select New
            if subject:
                u.selected=s
                s.selected_by.append(u)
            s.save()

        u.save()

        self.write({})
Esempio n. 5
0
    def post(self):
        u=self.current_user

        subject=self.get_argument('id')
        name=self.get_argument('name',default="")
        desc=self.get_argument('desc',default="")
        type1=self.get_argument('type1',default="")
        type2=self.get_argument('type2',default="")
        source=self.get_argument('source',default="")

        s=Subject.objects(id=ObjectId(subject)).first()
        if not s:
            return self.write({'err':'课题不存在'})

        if s.professor.username!=self.current_user.username:
            return self.write({'err':'不是你的课题'})

        for i in ['name','desc','type1','type2','source']:
            value=self.get_argument(i,default="")
            if value:
                s[i]=value
        s.save()

        self.write({})
Esempio n. 6
0
    def post(self):
        u=self.current_user

        name=self.get_argument('name')
        desc=self.get_argument('desc')
        type1=self.get_argument('type1')
        type2=self.get_argument('type2')
        source=self.get_argument('source')

        old_s=Subject.objects(name=name).first()
        if old_s and old_s.professor.username==u.username:
            return self.write({'err':'课题已存在'})

        s=Subject(
                name=name,
                desc=desc,
                type1=type1,
                type2=type2,
                source=source,
                professor=u,
        )
        s.save()

        return self.write({'id':str(s.id)})