• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python models.Student类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中students.models.Student的典型用法代码示例。如果您正苦于以下问题:Python Student类的具体用法?Python Student怎么用?Python Student使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了Student类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: _add_object_to_db

 def _add_object_to_db(self, name):
     if name == 'student':
         student = Student(
             first_name=self._random_value('first_name'),
             last_name=self._random_value('last_name'),
             ticket=self._random_value(),
             birthday=timezone.now(),
         )
         student.save()
     if name == 'group':
         group = Group(
             title=self._random_value('title'),
             notes='note about group',
         )
         group.save()
     if name == 'user':
         user = User(
             username=self._random_value('username'),
             first_name=self._random_value('first_name'),
             last_name=self._random_value('last_name'),
             email=self._random_value("email") + '@example.com',
         )
         # User model have an unique field 'username'.
         # Generated 'username' can be not unique
         #   in compare with existing objects.
         # In case of exception repeat creating object 'user'.
         try:
             user.save()
         except:
             self._add_object_to_db(name)
开发者ID:dimadvk,项目名称:studentsdb,代码行数:30,代码来源:fill_db.py


示例2: setUp

 def setUp(self):
     self.c = Client()
     
     # Create the test badge.
     self.b = Badge( name = "The Super Badge",
                     shortname = "superbadge",
                     description = "This badge is quite super.",
                     graphic = "superbadge" )
     self.b.save()
     
     # Create some test users.
     self.u1 = User.objects.create_user("ishara",
                                        "[email protected]",
                                        "ishararulz")
     self.u2 = User.objects.create_user("alexis",
                                        "[email protected]",
                                        "alexisrulz")
     self.s1 = Student( user=self.u1 )
     self.s2 = Student( user=self.u2 )
     self.s1.save()
     self.s2.save()
     
     # Award the badge to s1
     self.b.awarded_to.add( self.s2 )
     self.b.save()
     
     # Give the test users memorable names.
     self.ishara = self.s1
     self.alexis = self.s2
开发者ID:jessebikman,项目名称:8bitmooc,代码行数:29,代码来源:tests.py


示例3: test_create_new_student

    def test_create_new_student(self):
        new_student = Student(name='New Student',
                              dob=datetime.today(),
                              civil_id='1234567890',
                              mobile_number=generate_random_numbers(12),
                              home_number=generate_random_numbers(12),
                              parent_number=generate_random_numbers(12))
        new_student.save()

        self.assertIsInstance(new_student, Student)
        self.assertTrue(new_student.pk)
        self.assertEquals('P', new_student.status)
开发者ID:EmadMokhtar,项目名称:halaqat,代码行数:12,代码来源:test_models.py


示例4: create_demo_user

def create_demo_user(request):
    me = Student.from_request(request)
    if not settings.DEMO_MODE:
        request.session["alerts"].append(("alert-error","Demo users are not enabled at this time."))
        return redirect("index")
    
    username = "DemoUser%d"%len(Student.objects.all())
    user = User.objects.create_user(username, username+"@example.com", str(random.randint(100000000,999999999)))
    user.save()
    student = Student(user=user)
    student.save()
    user.backend = 'django.contrib.auth.backends.ModelBackend'
    login(request, user)
    return redirect("index")
开发者ID:isharacomix,项目名称:8bitmooc,代码行数:14,代码来源:views.py


示例5: view_feedback

def view_feedback(request, name):
    me = Student.from_request(request)
    if "alerts" not in request.session: request.session["alerts"] = []
    if not me:
        request.session["alerts"].append(("alert-error","Please sign in first."))
        return redirect("sign-in")   
    
    # First, try to get the challenge.
    try: challenge = Challenge.objects.get(slug=name)
    except exceptions.ObjectDoesNotExist: raise Http404()
    
    # Now get all of the SOSses related to this user and challenge.
    feedback = SOS.objects.filter(challenge=challenge, student=me)
    
    # Mark feedback as helpful or not.
    if "helpful" in request.GET or "unhelpful" in request.GET:
        helpful = True
        if "unhelpful" in request.GET: helpful = False
        f_id = request.GET["helpful" if helpful else "unhelpful"]
        if f_id.isdigit():
            f = Feedback.objects.get(id=int(f_id))
            if f.sos in feedback and f.helpful is None:
                f.helpful = helpful
                f.save()
                if helpful:
                    f.author.award_xp(50)
                me.award_xp(5)
                LogEntry.log(request, "Marked as %shelpful"%("" if helpful else "un"))

    
    return render(request, "feedback.html", {'challenge': challenge,
                                             'feedback': feedback})
