def test_data(request, group_slug, count): project = get_object_or_404(Project, slug=group_slug) admin_access_or_403(project, request.user) count = int(count) story_count = project.stories.all().count() for i in range(count): story = Story(rank=i + story_count, summary="Test story #" + str(story_count + i), local_id=i + story_count, detail="Test story detail data", creator=request.user, points=5, iteration=project.get_default_iteration(), project=project) story.save() return HttpResponse("OK")
def import_story(request, project_slug, queue_id): logger.debug("Adding story from StoryQueue") project = get_object_or_404(Project, slug=project_slug) write_access_or_403(project, request.user) try: story = StoryQueue.objects.get(id=queue_id) except: return HttpResponseRedirect( reverse("story_queue_url", kwargs={'project_slug': project_slug})) if story.project != project: # Shenanigans here! raise PermissionDenied() # TODO (Useability): # What should rank be set at to make the most sense? new_story = Story(project=project, rank=0, local_id=project.getNextId(), summary=story.summary, detail=story.detail, extra_1=story.extra_1, extra_2=story.extra_2, extra_3=story.extra_3, status=story.status, points=story.points, iteration=project.get_default_iteration(), creator=request.user) new_story.save() mapping = ExternalStoryMapping(story=new_story, external_id=story.external_id, external_url=story.external_url, extra_slug=story.extra_slug) mapping.save() request.user.message_set.create(message="Story imported.") story.delete() # delete the story queue object since we just imported it. signals.story_imported.send(sender=request, story=new_story, story_queue=story, user=request.user) return HttpResponseRedirect( reverse("story_queue_url", kwargs={'project_slug': project_slug})) #story_queue(request,project_slug)
def import_stories(request, project_slug): logger.debug("Adding story from StoryQueue") project = get_object_or_404(Project, slug=project_slug) write_access_or_403(project, request.user) queue_ids = str(request.POST.get("stories", "")).split(",") iteration = project.get_default_iteration() count = 0 for queue_id in queue_ids: try: story = StoryQueue.objects.get(id=queue_id) except: continue if story.project != project: # Shenanigans here! raise PermissionDenied() new_story = Story(project=project, rank=0, local_id=project.getNextId(), summary=story.summary, detail=story.detail, extra_1=story.extra_1, extra_2=story.extra_2, extra_3=story.extra_3, status=story.status, points=story.points, iteration=iteration, creator=request.user) new_story.save() logger.debug("Added story %d" % new_story.id) mapping = ExternalStoryMapping(story=new_story, external_id=story.external_id, external_url=story.external_url, extra_slug=story.extra_slug) mapping.save() story.delete( ) # delete the story queue object since we just imported it. signals.story_imported.send(sender=request, story=new_story, story_queue=story, user=request.user) count += 1 return HttpResponse("%d imported" % count)
def _importSingleRow(row, iteration, user): try: local_id = _getFieldFromImportData(row, "Story ID") story = None if local_id != None: try: story = Story.objects.get(project=iteration.project, local_id=int(local_id)) logger.debug("Found story to update (%d)" % int(local_id)) except: # Story didn't exist already, so we'll be making a new one # This is a little dangerous if there was a story id set, since we'll now be ignoring # that and that might not be what the user intended. story = Story(project=iteration.project, iteration=iteration, local_id=iteration.project.getNextId()) story.creator = user logger.debug("Creating new story to import into.") # A user could move rows from one iteration export to another, so set it here. It'll probably be rare to actually happen. story.iteration = iteration headers = _getHeaders(iteration.project) for header in headers: value = _getFieldFromImportData(row, header[1]) if value != None: try: f = header[ 4] # This should be a method capable of setting the property f(story, value) # logger.debug("Setting %s to %s" % (header[1],value) ) except: logger.info("Failed to set %s to %s, ignoring." % (header[1], unicode(value))) story.save() return True except Exception as e: logger.debug("Failed to import a record. %s" % e) return False