# Path: apps/board/models.py
# class Post(BasePost):
#     """
#     게시글을 구현한 모델.
#     """
# 
#     board = models.ForeignKey(
#         Board,
#         verbose_name=_("등록 게시판"))
# 
#     board_tab = models.ManyToManyField(
#         BoardTab,
#         blank=True,
#         verbose_name=_("등록 탭"))
# 
#     title = models.CharField(
#         _("제목"),
#         max_length=128)
# 
#     tag = models.ForeignKey(
#         Tag,
#         verbose_name=_("태그"),
#         null=True, blank=True)
# 
#     is_notice = models.BooleanField(
#         _("공지글"),
#         default=False)
# 
#     class Meta:
#         verbose_name = _('포스트')
#         verbose_name_plural = _('포스트(들)')
# 
#     def __str__(self):
#         return self.title
# 
#     def get_absolute_url(self):
#         # return os.path.join(self.board.get_absolute_url(), str(self.id))
#         return self.board.get_absolute_url()+'/'+str(self.id)
# 
#     def get_first_tab(self):
#         return self.board_tab.all().first()
# 
#     def pre_permitted(self, user, permission):
#         """
#         게시글 권한 확인 이전에 게시판 접근권한을 확인하는 메서드.
#         """
#         return self.board.is_permitted(user, PERM_ACCESS)
# 
#     def post_permitted(self, user, permission):
#         """
#         게시글 권한 확인 이후에 동일 권한이 게시판에도 있는지 확인하는 메서드.
#         """
#         return self.board.is_permitted(user, permission)
# 
# class AttachedFile(models.Model):
#     """
#     포스트, 댓글 첨부파일을 구현한 모델.
#     """
# 
#     post = models.ForeignKey(
#         BasePost,
#         verbose_name=_("연결된 포스트"))
# 
#     file = models.FileField(
#         _("첨부파일"),
#         upload_to=get_upload_path)
# 
#     class Meta:
#         verbose_name = _('첨부파일')
#         verbose_name_plural = _('첨부파일(들)')
# 
#     def __str__(self):
#         return os.path.basename(self.file.name)
# 
#     def get_absolute_url(self):
#         return os.path.join(MEDIA_URL, self.file.name)
# 
#     def get_file_size(self):
#         """
#         파일 크기를 반환하는 메서드.
#         """
#         try:
#             return self.file.size
#         except:
#             return 0


from rest_framework import serializers
from apps.board.models import Post, AttachedFile
from apps.manager.constants import *
        return obj.is_permitted(self.get_request_user(), PERM_READ)

    def get_is_permitted_to_edit(self, obj):
        return obj.is_permitted(self.get_request_user(), PERM_EDIT)

    def get_is_permitted_to_delete(self, obj):
        return obj.is_permitted(self.get_request_user(), PERM_DELETE)
    
    def get_absolute_url(self, obj):
        return obj.get_absolute_url()

    class Meta:
        model = Post
        fields = (
            'id',
            'title',
            'content',
            'is_deleted',
            'is_secret',
            'is_permitted_to_read',
            'is_permitted_to_edit',
            'is_permitted_to_delete',
            'absolute_url',
            'board',
            'attachedfile_set'
        )
        depth = 2

class RetrivePostSerializer(serializers.ModelSerializer):
    class Meta:

# Path: apps/board/models.py
# class Post(BasePost):
#     """
#     게시글을 구현한 모델.
#     """
# 
#     board = models.ForeignKey(
#         Board,
#         verbose_name=_("등록 게시판"))
# 
#     board_tab = models.ManyToManyField(
#         BoardTab,
#         blank=True,
#         verbose_name=_("등록 탭"))
# 
#     title = models.CharField(
#         _("제목"),
#         max_length=128)
# 
#     tag = models.ForeignKey(
#         Tag,
#         verbose_name=_("태그"),
#         null=True, blank=True)
# 
#     is_notice = models.BooleanField(
#         _("공지글"),
#         default=False)
# 
#     class Meta:
#         verbose_name = _('포스트')
#         verbose_name_plural = _('포스트(들)')
# 
#     def __str__(self):
#         return self.title
# 
#     def get_absolute_url(self):
#         # return os.path.join(self.board.get_absolute_url(), str(self.id))
#         return self.board.get_absolute_url()+'/'+str(self.id)
# 
#     def get_first_tab(self):
#         return self.board_tab.all().first()
# 
#     def pre_permitted(self, user, permission):
#         """
#         게시글 권한 확인 이전에 게시판 접근권한을 확인하는 메서드.
#         """
#         return self.board.is_permitted(user, PERM_ACCESS)
# 
#     def post_permitted(self, user, permission):
#         """
#         게시글 권한 확인 이후에 동일 권한이 게시판에도 있는지 확인하는 메서드.
#         """
#         return self.board.is_permitted(user, permission)
# 
# class AttachedFile(models.Model):
#     """
#     포스트, 댓글 첨부파일을 구현한 모델.
#     """
# 
#     post = models.ForeignKey(
#         BasePost,
#         verbose_name=_("연결된 포스트"))
# 
#     file = models.FileField(
#         _("첨부파일"),
#         upload_to=get_upload_path)
# 
#     class Meta:
#         verbose_name = _('첨부파일')
#         verbose_name_plural = _('첨부파일(들)')
# 
#     def __str__(self):
#         return os.path.basename(self.file.name)
# 
#     def get_absolute_url(self):
#         return os.path.join(MEDIA_URL, self.file.name)
# 
#     def get_file_size(self):
#         """
#         파일 크기를 반환하는 메서드.
#         """
#         try:
#             return self.file.size
#         except:
#             return 0


# Path: apps/board/serializers.py
from rest_framework import serializers
from apps.board.models import Post, AttachedFile
from apps.manager.constants import *

        return obj.is_permitted(self.get_request_user(), PERM_READ)

    def get_is_permitted_to_edit(self, obj):
        return obj.is_permitted(self.get_request_user(), PERM_EDIT)

    def get_is_permitted_to_delete(self, obj):
        return obj.is_permitted(self.get_request_user(), PERM_DELETE)
    
    def get_absolute_url(self, obj):
        return obj.get_absolute_url()

    class Meta:
        model = Post
        fields = (
            'id',
            'title',
            'content',
            'is_deleted',
            'is_secret',
            'is_permitted_to_read',
            'is_permitted_to_edit',
            'is_permitted_to_delete',
            'absolute_url',
            'board',
            'attachedfile_set'
        )
        depth = 2

class RetrivePostSerializer(serializers.ModelSerializer):
    class Meta:

        model = Post