开发者ID:whpeddyc,项目名称:8bitmooc,代码行数:32,代码来源:views.py


示例6: user_profile

def user_profile(request, username):
    me = Student.from_request(request)
    if "alerts" not in request.session: request.session["alerts"] = []
    if not me:
        request.session["alerts"].append(("alert-error","Please sign in first."))
        return redirect("sign-in")
    try: student = Student.objects.get( user=User.objects.get(username=username) )
    except: return redirect("user_list")
    
    # If we are doing a POST, then let's affect the output a bit.
    form = ProfileEditForm( {"bio": me.bio, "twitter": me.twitter, "email": me.public_email} )
    if request.method == "POST":
        form = ProfileEditForm(request.POST)
        if form.is_valid():
            data = form.cleaned_data
            me.bio = data["bio"]
            me.public_email = data["email"]
            me.twitter = data["twitter"]
            me.save()
            return redirect( "profile", username=me.username )
        else:
            request.session["alerts"].append(("alert-error",
                                              "There were some issues with your profile update."))
            for e in form.non_field_errors():
                alerts.append( ("alert-error", e ) )
    
    # Render the magic.
    projects = list(me.owns.all())+list(me.works_on.all())
    return render(request, "user_profile.html", {"student": student,
                                                 "collaborators": student.collaborators(),
                                                 "projects": projects,
                                                 "form": form,
                                                 'alerts': request.session.pop('alerts', []) } )
开发者ID:whpeddyc,项目名称:8bitmooc,代码行数:33,代码来源:views.py


示例7: view_feedback

def view_feedback(request, name):
    me = Student.from_request(request)
    
    # First, try to get the challenge.
    try: challenge = Challenge.objects.get(slug=name)
    except exceptions.ObjectDoesNotExist: raise Http404()
    
    # Now get all of the SOSses related to this user and challenge.
    feedback = SOS.objects.filter(challenge=challenge, student=me)
    
    # Mark feedback as helpful or not.
    if "helpful" in request.GET or "unhelpful" in request.GET:
        helpful = True
        if "unhelpful" in request.GET: helpful = False
        f_id = request.GET["helpful" if helpful else "unhelpful"]
        if f_id.isdigit():
            try:
                f = Feedback.objects.get(id=int(f_id))
                if f.sos in feedback and f.helpful is None:
                    f.helpful = helpful
                    f.save()
                    LogEntry.log(request, "Marked as %shelpful"%("" if helpful else "un"))
            except exceptions.ObjectDoesNotExist:
                LogEntry.log(request, "Feedback voting naughtiness.")
    
    return render(request, "feedback.html", {'challenge': challenge,
                                             'feedback': feedback})
开发者ID:isharacomix,项目名称:8bitmooc,代码行数:27,代码来源:views.py


示例8: register_student_add

def register_student_add(request):
    if request.method=="POST":        
        first_name=request.POST['first_name']
        last_name=request.POST['last_name']
        gender=request.POST['gender']
        username=request.POST['username']
        password=request.POST['password']
        class_id=request.POST['class_id']
        
        # hash the password
        hashed_password = sha256_crypt.encrypt(password)
        
        student=Student(first_name=first_name,last_name=last_name,gender=gender,username=username,password=hashed_password,classid_id=class_id)
        student.save()
        
        return login_student_form(request)
开发者ID:nyamburamuhia,项目名称:WorkingSchool,代码行数:16,代码来源:views.py


