Beispiel #1
0
class PapersIndexPage(Page):
    title_ko = models.CharField("Title (Korean)", max_length=255)
    tr_title = TranslatedField(
        'title',
        'title_ko',
    )
    description = models.TextField("Description (English)",
                                   help_text='Text to describe the page',
                                   blank=True)
    description_ko = models.TextField("Description (Korean)",
                                      help_text='Text to describe the page',
                                      blank=True)
    tr_description = TranslatedField(
        'description',
        'description_ko',
    )

    content_panels = Page.content_panels + [
        FieldPanel('title_ko'),
        FieldPanel('description', classname="full"),
        FieldPanel('description_ko', classname="full"),
    ]

    subpage_types = [
        'PaperPage',
    ]
    parent_page_types = [
        'home.SectionPage',
    ]

    def get_context(self, request):
        context = super(PapersIndexPage, self).get_context(request)
        papers = PaperPage.objects.live().descendant_of(self)
        paper_year = None
        paper_category = None
        if request.GET.get('year') == 'all':
            pass
        elif not request.GET.get('year') in [None, '']:
            try:
                paper_year = int(request.GET.get('year'))
                papers = papers.filter(date__year=paper_year)
            except ValueError:
                pass
        else:  # if (request.GET.get('year') in [None, '']) is True, paper_year will be this year.
            paper_year = datetime.now().year
            papers = papers.filter(date__year=paper_year)
        if not request.GET.get('category') in [None, '']:
            paper_category = request.GET.get('category')
            papers = papers.filter(category__slug=paper_category)
        context['papers'] = papers.order_by('-date')
        context['categories'] = Category.objects.all().order_by('name')
        context['years'] = range(datetime.now().year, 2012, -1)
        context['selected_year'] = paper_year
        context['selected_category'] = paper_category
        return context
Beispiel #2
0
class EquipmentIndexPage(Page):
    title_ko = models.CharField("Title (Korean)", max_length=255)
    tr_title = TranslatedField(
        'title',
        'title_ko',
    )
    description = models.TextField(
        "Description (English)",
        help_text='Text to describe the page',
        blank=True)
    description_ko = models.TextField(
        "Description (Korean)",
        help_text='Text to describe the page',
        blank=True)
    tr_description = TranslatedField(
        'description',
        'description_ko',
    )

    content_panels = Page.content_panels + [
        FieldPanel('title_ko'),
        FieldPanel('description', classname="full"),
        FieldPanel('description_ko', classname="full"),
    ]

    subpage_types = ['StandardEquipmentPage', ]
    parent_page_types = ['home.SectionPage', ]

    def get_equipment(self):
        return StandardEquipmentPage.objects.live().descendant_of(self).order_by('title')

    def children(self):
        return self.get_children().specific().live()

    def paginate(self, request, *args):
        page = request.GET.get('page')
        paginator = Paginator(self.get_equipment(), 12)
        try:
            pages = paginator.page(page)
        except PageNotAnInteger:
            pages = paginator.page(1)
        except EmptyPage:
            pages = paginator.page(paginator.num_pages)
        return pages

    def get_context(self, request):
        context = super(EquipmentIndexPage, self).get_context(request)
        equipment = self.paginate(request, self.get_equipment())
        context['equipment'] = equipment
        return context
Beispiel #3
0
class EventsIndexPage(Page):
    title_ko = models.CharField("Title (Korean)", max_length=255)
    tr_title = TranslatedField(
        'title',
        'title_ko',
    )
    description = models.TextField("Description (English)",
                                   help_text='Text to describe the page',
                                   blank=True)
    description_ko = models.TextField("Description (Korean)",
                                      help_text='Text to describe the page',
                                      blank=True)
    tr_description = TranslatedField(
        'description',
        'description_ko',
    )
    view_type = models.CharField(max_length=64,
                                 choices=[('list', 'List'),
                                          ('table', 'Table')],
                                 default='list')

    content_panels = Page.content_panels + [
        FieldPanel('title_ko'),
        FieldPanel('description', classname="full"),
        FieldPanel('description_ko', classname="full"),
        FieldPanel('view_type'),
    ]

    subpage_types = ['StandardEventPage']

    def get_context(self, request):
        context = super(EventsIndexPage, self).get_context(request)
        events = StandardEventPage.objects.live().descendant_of(self)
        year = None
        if request.GET.get('year') == 'all':
            pass
        elif not request.GET.get('year') in [None, '']:
            try:
                year = int(request.GET.get('year'))
                events = events.filter(start__year=year)
            except ValueError:
                pass
        else:  # if (request.GET.get('year') in [None, '']) is True, year will be this year.
            year = datetime.now().year
            events = events.filter(start__year=year)
        context['events'] = events.order_by('-start')
        context['years'] = range(datetime.now().year + 1, 2012, -1)
        context['selected_year'] = year
        return context
