Skip to content

Commit

Permalink
Enable Modify story
Browse files Browse the repository at this point in the history
  • Loading branch information
ttx committed Jul 5, 2013
1 parent 23b1afa commit 23553a6
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 11 deletions.
15 changes: 8 additions & 7 deletions stories/templates/stories.view.html
Original file line number Diff line number Diff line change
Expand Up @@ -88,32 +88,33 @@ <h4>{{ story.title }}</h4>
<button class="btn btn-mini" type="submit">Add comment</button>
</form>
</div>
<!-- Modal -->
<!-- Modify Story modal -->
<form method="POST" action="/story/{{story.id}}/edit">{% csrf_token %}
<div id="editstory" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="editStoryLabel" aria-hidden="true">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h3 id="editStoryLabel">Modify story</h3>
</div>
<div class="modal-body">
<label>Title</label>
<input class="input-block-level" type="text" value="{{ story.title }}">
<input class="input-block-level" name="title"
type="text" value="{{ story.title }}">
<label>Description <small>(can use Markdown)</small></label>
<textarea class="input-block-level" rows="9">{{ story.description }}
</textarea>
<textarea class="input-block-level" name="description" rows="9">{{ story.description }}</textarea>
<label>Tags</label>
<div class="input-prepend">
<span class="add-on"><i class="icon-tags"></i></span>
<input class="input-block-level" id="prependedInput" type="text"
<input class="input-block-level" name="tags" id="prependedInput" type="text"
value="{% for tag in story.storytag_set.all %}{{ tag.name }} {% endfor %}">
</span>
</div>
</div>
<div class="modal-footer">
<button class="btn" data-dismiss="modal" aria-hidden="true">Close</button>
<button class="btn btn-primary">Save changes</button>
<input class="btn btn-primary" type="submit" value="Save changes">
</div>
</div>
<!-- Modal -->
<!-- Set priority Modal -->
<form method="POST" action="/story/{{ story.id }}/priority">
<div id="editprio" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="editPriolLabel" aria-hidden="true">
{% csrf_token %}
Expand Down
1 change: 1 addition & 0 deletions stories/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
urlpatterns = patterns('stories.views',
(r'^$', 'dashboard'),
(r'^(\d+)$', 'view'),
(r'^(\d+)/edit$', 'edit_story'),
(r'^(\d+)/comment$', 'comment'),
(r'^(\d+)/priority$', 'set_priority'),
(r'^task/(\d+)$', 'edit_task'),
Expand Down
51 changes: 47 additions & 4 deletions stories/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from django.shortcuts import render
from django.contrib.auth.models import User
from projects.models import Milestone
from stories.models import Story, Task, Comment
from stories.models import Story, Task, Comment, StoryTag

def dashboard(request):
return render(request, "stories.dashboard.html")
Expand Down Expand Up @@ -63,7 +63,7 @@ def edit_task(request, taskid):
try:
actions = []
if (task.title != request.POST['title']):
actions.append("task title")
actions.append("title")
task.title = request.POST['title']
milestone = Milestone.objects.get(id=request.POST['milestone'])
if (milestone != task.milestone):
Expand All @@ -78,7 +78,8 @@ def edit_task(request, taskid):
actions.append("assignee -> %s" % assignee.username)
task.assignee = assignee
if actions:
msg = "Updated " + ", ".join(actions)
msg = "Updated %s/%s task " % (task.project.name, task.series.name)
msg += ", ".join(actions)
task.save()
newcomment = Comment(story=task.story,
action=msg,
Expand All @@ -87,5 +88,47 @@ def edit_task(request, taskid):
content=request.POST.get('comment', ''))
newcomment.save()
except KeyError as e:
print e
pass
return HttpResponseRedirect('/story/%s' % task.story.id)

@login_required
@require_POST
def edit_story(request, storyid):
story = Story.objects.get(id=storyid)
storytags = set(x.name for x in StoryTag.objects.filter(story=story))
onlytags = True
try:
actions = []
if (story.title != request.POST['title']):
onlytags = False
actions.append("title")
story.title = request.POST['title']
if (story.description != request.POST['description']):
onlytags = False
actions.append("description")
story.title = request.POST['title']
proposed_tags = set(request.POST['tags'].split())
print storytags
print proposed_tags
if proposed_tags != storytags:
actions.append("tags")
StoryTag.objects.filter(story=story).delete()
tags = []
for tag in proposed_tags:
tags.append(StoryTag(story=story, name=tag))
StoryTag.objects.bulk_create(tags)
if actions:
msg = "Updated story " + ", ".join(actions)
story.save()
if onlytags:
comment_type = "tags"
else:
comment_type = "align-left"
newcomment = Comment(story=story,
action=msg,
author=request.user,
comment_type=comment_type)
newcomment.save()
except KeyError as e:
print e
return HttpResponseRedirect('/story/%s' % story.id)

0 comments on commit 23553a6

Please sign in to comment.