示例9: get_context_data

 def get_context_data(self, **kwargs):
     context = super().get_context_data(**kwargs)
     exam_rooms = ExamRoom.objects.filter(available=True)
     context['student_count'] = Student.get_current(want_exam=True).order_by('name', 'prename').count()
     context['free_places_1'] = sum([exam_room.capacity(1) for exam_room in exam_rooms])
     context['free_places_2'] = sum([exam_room.capacity(2) for exam_room in exam_rooms])
     return context
开发者ID:d120,项目名称:pyophase,代码行数:7,代码来源:dashboard_views.py


示例10: list_badges

def list_badges(request):
    badge_list = Badge.objects.all()
    for b in badge_list:
        try: b.check = True if b.held_by( Student.from_request(request) ) else False
        except exceptions.ObjectDoesNotExist: b.check = False
    
    return render( request, "badge_list.html", {"badge_list":badge_list} )
开发者ID:pikpik,项目名称:8bitmooc,代码行数:7,代码来源:views.py


示例11: view_board

def view_board(request, category):
    me = Student.from_request(request)
    
    # First, try to get the board.
    try: board = DiscussionBoard.objects.get(slug=category)
    except exceptions.ObjectDoesNotExist: raise Http404()
    if not board.can_read(me): raise Http404()
    
    # Get the page number!
    page = 0
    pagination = 50
    if "page" in request.GET and request.GET["page"].isdigit():
        page = max(0,int(request.GET["page"])-1)
    
    # If this is a POST, we are creating a new topic. Redirect when finished.
    if request.method == "POST":
        if board.can_write(me):
            content = str(request.POST.get("content"))
            title = content[:100]+"..."
            if "title" in request.POST:
                title = request.POST["title"]
            
            t = DiscussionTopic()
            t.author = me
            t.board = board
            t.title = title
            t.save()
            
            p = DiscussionPost()
            p.topic = t
            p.author = me
            p.content = content
            p.save()
        
            return redirect( "thread", category=board.slug, thread=t.id )
        else:
            return redirect( "board", category=board.slug )
    
    # Get all of the topics, along with the last person who commented on them
    # and when that was.
    topic_tuples = []
    topics = DiscussionTopic.objects.filter(board=board)
    if not me.ta:
        topics = topics.filter(hidden=False)
    for t in topics[pagination*page:pagination*(page+1)]:
        posts = DiscussionPost.objects.filter(topic=t, hidden=False).order_by("-timestamp")
        count = len(posts)
        new = False
        if count == 0: posts = [None]
        else: new = ( posts[0].timestamp > me.unread_since )
        topic_tuples.append( (t,count,posts[0],new) )
    
    return render( request, "forum_topics.html", {'board': board,
                                                  'topics': topic_tuples,
                                                  'alerts': request.session.pop('alerts', []),
                                                  'page': page+1,
                                                  'pages': (len(topic_tuples)/pagination)+1,
                                                  'can_write': board.can_write(me) } )
开发者ID:isharacomix,项目名称:8bitmooc,代码行数:58,代码来源:views.py


示例12: test_link_course

 def test_link_course(self):
     course = Course.objects.create(
         name='Django Base',
         short_description='Django Base Course')
     course.save()
     student = Student(
         name="Ivan",
         surname="Ivanov",
         date_of_birth="1999-09-09",
         email="[email protected]",
         phone="1234567890",
         address="Mykolyiv",
         skype="test")
     student.save()
     student.courses.add(course)
     response = self.client.get('/students/1/')
     self.assertContains(response, '/courses/{}/'.format(student.id))
     self.assertContains(response, 'Django Base')
开发者ID:JackTRussell,项目名称:test,代码行数:18,代码来源:tests.py


示例13: student_add

def student_add(request):
    if request.method == 'POST':
        form = StudentForm(request.POST)
        if form.is_valid():
            print form.cleaned_data
            student = Student(
                first_name=form.cleaned_data['first_name'],
                last_name=form.cleaned_data['last_name'],
                email=form.cleaned_data['email'],
                phone_number=form.cleaned_data['phone_number'],
                package=form.cleaned_data['package'],
                # courses=form.cleaned_data['courses'], ???????????????????
            )
            student.save()
            return redirect('students_list')
    else:
        form = StudentForm()
    return render(request, 'student_edit.html', {'form': form, 'title': 'Add student'})
