当前位置: 首页>>代码示例>>Python>>正文


Python request.method方法代码示例

本文整理汇总了Python中urllib.request.method方法的典型用法代码示例。如果您正苦于以下问题:Python request.method方法的具体用法?Python request.method怎么用?Python request.method使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在urllib.request的用法示例。


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

示例1: search

# 需要导入模块: from urllib import request [as 别名]
# 或者: from urllib.request import method [as 别名]
def search(request, student_id=None):
    if student_id:
        student = get_object_or_404(Person, id=student_id)
    else:
        student = None
    if request.method == 'POST':
        form = RASearchForm(request.POST)
        if not form.is_valid():
            return HttpResponseRedirect(reverse('ra:found') + "?search=" + urllib.parse.quote_plus(form.data['search']))
        search = form.cleaned_data['search']
        # deal with people without active computing accounts
        if search.userid:
            userid = search.userid
        else:
            userid = search.emplid
        return HttpResponseRedirect(reverse('ra:student_appointments', kwargs={'userid': userid}))
    if student_id:
        form = RASearchForm(instance=student, initial={'student': student.userid})
    else:
        form = RASearchForm()
    context = {'form': form}
    return render(request, 'ra/search.html', context) 
开发者ID:sfu-fas,项目名称:coursys,代码行数:24,代码来源:views.py

示例2: edit_letter

# 需要导入模块: from urllib import request [as 别名]
# 或者: from urllib.request import method [as 别名]
def edit_letter(request, ra_slug):
    appointment = get_object_or_404(RAAppointment, slug=ra_slug, deleted=False, unit__in=request.units)

    if request.method == 'POST':
        form = RALetterForm(request.POST, instance=appointment)
        if form.is_valid():
            form.save()
            messages.success(request, 'Updated RA Letter Text for ' + appointment.person.first_name + " " + appointment.person.last_name)
            return HttpResponseRedirect(reverse('ra:student_appointments', kwargs=({'userid': appointment.person.userid})))
    else:
        if not appointment.offer_letter_text:
            letter_choices = RAAppointment.letter_choices(request.units)
            if len(letter_choices) == 1: # why make them select from one?
                appointment.build_letter_text(letter_choices[0][0])
            else:
                return HttpResponseRedirect(reverse('ra:select_letter', kwargs=({'ra_slug': ra_slug})))
        form = RALetterForm(instance=appointment)
    
    context = {'appointment': appointment, 'form': form}
    return render(request, 'ra/edit_letter.html', context)

# If we don't have an appointment letter yet, pick one. 
开发者ID:sfu-fas,项目名称:coursys,代码行数:24,代码来源:views.py

示例3: select_letter

# 需要导入模块: from urllib import request [as 别名]
# 或者: from urllib.request import method [as 别名]
def select_letter(request, ra_slug, print_only=None):
    appointment = get_object_or_404(RAAppointment, slug=ra_slug, deleted=False, unit__in=request.units)
    # Forcing sorting of the letter choices so the Standard template is first.
    letter_choices = sorted(RAAppointment.letter_choices(request.units))
    if request.method == 'POST':
        filled_form = LetterSelectForm(data=request.POST, choices=letter_choices)
        if filled_form.is_valid():
            appointment.build_letter_text(filled_form.cleaned_data['letter_choice'])
        if print_only == 'print':
            return HttpResponseRedirect(reverse('ra:letter', kwargs=({'ra_slug': ra_slug})))
        else:
            return HttpResponseRedirect(reverse('ra:edit_letter', kwargs=({'ra_slug': ra_slug})))

    else:
        new_form = LetterSelectForm(choices=letter_choices)
        context = {'form': new_form, 'ra_slug': ra_slug, 'print_only': print_only}
        return render(request, 'ra/select_letter.html', context)


#View RA Appointment 
开发者ID:sfu-fas,项目名称:coursys,代码行数:22,代码来源:views.py

示例4: semester_config

