Skip to content

Commit

Permalink
Merge pull request #110 from pinax/pinax-images-req
Browse files Browse the repository at this point in the history
Restore and update guidance for pinax-images usage
  • Loading branch information
grahamu authored Feb 21, 2018
2 parents 049944b + 1203e59 commit 5e92a0d
Show file tree
Hide file tree
Showing 7 changed files with 128 additions and 28 deletions.
37 changes: 35 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,13 @@ To install pinax-blog:
$ pip install pinax-blog
```

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

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

Expand All @@ -110,7 +111,35 @@ Add `pinax.blog.urls` to your project urlpatterns:
]
```

Optionally, if you want `creole` support for a mark up choice:
### 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:

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

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

```python
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:

```shell
$ pip install creole
Expand Down Expand Up @@ -363,6 +392,10 @@ Both templates ship already configured to work out of the box.

## Change Log

### 7.0.2

* Restore and improve documentation guidance for pinax-images usage

### 7.0.1

* Replace pinax-theme-bootstrap test dependency with pinax-templates
Expand Down
24 changes: 12 additions & 12 deletions pinax/blog/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,13 +120,24 @@ class PostForm(PostFormMixin, forms.ModelForm):
teaser = forms.CharField(widget=forms.Textarea())
content = forms.CharField(widget=forms.Textarea())

class Meta:
model = Post
fields = [
"section",
"title",
"teaser",
"content",
"description",
"state"
]

def __init__(self, *args, **kwargs):
super(PostForm, self).__init__(*args, **kwargs)
if Section.objects.count() < 2:
self.section = Section.objects.first()
del self.fields["section"]
else:
self.section is None
self.section = None

def save(self, blog=None, author=None):
post = super(PostForm, self).save(commit=False)
Expand All @@ -140,14 +151,3 @@ def save(self, blog=None, author=None):
post.slug = slugify(post.title)
post.markup = self.markup_choice
return self.save_post(post)

class Meta:
model = Post
fields = [
"section",
"title",
"teaser",
"content",
"description",
"state"
]
9 changes: 9 additions & 0 deletions pinax/blog/tests/templates/site_base.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<div>
{% block head_title %}
Title
{% endblock %}
</div>
<div>
{% block body %}
{% endblock %}
</div>
55 changes: 46 additions & 9 deletions pinax/blog/tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

import random

from django.contrib.auth import get_user_model
from django.core.exceptions import ValidationError
from django.http.request import HttpRequest
from django.test import TestCase
from django.urls import reverse
from django.utils.text import slugify

from test_plus import TestCase

from ..context_processors import scoped
from ..models import Blog, Post, Section

Expand All @@ -29,12 +29,7 @@ def setUp(self):
self.apples = Section.objects.create(name="Apples", slug="apples")
self.oranges = Section.objects.create(name="Oranges", slug="oranges")

self.password = "eldarion"
self.user = get_user_model().objects.create_user(
username="patrick",
password=self.password
)
self.user.save()
self.user = self.make_user("patrick")
self.markup = "markdown"

# Create two published Posts, one in each section.
Expand Down Expand Up @@ -68,7 +63,7 @@ def test_invalid_section_slug(self):
invalid_slug = "bananas"
url = reverse("pinax_blog:blog_section", kwargs={"section": invalid_slug})
try:
response = self.client.get(url)
response = self.get(url)
except Section.DoesNotExist:
self.fail("section '{}' does not exist".format(invalid_slug))
self.assertEqual(response.status_code, 404)
Expand Down Expand Up @@ -140,3 +135,45 @@ def test_no_resolver_match(self):
self.assertEqual(request.resolver_match, None)
result = scoped(request)
self.assertEqual(result, {"scoper_lookup": ""})


class TestViews(TestBlog):

def test_manage_post_create_get(self):
"""
Ensure template with external URL references renders properly
for user with proper credentials.
"""
with self.login(self.user):
response = self.client.get("pinax_blog:manage_post_create")
self.assertEqual(response.status_code, 404)

self.user.is_staff = True
self.user.save()
with self.login(self.user):
self.get("pinax_blog:manage_post_create")
self.response_200()
self.assertTemplateUsed("pinax/blog/manage_post_create")
pinax_images_upload_url = reverse("pinax_images:imageset_new_upload")
self.assertResponseContains(pinax_images_upload_url, html=False)

def test_manage_post_create_post(self):
"""
Ensure template with external URL references renders properly
for user with proper credentials.
"""
self.user.is_staff = True
self.user.save()
post_title = "You'll never believe what happened next!"
post_data = dict(
section=self.apples.pk,
title=post_title,
teaser="teaser",
content="content",
description="description",
state=Post.STATE_CHOICES[-1][0],
)
with self.login(self.user):
self.post("pinax_blog:manage_post_create", data=post_data)
self.assertRedirects(self.last_response, reverse("pinax_blog:manage_post_list"))
self.assertTrue(Post.objects.get(title=post_title))
1 change: 1 addition & 0 deletions pinax/blog/tests/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@

urlpatterns = [
url(r"^", include("pinax.blog.urls", namespace="pinax_blog")),
url(r"^ajax/images/", include("pinax.images.urls", namespace="pinax_images")),
]
19 changes: 18 additions & 1 deletion runtests.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,19 @@
INSTALLED_APPS=[
"django.contrib.auth",
"django.contrib.contenttypes",
"django.contrib.sessions",
"django.contrib.sites",
"pinax.images",

"bootstrapform",
"pinax.blog",
"pinax.blog.tests",
"pinax.images",
"pinax.templates",
],
MIDDLEWARE=[
"django.contrib.sessions.middleware.SessionMiddleware",
"django.contrib.auth.middleware.AuthenticationMiddleware",
],
DATABASES={
"default": {
"ENGINE": "django.db.backends.sqlite3",
Expand All @@ -30,11 +37,21 @@
TEMPLATES=[
{
"BACKEND": "django.template.backends.django.DjangoTemplates",
"DIRS": [
os.path.join(PACKAGE_ROOT, "templates"),
],
"APP_DIRS": True,
"OPTIONS": {
"debug": True,
"context_processors": [
"django.contrib.auth.context_processors.auth",
"django.template.context_processors.debug",
"django.template.context_processors.i18n",
"django.template.context_processors.media",
"django.template.context_processors.static",
"django.template.context_processors.tz",
"django.template.context_processors.request",
"django.contrib.messages.context_processors.messages",
]
}
},
Expand Down
11 changes: 7 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from setuptools import find_packages, setup

VERSION = "7.0.1"
VERSION = "7.0.2"
LONG_DESCRIPTION = """
.. image:: http://pinaxproject.com/pinax-design/patches/pinax-blog.svg
:target: https://pypi.python.org/pypi/pinax-blog/
Expand Down Expand Up @@ -97,13 +97,16 @@
install_requires=[
"django>=1.11",
"django-appconf>=1.0.1",
"markdown>=2.6.5",
"pillow>=3.0.0",
"pinax-images>=3.0.1",
"pygments>=2.0.2",
"pytz>=2016.6.1",
"Pillow>=3.0.0",
"Markdown>=2.6.5",
"Pygments>=2.0.2",
],
tests_require=[
"django-bootstrap-form>=3.0.0",
"django-test-plus>=1.0.22",
"mock>=2.0.0",
"pinax-templates>=1.0.0",
],
test_suite="runtests.runtests",
Expand Down

0 comments on commit 5e92a0d

Please sign in to comment.