开发者ID:rm-ponomarenko,项目名称:pybursa,代码行数:18,代码来源:views.py


示例14: view_board

def view_board(request, name):
    me = Student.from_request(request)
    if "alerts" not in request.session: request.session["alerts"] = []
    if not me:
        request.session["alerts"].append(("alert-error","Please sign in first."))
        return redirect("sign-in")   
    
    # First, try to get the board.
    try: board = DiscussionBoard.objects.get(slug=name)
    except exceptions.ObjectDoesNotExist: raise Http404()
    if board.restricted > me.level: raise Http404()
    
    # Get the page number!
    page = 0
    pagination = 200
    if "page" in request.GET and request.GET["page"].isdigit():
        page = max(0,int(request.GET["page"])-1)
    
    # If this is a POST, we are creating a new topic. Redirect when finished.
    if request.method == "POST" and (me.level >= board.wrestricted or me.ta):
        content = str(request.POST.get("content"))
        title = content[:100]+"..."
        if "title" in request.POST:
            title = request.POST["title"]
        
        t = DiscussionTopic()
        t.author = me
        t.board = board
        t.title = title
        t.save()
        
        p = DiscussionPost()
        p.topic = t
        p.author = me
        p.content = content
        p.save()
        
        return redirect( "thread", name=board.slug, thread=t.id )
    
    # Get all of the topics, along with the last person who commented on them
    # and when that was.
    topic_tuples = []
    for t in DiscussionTopic.objects.filter(hidden=False, board=board)[pagination*page:pagination*(page+1)]:
        posts = DiscussionPost.objects.filter(topic=t, hidden=False).order_by("-timestamp")
        count = len(posts)
        new = False
        if count == 0: posts = [None]
        else: new = ( posts[0].timestamp > me.last_login )
        topic_tuples.append( (t,count,posts[0],new) )
    
    return render( request, "forum_topics.html", {'board': board,
                                                  'topics': topic_tuples,
                                                  'student': me,
                                                  'alerts': request.session.pop('alerts', []),
                                                  'page': page+1,
                                                  'pages': (len(topic_tuples)/pagination)+1 } )
开发者ID:whpeddyc,项目名称:8bitmooc,代码行数:56,代码来源:views.py


示例15: test_log_student_deleted_event

    def test_log_student_deleted_event(self):
        """Check logging signals for deleted student"""
        student = Student(first_name='Demo', last_name='Student')
        student.save()

        # now override signal
        # add own root handler to catch student signals output
        out = StringIO()
        handler = logging.StreamHandler(out)
        logging.root.addHandler(handler)

        # delete existing student and check logger output
        sid = student.id
        student.delete()
        out.seek(0)
        self.assertEqual(out.readlines()[-1], 'Student Demo Student deleted (ID: %d)\n' % sid)

        # remove our handler from root logger
        logging.root.removeHandler(handler)
开发者ID:PyDev777,项目名称:studentsdb,代码行数:19,代码来源:test_signals.py


示例16: handle_login

def handle_login(request):
    me = Student.from_request(request)
    
    if me:
        request.session["alerts"].append(("alert-error","You are already logged in!"))
        return redirect("index")
    request.session["secret_state"] = str(random.randint(100000000,999999999))
    
    return redirect("https://github.com/login/oauth/authorize?client_id=%s&state=%s&scope=user:email"%
                    (settings.GITHUB_ID, request.session["secret_state"]))
开发者ID:isharacomix,项目名称:8bitmooc,代码行数:10,代码来源:views.py


示例17: view_thread

