# Path: apps/rule/const.py
# def get_choices(type_set):
#     return list(type_set.values())
# 
# def get_verbose(type_set, name):
#     value_dict = dict(list(type_set.values()))
#     return value_dict[name]
# 
# RULE_TYPE = {
#     'CONSTITUTION': ('CONST', _('회칙')),
#     'BYLAW': ('BYLAW', _('세칙')),
#     'RULE': ('RULE', _('규칙')),
#     'ETC': ('ETC', _('기타규정')),
# }
# 
# CHAPTER_TYPE = {
#     'PREAMBLE': ('PRE', _('전문')),
#     'CHAPTER': ('CHAP', _('장')),
#     'SECTION': ('SEC', _('절')),
#     'SUPPLEMENT': ('SUPPL', _('부칙')),
# }
# 
# REVISION_TYPE = {
#     'ESTABLISH': ('ESTAB', _('제정')),
#     'PARTIALLY': ('PART', _('일부개정')),
#     'FULLY': ('FULL', _('전부개정')),
# }


from django.db import models
from django.utils.translation import ugettext as _
from apps.rule.const import get_choices, get_verbose, RULE_TYPE, CHAPTER_TYPE, REVISION_TYPE
from itertools import chain
class Chapter(models.Model):
    """
    챕터.

    전문, 부칙이 아님에도 불구하고 번호가 없는 챕터는
    최하위 순서로 본다.
    """

    rule = models.ForeignKey(
        Rule,
        verbose_name=_('규정'),
        related_name='chapters',
        null=True, blank=True)

    parent_chapter = models.ForeignKey(
        'self',
        verbose_name=_('상위챕터'),
        related_name='child_chapters',
        null=True, blank=True,
        on_delete=models.SET_NULL)

    prev_chapter = models.ForeignKey(
        'self',
        verbose_name=_('직전연혁'),
        related_name='next_chapters',
        null=True, blank=True,
        on_delete=models.SET_NULL)

    chapter_type = models.CharField(
        _('종류'),

# Path: apps/rule/const.py
# def get_choices(type_set):
#     return list(type_set.values())
# 
# def get_verbose(type_set, name):
#     value_dict = dict(list(type_set.values()))
#     return value_dict[name]
# 
# RULE_TYPE = {
#     'CONSTITUTION': ('CONST', _('회칙')),
#     'BYLAW': ('BYLAW', _('세칙')),
#     'RULE': ('RULE', _('규칙')),
#     'ETC': ('ETC', _('기타규정')),
# }
# 
# CHAPTER_TYPE = {
#     'PREAMBLE': ('PRE', _('전문')),
#     'CHAPTER': ('CHAP', _('장')),
#     'SECTION': ('SEC', _('절')),
#     'SUPPLEMENT': ('SUPPL', _('부칙')),
# }
# 
# REVISION_TYPE = {
#     'ESTABLISH': ('ESTAB', _('제정')),
#     'PARTIALLY': ('PART', _('일부개정')),
#     'FULLY': ('FULL', _('전부개정')),
# }


# Path: apps/rule/models/rules.py
from django.db import models
from django.utils.translation import ugettext as _
from apps.rule.const import get_choices, get_verbose, RULE_TYPE, CHAPTER_TYPE, REVISION_TYPE
from itertools import chain

class Chapter(models.Model):
    """
    챕터.

    전문, 부칙이 아님에도 불구하고 번호가 없는 챕터는
    최하위 순서로 본다.
    """

    rule = models.ForeignKey(
        Rule,
        verbose_name=_('규정'),
        related_name='chapters',
        null=True, blank=True)

    parent_chapter = models.ForeignKey(
        'self',
        verbose_name=_('상위챕터'),
        related_name='child_chapters',
        null=True, blank=True,
        on_delete=models.SET_NULL)

    prev_chapter = models.ForeignKey(
        'self',
        verbose_name=_('직전연혁'),
        related_name='next_chapters',
        null=True, blank=True,
        on_delete=models.SET_NULL)

    chapter_type = models.CharField(
        _('종류'),

        max_length=8, choices=get_choices(CHAPTER_TYPE))