# 需要导入模块: from urllib import request [as 别名]
# 或者: from urllib.request import method [as 别名]
def semester_config(request, semester_name=None):
    if semester_name:
        semester = get_object_or_404(Semester, name=semester_name)
    else:
        semester = Semester.next_starting()

    unit_choices = [(u.id, u.name) for u in request.units]
    if request.method == 'POST':
        form = SemesterConfigForm(request.POST)
        form.fields['unit'].choices = unit_choices
        if form.is_valid():
            config = SemesterConfig.get_config(units=[form.cleaned_data['unit']], semester=semester)
            config.set_start_date(form.cleaned_data['start_date'])
            config.set_end_date(form.cleaned_data['end_date'])
            config.save()
            messages.success(request, 'Updated semester configuration for %s.' % (semester.name))
            return HttpResponseRedirect(reverse('ra:search'))
    else:
        config = SemesterConfig.get_config(units=request.units, semester=semester)
        form = SemesterConfigForm(initial={'start_date': config.start_date(), 'end_date': config.end_date()})
        form.fields['unit'].choices = unit_choices

    return render(request, 'ra/semester_config.html', {'semester': semester, 'form': form}) 
开发者ID:sfu-fas,项目名称:coursys,代码行数:25,代码来源:views.py

示例5: new_program

# 需要导入模块: from urllib import request [as 别名]
# 或者: from urllib.request import method [as 别名]
def new_program(request):
    if request.method == 'POST':
        form = ProgramForm(request.POST)
        if form.is_valid():
            program = form.save()
            messages.add_message(request,
                                 messages.SUCCESS,
                                 'Program was created')
            l = LogEntry(userid=request.user.username,
                         description="Added program %s" % program,
                         related_object=program)
            l.save()
            return HttpResponseRedirect(reverse('ra:programs_index'))
    else:
        form = ProgramForm()
        form.fields['unit'].choices = [(u.id, u.name) for u in request.units]
    return render(request, 'ra/new_program.html', {'form': form}) 
开发者ID:sfu-fas,项目名称:coursys,代码行数:19,代码来源:views.py

示例6: edit_program

# 需要导入模块: from urllib import request [as 别名]
# 或者: from urllib.request import method [as 别名]
def edit_program(request, program_slug):
    program = get_object_or_404(Program, slug=program_slug, unit__in=request.units)
    if request.method == 'POST':
        form = ProgramForm(request.POST, instance=program)
        if form.is_valid():
            program = form.save()
            messages.add_message(request,
                                 messages.SUCCESS,
                                 'Program was created')
            l = LogEntry(userid=request.user.username,
                         description="Added program %s" % program,
                         related_object=program)
            l.save()
            return HttpResponseRedirect(reverse('ra:programs_index'))
    else:
        form = ProgramForm(instance=program)
        form.fields['unit'].choices = [(u.id, u.name) for u in request.units]
    return render(request, 'ra/edit_program.html', {'form': form, 'program': program}) 
开发者ID:sfu-fas,项目名称:coursys,代码行数:20,代码来源:views.py

示例7: has_role

# 需要导入模块: from urllib import request [as 别名]
# 或者: from urllib.request import method [as 别名]
def has_role(role, request, get_only=None, **kwargs):
    """
    Return True is the given user has the specified role in ANY unit
    """
    if isinstance(role, (list, tuple)):
        allowed = list(role)
    else:
        allowed = [role]
    if get_only and request.method == 'GET':
        if isinstance(get_only, (list, tuple)):
            allowed += list(get_only)
        else:
            allowed.append(get_only)

    roles = Role.objects_fresh.filter(person__userid=request.user.username, role__in=allowed).select_related('unit')
    request.units = set(r.unit for r in roles)
    count = roles.count()
    return count > 0 
开发者ID:sfu-fas,项目名称:coursys,代码行数:20,代码来源:auth.py

示例8: reorder_activity