def view_thread(request, name, thread):
    me = Student.from_request(request)
    if "alerts" not in request.session: request.session["alerts"] = []
    if not me:
        request.session["alerts"].append(("alert-error","Please sign in first."))
        return redirect("sign-in")   
    
    # First, try to get the challenge, then thread.
    try:
        board = DiscussionBoard.objects.get(slug=name)
        topic = DiscussionTopic.objects.get(id=thread, board=board)
    except exceptions.ObjectDoesNotExist: raise Http404()
    if not me.ta and (topic.hidden or board.restricted > me.level): raise Http404()
    
    # If this is a POST, we are either replying to someone or we are voting.
    # Manage permissions respectively and redirect.
    if request.method == "POST":
        if "thread" in request.POST and (me.level >= board.wrestricted or me.ta):
            p = DiscussionPost()
            p.topic = topic
            p.author = me
            p.content = str(request.POST.get("content"))
            p.save()
            topic.save()
        elif "upvote" in request.POST or "downvote" in request.POST:
            upvote = True
            if "downvote" in request.POST: upvote = False
            p_id = request.POST["upvote" if upvote else "downvote"]
            if p_id.isdigit() and (me.modpoints > 0 or me.ta):
                p = DiscussionPost.objects.get(id=int(p_id))
                if upvote: p.upvotes += 1
                else:      p.downvotes += 1
                request.session["alerts"].append(("alert-success","Post %s."%("upvoted" if upvote else "downvoted")))
                LogEntry.log(request, "Thread %s"%("upvoted" if upvote else "downvoted"))
                p.save()
                me.modpoints -= 1
                me.award_xp(1)
                me.save()
        return redirect( "thread", name=board.slug, thread=topic.id )
    
    # Get all of the posts. Start on the last page by default.
    pagination = 20
    posts = DiscussionPost.objects.filter(hidden=False, topic=topic)
    pages = (len(posts)/pagination)+1
    page = pages-1
    if "page" in request.GET and request.GET["page"].isdigit():
        page = max(0,int(request.GET["page"])-1)
    
    return render( request, "forum_thread.html", {'board': board,
                                                  'topic': topic,
                                                  'student': me,
                                                  'posts': posts[pagination*page:pagination*(page+1)],
                                                  'alerts': request.session.pop('alerts', []),
                                                  'page': page+1,
                                                  'pages': pages })
开发者ID:whpeddyc,项目名称:8bitmooc,代码行数:55,代码来源:views.py


示例18: handle_logout

def handle_logout(request):
    me = Student.from_request(request)

    if me:
        logout(request)
        if "alerts" not in request.session: request.session["alerts"] = []
        request.session["alerts"].append(("alert-success","Successfully logged out - come back soon!"))
        return redirect("index") 
    else:
        request.session["alerts"].append(("alert-error","You're already logged out!"))
        return redirect("index") 
开发者ID:isharacomix,项目名称:8bitmooc,代码行数:11,代码来源:views.py


示例19: view_stage

def view_stage(request, world, stage):
    try: student = Student.from_request(request)
    except exceptions.ObjectDoesNotExist: return HttpResponse("Redirect to login")
    
    here = get_stage(world, stage)
    go = "lesson"
    # if in challenge-first group: go = "challenge"
    
    # If there is only one choice, then go to that one.
    if not here.lesson and here.challenge: go = "challenge"
    if not here.challenge and here.lesson: go = "lesson"
    return redirect( go, world = world, stage = stage )
开发者ID:jessebikman,项目名称:8bitmooc,代码行数:12,代码来源:views.py


示例20: StudentTests

class StudentTests(TestCase):
    def setUp(self):
        self.c = Client()
        self.u1 = User.objects.create_user("ishara",
                                           "[email protected]",
                                           "ishararulz")
        self.s1 = Student( user=self.u1 )
        self.s1.save()
    
        # Give the test users memorable names.
        self.ishara = self.s1
    
    # Test User Connection decorators.
    def test_user_fields(self):
        self.assertEquals(self.s1.username, self.u1.username)
        self.assertEquals(self.s1.email, self.u1.email)

    # Test the Profile page.
    def test_profile_page(self):
        response = self.c.get("/~ishara")
        self.assertEqual(response.status_code, 200)
开发者ID:jessebikman,项目名称:8bitmooc,代码行数:21,代码来源:tests.py



注:本文中的students.models.Student类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python stun.get_ip_info函数代码示例发布时间:2022-05-27
下一篇:
Python views.get_user_orders函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap