Example #1
0
def story(request):
    if request.method == 'POST':
        form = StoryForm(request.POST)
        if form.is_valid():
            form.save()
            return HttpResponseRedirect("/")
    else:
        form = StoryForm()
    return render(request, "stories/story.html", {"form": form})
Example #2
0
def stories_create(request):
    if request.method == 'POST':
        story_form = StoryForm(request.POST)
        # storytag_form = StoryTagForm(request.POST)
        if story_form.is_valid():
            story_post = story_form.save(commit=False)
            story_post.author = request.user
            story_post.save()
            tag_ids = request.POST.get('tags').split(',')
            print(tag_ids)
            for tag_id in tag_ids:
                story_tag = StoryTag(tag_id=tag_id, story_id=story_post.id)
                story_tag.save()
            messages.success(request,
                             f'Your story has been added!',
                             extra_tags='success')
            return redirect('stories-home')
        else:
            messages.error(request,
                           f'Something went wrong!',
                           extra_tags='danger')
    else:
        story_form = StoryForm()
        context = {
            'story_form': story_form,
        }
    return render(request, 'stories/story_create.html', context)
Example #3
0
def stories_detailview(request, story_id):
    if request.method == 'POST':


        form = StoryForm(request.POST)
        if form.is_valid():
            form.instance.sahip = request.user
            form.instance.evebeyn_id = story_id
            form.save()
    elif request.method == 'GET':
        form = StoryForm()
    return render(request, 'stories_detail.html',
                  {
                      'object': hikaye.objects.get(pk=story_id),
                      'form': form
                  })
Example #4
0
def add_story(request):
    if request.method == 'POST':
        project_id = request.POST.get('project', None)
        story = Story(accepted=True)
        story.order = Story.objects.filter(project=project_id).count()+1
        form = StoryForm(request.POST, instance=story)
        if form.is_valid():
            form.save()
            return redirect('project_page', project_id=project_id )
        else:
            request.session['error'] = {
                'ref':'add_error',
                'name':request.POST.get('name', ''),
                'time':request.POST.get('time', ''),
                'user':request.POST.get('user', ''),
            }
            return redirect('project_page', project_id=project_id)
    else:
        raise Http404
Example #5
0
    def test_save(self):
        # If we edit an existing form, can we re-save it without change?
        story = mommy.make(Story, text='Nothing')

        form = StoryForm(user=story.author.user, instance=story)
        # This is a hack to get the data=request.POST dict for save checking
        form = StoryForm(data=form.initial,
                         user=story.author.user,
                         instance=story)

        saved = form.save()
        for field in Story._meta.fields:
            name = field.name
            self.assertEqual(getattr(saved, name), getattr(story, name))

        # If we create a new story with the form, does it save as expected
        form = StoryForm(data={
            'title': 'This is the title',
            'author': story.author.id,
            'text': 'This is the text',
            'inspired_by': story.id,
            'private': True
        },
                         user=story.author.user)
        saved = form.save()
        self.assertEqual(saved.inspired_by.id,
                         story.id)  # Should be inspired by story
        self.assertIsNone(saved.published_at)
        self.assertIsNotNone(saved.id)

        # Save a new story without an inspired_by field
        form = StoryForm(data={
            'title': 'This is the title',
            'author': story.author.id,
            'text': 'This is the text',
            'private': False
        },
                         user=story.author.user)
        saved = form.save()
        self.assertIsNone(saved.inspired_by)  # Not inspired by anything
        self.assertIsNotNone(saved.published_at)  # And published
        self.assertIsNotNone(saved.id)
Example #6
0
def story(request):
    if request.method == 'POST':
        form = StoryForm(request.POST)
        if form.is_valid():
            story = form.save(commit=False)
            story.moderator = request.user
            story.save()
            return HttpResponseRedirect('/')
    else:
        form = StoryForm()
    return render(request, 'stories/story.html', {'form': form})
Example #7
0
def story(request):
	if request.method == 'POST':
		form = StoryForm(request.POST)
		if form.is_valid():
			story = form.save(commit = False)
			story.moderator = request.user
			story.save()
			return HttpResponseRedirect('/')
	else:
		form = StoryForm()
	return render(request, 'stories/story.html', {'form': form})
Example #8
0
def story(request):
	if request.method == 'POST':				# ako forma nije prazna
	 	form = StoryForm(request.POST)
	 	if form.is_valid():						# ako forma nije cijela ispunjena
	 		story = form.save(commit=False)		# snimi u "clipboard", ali nemoj još snimiti
	 		story.moderator = request.user		# ovo radimo zato što moderator je NOT_NULL
	 		story.save()						# snimi
	 		return HttpResponseRedirect('/')	# vrati na početnu stranicu
	else:
		form = StoryForm()						# forma je prazna

	return render(request, 'stories/story.html', {'form': form})
