Git Product home page Git Product logo

pinax-blog's Introduction

Pinax Blog

CircleCi Codecov

Table of Contents

About Pinax

Pinax is an open-source platform built on the Django Web Framework. It is an ecosystem of reusable Django apps, themes, and starter project templates. This collection can be found at http://pinaxproject.com.

Important Links

Where you can find what you need:

pinax-blog

Overview

pinax-blog is a blog app for Django.

Features

Current features include:

  • support for multiple channels (e.g. technical vs business)
  • use of Creole (optional) and Markdown as markup format
  • Atom and RSS feeds
  • previewing of blog posts before publishing
  • optional ability to announce new posts on twitter
  • Traditional date based urls or simpler slug-only urls, via configuration
  • Control over opengraph and twitter card meta data per post
  • Review comments per post for multi-author workflows
  • public but secret urls for unpublished blog posts for easier review

Dependencies

  • django-appconf
  • pytz
  • pillow
  • markdown
  • pygments
  • pinax-images

See setup.py for specific required versions of these packages.

Supported Django and Python Versions

Django / Python 3.6 3.7 3.8
2.2 * * *
3.0 * * *

Documentation

Installation

To install pinax-blog:

    $ pip install pinax-blog

Add pinax.blog and dependency pinax.images to your INSTALLED_APPS setting:

    INSTALLED_APPS = [
        # other apps
        "pinax.blog",
        "pinax.images",
    ]

Add pinax.blog.urls to your project urlpatterns:

    urlpatterns = [
        # other urls
        url(r"^blog/", include("pinax.blog.urls", namespace="pinax_blog")),
    ]

Optional Requirements

pinax-blog ships with a few management view templates. These templates reference pinax-images URLs for adding and viewing images. They also use "bootstrap" formatting.

In order to use these built-in templates, add django-bootstrap-form to your project requirements and "bootstrapform", to your INSTALLED_APPS:

    INSTALLED_APPS = [
        # other apps
        "pinax.blog",
        "pinax.images",
        "bootstrapform",
    ]

Then add pinax.images.urls to your project urlpatterns:

    urlpatterns = [
        # other urls
        url(r"^blog/", include("pinax.blog.urls", namespace="pinax_blog")),
        url(r"^ajax/images/", include("pinax.images.urls", namespace="pinax_images")),
    ]

If you want creole support for mark-up:

    $ pip install creole

NOTE: the creole package does not support Python 3.

Usage

As an author, you work with this app via the Django Admin.

You can customize the editor for the admin at the site level or just use the stock text areas.

The description field in the admin represents the text that will be used in different HTML META header tags that are useful for controlling the display on social networks like Twitter and Facebook.

This is the same idea behind the primary_image field in the admin.

Images

There are custom markdown and creole extensions for embedding images that have been uploaded via the inline on the post create or edit form in the admin.

You first upload the image or images you want to use in the post by selecting them in the file selector in the images section, and then hitting "Save and Continue Editing". Once the form reloads, you'll see indicators above each uploaded image with a number between two brackets, e.g. {{ 25 }}.

This is the syntax if you are using creole for adding that image to your post. You can just copy and paste that.

If you are using markdown however, you will need to use the following markup in your post:

![Alt Text](25)

or without alt text:

![](25)

Adjusting for the number of the image, of course.

Settings

PINAX_BLOG_SCOPING_MODEL

String in the format "app.Model" that will set a ForeignKey on the blog.Post model

PINAX_BLOG_SCOPING_URL_VAR

URL variable name used in your url prefix that will allow you to look up your scoping object

PINAX_BLOG_HOOKSET

A hookset pattern common to other Pinax apps. Just a single method: get_blog(self, **kwargs) is defined. Override this in your project to the Blog object that will scope your posts. By default there is only one Blog instance and that is returned.

Scoping

The idea of scoping allows you to setup your project to have multiple blogs partitioned by whatever domain object you would like.

Add pinax.blog.context_processors.scoped to your context processors to put scoper_lookup in templates for url reversing.

Example

To demonstrate how to set all this up let's walk through an example where we will scope by auth.User so that each user has their own blog at /users/:username/.

First we will modify the settings.py:

# ... abbreviated for clarity

TEMPLATES = [
    {
        # ...
        "OPTIONS": {
            # ...
            "context_processors": [
                # ...
                "pinax.blog.context_processors.scoped"
            ],
        },
    },
]

