Exemplo n.º 1
0
    def get(self, *arg):
        profile_id = int(arg[0])
        user_profile = dao.get_user_profile_by_id(profile_id)

        if hasattr(user_profile, 'self_block'):
            self.response.set_status(404)
            return

        def artworks_query_func():
            all_artworks = db.Favorite.all()
            all_artworks = all_artworks.filter('user_email =',
                                               user_profile.email)
            return all_artworks.order('-date')

        def href_create_func(offset):
            return '/profiles/' + str(profile_id) + '/favorites?offset=' + str(
                offset)

        def memcache_cursor_key_func(offset):
            return cache.MC_ARTWORK_LIST + 'user_favorites_' + str(
                profile_id) + '_' + str(offset)

        model = create_gallery_model(self.request.get('offset'),
                                     artworks_query_func, href_create_func,
                                     memcache_cursor_key_func)
        model['user_page_title'] = 'Favorites of'
        model['profile'] = convert.convert_user_profile(user_profile)

        if self.user_info.user and self.user_info.profile_id == profile_id:
            model['this_user_profile'] = True

        self.write_template('templates/user-favorites.html', model)
Exemplo n.º 2
0
    def get(self, *arg):
        profile_id = int(arg[0])
        user_profile = dao.get_user_profile_by_id(profile_id)

        model = {
            'profile_id': user_profile.key().id(),
            'nickname': user_profile.nickname
        }

        self.write_template('templates/comments.html', model)
Exemplo n.º 3
0
    def get(self, *arg):
        profile_id = int(arg[0])
        user_profile = dao.get_user_profile_by_id(profile_id)

        if hasattr(user_profile, 'self_block'):
            self.response.set_status(404)
            return

        model = {
            'user_page_title': 'Leaders of',
            'profile': convert.convert_user_profile(user_profile)
        }

        self.write_template('templates/user-leaders.html', model)
Exemplo n.º 4
0
    def get(self, *args):
        profile_id = int(args[0])
        tag_name = args[1]

        user = dao.get_user_profile_by_id(profile_id)
        if not user:
            self.response.set_status(404)
            return

        if hasattr(user, 'self_block'):
            self.response.set_status(404)
            return

        def artworks_query_func():
            all_artworks = db.Artwork.all()
            all_artworks = all_artworks.filter('author_email', user.email)
            all_artworks = all_artworks.filter('tags =',
                                               tags.tag_url_name(tag_name))
            return all_artworks.order('-date')

        def href_create_func(offset):
            return '/profiles/{}/tags/{}/images?offset={}'.format(
                profile_id, tag_name, offset)

        def memcache_cursor_key_func(offset):
            return cache.MC_ARTWORK_LIST + 'gallery_' + str(
                profile_id) + '_' + tag_name + '_' + str(offset)

        model = create_gallery_model(self.request.get('offset'),
                                     artworks_query_func, href_create_func,
                                     memcache_cursor_key_func)

        user_tag = db.UserTag.all().filter('user_id', profile_id).filter(
            'url_name', tag_name).get()
        if user_tag:
            tag_title = user_tag.title
            model['tag'] = convert.convert_tag_for_page(user_tag)
        else:
            tag_title = tag_name

        model['search_query'] = tag_name
        model['user_page_title'] = 'Images by tag "{}" of'.format(tag_title)
        model['profile'] = convert.convert_user_profile(user)

        self.write_template('templates/user-images-by-tag.html', model)
