Exemplo n.º 1
0
def generate_comment(userid, sequence_id, message='This is a test comment'):
    com = Comment()
    com.Message = message
    com.UserID = userid
    com.ParentID = sequence_id
    com.Type = 'Sequences'
    com.save()
Exemplo n.º 2
0
def create_attachment():
    data = request.form
    image = request.files['file']
    name = image.filename
    contenttype = image.content_type
    image = image.stream.read()
    parentid = data['ParentID']
    type = data['Type']

    comment = Comment(ParentID=parentid,
                      Type=type,
                      Message="",
                      RenderType='attachment',
                      UserID=g.user.UserID)
    comment.save()

    print comment.CommentID

    attachment = SequenceAttachment(Attachment=image,
                                    ParentID=comment.CommentID,
                                    Type='comments',
                                    FileName=name,
                                    ContentType=contenttype)
    attachment.save()

    comment.Message = json.dumps({
        "url":
        "/comment/%s/attachment/%s/" %
        (comment.CommentID, attachment.SequenceAttachmentID),
        "name":
        name
    })
    comment.save()

    if comment.Type == 'Forums':
        forum = Forum.query.filter(Forum.ForumID == comment.ParentID).first()
        if forum and forum.SFDC_ID:
            attachment.create_case_attachment(forum.SFDC_ID)

    print comment.CommentID
    resp = comment.to_hash()
    resp = json.dumps(resp)

    return Response(resp, content_type='application/json')
Exemplo n.º 3
0
def generate_issue(user,
                   subject,
                   subtitle,
                   message,
                   num_images,
                   num_attachments,
                   color,
                   sfdc_data=None):
    forum = Forum(Subject=subject,
                  AccountID=user.AccountID,
                  UserID=user.UserID,
                  Color=color,
                  Subtitle=subtitle,
                  Type='Issue')
    forum.save(sfdc_data)

    for image_id in xrange(num_images):
        img = request.files['image%s' % image_id]
        image = img.read()
        file_name = str(img.filename)
        comment = Comment(ParentID=forum.ForumID,
                          Type='Forums',
                          Message="",
                          RenderType='image',
                          UserID=user.UserID)
        comment.save()
        attachment = SequenceAttachment(Attachment=image,
                                        ParentID=comment.CommentID,
                                        Type='comments',
                                        FileName=file_name)
        attachment.save()

    for image_id in xrange(num_attachments):
        img = request.files['attachment%s' % image_id]
        image = img.read()
        file_name = str(img.filename)
        comment = Comment(ParentID=forum.ForumID,
                          Type='Forums',
                          Message="",
                          RenderType='attachment',
                          UserID=user.UserID)
        comment.save()
        attachment = SequenceAttachment(Attachment=image,
                                        ParentID=comment.CommentID,
                                        Type='comments',
                                        FileName=file_name)
        attachment.save()
        comment.Message = json.dumps({
            "url":
            "/comment/%s/attachment/%s" %
            (comment.CommentID, attachment.SequenceAttachmentID),
            "name":
            file_name
        })
        comment.save()

    print forum.ForumID

    team_members = user.account.users

    # Make all team members follow the issue
    for member in team_members:
        if user.UserID != member.UserID and str(
                member.UserID) not in SOFIE_AUTO_FOLLOWING_USER_IDS(
                ) and user.Active is True:
            team_follow = Follower(Type="Forums",
                                   ParentID=forum.ForumID,
                                   UserID=member.UserID,
                                   EmailSubscribed=False)
            team_follow.save()

    # Make the creator of the issue follow the case
    follow = Follower(Type="Forums",
                      ParentID=forum.ForumID,
                      UserID=user.UserID)
    follow.save()

    print follow.FollowerID

    sofie_users = User.query.filter(
        and_(User.UserID.in_(SOFIE_AUTO_FOLLOWING_USER_IDS()),
             User.Active == True))

    # Make all SOFIE members aware of the issue
    for sofie_user in sofie_users:
        sofie_userid = sofie_user.UserID
        if sofie_userid and user.UserID != sofie_userid:
            auto_follow = Follower(Type="Forums",
                                   ParentID=forum.ForumID,
                                   UserID=sofie_userid)
            auto_follow.save()

    Comment.make_comments(user.UserID, "Forums", forum.ForumID, message)

    return forum, follow