Exemplo n.º 1
0
def information(request, task):
    titleForm = TitleForm()
    if request.method == 'POST':
        titleForm = TitleForm(request.POST)
        if titleForm.is_valid():
            print "before lock in information " + str(request.user.id)
            lock = FileLock("/home/senderma/projects/banalnosti/lockAddTitle")
            with lock:
                print "in information " + str(request.user.id)
                if(len(titleForm.cleaned_data['title'].split()) > 0):
                    print "count information " + str(request.user.id)
                    titleInput = titleForm.cleaned_data['title']
                    userTitle = Titles.objects.filter(gameID = task.gameID, user = request.user)
                    if(len(userTitle) != 1 or userTitle[0].title != titleInput):
	                    Titles.objects.filter(gameID = task.gameID, user = request.user).delete()
	                    titlesNew = Titles(user = request.user, title = titleInput, gameID = task.gameID, tourID = -1)
	                    titlesNew.save()
                print "out information " + str(request.user.id)
                time.sleep(1)	
    if len(Titles.objects.filter(gameID = task.gameID, user = request.user)) > 0:
        titleYour = Titles.objects.filter(gameID = task.gameID, user = request.user)[0]
    
	#для html    
    peoplesInputTitles = map(lambda x: x.user, Titles.objects.filter(gameID = task.gameID))
    currentTime = timezone.now()
    taskNext = Tasks.objects.filter(taskTime__gt = task.taskTime).order_by('taskTime')[0]   
    NUMBER_SEC_REDIRECT = taskNext.taskTime - currentTime
    NUMBER_SEC_REDIRECT = NUMBER_SEC_REDIRECT.days*60*60*24 + NUMBER_SEC_REDIRECT.seconds + 1
    NEXT_PAGE = '/main/'
    message = "До игры осталось"
    return render_to_response('info.html', locals(), context_instance=RequestContext(request))
Exemplo n.º 2
0
def add_titles(request, gameID):
    gameID = int(gameID)
    form = WordForm()
    if request.method == 'POST':
        
        form = WordForm(request.POST)
            
        if form.is_valid() :
            if len(Titles.objects.filter(gameID = DataGame.objects.get(id = gameID), user = User.objects.get(id = 92))) > 0 :
                Titles.objects.filter(gameID = DataGame.objects.get(id = gameID), user = User.objects.get(id = 92)).delete()
            titlesInput = []
            for i in range(1, 11):
                titlesInput.append(form.cleaned_data["word" + str(i)])
            for title in titlesInput:
                if len(title.split()) == 0:
                    continue
                titleNew = Titles(gameID = DataGame.objects.get(id = gameID), user = User.objects.get(id = 92), tourID = -1, title = title)
                titleNew.save()
        message = "Темы добавлены в количестве " + str(len(Titles.objects.filter(gameID = DataGame.objects.get(id = gameID), user = User.objects.get(id = 92))))
    return render_to_response('add_titles.html', locals(), context_instance=RequestContext(request))