Repository: oppia/oppia
File: core/storage/blog/gae_models.py (Python)

Code before:
            BlogPostModel | None. The blog post model of the Blog or None if not
            found.
        """
        return BlogPostModel.query(
            datastore_services.all_of(
                cls.url_fragment == url_fragment,
                cls.deleted == False,  # pylint: disable=singleton-comparison
            )
        ).get()

    @classmethod
    def export_data(cls, user_id: str) -> Dict[str, BlogPostModelDataDict]:
        """Exports the data from BlogPostModel into dict format for Takeout.

        Args:
            user_id: str. The ID of the user whose data should be exported.

        Returns:
            dict. Dictionary of the data from BlogPostModel.
        """
        user_data: Dict[str, BlogPostModelDataDict] = {}
        blog_post_models: Sequence[BlogPostModel] = (
            cls.get_all().filter(cls.author_id == user_id).fetch()
        )
        for blog_post_model in blog_post_models:
            if blog_post_model.published_on is None:
                published_on = None
            if blog_post_model.published_on is not None:
                published_on = utils.get_time_in_millisecs(
                    blog_post_model.published_on
                )
            user_data[blog_post_model.id] = {
                'title': blog_post_model.title,
                'content': blog_post_model.content,
                'url_fragment': blog_post_model.url_fragment,
                'tags': blog_post_model.tags,
                'thumbnail_filename': blog_post_model.thumbnail_filename,
                'published_on': published_on,
            }

        return user_data


class BlogPostSummaryModel(base_models.BaseModel):
    """Summary model for blog posts.

    This should be used whenever the content of the blog post is not
    needed (e.g. in search results, displaying blog post cards etc).

    The key of each instance is the blog post id.
    """

Review comment (refactor):
I think you can simplify: drop the "if" statements and just say something like

```
published_on = (
    utils.get_time_in_millisecs(blog_post_model.published_on)
    if blog_post_model.published_on is not None else None)
```

Code after:
            BlogPostModel | None. The blog post model of the Blog or None if not
            found.
        """
        return BlogPostModel.query(
            datastore_services.all_of(
                cls.url_fragment == url_fragment,
                cls.deleted == False,  # pylint: disable=singleton-comparison
            )
        ).get()

    @classmethod
    def export_data(cls, user_id: str) -> Dict[str, BlogPostModelDataDict]:
        """Exports the data from BlogPostModel into dict format for Takeout.

        Args:
            user_id: str. The ID of the user whose data should be exported.

        Returns:
            dict. Dictionary of the data from BlogPostModel.
        """
        user_data: Dict[str, BlogPostModelDataDict] = {}
        blog_post_models: Sequence[BlogPostModel] = (
            cls.get_all().filter(cls.author_id == user_id).fetch()
        )
        for blog_post_model in blog_post_models:
            published_on = (
                utils.get_time_in_millisecs(blog_post_model.published_on)
                if blog_post_model.published_on is not None
                else None
            )
            user_data[blog_post_model.id] = {
                'title': blog_post_model.title,
                'content': blog_post_model.content,
                'url_fragment': blog_post_model.url_fragment,
                'tags': blog_post_model.tags,
                'thumbnail_filename': blog_post_model.thumbnail_filename,
                'published_on': published_on,
            }

        return user_data


class BlogPostSummaryModel(base_models.BaseModel):
    """Summary model for blog posts.

    This should be used whenever the content of the blog post is not
    needed (e.g. in search results, displaying blog post cards etc).

    The key of each instance is the blog post id.
    """