# 需要导入模块: from urllib import request [as 别名]
# 或者: from urllib.request import method [as 别名]
def reorder_activity(request, course_slug):
    """
    Ajax way to reorder activity.
    This ajax view function is called in the course_info page.
    """
    course = get_object_or_404(CourseOffering, slug=course_slug)
    if request.method == 'POST':
        neaten_activity_positions(course)
        # find the activities in question
        id_up = request.POST.get('id_up') 
        id_down = request.POST.get('id_down')
        if id_up == None or id_down == None:                      
            return ForbiddenResponse(request)
        # swap the position of the two activities
        activity_up = get_object_or_404(Activity, id=id_up, offering__slug=course_slug)
        activity_down = get_object_or_404(Activity, id=id_down, offering__slug=course_slug)

        activity_up.position, activity_down.position = activity_down.position, activity_up.position
        activity_up.save()
        activity_down.save()        
        
        return HttpResponse("Order updated!")
    return ForbiddenResponse(request) 
开发者ID:sfu-fas,项目名称:coursys,代码行数:25,代码来源:views.py

示例9: calculate_individual_ajax

# 需要导入模块: from urllib import request [as 别名]
# 或者: from urllib.request import method [as 别名]
def calculate_individual_ajax(request, course_slug, activity_slug):
    """
    Ajax way to calculate individual numeric grade.
    This ajav view function is called in the activity_info page.
    """
    if request.method == 'POST':
        userid = request.POST.get('userid') 
        if userid == None:                      
            return ForbiddenResponse(request)
            
        course = get_object_or_404(CourseOffering, slug=course_slug)
        activity = get_object_or_404(CalNumericActivity, slug=activity_slug, offering=course, deleted=False)
        member = get_object_or_404(Member, offering=course, person__userid=userid, role='STUD')

        try:
            displayable_result, _ = calculate_numeric_grade(course,activity, member)
        except ValidationError:
            return ForbiddenResponse(request)
        except EvalException:
            return ForbiddenResponse(request)
        except NotImplementedError:
            return ForbiddenResponse(request)
        return HttpResponse(displayable_result)
    return ForbiddenResponse(request) 
开发者ID:sfu-fas,项目名称:coursys,代码行数:26,代码来源:views.py

示例10: delete_activity

# 需要导入模块: from urllib import request [as 别名]
# 或者: from urllib.request import method [as 别名]
def delete_activity(request, course_slug, activity_slug):
    """
    Flag activity as deleted
    """
    course = get_object_or_404(CourseOffering, slug=course_slug)
    activity = get_object_or_404(Activity, slug=activity_slug, offering=course)

    if request.method == 'POST':
        if not Member.objects.filter(offering=course, person__userid=request.user.username, role="INST"):
            # only instructors can delete
            return ForbiddenResponse(request, "Only instructors can delete activities")
    
        activity.safely_delete()
        messages.success(request, 'Activity deleted.  It can be restored by the system adminstrator in an emergency.')

        #LOG EVENT#
        l = LogEntry(userid=request.user.username,
              description=("activity %s marked deleted") % (activity),
              related_object=course)
        l.save()

        return HttpResponseRedirect(reverse('offering:course_info', kwargs={'course_slug': course.slug}))

    else:
        return ForbiddenResponse(request) 
开发者ID:sfu-fas,项目名称:coursys,代码行数:27,代码来源:views.py

示例11: new_message

# 需要导入模块: from urllib import request [as 别名]
# 或者: from urllib.request import method [as 别名]
def new_message(request, course_slug):
    offering = get_object_or_404(CourseOffering, slug=course_slug)
    staff = get_object_or_404(Person, userid=request.user.username)
    default_message = NewsItem(user=staff, author=staff, course=offering, source_app="dashboard")
    if request.method =='POST':
        form = MessageForm(data=request.POST, instance=default_message)
        if form.is_valid()==True:
            NewsItem.for_members(member_kwargs={'offering': offering}, newsitem_kwargs={
                    'author': staff, 'course': offering, 'source_app': 'dashboard',
                    'title': form.cleaned_data['title'], 'content': form.cleaned_data['content'],
                    'url': form.cleaned_data['url'], 'markup': form.cleaned_data['_markup']})

            #LOG EVENT#
            l = LogEntry(userid=request.user.username,
                  description=("created a message for every student in %s") % (offering),
                  related_object=offering)
            l.save()
            messages.add_message(request, messages.SUCCESS, 'News item created.')
            return HttpResponseRedirect(reverse('offering:course_info', kwargs={'course_slug': offering.slug}))
    else:
        form = MessageForm()
    return render(request, "grades/new_message.html", {"form" : form,'course': offering}) 
