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


Python Room.get_absolute_url方法代码示例

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


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

示例1: test_anonymous_access

# 需要导入模块: from models import Room [as 别名]
# 或者: from models.Room import get_absolute_url [as 别名]
    def test_anonymous_access(self):
        anon_room = Room(
                        allow_anonymous_access=True,
                        name="Anonymous Room",
                        slug="anonymous-room")
        login_req_room = Room(
                        allow_anonymous_access=False,
                        name="Login required room",
                        slug="login-required-room")
        anon_room.save()
        login_req_room.save()

        client = Client()

        response = client.get(login_req_room.get_absolute_url())
        # a login view may not have been implemented, so assertRedirects fails
        self.assertEquals(response.status_code, 302)
        url = response['Location']
        expected_url = get_login_url(login_req_room.get_absolute_url())
        e_scheme, e_netloc, e_path, e_query, e_fragment = urlparse.urlsplit(
                                                                expected_url)
        if not (e_scheme or e_netloc):
            expected_url = urlparse.urlunsplit(('http', 'testserver', e_path,
                e_query, e_fragment))
        self.assertEquals(url, expected_url)

        response = client.get(
            anon_room.get_absolute_url(),
            follow=True)

        # assert redirect
        self.assertRedirects(
            response,
            'http://testserver/chat/setguestname/?room_slug=anonymous-room')

        # post guestname
        guestname_posted = client.post(
            response.redirect_chain[0][0],
            {'guest_name': 'guest',
             'room_slug': 'anonymous-room'},
            follow=True)
        self.assertRedirects(
            guestname_posted,
            anon_room.get_absolute_url()
        )
开发者ID:Mondego,项目名称:pyreco,代码行数:47,代码来源:allPythonContent.py

示例2: create_room

# 需要导入模块: from models import Room [as 别名]
# 或者: from models.Room import get_absolute_url [as 别名]
def create_room(request, extra_context={}):
	"""
	View for creating a room. Uses a clever combination of PollForm, RoomForm and ChoiceFormSet to achieve
	3-way model creation:
		- PollForm allows the user to specify the question
		- ChoiceFormSet allows the user to specify an arbitrary number of "choices" to go with the question
			(each one represented by its own DB object)
		- RoomForm gives more advanced "tweaks" for the room, for example:
			- period length (how long each period lasts, default is 30)
			- join threshold (the amount of time that a room is in lock mode before a poll begins)
	"""
	if request.method == "POST":
		# if the user has submitted the form, get the data from all three
		poll_form = PollForm(request.POST, request.FILES)
		choice_formset = ChoiceFormSet(request.POST, request.FILES)
		room_form = RoomForm(request.POST, request.FILES)
		
		if poll_form.is_valid() and choice_formset.is_valid() and room_form.is_valid():
			# if all 3 forms are valid, create a new question object and save it
			q = Question(text=poll_form.cleaned_data['question'])
			q.save()
			
			# create a new poll object that points to the question, and save it
			p = Poll(question=q)
			p.save()
			
			# for every choice the user has inputted
			for form in choice_formset.forms:
				# create a new choice object, and point it at the question created earlier
				c = Choice(question=q, text=form.cleaned_data['choice'])
				c.save()
			
			# finally, create the room itself, pointing to the question object, with the creator of the
			# currently logged in user, and the period length & join threshold as specified in the form
			# data.
			r = Room(question=q, opened_by=request.user, controller=request.user,
				period_length=room_form.cleaned_data['period_length'],
				join_threshold=room_form.cleaned_data['join_threshold'])
			r.save()
			
			# redirect the user to their newly created room
			return HttpResponseRedirect(r.get_absolute_url())
	else:
		# if the user has not submitted the form (i.e. wishes to fill the form in)
		# then initialise the 3 forms with no data
		poll_form = PollForm()
		choice_formset = ChoiceFormSet()
		room_form = RoomForm()
	
	# put the forms into a context dictionary (and update that with any extra context we have been given)
	data = {'poll_form': poll_form, 'choice_formset': choice_formset, 'room_form': room_form}
	data.update(extra_context)
	
	# render the page
	return render_to_response('rooms/room_form.html', data, context_instance=RequestContext(request))
开发者ID:robgolding,项目名称:mydebate,代码行数:57,代码来源:views.py


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