def comments(request): form = NewForm() if request.method=="POST": form = NewForm(request.POST) if form.is_valid(): App_new.objects.create(**{'field1':request.POST.get('field1'), 'field2':request.POST.get('field2')}) return HttpResponseRedirect('/') return render(request, 'apppshka/comments.html', locals())
def add(request): context = {} context['mapHeight'] = 500 context['mapWidth'] = 940 context['mapCenterLat'] = 48.998465 context['mapCenterLng'] = 21.239812 context['mapZoomLevel'] = 13 grounds = [] for grnd in ground.objects.all(): grounds.append(grnd) context['grounds'] = grounds saved = None user = User.objects.get(id=request.user.id) if request.method == 'POST': form = NewForm(request.POST, files=request.FILES) if form.is_valid(): event = Event(title = form.cleaned_data['title']) startDate = form.cleaned_data['startOfActionDate'] startTime = form.cleaned_data['startOfActionTime'] splitStartDate = startDate.split(".") splitStartTime = startTime.split(":") event.startOfAction = datetime.datetime(int(splitStartDate[2]), int(splitStartDate[1]), int(splitStartDate[0]), int(splitStartTime[0]), int(splitStartTime[1])) event.published = datetime.datetime.now() event.numberOfPlayers = form.cleaned_data['numberOfPlayers'] if form.data.get("loginCheckBox") == "on": event.login_since = datetime.datetime.now() else: loginDate = form.cleaned_data['login_sinceDate'] loginTime = form.cleaned_data['login_sinceTime'] splitLoginDate = loginDate.split(".") splitLoginTime = loginTime.split(":") event.login_since = datetime.datetime(int(splitLoginDate[2]), int(splitLoginDate[1]), int(splitLoginDate[0]), int(splitLoginTime[0]), int(splitLoginTime[1])) event.prologue = form.cleaned_data['prologue'] event.scenario = form.cleaned_data['scenario'] event.organizationNotes = form.cleaned_data['organizationNotes'] durationTime = form.cleaned_data['duration'] splitDurationTime = durationTime.split(":") event.duration = datetime.time(int(splitDurationTime[0]), int(splitDurationTime[1]), 0) event.entryFee = form.cleaned_data['entryFee'] event.author = user #event.ground = form.cleaned_data['ground'] event.locationLat = form.data['Latitude'] event.locationLng = form.data['Longitude'] event.titleImage = form.cleaned_data['titleImage'] event.published = datetime.datetime.now() groundId = int(form.data['groundId']) if (groundId > 0): event.ground = ground.objects.get(id=groundId) event.save() event.users.add(user.player) return HttpResponseRedirect('/events/detail/' + str(event.id)) else: context['form'] = form context['fail'] = True return render_to_response('event/newEvent.html', context, context_instance=RequestContext(request)) else: form = NewForm() context['form'] = form context['saved'] = saved return render_to_response('event/newEvent.html', context, context_instance=RequestContext(request))