开发者ID:sfu-fas,项目名称:coursys,代码行数:24,代码来源:views.py

示例12: index

# 需要导入模块: from urllib import request [as 别名]
# 或者: from urllib.request import method [as 别名]
def index(request):
    if request.method == 'POST':
        form = PathAnalysisForm(request.POST)
        if  form.is_valid():
            query = form.cleaned_data['search']
            print(query)
            #here is where the magic happens!
            #search in kegg
#            data = kegg_rest_request('list/pathway/hsa')
#            pathways = kegg_rest_request('find/pathway/%s' % (query))
            pathways = Pathway.objects.filter(Q(name__icontains=query))
            # print pathways
            
    else:
        form = PathAnalysisForm()
#        pathways = kegg_rest_request('list/pathway/hsa')
        pathways = Pathway.objects.all()    
    
    
    return render_to_response('pathway_analysis/index.html', {'form': form, 'pathways': pathways}, context_instance=RequestContext(request)) 
开发者ID:raonyguimaraes,项目名称:mendelmd,代码行数:22,代码来源:views.py

示例13: request_to_dict

# 需要导入模块: from urllib import request [as 别名]
# 或者: from urllib.request import method [as 别名]
def request_to_dict(self, request):
        '''
        Convert Request object to a dict.
        modified from scrapy.utils.reqser
        '''
        req_dict = {
            # urls should be safe (safe_string_url)
            'url': to_unicode(request.url),
            'method': request.method,
            'headers': dict(request.headers),
            'body': request.body,
            'cookies': request.cookies,
            'meta': request.meta,
            '_encoding': request._encoding,
            'priority': request.priority,
            'dont_filter': request.dont_filter,
             #  callback/errback are assumed to be a bound instance of the spider
            'callback': None if request.callback is None else request.callback.__name__,
            'errback': None if request.errback is None else request.errback.__name__,
        }
        return req_dict 
开发者ID:istresearch,项目名称:scrapy-cluster,代码行数:23,代码来源:distributed_scheduler.py

示例14: setUp

# 需要导入模块: from urllib import request [as 别名]
# 或者: from urllib.request import method [as 别名]
def setUp(self):
        # Create a list of temporary files. Each item in the list is a file
        # name (absolute path or relative to the current working directory).
        # All files in this list will be deleted in the tearDown method. Note,
        # this only helps to makes sure temporary files get deleted, but it
        # does nothing about trying to close files that may still be open. It
        # is the responsibility of the developer to properly close files even
        # when exceptional conditions occur.
        self.tempFiles = []

        # Create a temporary file.
        self.registerFileForCleanUp(support.TESTFN)
        self.text = b'testing urllib.urlretrieve'
        try:
            FILE = open(support.TESTFN, 'wb')
            FILE.write(self.text)
            FILE.close()
        finally:
            try: FILE.close()
            except: pass 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:22,代码来源:test_urllib.py

示例15: userScanList

# 需要导入模块: from urllib import request [as 别名]
# 或者: from urllib.request import method [as 别名]
def userScanList(request):
    template = 'radio/userscanlist.html'
    if request.method == "POST":
        form = UserScanForm(request.POST)
        if form.is_valid():
            print('Form Valid')
            name = form.cleaned_data['name']
            tgs = form.cleaned_data['talkgroups']
            print('Form Data [{}] [{}]'.format(name, tgs))
            sl = ScanList()
            sl.created_by = request.user
            sl.name = name
            sl.description = name
            sl.save()
            sl.talkgroups.add(*tgs)
            return redirect('user_profile')
        else:
            print('Form not Valid')
    else:
        form = UserScanForm()
    return render(request, template, {'form': form}) 
开发者ID:ScanOC,项目名称:trunk-player,代码行数:23,代码来源:views.py


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