Exemplo n.º 5
0
    def get(self, *arg):
        try:
            profile_id = int(arg[0])
        except ValueError:
            self.response.set_status(404)
            return

        user_profile = dao.get_user_profile_by_id(profile_id)
        if not user_profile:
            self.response.set_status(404)
            return

        if hasattr(user_profile, 'self_block'):
            self.response.set_status(404)
            return

        def artworks_query_func():
            return db.Artwork.all().filter('author_email =',
                                           user_profile.email).order('-date')

        def href_create_func(offset):
            return '/profiles/' + str(profile_id) + '/images?offset=' + str(
                offset)

        def memcache_cursor_key_func(offset):
            return cache.MC_ARTWORK_LIST + 'profile_' + str(
                profile_id) + '_' + str(offset)

        model = create_gallery_model(self.request.get('offset'),
                                     artworks_query_func, href_create_func,
                                     memcache_cursor_key_func)
        model['profile'] = convert.convert_user_profile(user_profile)
        if self.user_info.user:
            model['following'] = dao.is_follower(user_profile.email,
                                                 self.user_info.user_email)

        if self.user_info.user and profile_id == self.user_info.profile_id:
            model['this_user_profile'] = True

        model['user_page_title'] = 'Images of'

        self.write_template('templates/user-images.html', model)
Exemplo n.º 6
0
    def get(self, *arg):
        try:
            profile_id = int(arg[0])
        except ValueError:
            self.response.set_status(404)
            return

        user_profile = dao.get_user_profile_by_id(profile_id)
        if not user_profile:
            self.response.set_status(404)
            return

        recent_db_images = db.Artwork.all().filter(
            'author_email', user_profile.email).order('-date').fetch(3, 0)
        recent_user_images = [
            convert.convert_artwork_for_page(a, 200, 150)
            for a in recent_db_images
        ]

        recent_db_group_images = db.ArtworkCollaborator.all().filter(
            'user_id =', profile_id).order('-last_date').fetch(3, 0)
        recent_group_images = [
            convert.convert_artwork_for_page(a.artwork, 200, 150)
            for a in recent_db_group_images
        ]

        recent_db_tags = db.UserTag.all().filter(
            'user_id',
            user_profile.key().id()).order('-last_date').fetch(3, 0)
        recent_user_tags = [
            convert.convert_tag_for_page(t) for t in recent_db_tags
        ]
        for t in recent_user_tags:
            t['url'] = '/profiles/{}/tags/{}/images'.format(
                profile_id, t['url_name'])

        model = {
            'profile': convert.convert_user_profile(user_profile),
            'recent_images': recent_user_images,
            'has_any_recent_images': len(recent_user_images) > 0,
            'has_more_recent_images': len(recent_user_images) >= 3,
            'group_images': recent_group_images,
            'has_any_group_images': len(recent_group_images) > 0,
            'has_more_group_images': len(recent_group_images) >= 3,
            'recent_tags': recent_user_tags,
            'has_any_recent_tags': len(recent_user_tags) > 0,
            'has_more_recent_tags': len(recent_user_tags) >= 3,
        }

        if self.user_info.user:
            model['following'] = dao.is_follower(user_profile.email,
                                                 self.user_info.user_email)

        if self.user_info.superadmin:
            model['profile']['email'] = user_profile.email
            model['profile']['alternative_emails'] = getattr(
                user_profile, 'alternative_emails', [])

        if self.user_info.user and profile_id == self.user_info.profile_id:
            model['this_user_profile'] = True

        self.write_template('templates/profile.html', model)
