def _get_room_or_create(app_name,caler_id,opponent_id): ''' Function return existed room identifier or create new room. Also it create two records in ChatUser2Room model. ''' tpa = Tpa.objects.get(name=app_name) opponent = ChatUser.objects.get(tpa=tpa,user_id=opponent_id) caler = ChatUser.objects.get(tpa=tpa,user_id=caler_id) r = bd.select(""" SELECT DISTINCT u1.room_id AS id, u1.user_id AS opponent, u2.user_id AS caler FROM chat_chatuser2room u1, chat_chatuser2room u2, chat_chatroom WHERE chat_chatroom.is_closed=False AND chat_chatroom.id = u1.room_id AND u1.user_id = '%s' AND u2.user_id = '%s' AND u1.room_id = u2.room_id AND u1.tpa_id = u2.tpa_id AND u1.tpa_id = '%s' ORDER BY u1.room_id DESC LIMIT 1 """ % (int(opponent.id), int(caler.id), int(tpa.id))) #import pdb; pdb.set_trace() if r.rowcount > 0 : room_id = ChatRoom.objects.get(pk = r.record[0]['id']) return { 'status': 0, 'message': 'Room is exist', 'room_id': str(room_id.id) } if r.rowcount == 0 : room = ChatRoom() room.tpa = tpa room.save() room.add_user(caler) room.add_user(opponent) room.save() participans = { str(caler.user_id) : serialize_user(caler), str(opponent.user_id) : serialize_user(opponent) } return { 'status': 0, 'message': 'Room was created', 'room_id': str(room.id), 'participans': participans }
def clean(self, request, queryset): for room in ChatRoom.objects.all(): room.delete() for room in Room.objects.all(): new = ChatRoom(room_name=room.channel_name[5:], room_url="https://127.0.0.1:8000/chat/" + room.channel_name[5:]) new.save()
def create_chat(request, user): chat_name = request.POST.get('chat_name', '') if len(chat_name.strip()) == 0: user.show_wrong_chat_name_msg = True user.save() elif chat_name_unique(chat_name): user.chat_name = chat_name user.show_chat_panel = True user.chat_not_created = False user.save() chat = ChatRoom(name = chat_name) chat.save() else: user.show_wrong_chat_name_msg = True user.save()
def create_chat(request): if request.method == "POST": name = request.POST.get('chat_name') created_by = request.user token = str( int(timezone.now().hour) + int(timezone.now().minute) + (int(timezone.now().second) * randint(1, 9))) + (str( secrets.token_urlsafe(1))).replace('_', 'M').upper() token += str(request.user.id) + str( int(timezone.now().day) + (int(timezone.now().second) * randint(1, 9))) + (str( secrets.token_urlsafe(1))).replace('_', 'A').upper() token.replace('-', 'U') chat = ChatRoom(name=name, created_by=created_by, token=token) chat.save() return JsonResponse({})
def get(self, request, user_id): user_one = request.user.userprofile user_two = UserProfile.objects.get(pk=user_id) room = ChatRoom.get_or_create(user_one, user_two) # print(user_id) return Response( ChatRoomSerializer(room, context={ 'abonent': user_two.id }).data)
def test_chat_messages(self): """Tests the find of the instance in redis""" for i in range(30): uuid_id = uuid.uuid4() cm = ChatMessage(uuid_id, "room1") cm.msg = "Python rulz!%d" % i cm.user = "******" % i cm.time = time.time() cm.save() cr = ChatRoom("room1") messages = cr.messages(10) self.assertEqual(len(messages), 10) name_number = 20 for i in messages: self.assertEqual(i.user, "slok%d" % name_number) name_number += 1
def create_private_chat(request, other_user_id): pk = None other_user = User.objects.get(pk=other_user_id) try: existing_private_chats = ChatRoom.objects.filter( is_direct=True, users__id=request.user.pk) matches = existing_private_chats.filter(users__id=int(other_user_id)) if len(matches): pk = matches[0].pk except: pass if not pk: chatroom = ChatRoom(name="d_{}_{}".format(request.user.pk, other_user.pk), is_direct=True, is_public=False) chatroom.save() chatroom.users.add(request.user) chatroom.users.add(other_user) chatroom.save() pk = chatroom.pk data = {'success': True, 'id': pk} return HttpResponse(json.dumps(data))
def post(self, request): user_id = request.POST["user_id"] chat_type = request.POST["chat_type"] customer = User.objects.get(id=user_id) name = uuid.uuid4().hex[:16].upper() new_chat_room = ChatRoom() new_chat_room.name = name new_chat_room.customer = customer new_chat_room.type = chat_type new_chat_room.status = "on_queue" new_chat_room.save() return JsonResponse({'chat_room_name': name})
def connect(self): Room.objects.prune_presences() #print("DEBUG : connection") self.room_name = self.scope['url_route']['kwargs']['room_name'] self.room_group_name = 'chat_%s' % self.room_name self.user = self.scope["user"] grp_room = Group.objects.get(name='room_'+self.room_name) create = True for r in ChatRoom.objects.all(): if (r.room_name == self.room_group_name[5:]) and (r.room_url =="https://127.0.0.1/chat/"+self.room_group_name[5:] ): create = False if create == True: room_model = ChatRoom(room_name = self.room_group_name[5:],room_url ="https://127.0.0.1/chat/"+self.room_group_name[5:] ) room_model.save() self.user.groups.add(grp_room) users = [] for u in grp_room.user_set.all(): users.append(u.username) #print(users) # Join room group async_to_sync(self.channel_layer.group_add)( self.room_group_name, self.channel_name ) self.room = Room.objects.add(self.room_group_name, self.channel_name, self.user) print("Status update") num = 0 for user in self.room.get_users(): num += 1 print(user.username + " is connected to chat room " + self.room_group_name) print(str(num) + " players in chat room" + self.room_group_name) self.accept()
def save(self, **kwargs): request = self._context.get('request') members = self.validated_data.pop( 'members') if 'members' in self.validated_data else '' self.validated_data['channel_no'] = 'GP_' + str(random.randint( 2, 9999)) ct_room = ChatRoom(**self.validated_data) self.validated_data['members'] = members ct_room.save() ct_room.admins.add(request.user.profile) ct_room.save()
def create_room(request, main): """ Create a chat room for a game after going to the index page """ request.user.profile.save() name = request.POST.get('Enter a New Room Name') try: if name.strip(): request.user.profile.own_room = True request.user.profile.save() new_room = ChatRoom() new_room.name = name new_room.owner = request.user.profile new_room.main = main new_room.save() QUEUES[name] = {} return redirect('/chat/room/' + str(new_room.pk)) except IntegrityError, AttributeError: pass
def create_chatroom(request): post_data = json.loads(request.body.decode('utf-8')) if ('name' not in post_data) or ('publicity' not in post_data): data = {'message': "No name or publicity specified.", 'success': False} return HttpResponse(json.dumps(data), status=400) if (post_data['publicity'] != 'private') and (post_data['publicity'] != 'public'): data = {'message': "Invalid publicity.", 'success': False} return HttpResponse(json.dumps(data), status=400) try: existing_chatroom = None if post_data['publicity'] == 'public': existing_chatroom = ChatRoom.objects.get(name=post_data['name'], is_public=True) else: existing_chatroom = ChatRoom.objects.get(name="_private_{}".format( post_data['name']), is_public=False) if existing_chatroom: data = { 'message': "Chatroom with that name already exists.", 'success': False } return HttpResponse(json.dumps(data), status=400) except: pass chatroom_name = post_data['name'] is_public = True if post_data['publicity'] == 'private': chatroom_name = "_private_{}".format(post_data['private']) is_public = False chatroom = ChatRoom(name=chatroom_name, is_public=False) chatroom.save() chatroom.users.add(request.user) chatroom.save() data = {'id': chatroom.pk, 'message': "Chatroom created.", 'success': True} return HttpResponse(json.dumps(data))
def quiz(request): list_a = [] list_b = [] list_c = [] list_d = [] re_list_a = [] re_list_b = [] re_list_c = [] re_list_d = [] correct = 1 form = QuestionForm(request.POST, request.FILES) ansform = AnswerForm(request.POST or None) number_of_times = "0" _id = -1 post = Posted_Question.objects.all() if post: _id = post[0].question_id number_of_times = post[0].number_of_times print "id", _id switcher = {"0": "", "1": "Post", "2": "Repost"} question = Question.objects.filter(id=_id) uploaded = Question.objects.all() submission = "" ############################################Chat room Id Creation########################################## # chat=ChatRoom(name=request.user.username) # chat.save() if request.user.is_authenticated(): model = ChatRoom.objects.filter(name=request.user.username) if not model: create = ChatRoom(name=request.user.username) create.save() # bool,created=Question.objects.update_or_create(id=request.POST.get('id'),defaults=default_dict) # bool,created=ChatRoom.objects.update_or_create(name=request.user.username,defaults={}) # if(bool): # print "created" if question: ques = question[0] print "question_id", ques.id else: ques = "" if request.method == "POST": if form.is_valid(): instance = form.save(commit=False) correct = request.POST.get("correct") model = Question.objects.filter(id=int(request.POST.get("id"))) if model: model.delete() print "previous entry deleted" # print "instance.question",request.POST.get('question') question_id = str(request.POST.get("id")) instance.question = request.POST.get("question", "") instance.option_correct = correct # bool,created=Question.objects.update_or_create(id=request.POST.get('id'),defaults=default_dict) form.save() sql = Question.objects.latest("id") if sql: f = open("static_in_env/media_root/uploads/chats/" + str(sql.id) + ".txt", "w") f.write("No Chat happens!!") f.close() sql.file_path = "/uploads/chats/" + str(sql.id) + ".txt" sql.save() form = QuestionForm() else: print "not valid" if ansform.is_valid(): answer1 = request.POST.get("options", "") question_id = request.POST.get("question_id") repost = request.POST.get("number_of_times") print repost if answer1: if repost == "1": model = Answer.objects.filter(question_id=question_id).filter(user_name=request.user.username) if model: model.update(answer=answer1) else: create = Answer(question_id=question_id, user_name=request.user.username, answer=answer1) create.save() else: model = Reposted_Answer.objects.filter(question_id=question_id).filter( user_name=request.user.username ) if model: model.update(answer=answer1) else: create = Reposted_Answer( question_id=question_id, user_name=request.user.username, answer=answer1 ) # if(model):Answer(question_id=question_id,user_name=request.user.username,answer=answer) create.save() # bool,created=Reposted_Answer.objects.update_or_create(question_id=question_id,user_name=request.user.username,defaults={'answer':answer}) ques = "" submission = "Your answer has submitted!!" if question: correct = Question.objects.filter(id=_id)[0].option_correct option_a = Answer.objects.filter(answer="0").filter(question_id=_id) for l in option_a: list_a.append(str(l.user_name)) option_b = Answer.objects.filter(answer="1").filter(question_id=_id) for l in option_b: list_b.append(str(l.user_name)) option_c = Answer.objects.filter(answer="2").filter(question_id=_id) for l in option_c: list_c.append(str(l.user_name)) option_d = Answer.objects.filter(answer="3").filter(question_id=_id) for l in option_d: list_d.append(str(l.user_name)) repost_a = Reposted_Answer.objects.filter(answer="0").filter(question_id=_id) for l in repost_a: re_list_a.append(str(l.user_name)) repost_b = Reposted_Answer.objects.filter(answer="1").filter(question_id=_id) for l in repost_b: re_list_b.append(str(l.user_name)) repost_c = Reposted_Answer.objects.filter(answer="2").filter(question_id=_id) for l in repost_c: re_list_c.append(str(l.user_name)) repost_d = Reposted_Answer.objects.filter(answer="3").filter(question_id=_id) for l in repost_d: re_list_d.append(str(l.user_name)) return render_to_response( "quiz.html", { "request": request, "form": form, "ques": ques, "submission": submission, "uploaded": uploaded, "post": switcher[number_of_times], "number_of_times": number_of_times, "option_a": len(list_a), "option_b": len(list_b), "option_c": len(list_c), "option_d": len(list_d), "re_option_a": len(re_list_a), "re_option_b": len(re_list_b), "re_option_c": len(re_list_c), "re_option_d": len(re_list_d), "correct": correct, }, context_instance=RequestContext(request), )
def request_item_view(request, ids): print("Enter exchange/request_item_view") if request.method != "GET": raise Http404 ids = ids.split(" ") # double check the url data if len(ids) != 2 or not ids[0].isnumeric() or not ids[1].isnumeric(): raise Http404 myItemId, itemId = int(ids[0]), int(ids[1]) # check if the ids are valid if ExchangeItem.objects.filter(pk=myItemId).count() == 0 or \ ExchangeItem.objects.filter(pk=myItemId).count() ==0: raise Http404 # ids.append(roomname) # sendrequest.delay(" ".join(ids)) myItem = ExchangeItem.objects.get(pk=myItemId) user = request.user userEmail = user.email otherItem = ExchangeItem.objects.get(pk=itemId) owner = otherItem.user ownerEmail = owner.email roomname = generateRandomCode(ROOMNAME_LENGTH) chatroom = ChatRoom(user1=user, user2=owner, roomname=roomname) chatroom.save() # update both item status myItem.request.add(otherItem) if myItem.status < 1: myItem.status = 1 if otherItem.status < 1: otherItem.status = 1 myItem.save() otherItem.save() context = { "name": otherItem.name, "id": otherItem.pk, "description": otherItem.description, "price": otherItem.price, "status": otherItem.status, "item": otherItem, "owner": otherItem.user } # master # context = {"name": otherItem.name, # "id": otherItem.pk, # "description": otherItem.description, # "price": otherItem.price, # "status": otherItem.status, # "owner": otherItem.user, # "item": otherItem, # "myItem": myItem} # master print(userEmail, ownerEmail) msg1 = """Hi {0},\n\n User {1} would like to exchange for your "{2}" with "{3}".\n Accept this request if you are interested!\n You can contact {1} through:\n 1. SwapSpace's chatroom at http://74739114.ngrok.io/chat, enter code <{5}> to start chatting!\n 2. Or at {4}. Thanks!""".format(owner, user, otherItem, myItem, userEmail, roomname) sendEmail(ownerEmail, "request", msg1) msg2 = """Hi {0},\n\n Your exchange request for "{1}" with your "{2}" has been sent successfully!\n To follow up this request, \n 1. SwapSpace's chatroom at http://74739114.ngrok.io/chat, enter code <{4}> to start chatting!\n 2. Or at {3}. Thanks!""".format(user, otherItem, myItem, ownerEmail, roomname) sendEmail(userEmail, "request", msg2) return redirect(reverse('item_detail', kwargs={'id': otherItem.pk}))
def quiz(request): list_a=[] list_b=[] list_c=[] list_d=[] re_list_a=[] re_list_b=[] re_list_c=[] re_list_d=[] correct=1 form=QuestionForm(request.POST,request.FILES) ansform = AnswerForm(request.POST or None) number_of_times='0' _id=-1 post=Posted_Question.objects.all() if(post): _id=post[0].question_id number_of_times=post[0].number_of_times print "id" ,_id switcher={ '0':'', '1':'Post', '2':'Repost' } question=Question.objects.filter(id=_id) uploaded =Question.objects.all() submission='' ############################################Chat room Id Creation########################################## # chat=ChatRoom(name=request.user.username) # chat.save() if request.user.is_authenticated(): model=ChatRoom.objects.filter(name=request.user.username) if(not model): create=ChatRoom(name=request.user.username) create.save() #bool,created=Question.objects.update_or_create(id=request.POST.get('id'),defaults=default_dict) # bool,created=ChatRoom.objects.update_or_create(name=request.user.username,defaults={}) # if(bool): # print "created" if(question): ques= question[0] print "question_id",ques.id else: ques='' if request.method=='POST': if form.is_valid(): instance = form.save(commit=False) correct=request.POST.get('correct') # print default_dict model=Question.objects.filter(id=int(request.POST.get('id'))) if(model): model.delete() print "previous entry deleted" # model.update(question= str(request.POST.get('question')),option_a=str(request.POST.get('option_a')), # option_b=str(request.POST.get('option_b')),option_c=str(request.POST.get('option_c')), # option_d=str(request.POST.get('option_d')),option_correct=str(request.POST.get('correct')), # image='uploads/'+str(request.POST.get('question')+'/'+str(request.FILES['image'].name)) # ) print instance.question question_id = str(request.POST.get('id')) instance.option_correct=correct #bool,created=Question.objects.update_or_create(id=request.POST.get('id'),defaults=default_dict) form.save() sql=Question.objects.latest('id') if(sql): f=open('static_in_env/media_root/uploads/chats/'+str(sql.id)+'.txt','w') f.write('No Chat happens!!') f.close() sql.file_path='/uploads/chats/'+str(sql.id)+'.txt' sql.save() form=QuestionForm() else: print 'not valid' if ansform.is_valid(): answer1=request.POST.get('options','') question_id=request.POST.get('question_id') repost = request.POST.get('number_of_times') print repost if(answer1): if repost=='1': model=Answer.objects.filter(question_id=question_id).filter(user_name=request.user.username) if(model): model.update(answer =answer1) else: create=Answer(question_id=question_id,user_name=request.user.username,answer=answer1) create.save() #bool,created=Answer.objects.update_or_create(question_id=question_id,user_name=request.user.username,defaults={'answer':answer}) else: model=Reposted_Answer.objects.filter(question_id=question_id).filter(user_name=request.user.username) if(model): model.update(answer =answer1) else: create=Reposted_Answer(question_id=question_id,user_name=request.user.username,answer=answer1) # if(model):Answer(question_id=question_id,user_name=request.user.username,answer=answer) create.save() #bool,created=Reposted_Answer.objects.update_or_create(question_id=question_id,user_name=request.user.username,defaults={'answer':answer}) ques ='' submission='Your answer has submitted!!' if question: correct=Question.objects.filter(id=_id)[0].option_correct option_a=Answer.objects.filter(answer='0').filter(question_id=_id) for l in option_a: list_a.append(str(l.user_name)) option_b=Answer.objects.filter(answer='1').filter(question_id=_id) for l in option_b: list_b.append(str(l.user_name)) option_c=Answer.objects.filter(answer='2').filter(question_id=_id) for l in option_c: list_c.append(str(l.user_name)) option_d=Answer.objects.filter(answer='3').filter(question_id=_id) for l in option_d: list_d.append(str(l.user_name)) repost_a=Reposted_Answer.objects.filter(answer='0').filter(question_id=_id) for l in repost_a: re_list_a.append(str(l.user_name)) repost_b=Reposted_Answer.objects.filter(answer='1').filter(question_id=_id) for l in repost_b: re_list_b.append(str(l.user_name)) repost_c=Reposted_Answer.objects.filter(answer='2').filter(question_id=_id) for l in repost_c: re_list_c.append(str(l.user_name)) repost_d=Reposted_Answer.objects.filter(answer='3').filter(question_id=_id) for l in repost_d: re_list_d.append(str(l.user_name)) return render_to_response( 'quiz.html', {'request':request,'form':form,'ques':ques,'submission':submission,'uploaded':uploaded, 'post':switcher[number_of_times],'number_of_times':number_of_times,'option_a':len(list_a),'option_b':len(list_b), 'option_c':len(list_c),'option_d':len(list_d),'re_option_a':len(re_list_a),'re_option_b':len(re_list_b), 're_option_c':len(re_list_c),'re_option_d':len(re_list_d),'correct':correct}, context_instance=RequestContext(request))
def create(request): prof = request.user.get_profile() err_msg = "" if request.method == 'POST': form = CreateCompetitionForm(request.POST) if form.is_valid() and request.user.is_authenticated(): # create and save the Competition comp = Competition() comp.title = form.cleaned_data.get('title') comp.host = request.user comp.preview_theme = form.cleaned_data.get('preview_theme', False) if form.cleaned_data.get('have_theme', False): comp.theme = form.cleaned_data.get('theme', '') comp.preview_rules = form.cleaned_data.get('preview_rules', False) if form.cleaned_data.get('have_rules', False): comp.rules = form.cleaned_data.get('rules', '') tz_offset = form.cleaned_data.get('tz_offset') tz_delta = timedelta(hours=tz_offset) comp.start_date = form.cleaned_data.get('start_date') + tz_delta comp.submit_deadline = form.cleaned_data.get( 'submission_deadline_date') + tz_delta # calculate vote deadline quantity = int(form.cleaned_data.get('vote_time_quantity')) quantifier = int(form.cleaned_data.get('vote_time_measurement')) comp.vote_period_length = quantity * TimeUnit.seconds_multiplier[ quantifier] vote_period_delta = timedelta(seconds=comp.vote_period_length) comp.have_listening_party = form.cleaned_data.get( 'have_listening_party', True) if comp.have_listening_party: if form.cleaned_data.get('party_immediately'): comp.listening_party_start_date = comp.submit_deadline else: comp.listening_party_start_date = form.cleaned_data.get( 'listening_party_date') + tz_delta # initialize end date to start date. we make modifications to it # when entries are submitted. comp.listening_party_end_date = comp.listening_party_start_date # this changes whenever listening_party_end_date changes. comp.vote_deadline = comp.listening_party_end_date + vote_period_delta else: comp.vote_deadline = comp.submit_deadline + vote_period_delta # create a chatroom for it chatroom = ChatRoom() chatroom.permission_type = ChatRoom.OPEN # open the chat room an hour before the competition chatroom.start_date = comp.start_date - timedelta(hours=1) # chat room is open an hour before and after competition chatroom.end_date = comp.listening_party_end_date + timedelta( hours=1) chatroom.save() comp.chat_room = chatroom comp.save() # automatically bookmark it prof.competitions_bookmarked.add(comp) prof.save() return HttpResponseRedirect(reverse("arena.home")) else: initial = { 'have_theme': True, 'have_rules': True, 'preview_rules': True, 'have_listening_party': True, 'party_immediately': True, 'vote_time_quantity': 1, 'vote_time_measurement': TimeUnit.WEEKS, } form = CreateCompetitionForm(initial=initial) return render_to_response('arena/create.html', locals(), context_instance=RequestContext(request))
def unread_chat_rooms(request): return JsonResponse( data={'count': ChatRoom.unread_chat_rooms(request.user)})
def test_chat_disconnect(self): ChatRoom.join("room1", "slok") self.assertTrue(ChatRoom.connected("room1", "slok")) ChatRoom.disconnect("room1", "slok") self.assertFalse(ChatRoom.connected("room1", "slok"))
def test_chat_join(self): ChatRoom.join("room1", "slok") self.assertTrue(ChatRoom.connected("room1", "slok"))
def create(request): prof = request.user.get_profile() err_msg = "" if request.method == 'POST': form = CreateCompetitionForm(request.POST) if form.is_valid() and request.user.is_authenticated(): # create and save the Competition comp = Competition() comp.title = form.cleaned_data.get('title') comp.host = request.user comp.preview_theme = form.cleaned_data.get('preview_theme', False) if form.cleaned_data.get('have_theme', False): comp.theme = form.cleaned_data.get('theme', '') comp.preview_rules = form.cleaned_data.get('preview_rules', False) if form.cleaned_data.get('have_rules', False): comp.rules = form.cleaned_data.get('rules', '') tz_offset = form.cleaned_data.get('tz_offset') tz_delta = timedelta(hours=tz_offset) comp.start_date = form.cleaned_data.get('start_date') + tz_delta comp.submit_deadline = form.cleaned_data.get('submission_deadline_date') + tz_delta # calculate vote deadline quantity = int(form.cleaned_data.get('vote_time_quantity')) quantifier = int(form.cleaned_data.get('vote_time_measurement')) comp.vote_period_length = quantity * TimeUnit.seconds_multiplier[quantifier] vote_period_delta = timedelta(seconds=comp.vote_period_length) comp.have_listening_party = form.cleaned_data.get('have_listening_party', True) if comp.have_listening_party: if form.cleaned_data.get('party_immediately'): comp.listening_party_start_date = comp.submit_deadline else: comp.listening_party_start_date = form.cleaned_data.get('listening_party_date') + tz_delta # initialize end date to start date. we make modifications to it # when entries are submitted. comp.listening_party_end_date = comp.listening_party_start_date # this changes whenever listening_party_end_date changes. comp.vote_deadline = comp.listening_party_end_date + vote_period_delta else: comp.vote_deadline = comp.submit_deadline + vote_period_delta # create a chatroom for it chatroom = ChatRoom() chatroom.permission_type = ChatRoom.OPEN # open the chat room an hour before the competition chatroom.start_date = comp.start_date - timedelta(hours=1) # chat room is open an hour before and after competition chatroom.end_date = comp.listening_party_end_date + timedelta(hours=1) chatroom.save() comp.chat_room = chatroom; comp.save() # automatically bookmark it prof.competitions_bookmarked.add(comp) prof.save() return HttpResponseRedirect(reverse("arena.home")) else: initial = { 'have_theme': True, 'have_rules': True, 'preview_rules': True, 'have_listening_party': True, 'party_immediately': True, 'vote_time_quantity': 1, 'vote_time_measurement': TimeUnit.WEEKS, } form = CreateCompetitionForm(initial=initial) return render_to_response('arena/create.html', locals(), context_instance=RequestContext(request))