Exemple #1
0
Fichier : views.py Projet : jw/zink
def home(request):
    """Show the home page."""

    assets = get_assets(prefix="index")

    entry_list = Entry.objects.filter(active=True).reverse()
    logger.info(f"Retrieved {len(entry_list)} blog entries.")

    books = list(Text.objects.filter(reading=True))
    if books:
        logger.info(f"Reading one (or more) books: {books}.")
    else:
        logger.info("Not reading any book! So sad.")

    try:
        entry = entry_list.first()
    except IndexError:
        entry = None

    attributes = {'entry': entry,
                  'entries': entry_list[1:],
                  'books': books,
                  'assets': assets}

    return render(request, 'index.html', attributes)
Exemple #2
0
 def test_get_statics(self):
     """Get the generic assets and more"""
     assets = get_assets('index.header')
     self.assertIn('rero', assets)
     self.assertIn('copyright', assets)
     self.assertIn('title', assets)
     self.assertIn('index.header', assets)
Exemple #3
0
Fichier : tests.py Projet : jw/zink
 def test_get_statics(self):
     """Get the generic assets and more"""
     assets = get_assets('index.header')
     self.assertIn('rero', assets)
     self.assertIn('copyright', assets)
     self.assertIn('title', assets)
     self.assertIn('index.header', assets)
Exemple #4
0
def blog(request, page=1):
    """Get all blog entries for a specific page."""

    static = get_assets()
    deployment = get_deployment()

    tags = Tag.objects.all()
    logger.info(f"Retrieved {len(tags)} tags.")

    menus = create_menus(Menu.roots[0], 'blog')
    logger.info(f"Retrieved {len(menus)} menu items.")

    all_entries = Entry.objects.filter(page=Entry.BLOG, active=True).reverse()
    logger.info(f"Retrieved total of {len(all_entries)} blog entries.")

    try:
        size = settings.BLOG_PAGE_SIZE
    except AttributeError:
        size = 5
    paginator = Paginator(all_entries, size)

    attributes = {'deployment': deployment,
                  'assets': static,
                  'page_entries': paginator.get_page(page),
                  'menus': menus,
                  'tags': tags}

    return render(request, 'blog.html', attributes)
Exemple #5
0
def search(request):
    """The search page."""

    form = Form(request.GET, load_all=True)
    # entries = form.search()
    tags = []
    blogs = []
    # for entry in entries:
    #     if entry.model_name == 'tag':
    #         tags.append(entry)
    #     elif entry.model_name == 'entry' and entry.object.active:
    #         blogs.append(entry)
    #
    query = form.data['q']
    #
    static = get_assets("blog.header")
    deployment = get_deployment()

    attributes = {
        'deployment': deployment,
        'assets': static,
        'blogs': blogs,
        'tags': tags,
        'query': query
    }

    return render(request, 'search.html', attributes)
Exemple #6
0
def home(request):
    """Show the home page."""

    assets = get_assets(prefix="index")

    menus = create_menus(Menu.roots[0])
    logger.info(f"Retrieved {len(menus)} menu items.")

    entry_list = Entry.objects.filter(page=Entry.BLOG, active=True).reverse()
    logger.info(f"Retrieved {len(entry_list)} blog entries.")

    books = list(Text.objects.filter(reading=True))
    if books:
        logger.info(f"Reading one (or more) books: {books}.")
    else:
        logger.info("Not reading any book! So sad.")

    try:
        entry = entry_list.first()
    except IndexError:
        entry = None

    attributes = {'entry': entry,
                  'entries': entry_list[1:],
                  'books': books,
                  'menus': menus,
                  'assets': assets}

    return render(request, 'index.html', attributes)
Exemple #7
0
Fichier : tests.py Projet : jw/zink
 def test_get_prefix(self):
     """Get the generic assets and a prefix"""
     assets = get_assets(prefix="header")
     self.assertIn('rero', assets)
     self.assertIn('copyright', assets)
     self.assertIn('title', assets)
     self.assertIn('header.description', assets)
     self.assertIn('header.host', assets)
Exemple #8
0
 def test_get_prefix_and_two_extras(self):
     """Get the generic assets, a prefix set and two extras"""
     assets = get_assets('title', 'index.header', prefix="contact")
     self.assertIn('rero', assets)
     self.assertIn('copyright', assets)
     self.assertIn('title', assets)
     self.assertIn('index.header', assets)
     self.assertIn('contact.name', assets)
