Example #1
0
def new_discussion(title, text, current_user_id=None, topic=None):
    disc_id = idgen_client.get()
    post_id = idgen_client.get()

    slug = slugify(title)

    d = Discussion()
    d.id = disc_id
    d.post_id = post_id
    d.message_count = 1
    d.user_id = current_user_id
    d.title = title
    d.user_count = 1
    d.topic_id = topic_slug_to_id(topic) if topic is not None else 0
    d.users = {current_user_id}
    d.slug = slug

    d.save()

    disc_counter = DiscussionCounter(id=disc_id)
    disc_counter.message_count = 1
    disc_counter.user_count = 1
    disc_counter.view_count = 1
    disc_counter.save()

    UserDiscussion.create(user_id=current_user_id, discussion_id=d.id)

    new_post(text, code='', current_user_id=current_user_id, post_id=post_id)

    return disc_id, slug
Example #2
0
 def follow_user(cls, user, following):
     """A user followed another user"""
     following_id = following
     create_story(id=idgen_client.get(),
                  actor=user.id,
                  type=StoryTypes.FOLLOW,
                  target=following_id)
Example #3
0
 def discussion(cls, user, discussion):
     """A User started a discussion"""
     discussion_id = discussion
     create_story(id=idgen_client.get(),
                  actor=user.id,
                  type=StoryTypes.DISCUSS,
                  target=discussion_id)
Example #4
0
 def up_vote(cls, user, message):
     """A User up-voted a message(or discussion)"""
     message_id = message
     user_id = user
     create_story(id=idgen_client.get(),
                  actor=user_id,
                  type=StoryTypes.UP_VOTE,
                  target=message_id)
     pass
Example #5
0
def new_post(text,
             code=None,
             current_user_id=None,
             post_id=None,
             nick=None,
             reply_to_id=None):
    logging.warn("Post is=>{}".format(post_id))

    html = markdown_to_html(text)

    message = Post()
    message.id = post_id or idgen_client.get()
    message.text = text
    message.html = html
    message.user_id = current_user_id
    message.user_nick = nick
    message.reply_to_id = reply_to_id
    message.save()

    if reply_to_id is not None:
        PostReply.create(reply_post_id=message.id, post_id=reply_to_id)

    Event.message(current_user_id, message.id, None, reply_to_id=None)
Example #6
0
def new_discussion_message(discussion_id, text, current_user_id, nick=''):
    logging.warn("DSCSS:[{}]USER:[{}]".format(discussion_id, current_user_id))
    discussion = Discussion.objects.get(id=discussion_id)

    p = Post()
    p.id = idgen_client.get()
    p.discussion_id = discussion_id
    p.text = text
    p.html = markdown_to_html(text)
    p.user_id = current_user_id
    p.user_nick = nick
    ## Create an entry in the timeline to say that this user
    # has created a post in the given discussion
    # Event.new_post_message

    p.save()

    Event.message(current_user_id, p.id, None)

    # FIXME: Move all this part to the JOB WORKER! Speed my friend.

    discussion.last_message = p.id
    discussion.users.union({current_user_id})
    discussion.save()

    UserDiscussion.create(user_id=current_user_id, discussion_id=discussion_id)

    dp = DiscussionPost.create(disc_id=discussion_id,
                               post_id=p.id,
                               user_id=current_user_id)
    dp.save()

    disc_counter = DiscussionCounter(id=discussion_id)
    disc_counter.message_count += 1
    disc_counter.save()

    return p.id
Example #7
0
 def new_user(cls, user):
     """A user is registered"""
     Story.create(id=idgen_client.get(),
                  actor=user.id,
                  type=StoryTypes.JOIN)
     pass
Example #8
0
 def follow_project(cls, user, project):
     """A user started to follow a project"""
     create_story(id=idgen_client.get(),
                  actor=user.id,
                  type=StoryTypes.STAR,
                  target=project)
Example #9
0
def before_inventory_source_insert(mapper, connection, target):
    target.id = idgen_client.get()
Example #10
0
def before_inventory_source_insert(mapper, connection, target):
    target.id = idgen_client.get()
Example #11
0
def generate():
    return str(idgen_client.get())