Skip to content

Commit

Permalink
Merge pull request #42 from pinax/django-20
Browse files Browse the repository at this point in the history
Update for Django v2.0
  • Loading branch information
grahamu committed Jan 20, 2018
2 parents 1101fc5 + d7f973d commit a682af6
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 36 deletions.
3 changes: 1 addition & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ common: &common
- restore_cache:
keys:
- v2-deps-{{ .Environment.CIRCLE_JOB }}-{{ checksum "setup.py" }}-{{ checksum "tox.ini" }}
- v2-deps-
- run:
name: install dependencies
command: pip install --user tox
Expand Down Expand Up @@ -35,7 +34,7 @@ jobs:
lint:
<<: *common
docker:
- image: circleci/python:3.6.1
- image: circleci/python:3.6
environment:
- TOXENV=checkqa
- UPLOAD_COVERAGE=0
Expand Down
9 changes: 2 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
all: init docs test
all: init test

init:
python setup.py develop
pip install detox coverage mkdocs
pip install detox coverage

test:
coverage erase
detox
coverage html

docs:
mkdocs build

.PHONY: docs
67 changes: 50 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,23 +54,33 @@ Django \ Python | 2.7 | 3.4 | 3.5 | 3.6

To install pinax-ratings:

pip install pinax-ratings
```shell
$ pip install pinax-ratings
``

Add ``pinax-ratings`` to your ``INSTALLED_APPS`` setting:

INSTALLED_APPS = (
```python
INSTALLED_APPS = [
# other apps
"pinax.ratings",
)
]
```

See the list of [`settings`](#settings) to modify pinax-ratings's default behavior and make adjustments for your website.
Next add `pinax.ratings.urls` to your urls definition:

Lastly you will want to add `pinax-ratings.urls` to your urls definition:
```python
urlpatterns = [
# other urls
url(r"^ratings/", include("pinax.ratings.urls", namespace="pinax_ratings")),
]
```

url(r"^ratings/", include("pinax.ratings.urls")),
Finally, view the list of [settings](#settings) to modify pinax-ratings's default behavior and make adjustments for your website.

Optionally, if want to use the ratings category feature of `pinax-ratings` then you will need to add the `pinax-RATINGS_CATEGORY_CHOICES` setting in your `settings.py`:

```python
PINAX_RATINGS_CATEGORY_CHOICES = {
"app.Model": {
"exposure": "How good is the exposure?",
Expand All @@ -83,7 +93,9 @@ Optionally, if want to use the ratings category feature of `pinax-ratings` then
"compelling": "Is the article compelling?"
}
}
```


### Usage

Integrating `pinax-ratings` into your project is just a matter of using a couple of
Expand All @@ -92,71 +104,85 @@ to function via AJAX and as such returns JSON.

Firstly, add load the template tags for `pinax-ratings`:

```django
{% load pinax_ratings_tags %}

```

Then, if you want to display an overall rating average for an object you can set
a context variable and display it:

```django
{% overall_rating obj as the_overall_rating %}
<div class="overall_rating">{{ the_overall_rating }}</div>
```


Likewise for displaying a user's rating:
```django
{% user_rating request.user obj as the_user_rating %}
<div class="user_rating">{{ the_user_rating }}</div>
```
If you want to add an AJAX form for allowing a user to set a rating, add the
following in the appropriate location on your page:
```django
<div id="user_rating"></div>