Exemple #9
0
 def test_get_prefix(self):
     """Get the generic assets and a prefix"""
     assets = get_assets(prefix="index")
     self.assertIn('rero', assets)
     self.assertIn('copyright', assets)
     self.assertIn('title', assets)
     self.assertIn('index.header', assets)
     self.assertIn('index.latest', assets)
     self.assertIn('index.entries', assets)
Exemple #10
0
Fichier : tests.py Projet : jw/zink
 def test_get_prefix_and_extra(self):
     """Get the generic assets, a prefix set and an extra"""
     assets = get_assets('static.author', prefix="header")
     self.assertIn('rero', assets)
     self.assertIn('copyright', assets)
     self.assertIn('title', assets)
     self.assertIn('header.description', assets)
     self.assertIn('header.host', assets)
     self.assertIn('static.author', assets)
Exemple #11
0
 def test_get_prefix_and_extra(self):
     """Get the generic assets, a prefix set and an extra"""
     assets = get_assets('contact.country', prefix="index")
     self.assertIn('rero', assets)
     self.assertIn('copyright', assets)
     self.assertIn('title', assets)
     self.assertIn('contact.country', assets)
     self.assertIn('index.header', assets)
     self.assertIn('index.latest', assets)
     self.assertIn('index.entries', assets)
Exemple #12
0
def tag(request, tag, page=1):
    """Get all entries for a specific tag."""

    static = get_assets()
    deployment = get_deployment()

    tags = Tag.objects.all()
    logger.info(f"Retrieved {len(tags)} tags.")

    menus = create_menus(Menu.roots[0])
    logger.info(f"Retrieved {len(menus)} menu items.")

    entry_list = Entry.objects.filter(active=True, tags__pk=tag).reverse()

    # create the header
    try:
        tag = Tag.objects.get(id=tag)
        static['header'] = f"{entry_list.count()} entries " \
                           f"tagged with '{tag.tag}'"
        tag_id = tag.id
    except Tag.DoesNotExist:
        static['header'] = f"Tag with id {tag} not found."
        tag_id = None

    try:
        size = settings.BLOG_PAGE_SIZE
    except AttributeError:
        logger.warning("No blog page size found in settings. Defaulting to 5.")
        size = 5
    paginator = Paginator(entry_list, size)

    # make sure page request is an int; if not, deliver the first page
    try:
        page = int(page)
    except ValueError:
        logger.debug(f"'{page}' is an invalid page number; "
                     f"showing first page.")
        page = 1

    # if page is out of range, deliver last page
    try:
        entries = paginator.page(page)
    except (EmptyPage, InvalidPage):
        entries = paginator.page(paginator.num_pages)

    attributes = {'deployment': deployment,
                  'assets': static,
                  'entries': entries,
                  'tag_id': tag_id,
                  'menus': menus,
                  'tags': tags}

    return render(request, 'tags.html', attributes)
Exemple #13
0
Fichier : views.py Projet : jw/zink
def tag(request, tag, page=1):
    """Get all entries for a specific tag."""

    static = get_assets()
    deployment = get_deployment()

    tags = Tag.objects.all()
    logger.info(f"Retrieved {len(tags)} tags.")

    entry_list = Entry.objects.filter(active=True, tags__pk=tag).reverse()

    # create the header
    try:
        tag = Tag.objects.get(id=tag)
        static['header'] = f"{entry_list.count()} entries " \
                           f"tagged with '{tag.tag}'"
        tag_id = tag.id
    except Tag.DoesNotExist:
        static['header'] = f"Tag with id {tag} not found."
        tag_id = None

    try:
        size = settings.BLOG_PAGE_SIZE
    except AttributeError:
        logger.warning("No blog page size found in settings. Defaulting to 5.")
        size = 5
    paginator = Paginator(entry_list, size)

    # make sure page request is an int; if not, deliver the first page
    try:
        page = int(page)
    except ValueError:
        logger.debug(f"'{page}' is an invalid page number; "
                     f"showing first page.")
        page = 1

    # if page is out of range, deliver last page
    try:
        entries = paginator.page(page)
    except (EmptyPage, InvalidPage):
        entries = paginator.page(paginator.num_pages)

    attributes = {'deployment': deployment,
                  'assets': static,
                  'entries': entries,
                  'tag_id': tag_id,
                  'tags': tags}

    return render(request, 'tags.html', attributes)