Exemplo n.º 7
0
    def get(self, *arg):
        artwork_id = arg[0]
        artwork = dao.get_artwork(artwork_id)
        if not artwork:
            self.response.set_status(404)
            return

        favorite_count = dao.get_artwork_favorite_count(artwork)
        favorite = dao.is_artwork_favorite_by_user(artwork,
                                                   self.user_info.user_email)

        db_comments = db.Comment.all().filter(
            'artwork_ref =',
            artwork).order('-date').fetch(const.MAX_COMMENT_PACK + 1)
        all_db_comments = [
            convert.convert_comment_for_page(c) for c in db_comments
        ]
        comments = all_db_comments[:const.MAX_COMMENT_PACK]
        has_more_comments = len(all_db_comments) > const.MAX_COMMENT_PACK

        converted_artwork = convert.convert_artwork_for_page(artwork, 600, 400)
        author_user_id = converted_artwork.get('author', {}).get('profile_id')

        if 'tags' in converted_artwork:
            converted_artwork['tags_merged'] = ','.join([
                tags.tag_by_url_name(t.title).title
                for t in converted_artwork['tags']
            ])

        if 'self_block' in converted_artwork['author']:
            self.write_template('templates/artwork-details-blocked.html',
                                {'artwork': converted_artwork})
            return

        user_is_author = artwork.author_email == self.user_info.user_email

        db_collaborators = db.ArtworkCollaborator.all().filter(
            'artwork =', artwork).order('-last_date')
        collaborators = [
            convert.convert_user_profile(dao.get_user_profile_by_id(c.user_id))
            for c in db_collaborators if c.user_id != author_user_id
        ]

        user_is_collaborator = False
        if self.user_info.user:
            user_is_collaborator = self.user_info.profile_id in [
                c['profile_id'] for c in collaborators
            ]

        can_edit_artwork = self.user_info.superadmin or user_is_author or user_is_collaborator
        if ('block' in converted_artwork or 'copyright_block'
                in converted_artwork) and not can_edit_artwork:
            self.write_template('templates/artwork-details-blocked.html',
                                {'artwork': converted_artwork})
            return

        if self.user_info.user:
            following = dao.is_follower(artwork.author_email,
                                        self.user_info.user_email)
        else:
            following = None

        settings = get_settings()

        template_name = 'templates/artwork-details.html'
        if 'block' in converted_artwork or 'copyright_block' in converted_artwork:
            template_name = 'templates/artwork-details-limited.html'

        self.write_template(
            template_name, {
                'artwork':
                converted_artwork,
                'collaborators':
                collaborators,
                'can_edit_artwork':
                can_edit_artwork,
                'user_is_author':
                user_is_author,
                'user_is_collaborator':
                user_is_collaborator,
                'comments_offset':
                len(comments),
                'comments':
                comments,
                'has_more_comments':
                has_more_comments,
                'favorite_count':
                favorite_count,
                'favorite':
                favorite,
                'following':
                following,
                'og_title':
                converted_artwork['name'],
                'og_image':
                'https://grid-paint.com/images/png/' + artwork_id + '.png',
                'og_image_width':
                converted_artwork['full_image_width'],
                'og_image_height':
                converted_artwork['full_image_height'],
                'og_url':
                'https://grid-paint.com/images/details/' + artwork_id,
                'og_description':
                u'Created by {} in Grid Paint'.format(
                    converted_artwork['author']['nickname']),
                'settings':
                settings
            })
Exemplo n.º 8
0
    def get(self, *args):
        profile_id = int(args[0])
        if self.request.get('offset'):
            offset = int(self.request.get('offset'))
        else:
            offset = 0

        user_profile = dao.get_user_profile_by_id(profile_id)
        if not user_profile:
            self.response.set_status(404)
            return

        if hasattr(user_profile, 'self_block'):
            self.response.set_status(404)
            return

        limit = 11 if offset == 0 else 10

        fetched_tags = db.UserTag.all().filter(
            'user_id',
            profile_id).order('-last_date').fetch(limit + 1, offset)
        query_tags = [convert.convert_tag_for_page(t) for t in fetched_tags]
        for t in query_tags:
            t['url'] = '/profiles/{}/tags/{}/images'.format(
                profile_id, t['url_name'])

        if offset == 11:
            prev_offset = 0
        else:
            prev_offset = offset - limit
        if prev_offset < 0:
            prev_offset = 0

        has_prev_page = offset > 0

        if len(query_tags) > limit:
            query_tags = query_tags[:-1]
            next_offset = offset + limit
            has_next_page = True
        else:
            next_offset = -1
            has_next_page = False

        self.write_template(
            'templates/user-tags.html', {
                'user_page_title':
                'Tags of',
                'profile':
                convert.convert_user_profile(user_profile),
                'tags':
                query_tags,
                'limit':
                limit,
                'offset':
                offset,
                'next_offset':
                next_offset,
                'prev_offset':
                prev_offset,
                'has_next_page':
                has_next_page,
                'has_prev_page':
                has_prev_page,
                'next_page_href':
                '/profiles/{}/tags?offset={}'.format(profile_id, next_offset),
                'prev_page_href':
                '/profiles/{}/tags?offset={}'.format(profile_id, prev_offset)
            })