```
And then add this near the end of your HTML `<body>` to emit some Javascript
libraries and hook up the ratings UI:
```django
{% user_rating_js request.user obj %}
```
If you want to do any rating based on categories of ratings for an object or
objects then you do the same as above but just use an optional argument on
the tags:
```django
{% overall_rating obj "accuracy" as category_rating %}
<div class="overall_rating category-accuracy">
{{ category_rating }}
</div>
```
and
```django
{% user_rating request.user obj "accuracy" as category_rating %}
<div class="user_rating category-accuracy">
{{ category_rating }}
</div>
```
and
```django
<div id="user_rating" class="category-accuracy"></div>
{% user_rating_js request.user obj "accuracy" %}
```
### Settings
_pinax_ratings_num_of_ratings:

PINAX_RATINGS_NUM_OF_RATINGS
#### PINAX_RATINGS_NUM_OF_RATINGS
Default: 5
Defines the number of different rating choices there will be.
PINAX_RATINGS_CATEGORY_CHOICES
#### PINAX_RATINGS_CATEGORY_CHOICES
Default: `None`
Expand All @@ -168,6 +194,7 @@ It should follow the format of a dictionary of dictionaries. For example, think
the context of a website that allowed ratings of photographs and articles
published by other users:
```python
PINAX_RATINGS_CATEGORY_CHOICES = {
"app.Model": {
"exposure": "How good is the exposure?",
Expand All @@ -180,13 +207,18 @@ published by other users:
"compelling": "Is the article compelling?"
}
}
```
### Templates
`pinax-ratings` comes with one template that is a minimal snippet that gets rendered
from the template tags for displaying the rating form.
`pinax-ratings` comes with two minimal template snippets rendered
by template tags for displaying the rating form.
Templates are found in "pinax/ratings/" subdirectory for your project.
#### `_rating.html`
#### _script.html
#### `_script.html`
This is a snippet that renders the bundled Javascript and a simple AJAX posting and
hooking up of a rating UI. This is optional and overridable by the site developer.
Expand All @@ -198,6 +230,7 @@ hooking up of a rating UI. This is optional and overridable by the site develope
* Add Django 2.0 compatibility testing
* Drop Django 1.8, 1.9, 1.10, and Python 3.3 support
* Add URL namespacing (BI: urlname "pinax_ratings_rate" is now "pinax_ratings:rate")
* Move documentation into README and standardize layout
* Convert CI and coverage to CircleCi and CodeCov
* Add PyPi-compatible long description
Expand Down Expand Up @@ -285,4 +318,4 @@ and check out our [Pinax Project blog](http://blog.pinaxproject.com).
## License
Copyright (c) 2012-2018 James Tauber and contributors under the [MIT license](https://opensource.org/licenses/MIT).
Copyright (c) 2012-2018 James Tauber and contributors under the [MIT license](https://opensource.org/licenses/MIT).
2 changes: 1 addition & 1 deletion pinax/ratings/tests/urls.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from django.conf.urls import include, url

urlpatterns = [
url(r"^", include("pinax.ratings.urls")),
url(r"^", include("pinax.ratings.urls", namespace="pinax_ratings")),
]
5 changes: 4 additions & 1 deletion pinax/ratings/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

from pinax.ratings import views

app_name = "pinax_ratings"


urlpatterns = [
url(r"^(?P<content_type_id>\d+)/(?P<object_id>\d+)/rate/$", views.RateView.as_view(), name="pinax_ratings_rate"),
url(r"^(?P<content_type_id>\d+)/(?P<object_id>\d+)/rate/$", views.RateView.as_view(), name="rate"),
]
1 change: 0 additions & 1 deletion runtests.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
"pinax.ratings",
"pinax.ratings.tests"
],
MIDDLEWARE_CLASSES=[],
DATABASES={
"default": {
"ENGINE": "django.db.backends.sqlite3",
Expand Down
5 changes: 3 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from setuptools import find_packages, setup

VERSION = "3.0.0"
LONG_DESCRIPTION = """
.. image:: http://pinaxproject.com/pinax-design/patches/pinax-ratings.svg
:target: https://pypi.python.org/pypi/pinax-ratings/
Expand Down Expand Up @@ -53,7 +54,7 @@
description="a ratings app for Django",
name="pinax-ratings",
long_description=LONG_DESCRIPTION,
version="3.0.0",
version=VERSION,
url="http://github.com/pinax/pinax-ratings/",
license="MIT",
packages=find_packages(),
Expand Down Expand Up @@ -83,8 +84,8 @@
"Topic :: Software Development :: Libraries :: Python Modules",
],
install_requires=[
"django>=1.11",
"django-user-accounts>=2.0.3",
"Django>=1.8"
],
tests_require=[
],
Expand Down
11 changes: 6 additions & 5 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,25 @@
ignore = E265,E501
max-line-length = 100
max-complexity = 10
exclude = pinax/ratings/migrations/*
exclude = **/*/migrations/*
inline-quotes = double

[isort]
multi_line_output=3
known_django=django
known_third_party=pinax
known_third_party=account,pinax
sections=FUTURE,STDLIB,DJANGO,THIRDPARTY,FIRSTPARTY,LOCALFOLDER
skip_glob=*/pinax/ratings/migrations/*
include_trailing_comma=True
skip_glob=**/*/migrations/*

[coverage:run]
source = pinax
omit = pinax/ratings/conf.py,pinax/ratings/tests/*,pinax/ratings/migrations/*
omit = **/*/conf.py,**/*/tests/*,**/*/migrations/*
branch = true
data_file = .coverage

[coverage:report]
omit = pinax/ratings/conf.py,pinax/ratings/tests/*,pinax/ratings/migrations/*
omit = **/*/conf.py,**/*/tests/*,**/*/migrations/*
exclude_lines =
coverage: omit
show_missing = True
Expand Down

0 comments on commit a682af6

Please sign in to comment.