예제 #1
0
def update_story(event):
    nest_id = event["arguments"].pop('nestId')
    story_id = event["arguments"].pop('storyId')
    story = Story.get(nest_id, f"STORY.{story_id}")

    # handle comments first because they don't line up with model
    if event["arguments"].get('comment'):
        comment = Comment(
            username=(event["identity"] or {}).get("username", ""),
            content=event["arguments"].pop('comment'),
            createdAt=datetime.now().replace(tzinfo=dateutil.tz.gettz()),
        )
        story.comments.insert(0, comment)

    dateToBeCompleted = event["arguments"].get("dateToBeCompleted")

    # Parse string to datetime obj
    if dateToBeCompleted:
        event["arguments"]["dateToBeCompleted"] = datetime.strptime(
            dateToBeCompleted, '%Y-%m-%d')

    # Set parameters
    for arg, value in event["arguments"].items():
        if value:
            setattr(story, arg, value)

    story.save()

    return Nest.get(nest_id,
                    "NEST").to_dict()  # Return Nest for UI simplification
예제 #2
0
def delete_story(event):
    nest_id = event["arguments"].pop('nestId')
    story_id = event["arguments"].pop('storyId')

    story = Story.get(nest_id, f"STORY.{story_id}")
    story.delete()

    return Nest.get(nest_id,
                    "NEST").to_dict()  # Return Nest for UI simplification
예제 #3
0
def add_story_attachment(event):
    # get story so we know it exists first
    story = Story.get(event["arguments"]["nestId"],
                      f"STORY.{event['arguments']['storyId']}")
    new_attachment = Attachment(name=event["arguments"]["name"],
                                key=event["arguments"]["key"])
    story.attachments.append(new_attachment)
    story.save()

    return story.to_dict()
예제 #4
0
def add_comment(event):
    # get story so we know it exists first
    story = Story.get(event["arguments"]["nestId"],
                      f"STORY.{event['arguments']['storyId']}")

    comment_data = event["arguments"].pop('comment')

    comment = Comment(
        username=(event["identity"] or {}).get("username", ""),
        content=comment_data,
        createdAt=datetime.now().replace(tzinfo=dateutil.tz.gettz()),
    )

    story.comments.insert(0, comment)
    story.save()

    return story.to_dict()
예제 #5
0
def delete_story_attachment(event):
    # get story so we know it exists first
    story = Story.get(event["arguments"]["nestId"],
                      f"STORY.{event['arguments']['storyId']}")
    attachment_key = event["arguments"]["key"]

    attachments = story.attachments

    for i, attachment in enumerate(attachments):
        if attachment["key"] == attachment_key:
            attachments.pop(i)
            break

    story.attachments = attachments
    story.save()

    return story.to_dict()