def HandlePostStoryRequest(request): if request.method == 'POST': authorValue = Author.objects.get(username=request.user) received_json_data = json.loads(request.body.decode("utf-8")) if request.user.is_authenticated: if (received_json_data.get('category') in ['tech', 'pol', 'art', 'trivia']): if (received_json_data.get('region') in ['uk', 'w', 'eu']): row = Story(headline=received_json_data.get('headline'), category=received_json_data.get('category'), auth=authorValue, details=received_json_data.get('details'), region=received_json_data.get('region')) row.save() return HttpResponse("CREATED", status=201, content_type='text/plain') else: return HttpResponse("The region value is invalid", status=503, content_type='text/plain') else: return HttpResponse("The category value is invalid", status=503, content_type='text/plain') else: return HttpResponse("Not authenticated, unable to post story", status=503, content_type='text/plain') else: return HttpResponse(status=405, content_type='text/plain')
def get(self, story_uid=None): """Get a story or a list of a user's stories""" request_args = get_current_request_args() user_uid = request_args.get('user_uid') if user_uid is not None: user = User.get_active(uid=user_uid) if user is None: raise ResourceNotFound('User not found') else: user = get_current_user() if story_uid is not None: story = Story.get_active(uid=story_uid, has_expired=False) if story is None: raise ResourceNotFound('Story not found') return api_success_response(data=story.as_json()) todays_stories = Story.prepare_get_active(user_id=user.id).filter_by( has_expired=False).all() return api_success_response( [story.as_json() for story in todays_stories])
def seite_backlog_post(): data = json.loads(request.form.get("data")) story = Story.query.get(data.get("id")) sprint_id = data.get("sprint_id", "-1") if data.get("to_delete"): if story: db.session.delete(story) db.session.commit() return redirect("/backlog") if not story: story = Story() db.session.add(story) story.titel = data.get("titel") story.beschreibung = data.get("beschreibung") story.sprint = Sprint.query.get(sprint_id) Kriterium.query.filter_by(story=story).delete() for kriterium in data.get("kriterien", []): k = Kriterium() k.beschreibung = kriterium.get("beschreibung") db.session.add(k) story.kriterien.append(k) db.session.commit() return redirect("/backlog")
def newstory(request): if request.user.is_authenticated(): elem= { 'title':'Ny Story', } if request.method=='POST': story_form=StoryForm(request.POST) elem.update({'story_form':story_form,}) if story_form.is_valid(): print story_form.cleaned_data title = request.POST['title'] length = request.POST['length'] if request.POST.get('availability'): availability = request.POST['availability'] else: availability="Public" language=request.POST['language'] category=request.POST['category'] newstory=Story(created=datetime.datetime.now(),creator=request.user,title=title,length=length,availability=availability,language=language,category=category) newstory.save() return HttpResponseRedirect('/home') else: print "invalid story_form" else: story_form=StoryForm() elem.update({'story_form':story_form,}) return render_to_response("newstory.html",elem,context_instance=RequestContext(request)) else: return HttpResponseRedirect("/")
def test_uniformity(self): p = create_project() Story.create(text="As a User, I want to add a user story, so that I document a requirement", project_id=p.id) Story.create(text="As a User, I want to add a user story, so that I document another requirement", project_id=p.id) story = Story.create(text="As a User, I am able to add a user story, so that I register a requirement", project_id=p.id) p.analyze() defect = story.defects.filter(Defect.subkind=='uniform')[0] assert defect.kind == 'uniform' assert defect.severity == 'medium'
def test_identical(self): p = create_project() story = Story.create(text="As a User, I want to add a user story, so that I document a requirement and sell the system", project_id=p.id) story2 = Story.create(text="As a User, I want to add a user story, so that I document a requirement and sell the system", project_id=p.id) p.analyze() defect1 = story.defects.filter(Defect.subkind=='identical')[0] defect2 = story2.defects.filter(Defect.subkind=='identical')[0] assert defect1.kind == defect2.kind == 'unique' assert defect1.subkind == defect2.subkind == 'identical' assert defect1.severity == defect2.severity == 'high'
def write_story(request): context_dict = {} # Check if the request is of type post if request.method == 'POST': # Get the data in required format data = { 'hospital': Hospital.objects.get(pk=request.user.id), 'date': request.POST.get("time"), 'story': request.POST.get("story"), 'heading': request.POST.get("heading"), 'likes': 0 } # Handle image import if request.FILES.get("file") is not None: image = request.FILES["file"] fs = FileSystemStorage() filename = fs.save(image.name, image) uploaded_file_url = filename data = { 'hospital': Hospital.objects.get(pk=request.user.id), 'date': request.POST.get("time"), 'story': request.POST.get("story"), 'heading': request.POST.get("heading"), 'picture': uploaded_file_url, 'likes': 0 } # Try to create a new story try: story = Story() story.new_story(data) return JsonResponse({ 'success': True, 'message': "The review has been succesfully published!" }) except: return JsonResponse({ 'success': False, 'message': "The provided login details are incorrect!" }) else: return redirect("app:app")
def write(): if request.method == 'POST': token = request.headers['token'] uid = request.get_json().get('uid') user = User.query.filter_by(id=uid).first() if user.confirm(token): story = request.get_json().get('story') user.userwords += len(story) keyword1 = request.get_json().get('keyword') c = '&' keyword = '' for key in keyword1: a = keyword1[key] keyword += (a + c) likenum = 0 user.usb += 1 user.usa += 1 story1 = Story(story = story, user_id = uid, likenum = likenum, keywords = keyword) db.session.add(story1,user) db.session.commit() return jsonify({ "storyid":story1.id }),200
def new_story(): if(session and session['logged_in']): if request.method == 'POST': story = Story(genre_id = request.form.get('genre_id'), country_id = request.form.get('country_id'), storytype_id = request.form.get('storytype_id'), media_topic = request.form.get('media_topic'), media_text = request.form.get('media_text'), media_desc = request.form.get('media_desc'), hidden = request.form.get('hidden') != None, owner = session['username'], create_time = utils.get_now(), lang_id = 2) db.session.add(story) db.session.commit() flash("New story created") return redirect(url_for("home")) else: my_uploads = db.session.query(Uploads).filter(Uploads.user_id==session['user_id']).order_by(Uploads.create_time.desc()) blobs = [] for blob in my_uploads: blobs.append(blob) return render_template("user/new_story.html", blobs=blobs) else: flash("Please login first") return redirect(url_for("home"))
def add_stories(self): """ Adds stories to the database :return: """ authors = open("app/utils/authors.json", "r") stories = open("app/utils/stories.json", "r") with stories as story_data: loaded_stories = json.load(story_data) with authors as author_data: loaded_authors = json.load(author_data) author_story = list(zip(loaded_authors, loaded_stories)) for au_st in author_story: author = AuthorAccount(first_name=au_st[0]["first_name"], last_name=au_st[0]["last_name"], email=au_st[0]["email"], username=au_st[0]["username"], password=au_st[0]["password"], registered_on=datetime.now()) story = Story(title=au_st[1]["title"], tagline=au_st[1]["tagline"], category=au_st[1]["category"], content=au_st[1]["content"], author_id=author.id) db.session.add(author) db.session.add(story) db.session.commit()
def write(): if request.method == 'POST': token = request.headers['token'] uid = request.get_json().get('uid') user = User.query.filter_by(id=uid).first() if user.confirm(token): user.usb = int(user.usb) + 1 title = request.get_json().get('title') storyckeyword = request.get_json().get('storyckeyword') storyc = request.get_json().get('storyc') storykeyword = storyckeyword story = Story(title = title, likenum = 0, keywords = storykeyword, user_id = uid) db.session.add(story) db.session.commit() storyc = Storyc(storyc = storyc, likenum = 0, storyckeyword = storyckeyword, story_id = story.id, user_id = uid) db.session.add(storyc) db.session.commit() return jsonify({ "storyid":story.id }),200 else: return jsonify({}),403
def write(): if request.method == 'POST': token = request.headers['token'] uid = request.get_json().get('uid') user = User.query.filter_by(id=uid).first() if user.confirm(token): user.usb = int(user.usb) + 1 title = request.get_json().get('title') storyckeyword = request.get_json().get('storyckeyword') storyc = request.get_json().get('storyc') storykeyword = storyckeyword localtime = time.strftime('%Y-%m-%d %a %H:%M:%S', time.localtime(time.time())) story = Story(title=title, likenum=0, floors=1, time=localtime, keywords=storykeyword, user_id=uid) db.session.add(story) db.session.commit() storyc = Storyc(storyc=storyc, likenum=0, storyckeyword=storyckeyword, time=localtime, story_id=story.id, user_id=uid) db.session.add(storyc) db.session.commit() return jsonify({"storyid": story.id, "time": localtime}), 200 else: return jsonify({}), 403
def seite_sprint_post(sprint_id): db.session.autoflush = False sprint = Sprint.query.get_or_404(sprint_id) sprint.start = request.form.get("start") sprint.ende = request.form.get("ende") sprint.ziel = request.form.get("ziel") for story_data in json.loads(request.form.get("data")): story = Story.query.get(story_data.get("id")) if story_data.get("to_delete"): if story: db.session.delete(story) continue if not story: story = Story(sprint=sprint) db.session.add(story) story.titel = story_data.get("titel") story.beschreibung = story_data.get("beschreibung") for task_data in story_data.get("tasks", []): task = Task.query.get(task_data.get("id")) if task and task_data.get("delete", False): db.session.delete(task) continue if not task: task = Task() task.story = story task.name = task_data.get("name") task.user = User.query.get(task_data.get("user_id")) neuer_status = task_data.get("status") if task.status != neuer_status and neuer_status == 2: task._fertig_datum = datetime.now() task.status = neuer_status story.tasks.append(task) db.session.add(task) db.session.commit() return redirect(f"/sprints/{sprint_id}")
def seed_stories(): demo = Story(title='Title Demo', body='This is a Body Demo', author_id=User.query.filter_by(username='******').first().id) demo2 = Story(title="This is Bob's story", body="This story is awesome", author_id=User.query.filter_by(username='******').first().id) demo3 = Story(title='Who wrote this one?', body='This story is written by no one', author_id=User.query.filter_by(username='******').first().id) db.session.add(demo) db.session.add(demo2) db.session.add(demo3) db.session.commit()
def test_punctuation(self): p = create_project() story = Story.create(text="As a User, I want to add a user story, so that I document a requirement and sell the system. This is extra info", project_id=p.id) p.analyze() defect = story.defects.filter(Defect.subkind=='punctuation')[0] assert defect.kind == 'minimal' assert defect.subkind == 'punctuation' assert defect.severity == 'high'
def index(): form = OrderForm() print(form) if request.method == 'POST': buyer = Buyer( first_name=form.first_name.data, last_name=form.last_name.data, email=form.email.data, address_1=form.address_1.data, address_2=form.address_2.data, city=form.city.data, country=form.country.data, postal_code=form.postal_code.data, state=form.state.data, ) db.session.add(buyer) db.session.commit() story = Story( nickname=form.nickname.data, nickname_gender=form.nickname_gender.data, location=form.location.data, dog=form.dog.data, friend=form.friend.data, friend_gender=form.friend_gender.data, cake=form.cake.data, cake_gender=form.cake_gender.data, body=form.body.data, author=Buyer.query.filter_by(email=form.email.data).first_or_404()) story.link_album() db.session.add(story) db.session.commit() db_to_sheet( "buyer", 'sqlite:///app.db', #current_app.config["SQLALCHEMY_DATABASE_URI"], SHEET_REFERENCE, BUYER_TAB_NAME, ) db_to_sheet( "story", 'sqlite:///app.db', #current_app.config["SQLALCHEMY_DATABASE_URI"], SHEET_REFERENCE, STORY_TAB_NAME, ) flash(_('Votre commande a bien été enregistrée')) return redirect(url_for('main.index')) return render_template('index.html', form=form)
def test_brackets(self): p = create_project() story = Story.create(text="As a User, I want to add a user story, so that I document a requirement and sell the system (for money)", project_id=p.id) p.analyze() defect = story.defects.filter(Defect.subkind=='brackets')[0] assert defect.kind == 'minimal' assert defect.subkind == 'brackets' assert defect.severity == 'medium'
def test_not_atomic(self): p = create_project() story = Story.create(text="As a User, I want to add a user story, so that I document a requirement and sell the system", project_id=p.id) p.analyze() defect = story.defects.filter(Defect.subkind=='conjunctions')[0] assert defect.kind == 'atomic' assert defect.subkind == 'conjunctions' assert defect.severity == 'high'
def test_no_role(self): p = create_project() story = Story.create(text="User wants to add a user story, so that I document a requirement", project_id=p.id) p.analyze() defect = story.defects.filter(Defect.subkind=='no_role')[0] assert defect.kind == 'well_formed' assert defect.subkind == 'no_role' assert defect.severity == 'high' assert defect.highlight == "Add a role"
def generate(self): """Creates story by adding scenes to pages until the end is reached. Story added to MongoDB instance and the UUID of the story is returned to the caller""" pages = [] self.characters[1] = self.locations[1].character # load next non-user character pages.append(Pages(page=self.story_index, sentences=[self.realise(self.aggregation(['opening', 'intro'])), self.realise(self.phrase('quest'))])) self.story_index += 1 while not self.end: pages.append(Pages(page=self.story_index, sentences=self.scene())) self.add_location() self.story_index += 1 pages.append(Pages(page=self.story_index, sentences=[self.realise(self.phrase("end")), "And they all lived happily ever after.", "The end."])) story = Story(title=self.title, author=self.author, pages=pages) story.save() return story.id
def test_no_comma(self): p = create_project() story = Story.create(text="As a User I want to add a user story so that I document a requirement", project_id=p.id) p.analyze() defect = story.defects.all()[0] assert defect.kind == 'well_formed' assert defect.subkind == 'no_comma' assert defect.severity == 'medium' assert defect.highlight == "As a User<span class='highlight-text'>,</span> I want to add a user story"
def postStory(request, format=None): storyJ = json.loads(json.dumps(request.data)) print(storyJ) with transaction.atomic(): story = Story(title=storyJ["title"], creator=request.user) story.save() for p in storyJ["pieces"]: if p == None: continue pType = p["type"] del p["type"] p["story"] = story.pk if pType == 0: piece = Piece() seriaP = PieceSerializer(piece, data=p) seriaP.is_valid(raise_exception=True) seriaP.save() elif pType == 1: piece = DecisionPiece() choices = p["choices"] del p["choices"] print(p) seriaD = DecisionSerializer(piece, data=p) seriaD.is_valid(raise_exception=True) seriaD.save() for c in choices: print(c) choice = ChoicePiece(story=story, decision=piece) seriaC = ChoiceSerializer(choice, data=c) seriaC.is_valid(raise_exception=True) seriaC.save() elif pType == 2: piece = LosePiece() seriaP = LoseSerializer(piece, data=p) seriaP.is_valid(raise_exception=True) seriaP.save() elif pType == 3: piece = WinPiece() seriaP = WinSerializer(piece, data=p) seriaP.is_valid(raise_exception=True) seriaP.save() return HttpResponse(status=201)
def newstory(request): if request.user.is_authenticated(): elem = { 'title': 'Ny Story', } if request.method == 'POST': story_form = StoryForm(request.POST) elem.update({ 'story_form': story_form, }) if story_form.is_valid(): print story_form.cleaned_data title = request.POST['title'] length = request.POST['length'] if request.POST.get('availability'): availability = request.POST['availability'] else: availability = "Public" language = request.POST['language'] category = request.POST['category'] newstory = Story(created=datetime.datetime.now(), creator=request.user, title=title, length=length, availability=availability, language=language, category=category) newstory.save() return HttpResponseRedirect('/home') else: print "invalid story_form" else: story_form = StoryForm() elem.update({ 'story_form': story_form, }) return render_to_response("newstory.html", elem, context_instance=RequestContext(request)) else: return HttpResponseRedirect("/")
def story(): story1 = Story(title='Elephone1', imgurl='elephone1.jpg', location='AAA', description='daassdfsdfkjfksljfklsjfljsdlfjsd', author='Tim', hitnumber=0, available=True) story2 = Story(title='Montain1', imgurl='images_11.jpg', location='BBB', description='dsfdfdaaskjfksljfklsjfljsdlfjsd', author='Grace', hitnumber=0, available=True) story3 = Story(title='Sea1', imgurl='images1.jpg', location='CCC', description='13232daaskjfksljfklsjfljsdlfjsd', author='Tony', hitnumber=3, available=True) story4 = Story(title='Sea2', imgurl='images2.jpg', location='CCC', description='13232daaskjfksljfklsjfljsdlfjsd', author='Tony', hitnumber=2, available=True) story5 = Story(title='Sea3', imgurl='images3.jpg', location='CCC', description='13232daaskjfksljfklsjfljsdlfjsd', author='Tony', hitnumber=1, available=True) db.session.add(story1) db.session.add(story2) db.session.add(story3) db.session.add(story4) db.session.add(story5) db.session.commit()
def delete(self, story_uid): """Delete a slide from a user's story""" story = Story.get_active(uid=story_uid) if story is None: raise ResourceNotFound('Story not found') if story.user != get_current_user(): raise UnauthorizedError() story.delete() return api_deleted_response()
def add_story(): title = request.json['title'] body = request.json['body'] author_id = User.query.filter_by( username=request.json['author']).first().id new_story = Story(title, body, author_id) db.session.add(new_story) db.session.commit() return {"id": new_story.id}
def create_authors(): """ creates dummy users and stories for this model test cases :return: new """ author1 = AuthorAccount(first_name="test11", last_name="hadithi11", username="******", email="*****@*****.**", password="******", registered_on=datetime.now()) author2 = AuthorAccount(first_name="test22", last_name="hadithi22", username="******", email="*****@*****.**", password="******", registered_on=datetime.now()) db.session.add(author1) db.session.add(author2) db.session.commit() story1 = Story(title="Some random story", tagline="Dark city catches fire", category="Fiction", content="", author_id=author1.id) story2 = Story(title="Anther Random story", tagline="Dark city catches fire", category="Fiction", content="", author_id=author2.id) db.session.add(story1) db.session.add(story2) db.session.commit() return author1, author2
def add_story(self): author = self.create_author_account() story = Story.query.filter_by(author_id=author.id).first() if story is None: try: story = Story(title="Gotham in flames", tagline="Dark city catches fire", content="", author_id=author.id) db.session.add(story) except IntegrityError as e: print(e) db.session.rollback() return story
def create_story(): data = request.json story = Story(title=data["newStoryTitle"], tier=data["tier"], author_id=data["author_id"], created_at=datetime.now()) db.session.add(story) db.session.commit() db.session.flush() micro_story = Micro_Story(title=data["microStoryTitle"], part=1, content=data["content"], story_id=story.id, format_id=1) db.session.add(micro_story) db.session.commit() return {'Message': 'Success!', "storyId": story.id}
def add_story(self): """ Adds a dummy story to the database :return: """ author1, author2, author3, author4 = self.create_author_accounts() story = Story.query.filter_by(author_id=author1.id).first() if story is None: try: story = Story(title="Gotham in flames", tagline="Dark city catches fire", category="Fiction", content="", author_id=author1.id) db.session.add(story) except IntegrityError as e: print(e) db.session.rollback() return story
def write_story(username): """ Allows Author to write a new story :return new story template """ story_form = StoryForm(request.form) user = current_user if request.method == "POST": if story_form.validate_on_submit(): story = Story(title=story_form.story_title.data, tagline=story_form.tagline.data, category=story_form.category.data, content=story_form.content.data, author_id=user.id) db.session.add(story) db.session.commit() return redirect( url_for('dashboard.user_dashboard', username=user.full_name)) return render_template("dashboard.new_story.html", user=user, story_form=story_form)
def addStory(updateDat): assert 'story' in updateDat story = updateDat['story'] assert 'name' in story assert 'auth' in story assert 'fname' in story assert 'file' in story assert 'desc' in story assert 'tags' in story data = DataURI(story['file']) dathash = getHash(data.data).lower() have = Story.query.filter(Story.hash == dathash).scalar() if have: # print("Have file already!") return getResponse( "A file with that MD5 hash already exists! Are you accidentally adding a duplicate?", True) have = Story.query.filter(Story.title == story['name']).scalar() if have: orig_name = story['name'] loop = 2 while have: print("Have story with that name ('%s')!" % story['name']) story['name'] = orig_name + " (%s)" % loop have = Story.query.filter(Story.title == story['name']).scalar() loop += 1 print("Story added with number in name: '%s'" % story['name']) if len(story['name']) > 80: return getResponse("Maximum story title length is 80 characters!", True) if len(story['name']) < 3: return getResponse("Minimum story title length is 3 characters!", True) if len(story['auth']) < 5: return getResponse("Minimum story author name length is 5 characters!", True) if len(story['auth']) > 60: return getResponse( "Maximum story author name length is 60 characters!", True) if len(story['desc']) < 30: return getResponse( "Minimum story description length is 30 characters!", True) if len(story['desc']) > 500: return getResponse( "Maximum story description length is 500 characters!", True) fspath = saveFile(data.data, story['fname']) stags = ["-".join(itm_tags.split(" ")) for itm_tags in story['tags']] stags = [bleach.clean(tag, tags=[], strip=True) for tag in stags] # print("Author: ", story['auth']) # print("stags: ", story['tags']) # print("stags: ", stags) post_date = datetime.datetime.now() if 'ul_date' in story and isinstance(story['ul_date'], datetime.datetime): post_date = story['ul_date'] new = Story( title=bleach.clean(story['name'], tags=[], strip=True), srcfname=story['fname'], description=markdown.markdown(bleach.clean(story['desc'], strip=True)), fspath=fspath, hash=dathash, # author = [story['auth']], # tags = stags, pub_date=post_date) [new.tags.append(Tags(tag=tag)) for tag in stags] new.author.append( Author(name=bleach.clean(story['auth'], tags=[], strip=True))) db.session.add(new) db.session.commit() flash('Your story has been added! Thanks for posting your content!') return getResponse("Story added", error=False)
def create_story(project_id): s = Story.create(text="As a User, I want to add a user story, so that I document a requirement", project_id=project_id) return s
def test_role_means_ends_chunks(self): p = create_project() s = Story.create(text="As a User, I want to add a user story, so that I document a requirement", project_id=p.id) assert s.role == "As a User," assert s.means == "I want to add a user story," assert s.ends == "so that I document a requirement"
def test_well_formed(self): p = create_project() s = Story.create(text="As a User, I'm able to add a user story, so that I document a requirement", project_id=p.id) s.analyze() assert len(s.defects.all()) == 0