PINAX_BLOG_SCOPING_URL_VAR = "username"
PINAX_BLOG_SCOPING_MODEL = "auth.User"
PINAX_BLOG_HOOKSET = "multiblog.hooks.HookSet"  # where `multiblog` is the package name of our project

Now, we'll add the url in urls.py:

url(r"^users/(?P<username>[-\w]+)/", include("pinax.blog.urls", namespace="pinax_blog"))

And finally we'll implement our hookset by adding a hooks.py:

from django.contrib.auth.models import User


class HookSet(object):

    def get_blog(self, **kwargs):
        username = kwargs.get("username", None)
        return User.objects.get(username=username).blog

This is designed to work out of the box with templates in pinax-theme-bootstrap so you can either use them directly or use them as a reference. If you need to reverse a URL for any of the pinax-blog urls you can simply do:

{% url "pinax_blog:blog" scoper_lookup %}

Customizing Admin

Customizing the admin functionality can be as complex as overriding the ModelAdmin and ModelForm that ships with pinax-blog or as simple as just overriding the admin/blog/post/change_form.html template.

Here is an example of an actual customization to use the ACE Editor for teaser and body content:

{% extends "admin/change_form.html" %}
{% load i18n admin_urls %}
{% block extrahead %}
    {{ block.super }}
    <script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
    <script src="//cdnjs.cloudflare.com/ajax/libs/ace/1.1.8/ace.js"></script>
    <script>
    $(function () {
        var contentDiv = $("<div>").attr("id", "content-editor"),
            teaserDiv = $("<div>").attr("id", "teaser-editor"),
            setupEditor = function (editor, textarea) {
                editor.setTheme("ace/theme/twilight");
                editor.getSession().setMode("ace/mode/markdown");
                editor.getSession().setValue(textarea.val());
                editor.getSession().setUseWrapMode(true);
                editor.getSession().on('change', function(){
                  textarea.val(editor.getSession().getValue());
                });
                editor.getSession().setTabSize(4);
                editor.getSession().setUseSoftTabs(true);
            };
        $(".field-content div").append(contentDiv);
        $(".field-teaser div").append(teaserDiv);
        var editor1 = ace.edit("content-editor");
        var editor2 = ace.edit("teaser-editor");
        var textarea1 = $('textarea[name="content"]').hide();
        var textarea2 = $('textarea[name="teaser"]').hide();
        setupEditor(editor1, textarea1);
        setupEditor(editor2, textarea2);
    });
    </script>
    <style type="text/css" media="screen">
    #content-editor {
        min-height: 300px;
        width: 80%;
        min-width: 800px;
    }
    #teaser-editor {
        min-height: 100px;
        width: 80%;
        min-width: 800px;
    }
</style>
{% endblock %}

Templates

Default templates are provided by the pinax-templates app in the blog section of that project.

Reference pinax-templates installation instructions to include these templates in your project.

View live pinax-templates examples and source at Pinax Templates!

Customizing Templates

Override the default pinax-templates templates by copying them into your project subdirectory pinax/blog/ on the template path and modifying as needed.

For example if your project doesn't use Bootstrap, copy the desired templates then remove Bootstrap and Font Awesome class names from your copies. Remove class references like class="btn btn-success" and class="icon icon-pencil" as well as bootstrap from the {% load i18n bootstrap %} statement. Since bootstrap template tags and filters are no longer loaded, you'll also need to update {{ form|bootstrap }} to {{ form }} since the "bootstrap" filter is no longer available.

blog_base.html

blog_list.html

BlogIndexView and SectionIndexView both render the template pinax/blog/blog_list.html with post_list, search_query, current_section context variables, where current_section is either a Section object or the string "all".

The post_list variable is a queryset of current blog posts. If the GET parameter, q is found, it filters the queryset create a simple search mechanism, then assigns the value to search_query.

blog_post.html

The four blog detail views (DateBasedPostDetailView, SecretKeyPostDetailView, SlugUniquePostDetailView, and StaffPostDetailView) all render the template pinax/blog/blog_post.html with the post and current_section context variables.

The post is the requested post. It may or may not be public depending on the url requested.

dateline.html

dateline_stale.html

Blog Feed Templates

atom_feed.xml and rss_feed.xml

The url blog_feed will either render pinax/blog/atom_feed.xml or pinax/blog/rss_feed.xml depending on the parameters in the URL. It will pass both templates the context variables of feed_id, feed_title, blog_url, feed_url, feed_updated, entries, and current_site.

Both templates ship already configured to work out of the box.

Change Log

8.0.1

  • Change from django.utils.functional import curry to from functools import partial as curry

