예제 #1
0
파일: parser.py 프로젝트: sydneyjd/pjuu
def parse_links(body):
    """Parses URLs out of a post.

    .. note: This will need to be refined as edge cases are discovered.

    """
    links = URL_RE.finditer(body)

    result = []
    for link in links:
        result.append({'link': fix_url(link.group(0)), 'span': link.span()})

    return result
예제 #2
0
파일: parser.py 프로젝트: Velody/pjuu
def parse_links(body):
    """Parses URLs out of a post.

    .. note: This will need to be refined as edge cases are discovered.

    """
    links = URL_RE.finditer(body)

    result = []
    for link in links:
        result.append({"link": fix_url(link.group(0)), "span": link.span()})

    return result
예제 #3
0
def update_profile_settings(user_id,
                            about="",
                            hide_feed_images=False,
                            feed_size=25,
                            replies_size=25,
                            alerts_size=50,
                            reply_sort_order=-1,
                            homepage='',
                            location='',
                            upload=None,
                            permission=0):
    """Update all options on a users profile settings in MongoDB."""
    # Ensure the homepage URL is as valid as it can be
    if homepage != '':
        homepage = fix_url(homepage)

    avatar = None
    if upload:
        filename = process_upload(upload, image_size=(96, 96), thumbnail=False)
        if filename is not None:  # pragma: no cover
            avatar = filename

    update_dict = {
        'about': about,
        'hide_feed_images': hide_feed_images,
        'feed_pagination_size': int(feed_size),
        'replies_pagination_size': int(replies_size),
        'alerts_pagination_size': int(alerts_size),
        'reply_sort_order': reply_sort_order,
        'homepage': homepage,
        'location': location,
        'default_permission': int(permission)
    }

    if avatar is not None:
        update_dict['avatar'] = avatar

        user = get_user(user_id)

        if user.get('avatar'):
            # Clean up any old avatars
            # There is no update in GridFS
            delete_upload(user.get('avatar'))

    # Update the users profile
    m.db.users.update({'_id': user_id}, {'$set': update_dict})

    # Return the user object. We can update the current_user from this
    return get_user(user_id)
예제 #4
0
파일: backend.py 프로젝트: pjuu/pjuu
def update_profile_settings(user_id, about="", hide_feed_images=False,
                            feed_size=25, replies_size=25, alerts_size=50,
                            reply_sort_order=-1, homepage='', location='',
                            upload=None, permission=0):
    """Update all options on a users profile settings in MongoDB."""
    # Ensure the homepage URL is as valid as it can be
    if homepage != '':
        homepage = fix_url(homepage)

    avatar = None
    if upload:
        filename, _ = process_upload(upload, image_size=(96, 96),
                                     thumbnail=False)
        if filename is not None:  # pragma: no cover
            avatar = filename

    update_dict = {
        'about': about,
        'hide_feed_images': hide_feed_images,
        'feed_pagination_size': int(feed_size),
        'replies_pagination_size': int(replies_size),
        'alerts_pagination_size': int(alerts_size),
        'reply_sort_order': reply_sort_order,
        'homepage': homepage,
        'location': location,
        'default_permission': int(permission)
    }

    if avatar is not None:
        update_dict['avatar'] = avatar

        user = get_user(user_id)

        if user.get('avatar'):
            # Clean up any old avatars
            # There is no update in GridFS
            delete_upload(user.get('avatar'))

    # Update the users profile
    m.db.users.update({'_id': user_id}, {'$set': update_dict})

    # Return the user object. We can update the current_user from this
    return get_user(user_id)
예제 #5
0
파일: backend.py 프로젝트: cycle-chen/pjuu
def update_profile_settings(user_id, about="", hide_feed_images=False,
                            feed_size=25, replies_size=25, alerts_size=50,
                            homepage='', location='', upload=None):
    """Update all options on a users profile settings in MongoDB."""
    # Ensure the homepage URL is as valid as it can be
    if homepage != '':
        homepage = fix_url(homepage)

    avatar = None
    if upload:
        filename = process_upload(user_id, upload, collection='avatars',
                                  image_size=(96, 96))
        if filename is not None:  # pragma: no cover
            avatar = filename

    update_dict = {
        'about': about,
        'hide_feed_images': hide_feed_images,
        'feed_pagination_size': int(feed_size),
        'replies_pagination_size': int(replies_size),
        'alerts_pagination_size': int(alerts_size),
        'homepage': homepage,
        'location': location,
    }

    if avatar is not None:
        # Add the avatar to the dict
        update_dict['avatar'] = avatar

        # Clean up any old avatars
        # There is no update in GridFS
        grid = gridfs.GridFS(m.db, collection='avatars')
        # Get all old ones
        cursor = grid.find(
            {'filename': avatar}).sort('uploadDate', -1).skip(1)
        for f in cursor:
            grid.delete(f._id)

    # Update the users profile
    m.db.users.update({'_id': user_id}, {'$set': update_dict})

    # Return the user object. We can update the current_user from this
    return get_user(user_id)