Example #9
0
def story(request):
	if request.method == "POST":
		form = StoryForm(request.POST)
		if form.is_valid():
			story = form.save(commit=False)
			story.moderator = request.user
			story.save()
			return HttpResponseRedirect('/post/%s/' % (story.id))
	else:
		form = StoryForm()

	return render(request, 'tidder/story.html', {'form': form})
Example #10
0
def story(request):
    if request.method == 'POST':
        #call the class constructor and pass a dict. In this case StoryForm is the constructor. The dict is the form name and form dict.
        form = StoryForm(request.POST)
        if form.is_valid():
            story = form.save(commit=False)
            story.moderator = request.user
            story.save()
            return HttpResponseRedirect('/')
    else:
        form = StoryForm()
    return render(request, 'stories/story.html', {'form': form})
Example #11
0
def edit_story(request):
    if request.method == 'POST':
        edit_id = request.POST.get('id', 0)
        try:
            story = Story.objects.get(id=edit_id)
        except Story.DoesNotExist:
            raise Http404
        form = StoryForm(request.POST, instance=story)
        if form.is_valid():
            form.save()
            return redirect('project_page', project_id=story.project_id)
        else:
            request.session['error'] = {
                'ref':'edit_error',
                'id':request.POST.get('id', ''),
                'name':request.POST.get('name', ''),
                'time':request.POST.get('time', ''),
                'user':request.POST.get('user', ''),
            }
            return redirect('project_page', project_id=request.POST['project'])
    else:
        raise Http404
Example #12
0
def story(request):
	# Check to see if the form has been posted or not
	if request.method == 'POST':
		# Create a bound form object by passing the posted data through. 
		form = StoryForm(request.POST)
		if form.is_valid():
			story = form.save(commit=False)
			story.moderator = request.user
			story.save()
			return HttpResponseRedirect('/')
	else :
		# Otherwise just create an unbound form - creates the HTML for the form and sends that back
		form = StoryForm()
	return render(request, 'stories/story.html', {'form': form})
Example #13
0
def story(request):
	if request.method == "POST":
		form = StoryForm(request.POST)
		if form.is_valid():
			#Get object back
			story = form.save(commit=False)
			story.moderator = request.user
			#Now save to DB
			story.save()
			return HttpResponseRedirect("/")
	else:
		form = StoryForm()

	return render(request, "stories/story.html", {"form": form})
Example #14
0
def add_story(request):
    if request.method == 'POST':
        form = StoryForm(data=request.POST, files=request.FILES)
        current_category = Categories.objects.filter(category='Story')
        if form.is_valid():
            pending_form = form.save(commit=False)
            pending_form.author = request.user
            pending_form.categoryid = current_category[0]
            pending_form.save()
            # return redirect('stories:list_stories')
            return redirect(pending_form.get_absolute_url())
    else:
        form = StoryForm()
        return render(request,
                      'stories/add_story.html',
                      {'form': form})
Example #15
0
def add_story(request):
    """
    Create a new Story for the user
    """
    if request.method == 'POST':
        form = StoryForm(request.POST)
        if form.is_valid():
            story = form.save()
            return HttpResponseRedirect(reverse('stories_edit_story',args=[story.id]))
        else:
            print form.errors
    else:
        form = StoryForm()

    return render_to_response(
                'stories/add_story.html',
                locals(),
                context_instance=RequestContext(request))
Example #16
0
def stories_edit(request, pk):
    story = get_object_or_404(Story, pk=pk)
    if request.method == "POST":
        story_form = StoryForm(request.POST, instance=story)
        if story_form.is_valid():
            story_post = story_form.save()
            # story_post.author = request.user
            # story_post.save()
            messages.success(request,
                             f'Your story has been updated!',
                             extra_tags='success')
            return redirect('stories-detail', pk=story_post.pk)
        else:
            messages.error(request,
                           f'Something went wrong!',
                           extra_tags='danger')
    else:
        story_form = StoryForm(instance=story)
    return render(request, 'stories/story_edit.html',
                  {'story_form': story_form})
Example #17
0
def submit(request):
    genres = Genres.objects.all()
    if request.method == "POST":  # If the form has been submitted...
        form = StoryForm(request.POST)  # A form bound to the POST data
        if form.is_valid():  # All validation rules pass
            story = form.save(commit=False)
            story.user = request.user
            # genre = Genres.objects.get(pk=form['genre'])
            # genre.story_count += 1
            # genre.save()
            global STORYID
            STORYID += 1
            story.id = STORYID
            story.save()
            response = {"result": "true"}

            return HttpResponse(simplejson.dumps(response), mimetype="application/json")
    else:
        form = StoryForm()
        return render_to_response(
            "stories/submit.html", {"form": form, "genres": genres}, context_instance=RequestContext(request)
        )