8.0.0

  • Drop Django 1.11, 2.0, and 2.1, and Python 2,7, 3.4, and 3.5 support
  • Add Django 2.2 and 3.0, and Python 3.6, 3.7, and 3.8 support
  • Update packaging configs
  • Direct users to community resources

7.0.5

  • Enable installation of both .html and .xml template files via egg

7.0.4-image-reenabled

  • Reenable imagesets to be inline in the post creation
  • Fix Markdown 3 installation exception by changing to 2.6.11 which is the latest working version

7.0.3

  • Fix migration missing on_delete=

7.0.2

  • Restore and improve documentation guidance for pinax-images usage

7.0.1

  • Replace pinax-theme-bootstrap test dependency with pinax-templates

7.0.0

  • Add Django 2.0 compatibility testing
  • Drop Django 1.8, 1.9, 1.10 and Python 3.3 support
  • Move documentation into README, and standardize layout
  • Convert CI and coverage to CircleCi and CodeCov
  • Add PyPi-compatible long description
  • Bump minimum required version of pinax-images to v3.0.0 for Django 2.0 compatibility

6.3.1

  • Bump minimum required version of pinax-images

6.3.0

  • Add image support in admin

6.2.0

  • Make the js inclusions a setting

6.1.1

  • remove inadvertently included IDE file

6.1.0

  • Add Django 2.0 compatibility testing
  • Drop Django 1.9 and Python 3.3 support
  • Move documentation into README
  • Convert CI and coverage to CircleCi and CodeCov
  • Add PyPi-compatible long description

6.0.3

  • scoped context processor handles case when request.resolver_match is None

6.0.2

  • increased max_length of Post.slug field from 50 to 90 chars, matching Post.title field length.

6.0.1

  • fix templatetag scoping

6.0.0

  • added support for frontend editing
  • removed twitter integrations
  • swapped out internal image management for pinax-images
  • added a Blog scoping model and enabled site defined one to one relationship custom site-defined scoping.

5.0.2

