Ejemplo n.º 1
0
def add_comment(real_user, user, body, change=None, extract=None, in_reply_to=None, **kw):
    """
    Add a comment for either a change or an extract.
    """

    commentable = change or extract or in_reply_to.change
    
    comment = commentable.add_comment(user, body, in_reply_to=in_reply_to, **kw)
    
    #email
    if in_reply_to:
        users = in_reply_to.interested_users
        if user in users: users.remove(user)
        email.send(users, 'create_reply.txt', {
            'comment': comment,
            'creator': user,
            'parent_comment': in_reply_to,
            'entity': in_reply_to.change.entity,
            'change': in_reply_to.change,
        })
    else:
        ch = change or extract.change
        entity = ch.entity
        
        users = entity.interested_users
        if user in users: users.remove(user)
        email.send(users, 'create_comment.txt', {
            'comment': comment,
            'entity': entity,
            'change': ch,
            'creator': user
        })
    
    return commentable, comment
Ejemplo n.º 2
0
def create(real_user, user, organization, **params):
    """
    Creates a project.
    """
    class ProjectForm(formencode.Schema):
        name = formencode.All(fv.UnicodeString(not_empty=True), UniqueName(organization))
        description = fv.UnicodeString(not_empty=False)
    
    scrubbed = validate(ProjectForm, **params)

    project = projects.Project(name=scrubbed.name,
                               creator=user,
                               description=scrubbed.description,
                               organization=organization)
    Session.add(project)
    Session.flush()
    
    #email
    users = organization.interested_users
    if user in users: users.remove(user)
    email.send(users, 'create_project.txt', {
        'project': project,
        'creator': user
    })
    
    return project
Ejemplo n.º 3
0
def upload(real_user, user, project, **kw):
    """
    File is binary in the request body.
    """
    from pylons import request
    fname = utils.to_unicode(request.headers.get('X-Up-Filename'))
    type = utils.to_unicode(request.headers.get('X-Up-Type'))
    path = utils.to_unicode(request.headers.get('X-Up-Path'))
    description = utils.to_unicode(request.headers.get('X-Up-Description'))
    
    if not fname or not type or not path: return None
    
    ext = None
    if type:
        ext = mimetypes.guess_extension(type)
        if not ext:
            _, ext = os.path.splitext(fname)
        ext = ext or ''
    
    f, tmpname = tempfile.mkstemp(ext)
    #why is this returning an int on my machine? Supposed to be a file pointer.
    if isinstance(f, int):
        f = open(tmpname, 'wb')
    
    #this is inefficient. Pylons supposedly already creates a tmp file. We are instead
    #reading the thing into memory. I'm lazy until this beomes an issue (prolly soon)
    #V: please make this not suck
    f.write(request.environ['wsgi.input'].read())
    f.close()
    
    change = project.add_change(user, os.path.join(path, fname), tmpname, u'')
    
    if change.version == 1:
        #email
        users = project.interested_users
        if user in users: users.remove(user)
        email.send(users, 'create_file.txt', {
            'project': project,
            'change': change,
            'creator': user
        })
    else:
        #email
        users = change.entity.interested_users
        if user in users: users.remove(user)
        email.send(users, 'create_change.txt', {
            'project': project,
            'change': change,
            'creator': user
        })
    
    return change.entity, change
Ejemplo n.º 4
0
def upload(real_user, user, project, **kw):
    """
    File is binary in the request body.
    """
    from pylons import request
    fname = utils.to_unicode(request.headers.get('X-Up-Filename'))
    type = utils.to_unicode(request.headers.get('X-Up-Type'))
    path = utils.to_unicode(request.headers.get('X-Up-Path'))
    description = utils.to_unicode(request.headers.get('X-Up-Description'))

    if not fname or not type or not path: return None

    ext = None
    if type:
        ext = mimetypes.guess_extension(type)
        if not ext:
            _, ext = os.path.splitext(fname)
        ext = ext or ''

    f, tmpname = tempfile.mkstemp(ext)
    #why is this returning an int on my machine? Supposed to be a file pointer.
    if isinstance(f, int):
        f = open(tmpname, 'wb')

    #this is inefficient. Pylons supposedly already creates a tmp file. We are instead
    #reading the thing into memory. I'm lazy until this beomes an issue (prolly soon)
    #V: please make this not suck
    f.write(request.environ['wsgi.input'].read())
    f.close()

    change = project.add_change(user, os.path.join(path, fname), tmpname, u'')

    if change.version == 1:
        #email
        users = project.interested_users
        if user in users: users.remove(user)
        email.send(users, 'create_file.txt', {
            'project': project,
            'change': change,
            'creator': user
        })
    else:
        #email
        users = change.entity.interested_users
        if user in users: users.remove(user)
        email.send(users, 'create_change.txt', {
            'project': project,
            'change': change,
            'creator': user
        })

    return change.entity, change
Ejemplo n.º 5
0
def add_comment(real_user,
                user,
                body,
                change=None,
                extract=None,
                in_reply_to=None,
                **kw):
    """
    Add a comment for either a change or an extract.
    """

    commentable = change or extract or in_reply_to.change

    comment = commentable.add_comment(user,
                                      body,
                                      in_reply_to=in_reply_to,
                                      **kw)

    #email
    if in_reply_to:
        users = in_reply_to.interested_users
        if user in users: users.remove(user)
        email.send(
            users, 'create_reply.txt', {
                'comment': comment,
                'creator': user,
                'parent_comment': in_reply_to,
                'entity': in_reply_to.change.entity,
                'change': in_reply_to.change,
            })
    else:
        ch = change or extract.change
        entity = ch.entity

        users = entity.interested_users
        if user in users: users.remove(user)
        email.send(users, 'create_comment.txt', {
            'comment': comment,
            'entity': entity,
            'change': ch,
            'creator': user
        })

    return commentable, comment