def story(story_id=None): form = StoryForm(request.form) if request.method == 'POST': if form.validate(): story = Archive().write_story(form.data) return redirect(url_for('story') + '/' + story['id'], ) #return render_template('story.html', story=story) else: return redirect(url_for('index')) #sid = str(request.args.get('id')) story_exists, story = Archive().read_story(story_id) if story_exists: web_intent = { "facebook": urlencode({ "u": request.url, "title": story['title'] }), "twitter": urlencode({ "url": request.url, "text": story['title'] }) } return render_template('story.html', story=story, web_intent=web_intent, archive=Archive()) else: return redirect(url_for('index'))
def storynew(): if 'username' in session: user = session['username'] form = StoryForm() if form.validate_on_submit(): uid = dbsession.query(User.id).filter_by(name=user).first() newstory = Story(form.title.data) newstory.text = markdown.markdown(form.body.data) newstory.uid = uid[0] newstory.adult = form.adult.data tagslist = form.tags.data tagslist = tagslist.split(',') for tagitem in tagslist: tagitem = tagitem.strip() tagitem = tagitem.lower() tag = dbsession.query(Tag).filter_by(tagname=tagitem).first() if tag is None: tag = Tag(tagitem) newstory.tags.append(tag) dbsession.add(newstory) dbsession.commit() return redirect("~"+user) return render_template("storynew.html", form=form) else: return render_template("storynew.html")
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 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 add_story(): check_admin() add_story = True form = StoryForm() if form.validate_on_submit(): filename = secure_filename(form.upload.data.filename) src = UPLOADPATH + filename form.upload.data.save(src) filemd5 = hashlib.md5() with open(UPLOADPATH + filename, 'rb') as f: for chunk in iter(lambda: f.read(4096), b""): filemd5.update(chunk) if form.available.data: available = True else: available = False dst = S_IMAGEPATH + filemd5.hexdigest() + '.' + filename.split('.')[1] if Story.query.filter_by(imgurl=filemd5.hexdigest() + '.' + filename.split('.')[1]).first() == None: copyfile(src, dst) os.remove(src) story = Story(title=form.title.data, author=form.author.data, imgurl=filemd5.hexdigest() + '.' + filename.split('.')[1], location=form.location.data, description=form.description.data, hitnumber=0, available=available) db.session.add(story) db.session.commit() flash('Add story successfull.') else: os.remove(src) flash('Upload image file was in used.') # redirect to the departments page return redirect(url_for('admin.stories', page=1)) # form.common_name.data = product.common_name # form.price.data = product.price catalogs = Catalog.get_all() stories = Story.get_all() return render_template('admin/story.html', action="Add", add_story=add_story, form=form, stories=stories, title="Add Story", catalogs=catalogs)
def add_story(): form = StoryForm(request.form) if request.method == 'POST' and form.validate_on_submit(): story = Story(form.title.data, form.content.data) try: StoryService.add_story(_story=story, _nick_name=current_user.username, _category=form.category.data, _author=current_user.username) flash("add success") return redirect(url_for('index')) except Exception, e: return jsonify({"errorMessage": e.message})
def render_form(): """Render questions for madlibs form""" form = StoryForm() if form.validate_on_submit(): place = form.place.data noun = form.noun.data verb = form.verb.data adjective = form.adjective.data plural_noun = form.plural_noun.data return f"These are the things in the form: {place}, {noun}, {verb}, {adjective}, {plural_noun}" else: return render_template("questions_form.html", form=form)
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 delete_story(request, projectID, storyID): project = project_api.get_project(projectID) association = UserAssociation.objects.get(user=request.user, project=project) story = models.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': story.delete() # return empty string and do the redirect stuff in front-end return HttpResponse('') # if not 'next' in request.POST: # return redirect('/req/projectdetail/' + projectID) # else: # next = request.POST['next'] # return redirect(next) else: form = StoryForm(instance=story, project=project) context = { 'title': 'Delete User Story', 'confirm_message': 'This is an irreversible procedure ! You will lose all information about this user story !', 'project': project, 'association': association, 'form': form, 'action': '/req/deletestory/' + projectID + '/' + storyID, 'button_desc': 'Delete 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 == 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 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 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 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 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 delete_story(request, projectID, storyID): project = project_api.get_project(projectID) story = models.story.get_story(storyID) if story == None: return redirect('/req/projectdetail/' + projectID) if request.method == 'POST': story.delete() if not 'next' in request.POST: return redirect('/req/projectdetail/' + projectID) else: next = request.POST['next'] return redirect(next) else: form = StoryForm(instance=story, project=project) context = { 'title': 'Delete User Story', 'confirm_message': 'This is an irreversible procedure ! You will lose all information about this user story !', 'form': form, 'action': '/req/deletestory/' + projectID + '/' + storyID, 'button_desc': 'Delete 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 index(): ## some intro # a form to create stories form = StoryForm() return render_template('index.html', form=form)
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")