Exemple #14
0
def stilus(request):

    assets = get_assets(prefix="index")

    menus = create_menus(Menu.roots[0], 'stilus')
    logger.info(f"Retrieved {len(menus)} menu items.")

    stilus = Entry.objects.filter(page=Entry.STILUS, active=True)
    if stilus:
        stilus = stilus[0]
        logger.info(f"Retrieved stilus entry.")

    attributes = {'menus': menus,
                  'stilus': stilus,
                  'assets': assets}

    return render(request, 'stilus.html', attributes)
Exemple #15
0
Fichier : views.py Projet : jw/zink
def detail(request, id):
    """Get one specific entry."""

    static = get_assets(prefix="static")

    deployment = get_deployment()

    tags = Tag.objects.all()
    logger.info(f"Retrieved {len(tags)} tags.")

    entry = get_object_or_404(Entry, pk=id)

    attributes = {'deployment': deployment,
                  'assets': static,
                  'tags': tags,
                  'entry': entry}

    return render(request, 'detail.html', attributes)
Exemple #16
0
Fichier : views.py Projet : jw/zink
def contact(request):
    static = get_assets(prefix='contact')
    deployment = get_deployment()

    if request.method == 'POST':

        form = ContactForm(request.POST)

        if form.is_valid():

            email = form.cleaned_data['email']
            subject = form.cleaned_data['subject']
            message = form.cleaned_data['message']

            try:
                send_mail(f"[ZINK] {subject}", message, '*****@*****.**',
                          [email], fail_silently=False)
            except BadHeaderError:
                messages.warning(request, "Invalid header found!")

            # show success message to user
            highlight = "<strong>Thanks for your message!</strong>"
            question = "Want to send another one?"
            messages.success(request, f"{highlight} {question}")

            return HttpResponseRedirect(reverse('contact:contact'))

        # else:
        #     # report invalid form
        #     warning = "Form is invalid.  Please check carefully."
        #     messages.warning(request, warning)

    else:
        form = ContactForm()  # create an empty form

    attributes = {'deployment': deployment,
                  'assets': static,
                  'contact': contact,
                  'key': settings.GOOGLE_MAPS_KEY,
                  'form': form}

    return render(request, 'contact.html', attributes)
Exemple #17
0
def contact(request):
    static = get_assets(prefix='contact')
    deployment = get_deployment()

    menus = create_menus(Menu.roots[0], 'contact')
    logger.info(f"Retrieved {len(menus)} menu items.")

    if request.method == 'POST':

        form = ContactForm(request.POST, error_class=UiKitErrorList)
        if form.is_valid():

            email = form.cleaned_data['email']
            subject = form.cleaned_data['subject']
            message = form.cleaned_data['message']

            try:
                send_mail(f"[ZINK] {subject}", message, '*****@*****.**',
                          [email], fail_silently=False)
            except BadHeaderError:
                messages.warning(request, "Invalid header found!")

            # show success message to user
            highlight = "<strong>Thanks for your message!</strong>"
            question = "Want to send another one?"
            messages.success(request, f"{highlight} {question}")

            return HttpResponseRedirect(reverse('contact:contact'))

    else:
        form = ContactForm()  # create an empty form

    attributes = {'deployment': deployment,
                  'assets': static,
                  'contact': contact,
                  'menus': menus,
                  'key': settings.GOOGLE_MAPS_KEY,
                  'form': form}

    return render(request, 'contact.html', attributes)
Exemple #18
0
def detail(request, id):
    """Get one specific entry."""

    static = get_assets(prefix="static")

    deployment = get_deployment()

    tags = Tag.objects.all()
    logger.info(f"Retrieved {len(tags)} tags.")

    menus = create_menus(Menu.roots[0])
    logger.info(f"Retrieved {len(menus)} menu items.")

    entry = get_object_or_404(Entry, pk=id)

    attributes = {'deployment': deployment,
                  'assets': static,
                  'tags': tags,
                  'menus': menus,
                  'entry': entry}

    return render(request, 'detail.html', attributes)
Exemple #19
0
Fichier : views.py Projet : jw/zink
def blog(request, page=1):
    """Get all blog entries for a specific page."""

    static = get_assets()
    deployment = get_deployment()

    tags = Tag.objects.all()
    logger.info(f"Retrieved {len(tags)} tags.")

    all_entries = Entry.objects.filter(active=True).reverse()
    logger.info(f"Retrieved total of {len(all_entries)} blog entries.")

    try:
        size = settings.BLOG_PAGE_SIZE
    except AttributeError:
        size = 5
    paginator = Paginator(all_entries, size)

    attributes = {'deployment': deployment,
                  'assets': static,
                  'page_entries': paginator.get_page(page),
                  'tags': tags}

    return render(request, 'blog.html', attributes)