def __init__(self, instance=None, *args, **kwargs):
    self.instance = instance
    super(BaseCMSPageForm, self).__init__(*args, **kwargs)
    if self.page:
        site = self.page.site_id
    else:
        site = Site.objects.get_current()
    if ('page_type' in self.fields):
        root = Page.objects.filter(publisher_is_draft=True, reverse_id=PAGE_TYPES_ID, site=site).first()
        if root:
            page_types = root.get_descendants()
        else:
            page_types = Page.objects.none()
        if (root and page_types):
            language = get_language()
            type_ids = page_types.values_list('pk', flat=True)
            titles = Title.objects.filter(page__in=type_ids, language=language)
            choices = [('', '---------')]
            for title in titles:
                choices.append((title.page_id, title.title))
            self.fields['page_type'].choices = choices
        else:
            del self.fields['page_type']
def __init__(self, instance=None, *args, **kwargs):
    self.instance = instance
    super(BaseCMSPageForm, self).__init__(*args, **kwargs)
    if self.page:
        site = self.page.site_id
    else:
        site = Site.objects.get_current()
    if ('page_type' in self.fields):
        root = Page.objects.filter(publisher_is_draft=True, reverse_id=PAGE_TYPES_ID, site=site).first()
        if root:
            page_types = root.get_descendants()
        else:
            page_types = Page.objects.none()
        if (root and page_types):
            language = get_language()
            type_ids = page_types.values_list('pk', flat=True)
            titles = Title.objects.filter(page__in=type_ids, language=language)
            choices = [(, '---------')]
            for title in titles:
                choices.append((title.page_id, title.title))
            self.fields['page_type'].choices = choices
        else:
            del self.fields['page_type']