Beispiel #4
0
class TweetIndexPage(Page):
    title_ko = models.CharField("Title (Korean)", max_length=255)
    tr_title = TranslatedField(
        'title',
        'title_ko',
    )
    description = models.TextField(
        "Description (English)",
        help_text='Text to describe the page',
        blank=True)
    description_ko = models.TextField(
        "Description (Korean)",
        help_text='Text to describe the page',
        blank=True)
    tr_description = TranslatedField(
        'description',
        'description_ko',
    )

    content_panels = Page.content_panels + [
        FieldPanel('title_ko'),
        FieldPanel('description', classname="full"),
        FieldPanel('description_ko', classname="full"),
    ]

    subpage_types = ['TweetPage']

    def get_tweets(self):
        return TweetPage.objects.descendant_of(self).live().order_by('-date_published')

    def paginate(self, request, *args):
        page = request.GET.get('page')
        paginator = Paginator(self.get_tweets(), 12)
        try:
            pages = paginator.page(page)
        except PageNotAnInteger:
            pages = paginator.page(1)
        except EmptyPage:
            pages = paginator.page(paginator.num_pages)
        return pages

    def get_context(self, request):
        context = super(TweetIndexPage, self).get_context(request)
        context['tweets'] = self.paginate(request, self.get_tweets())
        return context
Beispiel #5
0
class SeminarsIndexPage(Page):
    title_ko = models.CharField("Title (Korean)", max_length=255)
    tr_title = TranslatedField(
        'title',
        'title_ko',
    )
    description = models.TextField("Description (English)",
                                   help_text='Text to describe the page',
                                   blank=True)
    description_ko = models.TextField("Description (Korean)",
                                      help_text='Text to describe the page',
                                      blank=True)
    tr_description = TranslatedField(
        'description',
        'description_ko',
    )

    content_panels = Page.content_panels + [
        FieldPanel('title_ko'),
        FieldPanel('description', classname="full"),
        FieldPanel('description_ko', classname="full"),
    ]

    subpage_types = ['SeminarPage']

    def get_context(self, request):
        context = super(SeminarsIndexPage, self).get_context(request)
        seminars = SeminarPage.objects.live().descendant_of(self)
        year = None
        if request.GET.get('year') == 'all':
            pass
        elif not request.GET.get('year') in [None, '']:
            try:
                year = int(request.GET.get('year'))
                seminars = seminars.filter(date__year=year)
            except ValueError:
                pass
        else:  # if (request.GET.get('year') in [None, '']) is True, year will be this year.
            year = datetime.now().year
            seminars = seminars.filter(date__year=year)
        context['seminars'] = seminars.order_by('-date')
        context['years'] = range(datetime.now().year, 2012, -1)
        context['selected_year'] = year
        return context
Beispiel #6
0
class JournalIndexPage(RoutablePageMixin, Page):
    title_ko = models.CharField("Title (Korean)", max_length=255)
    tr_title = TranslatedField(
        'title',
        'title_ko',
    )

    content_panels = Page.content_panels + [
        FieldPanel('title_ko'),
    ]

    def get_context(self, request):
        context = super(JournalIndexPage, self).get_context(request)
        context['journals'] = Journal.objects.all().order_by('title')
        return context

    @route(r'^byid/([\d]+)/$', name='id')
    def journal_byid(self, request, id):
        context = super(JournalIndexPage, self).get_context(request)
        context['journal'] = Journal.objects.get(id=id)
        context['papers'] = PaperPage.objects.live().filter(journal__id=id)
        return render(request, 'publication/journal_index_page.html', context)
Beispiel #7
0
class BlogIndexPage(RoutablePageMixin, Page):
    title_ko = models.CharField("Title (Korean)", max_length=255)
    tr_title = TranslatedField(
        'title',
        'title_ko',
    )
    description = models.TextField(
        "Description (English)",
        help_text='Text to describe the page',
        blank=True)
    description_ko = models.TextField(
        "Description (Korean)",
        help_text='Text to describe the page',
        blank=True)
    tr_description = TranslatedField(
        'description',
        'description_ko',
    )
    image = models.ForeignKey(
        'wagtailimages.Image',
        null=True,
        blank=True,
        on_delete=models.SET_NULL,
        related_name='+',
        help_text='Landscape mode only; horizontal width between 1000px and 3000px.'
    )

    content_panels = Page.content_panels + [
        FieldPanel('title_ko'),
        FieldPanel('description', classname="full"),
        FieldPanel('description_ko', classname="full"),
        ImageChooserPanel('image'),
    ]

    subpage_types = ['BlogPage']

    def children(self):
        return self.get_children().specific().live()

    def get_posts(self, tag=None):
        posts = BlogPage.objects.live().descendant_of(self).order_by('-date_published')
        if tag:
            posts = posts.filter(tags=tag)
        return posts

    def paginate(self, request, *args):
        page = request.GET.get('page')
        paginator = Paginator(self.get_posts(), 12)
        try:
            pages = paginator.page(page)
        except PageNotAnInteger:
            pages = paginator.page(1)
        except EmptyPage:
            pages = paginator.page(paginator.num_pages)
        return pages

    def get_context(self, request):
        context = super(BlogIndexPage, self).get_context(request)
        context['posts'] = self.paginate(request, self.get_posts())
        return context

    @route(r'^tags/$', name='tag_archive')
    @route(r'^tags/([\w-]+)/$', name='tag_archive')
    def tag_archive(self, request, tag=None):
        try:
            tag = Tag.objects.get(slug=tag)
        except Tag.DoesNotExist:
            if tag:
                msg = 'There are no blog posts tagged with "{}"'.format(tag)
                messages.add_message(request, messages.INFO, msg)
            return redirect(self.url)

        posts = self.get_posts(tag=tag)
        context = {
            'tag': tag,
            'posts': posts
        }
        return render(request, 'blog/blog_index_page.html', context)

    def get_child_tags(self):
        tags = []
        for post in self.get_posts():
            tags += post.get_tags
        tags = sorted(set(tags))
        return tags

    def serve_preview(self, request, mode_name):
        return self.serve(request)