5.0.1

  • Fixed feed_url creation in blog_feed view (PR #82)
  • Updated docs to use url namespace (PR #87)

5.0.0

  • Initial version for core distribution

History

This app was named biblion when originally developed by Eldarion, Inc. After donation to Pinax, the app was renamed to pinax-blog, making it easier to find and know what it is.

Contribute

Contributing information can be found in the Pinax community health file repo.

Code of Conduct

In order to foster a kind, inclusive, and harassment-free community, the Pinax Project has a Code of Conduct. We ask you to treat everyone as a smart human programmer that shares an interest in Python, Django, and Pinax with you.

Connect with Pinax

For updates and news regarding the Pinax Project, please follow us on Twitter @pinaxproject and check out our Pinax Project blog.

License

Copyright (c) 2012-present James Tauber and contributors under the MIT license.

pinax-blog's People

Contributors

alexissantos avatar arthur-wsw avatar brosner avatar chrisgemignani avatar doktormerlin avatar flaviabastos avatar garcianavalon avatar gitter-badger avatar gnunicorn avatar grahamu avatar hugodby avatar huwshimi avatar issackelly avatar joeydi avatar jpwku avatar jtauber avatar katherinemichel avatar lukeman avatar mfonism avatar miurahr avatar neilmillard avatar paltman avatar rizumu avatar swilcox avatar vleong2332 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pinax-blog's Issues

settings.AUTH_USER_MODEL

I am getting an error regarding the user model used:
blog.Post.author: (fields.E301) Field defines a relation with the model 'auth.User', which has been swapped out.
HINT: Update the relation to point at 'settings.AUTH_USER_MODEL'.
blog.Revision.author: (fields.E301) Field defines a relation with the model 'auth.User', which has been swapped out.
HINT: Update the relation to point at 'settings.AUTH_USER_MODEL'.

This setting defaults to django's default user model, but is preferred to support custom users: https://docs.djangoproject.com/en/1.8/topics/auth/customizing/#substituting-a-custom-user-model

Provide help for title and description

It's ideal to have titles no longer than 60 characters and meta descriptions no longer than 150 characters.

We should at least provide that help text in the admin, but ideally we should provide a character counter that decrements as you type.

Improve markdown image support

  • add sample markup for markdown in the help text of each image inline (currently just defaults to creole sample)
  • make sure that normally linked images work as well so that external images can be used in the markdown

Add RSS feed

Some forms of integration only support RSS. We should offer both feed types, not just ATOM.

Missing template files

I've got latest version from git today, but after i tried to setup biblion app and run it - i got -

Exception Type: TemplateDoesNotExist
Exception Value: biblion/blog_list.html

and this file is really missing. Could you please add this and other templates to repo.
Thanks for you job !

Fix migration for unique slugs

the PINAX_BLOG_SLUG_UNIQUE setting when set to True, causes a migration to be generated after install. the migrations that ship with pinax-blog were created with the default settings which is False.

perhaps the migration should be edited to be dynamic based on that setting. that doesn't handle the case where you might want to switch after you have installed but could handle the case where you know what you want from the start.

NoReverseMatch hitting feed

After a recent upgrade, I'm getting:

NoReverseMatch: Reverse for '('pinax_blog:blog_feed',)' with arguments '()' and keyword arguments '{'section': 'all', 'feed_type': u'atom'}' not found. 0 pattern(s) tried: []

hitting the feed.

The problem seems to be line 171 in views.py:

 feed_url = "http://%s%s" % (current_site.domain, reverse(url_name, kwargs=kwargs)) 

Make the primary image selection easier

Currently it's a dropdown with image pks. It should at least have the image file names, but even better would be some type of AJAX image browser in the admin that you could just select the thumbnail.

obscure URLs for unauth'd review

At the moment an unpublished blog post can be reviewed by an auth'd user but it would be nice if they could be viewed by unauth'd users at obscure URLs too.

Make sections something that is modeled rather than a setting

A model like:

class Section(models.Model):
    name = models.CharField(max_length=150)
    slug = models.SlugField(unique=True)

That the Post model would have a FK to instead of just storing integers that are calculated from the position of a section in the list, would make it a lot easier to add a section to the blog in run time.

I realize that this isn't something that happens frequently, but it just seems cleaner.

Assume HTML in summary

to fix #60 we changed content to be html but I've just found a case where I had to make the summary html too. Similar change but to summary element

RuntimeErorr on the very first migration

When running the first migration after installing, this error was thrown:

RuntimeError: Model class django.contrib.sites.models.Site doesn't declare an explicit app_label and isn't in a
n application in INSTALLED_APPS.

I had to add django.contrib.sites to the INSTALLED_APPS and set SITE_ID = 1 in settings.py.

Is this related to #69?

Allow setting of publication date other than now

At the moment if I want the publication date (e.g. what's shown in the dateline and, in many cases, the URL) to be other than when I actually switched it from "draft" to "published", I have to use the shell.

It would be nice if there was a way to publish with a datetime other than now.

Broken dependencies?

Hello people,

i'm having this problem with creole.

I've installed the dependencies, but can't import creole.Parser.

What's going on? Has the library changed?

NoReverseMatch at /admin/blog/post/

Hi,

I have installed the last version of Pinax and I'm getting an error in the admin page. If I try to access /admin/blog/post/ I get aNoReverseMatch u'pinax_blog' is not a registered namespace. I only get this error in the /post/ sections, the rest are working fine.

I have the following code:
At settings.py

INSTALLED_APPS = (
    ...
    'pinax.blog',
...
)

at urls.py
url(r"^blog/", include("pinax.blog.urls")),
I have also done a python manage.py migrate.

Any idea of whats going on? The rest of the sections work perfectly.
Cheers

captura de pantalla 2016-07-10 a las 18 00 07
captura de pantalla 2016-07-10 a las 18 00 27

atom feed template assumes xhtml which is dangerous

It's easy to get an invalid feed if someone has non-xml html in their content. However, the fix is also easy, just use:

<content type="html" xml:lang="en">
    {{ entry.teaser_html }}
    {{ entry.content_html }}
</content>

Missing templates

There appears to be no base template examples, such as the ones referenced in views.py :
biblion/blog_list.html
biblion/blog_section_list.html

get working with Python 3

The problem seems to be the creole library which hasn't been updated in 5 years! I'm happy to deprecate its use but perhaps as a start we should not require it.

Can't run app

I keep getting a
RuntimeError: Model class django.contrib.sites.models.Site doesn't declare an explicit app_label and isn't in an application in INSTALLED_APPS. whenever I tried to run the app.

I followed the exact instructions on the docs, installed deps and did not install creole since I'm using py3.

Any ideas?

Django 1.9.2
Py 3.4.3

Installing with easy_install

I couldn't install biblion using easy_install with:

easy_install biblion

But I've figured it could be done this way instead:

easy_install https://github.com/eldarion/biblion/tarball/master#egg=0.1.dev10.1

Perhaps this should be added to the docs

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.