def parks_page(request, park_slug): park = get_object_or_404(Park, slug=park_slug) encoder = cgpolyencode.GPolyEncoder() coordinates = simplejson.loads(park.geometry.geojson) map = encoder.encode(coordinates['coordinates'][0][0]) stories = Story.objects.filter(park=park).order_by("-date") #stops = MBTAStop.objects.filter(lat_long__distance_lte=(park.geometry.centroid,D(mi=settings.MBTA_DISTANCE))) # this distance doesn't overload the page with a million stops. if request.method == 'POST': story = Story() f = StoryForm(request.POST, instance=story) if f.is_valid(): story.park = park f.save() f = StoryForm() else: f = StoryForm() return render_to_response( 'parkmap/park.html', { 'park': park, 'map': map, #'stops': stops, 'story_form': f, 'stories': stories, 'request': request, 'acres': park.geometry.area * 0.000247, }, context_instance=RequestContext(request))
def parks_page(request, park_slug): park = get_object_or_404(Park, slug=park_slug) encoder = cgpolyencode.GPolyEncoder() coordinates = simplejson.loads(park.geometry.geojson) map = encoder.encode(coordinates['coordinates'][0][0]) stories = Story.objects.filter(park=park).order_by("-date") #stops = MBTAStop.objects.filter(lat_long__distance_lte=(park.geometry.centroid,D(mi=settings.MBTA_DISTANCE))) # this distance doesn't overload the page with a million stops. if request.method == 'POST': story = Story() f = StoryForm(request.POST, instance=story) if f.is_valid(): story.park = park f.save() f = StoryForm() else: f = StoryForm() return render_to_response('parkmap/park.html', {'park': park, 'map': map, #'stops': stops, 'story_form': f, 'stories': stories, 'request': request, 'acres': park.geometry.area * 0.000247, }, context_instance=RequestContext(request) )
def new_story(request, projectID): story = Story() project = project_api.get_project(projectID) association = UserAssociation.objects.get(user=request.user, project=project) if request.method == 'POST': form = StoryForm(request.POST, project=project) if form.is_valid(): # <<<<<<< HEAD story = form.save(commit=False) formset = TaskFormSet(request.POST, instance=story) if formset.is_valid(): story = mdl_story.create_story(project, request.POST) formset.instance = story formset.save() # return redirect('/req/projects/' + projectID) # return empty string and do the redirect stuff in front-end return HttpResponse('') else: formset = TaskFormSet(request.POST, instance=story) # formset.extra = 1 # ======= # story = mdl_story.create_story(project, request.POST) # story = form.save(commit=False) # if not 'next' in request.POST: # return redirect('/req/projectdetail/' + projectID) # else: # next = request.POST['next'] # return redirect(next) # >>>>>>> newfeature-additerationdetail else: form = StoryForm(project=project) formset = TaskFormSet(instance=story) formset.extra = 1 # project = project_api.get_project(projectID) # association = UserAssociation.objects.get(user=request.user, project=project) context = { 'title': 'New User Story', 'form': form, 'project': project, 'association': association, # <<<<<<< HEAD # # 'formset' : formset, # 'action' : '/req/newstory/' + projectID , # 'button_desc' : 'Create User Story', # } # return render(request, 'StorySummary.html', context ) # ======= 'formset': formset, 'initTasks': formset.initial_form_count(), 'numTasks': formset.total_form_count(), 'action': '/req/newstory/' + projectID, 'button_desc': 'Create User Story' } return render(request, 'StorySummary.html', context)
def new_story(request, projectID): story = Story() project = project_api.get_project(projectID) association = UserAssociation.objects.get( user=request.user, project=project) if request.method == 'POST': form = StoryForm(request.POST, project=project) if form.is_valid(): # <<<<<<< HEAD story = form.save(commit=False) formset = TaskFormSet(request.POST, instance=story) if formset.is_valid(): story = mdl_story.create_story(project, request.POST) formset.instance = story formset.save() # return redirect('/req/projects/' + projectID) # return empty string and do the redirect stuff in front-end return HttpResponse('') else: formset = TaskFormSet(request.POST, instance=story) # formset.extra = 1 # ======= # story = mdl_story.create_story(project, request.POST) # story = form.save(commit=False) # if not 'next' in request.POST: # return redirect('/req/projectdetail/' + projectID) # else: # next = request.POST['next'] # return redirect(next) # >>>>>>> newfeature-additerationdetail else: form = StoryForm(project=project) formset = TaskFormSet(instance=story) formset.extra = 1 # project = project_api.get_project(projectID) # association = UserAssociation.objects.get(user=request.user, project=project) context = {'title': 'New User Story', 'form': form, 'project': project, 'association': association, # <<<<<<< HEAD # # 'formset' : formset, # 'action' : '/req/newstory/' + projectID , # 'button_desc' : 'Create User Story', # } # return render(request, 'StorySummary.html', context ) # ======= 'formset': formset, 'initTasks': formset.initial_form_count(), 'numTasks': formset.total_form_count(), 'action': '/req/newstory/' + projectID, 'button_desc': 'Create User Story'} return render(request, 'StorySummary.html', context)
def edit_story(request, projectID, storyID): project = project_api.get_project(projectID) association = UserAssociation.objects.get( user=request.user, project=project) story = mdl_story.get_story(storyID) if story is None: # return redirect('/req/projectdetail/' + projectID) # return empty string and do the redirect stuff in front-end return HttpResponse('') if request.method == 'POST': form = StoryForm(request.POST, instance=story, project=project) if form.is_valid(): # <<<<<<< HEAD story = form.save(commit=False) formset = TaskFormSet(request.POST, instance=story) if formset.is_valid(): story.save() # formset.instance=story formset.save() # return redirect('/req/projects/' + projectID) # return empty string and do the redirect stuff in front-end return HttpResponse('') else: formset = TaskFormSet(request.POST, instance=story) else: form = StoryForm(instance=story, project=project) formset = TaskFormSet(instance=story) numTasks = initTasks = mdl_task.get_tasks_for_story( story).count() # story.task_set.count() if numTasks == 0: numTasks = 1 else: numTasks = numTasks + 1 formset.extra = 1 context = {'title': 'Edit User Story', 'project': project, 'association': association, 'title': 'Edit User Story', 'form': form, 'formset': formset, 'initTasks': formset.initial_form_count(), 'numTasks': formset.total_form_count(), 'action': '/req/editstory/' + projectID + '/' + storyID, 'button_desc': 'Save Changes'} return render(request, 'StorySummary.html', context)
def edit_story(request, projectID, storyID): project = project_api.get_project(projectID) association = UserAssociation.objects.get(user=request.user, project=project) story = mdl_story.get_story(storyID) if story is None: # return redirect('/req/projectdetail/' + projectID) # return empty string and do the redirect stuff in front-end return HttpResponse('') if request.method == 'POST': form = StoryForm(request.POST, instance=story, project=project) if form.is_valid(): # <<<<<<< HEAD story = form.save(commit=False) formset = TaskFormSet(request.POST, instance=story) if formset.is_valid(): story.save() # formset.instance=story formset.save() # return redirect('/req/projects/' + projectID) # return empty string and do the redirect stuff in front-end return HttpResponse('') else: formset = TaskFormSet(request.POST, instance=story) else: form = StoryForm(instance=story, project=project) formset = TaskFormSet(instance=story) numTasks = initTasks = mdl_task.get_tasks_for_story( story).count() # story.task_set.count() if numTasks == 0: numTasks = 1 else: numTasks = numTasks + 1 formset.extra = 1 context = { 'title': 'Edit User Story', 'project': project, 'association': association, 'title': 'Edit User Story', 'form': form, 'formset': formset, 'initTasks': formset.initial_form_count(), 'numTasks': formset.total_form_count(), 'action': '/req/editstory/' + projectID + '/' + storyID, 'button_desc': 'Save Changes' } return render(request, 'StorySummary.html', context)
def edit_story(request, projectID, storyID): project = project_api.get_project(projectID) association = UserAssociation.objects.get(user=request.user, project=project) story = mdl_story.get_story(storyID) if story == None: return redirect('/req/projectdetail/' + projectID) if request.method == 'POST': form = StoryForm(request.POST, instance=story, project=project) if form.is_valid(): # <<<<<<< HEAD # story = form.save(commit=False) # formset = TaskFormSet(request.POST, instance=story) # if formset.is_valid(): # story.save() # formset.save() # return redirect('/req/projects/' + projectID) # ======= story = form.save(commit=True) if not 'next' in request.POST: return redirect('/req/projectdetail/' + projectID) else: next = request.POST['next'] return redirect(next) # >>>>>>> newfeature-additerationdetail else: form = StoryForm(instance=story, project=project) # formset = TaskFormSet(instance=story) # if story.task_set.count() == 0: formset.extra = 1 # test that association and permissions are working # print "UserID "+str(request.user.id)+" and ProjectID "+projectID+" and storyID "+storyID # can_edit_hours = association.get_permission("EditHours") # should become unnecessary # str_edit_hours = str(can_edit_hours) # print "In association of user and project, permission EditHours is "+str_edit_hours context = { 'title': 'Edit User Story', 'project': project, 'association': association, 'title': 'Edit User Story', 'form': form, # 'formset' : formset, 'action': '/req/editstory/' + projectID + '/' + storyID, 'button_desc': 'Save Changes' } return render(request, 'StorySummary.html', context)
def edit(request, story_id):#only the invitor can modify it user = request.user story = Activity.objects.get(id=story_id) if story.invitor == user: if request.method == 'POST': form = StoryForm(request.POST, instance=story) if form.is_valid(): form.save() else: form = StoryForm(instance=story) return render_to_response('story/edit.html', {'form': form, 'story_id': story_id,}, context_instance=RequestContext(request)) else: return HttpResponse('you are not permit to do this!')
def edit_story(request, projectID, storyID): project = project_api.get_project(projectID) association = UserAssociation.objects.get(user=request.user, project=project) story = mdl_story.get_story(storyID) if story == None: return redirect('/req/projectdetail/' + projectID) if request.method == 'POST': form = StoryForm(request.POST, instance=story, project=project) if form.is_valid(): # <<<<<<< HEAD # story = form.save(commit=False) # formset = TaskFormSet(request.POST, instance=story) # if formset.is_valid(): # story.save() # formset.save() # return redirect('/req/projects/' + projectID) # ======= story = form.save(commit=True) if not 'next' in request.POST: return redirect('/req/projectdetail/' + projectID) else: next = request.POST['next'] return redirect(next) # >>>>>>> newfeature-additerationdetail else: form = StoryForm(instance=story, project=project) # formset = TaskFormSet(instance=story) # if story.task_set.count() == 0: formset.extra = 1 # test that association and permissions are working # print "UserID "+str(request.user.id)+" and ProjectID "+projectID+" and storyID "+storyID # can_edit_hours = association.get_permission("EditHours") # should become unnecessary # str_edit_hours = str(can_edit_hours) # print "In association of user and project, permission EditHours is "+str_edit_hours context = {'title' : 'Edit User Story', 'project' : project, 'association' : association, 'title' : 'Edit User Story', 'form' : form, # 'formset' : formset, 'action' : '/req/editstory/' + projectID + '/' + storyID, 'button_desc' : 'Save Changes'} return render(request, 'StorySummary.html', context )
def new_story(request, projectID): # story = Story() project = project_api.get_project(projectID) association = UserAssociation.objects.get(user=request.user, project=project) if request.method == 'POST': form = StoryForm(request.POST, project=project) if form.is_valid(): # <<<<<<< HEAD # formset = TaskFormSet(request.POST, instance=story) # if formset.is_valid(): # story = models.story.create_story(request.user, # project_api.get_project(projectID), # request.POST) # formset.instance=story # formset.save() # return redirect('/req/projects/' + projectID) # ======= story = mdl_story.create_story(project, request.POST) story = form.save(commit=False) if not 'next' in request.POST: return redirect('/req/projectdetail/' + projectID) else: next = request.POST['next'] return redirect(next) # >>>>>>> newfeature-additerationdetail else: form = StoryForm(project=project) # formset = TaskFormSet(instance=story) # formset.extra = 1 project = project_api.get_project(projectID) association = UserAssociation.objects.get(user=request.user, project=project) context = { 'title': 'New User Story', 'form': form, # 'formset' : formset, 'project': project, 'association': association, 'action': '/req/newstory/' + projectID, 'button_desc': 'Create User Story', } return render(request, 'StorySummary.html', context)
def create(request): if request.method == 'POST': form = StoryForm(request.POST) if form.is_valid(): story = form.save(False) story.invitor = request.user story.state = 'O' story.save() return redirect('/story/detail/' + str(story.id)) else: try: year = int(request.GET['year']) month = int(request.GET['month']) day = int(request.GET['day']) start_time = datetime.datetime(year, month, day) form = StoryForm(initial={'start_time':start_time}) except: form = StoryForm() return render_to_response('story/create.html', {'form': form,}, context_instance=RequestContext(request))
def new_story(request, projectID): # story = Story() project = project_api.get_project(projectID) association = UserAssociation.objects.get(user=request.user, project=project) if request.method == 'POST': form = StoryForm(request.POST,project=project) if form.is_valid(): # <<<<<<< HEAD # formset = TaskFormSet(request.POST, instance=story) # if formset.is_valid(): # story = models.story.create_story(request.user, # project_api.get_project(projectID), # request.POST) # formset.instance=story # formset.save() # return redirect('/req/projects/' + projectID) # ======= story = mdl_story.create_story(project, request.POST) story = form.save(commit=False) if not 'next' in request.POST: return redirect('/req/projectdetail/' + projectID) else: next = request.POST['next'] return redirect(next) # >>>>>>> newfeature-additerationdetail else: form = StoryForm(project=project) # formset = TaskFormSet(instance=story) # formset.extra = 1 project = project_api.get_project(projectID) association = UserAssociation.objects.get(user=request.user, project=project) context = {'title' : 'New User Story', 'form' : form, # 'formset' : formset, 'project': project, 'association': association, 'action' : '/req/newstory/' + projectID , 'button_desc' : 'Create User Story', } return render(request, 'StorySummary.html', context )
def new_story(request, projectID): story = Story() project = project_api.get_project(projectID) association = UserAssociation.objects.get( user=request.user, project=project) if request.method == 'POST': form = StoryForm(request.POST, project=project) if form.is_valid(): story = form.save(commit=False) formset = TaskFormSet(request.POST, instance=story) if formset.is_valid(): story = mdl_story.create_story(project, request.POST) formset.instance = story formset.save() # return empty string and do the redirect stuff in front-end return HttpResponse('') else: formset = TaskFormSet(request.POST, instance=story) else: form = StoryForm(project=project) formset = TaskFormSet(instance=story) formset.extra = 1 context = { 'title': 'New User Story', 'form': form, 'project': project, 'association': association, 'formset': formset, 'initTasks': formset.initial_form_count(), 'numTasks': formset.total_form_count(), 'action': '/requirements/newstory/' + projectID, 'button_desc': 'Create User Story' } return render(request, 'StorySummary.html', context)
def edit_story(request, projectID, storyID): project = project_api.get_project(projectID) association = UserAssociation.objects.get( user=request.user, project=project) story = mdl_story.get_story(storyID) if story is None: # return redirect('/req/projectdetail/' + projectID) # return empty string and do the redirect stuff in front-end return HttpResponse('') if request.method == 'POST': form = StoryForm(request.POST, instance=story, project=project) if form.is_valid(): # <<<<<<< HEAD story = form.save(commit=False) formset = TaskFormSet(request.POST, instance=story) if formset.is_valid(): story.save() # formset.instance=story formset.save() # return redirect('/req/projects/' + projectID) # return empty string and do the redirect stuff in front-end return HttpResponse('') # ======= # story = form.save(commit=True) # if not 'next' in request.POST: # return redirect('/req/projectdetail/' + projectID) # else: # next = request.POST['next'] # return redirect(next) else: formset = TaskFormSet(request.POST, instance=story) # >>>>>>> newfeature-additerationdetail else: # <<<<<<< HEAD # form = StoryForm(instance=story, project=project) # formset = TaskFormSet(instance=story) # if story.task_set.count() == 0: formset.extra = 1 # test that association and permissions are working # print "UserID "+str(request.user.id)+" and ProjectID "+projectID+" and storyID "+storyID # can_edit_hours = association.get_permission("EditHours") # should become unnecessary # str_edit_hours = str(can_edit_hours) # print "In association of user and project, permission EditHours is "+str_edit_hours # ======= form = StoryForm(instance=story, project=project) formset = TaskFormSet(instance=story) numTasks = initTasks = mdl_task.get_tasks_for_story( story).count() # story.task_set.count() if numTasks == 0: numTasks = 1 else: numTasks = numTasks + 1 formset.extra = 1 # >>>>>>> newfeature-TasksFormset context = {'title': 'Edit User Story', 'project': project, 'association': association, 'title': 'Edit User Story', 'form': form, # <<<<<<< HEAD # # 'formset' : formset, # 'action' : '/req/editstory/' + projectID + '/' + storyID, # 'button_desc' : 'Save Changes'} # ======= 'formset': formset, 'initTasks': formset.initial_form_count(), 'numTasks': formset.total_form_count(), 'action': '/req/editstory/' + projectID + '/' + storyID, 'button_desc': 'Save Changes'} # >>>>>>> newfeature-TasksFormset return render(request, 'StorySummary.html', context)
def edit_story(request, projectID, storyID): project = project_api.get_project(projectID) association = UserAssociation.objects.get(user=request.user, project=project) story = mdl_story.get_story(storyID) if story is None: # return redirect('/req/projectdetail/' + projectID) # return empty string and do the redirect stuff in front-end return HttpResponse('') if request.method == 'POST': form = StoryForm(request.POST, instance=story, project=project) if form.is_valid(): # <<<<<<< HEAD story = form.save(commit=False) formset = TaskFormSet(request.POST, instance=story) if formset.is_valid(): story.save() # formset.instance=story formset.save() # return redirect('/req/projects/' + projectID) # return empty string and do the redirect stuff in front-end return HttpResponse('') # ======= # story = form.save(commit=True) # if not 'next' in request.POST: # return redirect('/req/projectdetail/' + projectID) # else: # next = request.POST['next'] # return redirect(next) else: formset = TaskFormSet(request.POST, instance=story) # >>>>>>> newfeature-additerationdetail else: # <<<<<<< HEAD # form = StoryForm(instance=story, project=project) # formset = TaskFormSet(instance=story) # if story.task_set.count() == 0: formset.extra = 1 # test that association and permissions are working # print "UserID "+str(request.user.id)+" and ProjectID "+projectID+" and storyID "+storyID # can_edit_hours = association.get_permission("EditHours") # should become unnecessary # str_edit_hours = str(can_edit_hours) # print "In association of user and project, permission EditHours is "+str_edit_hours # ======= form = StoryForm(instance=story, project=project) formset = TaskFormSet(instance=story) numTasks = initTasks = mdl_task.get_tasks_for_story( story).count() # story.task_set.count() if numTasks == 0: numTasks = 1 else: numTasks = numTasks + 1 formset.extra = 1 # >>>>>>> newfeature-TasksFormset context = { 'title': 'Edit User Story', 'project': project, 'association': association, 'title': 'Edit User Story', 'form': form, # <<<<<<< HEAD # # 'formset' : formset, # 'action' : '/req/editstory/' + projectID + '/' + storyID, # 'button_desc' : 'Save Changes'} # ======= 'formset': formset, 'initTasks': formset.initial_form_count(), 'numTasks': formset.total_form_count(), 'action': '/req/editstory/' + projectID + '/' + storyID, 'button_desc': 'Save Changes' } # >>>>>>> newfeature-TasksFormset return render(request, 'StorySummary.html', context)
def create_stories(request): if request.user.is_authenticated(): if request.POST: current_user = request.user list_form = [] #Get the story form storyform = StoryForm(request.POST,prefix = "Story") #Check if text and image exists if not (request.POST.getlist('text') and request.FILES.getlist('source')): from django.contrib import messages messages.add_message(request, messages.WARNING, 'Please insert at least 1 text and 1 image') return render_page(request,"create_stories.html","custom error") print storyform #Handle insertion for the title. if storyform.is_valid(): story = storyform.save(commit = False) story.user_id = current_user.id story.save() #Handle insertion of the text for f,p in zip(request.POST.getlist('text'),request.POST.getlist('text_position')): text = TextForm(request.POST,{'position' : p,'text': f }) if text.is_valid(): addtext = text.save(commit = False) addtext.storyid_id = story.id addtext.user = current_user addtext.position = p addtext.text = f list_form.append(addtext); else: return render_page(request,"create_stories.html",{'form': text}) #Handle insertion of the image for f,p in zip(request.FILES.getlist('source'),request.POST.getlist('position')): if f.size > 5000000: from django.contrib import messages messages.add_message(request, messages.WARNING, 'Image size should not be more than 5MB.') return render_page(request,"create_stories.html","custom error") form = ImageForm(request.POST, {'source': f }) if form.is_valid(): addimage = form.save(commit = False) addimage.storyid_id = story.id addimage.user = current_user addimage.position = p list_form.append(addimage); else: return render_page(request,"create_stories.html",{'form': form}) #All form has been validated. Save it permanently for item_form in list_form: item_form.save() #Change the story complete to true so user can see it. story.complete = True; story.save(); #Stream to all users who follows. stream_feed(request.user.id,str(request.user.id) + ':' + str(story.storyid)) return HttpResponseRedirect("/stories/read/?s=" + str(story.storyid)) else: return render_page(request,"create_stories.html",{'form': storyform}) else: return render_page(request,"create_stories.html","no error") else: return HttpRespondeRedirect("home.html")