From 0905a03248fd0c21e37019e57706872f0a304259 Mon Sep 17 00:00:00 2001 From: agusmakmun Date: Tue, 14 Aug 2018 05:51:09 +0700 Subject: [PATCH 1/5] issue #33 --- updown/models.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/updown/models.py b/updown/models.py index 7725fd0..00dc2e1 100644 --- a/updown/models.py +++ b/updown/models.py @@ -31,7 +31,7 @@ class Vote(models.Model): date_added = models.DateTimeField(default=timezone.now, editable=False) date_changed = models.DateTimeField(default=timezone.now, editable=False) - content_object = GenericForeignKey() + content_object = GenericForeignKey('content_type', 'object_id') class Meta: unique_together = (('content_type', 'object_id', 'key', 'user', From cd05d878ecb3fa4add94b2134947e4eba456f63b Mon Sep 17 00:00:00 2001 From: agusmakmun Date: Thu, 17 Sep 2020 18:02:30 +0700 Subject: [PATCH 2/5] upgrade --- .gitignore | 3 +- .travis.yml | 17 ++++----- README.md | 60 ++++++++++++++++++------------- setup.py | 6 ++-- tests/test_model.py | 6 ++-- updown/__init__.py | 2 +- updown/migrations/0001_initial.py | 2 +- updown/models.py | 4 +-- 8 files changed, 53 insertions(+), 47 deletions(-) diff --git a/.gitignore b/.gitignore index 263fd6e..1956a6e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,8 @@ *.pyc dist/ build/ -django_updown.egg-info/ +*.egg-info/ env/ .cache/ .tox/ +*backup* diff --git a/.travis.yml b/.travis.yml index a36a250..9df82ff 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,27 +2,22 @@ language: python cache: pip python: - - "2.7" - "3.4" - "3.5" + - "3.6" + - "3.7" + - "3.8" sudo: false env: - - DJANGO=1.10 - - DJANGO=1.11 - - DJANGO=2.0 + - DJANGO=2.0.* + - DJANGO=3.0.* + - DJANGO=3.1.* matrix: fast_finish: true - include: - - { python: "3.6", env: DJANGO=1.11 } - - { python: "3.6", env: DJANGO=2.0 } - - exclude: - - { python: "2.7", env: DJANGO=2.0 } - install: - pip install tox tox-travis diff --git a/README.md b/README.md index 666cea6..52f11b9 100644 --- a/README.md +++ b/README.md @@ -1,44 +1,56 @@ -# django-updown +# django-updown-ratings -> Simple Django application for adding Youtube like up and down voting. +> Simple Django application for adding Youtube like up and down voting. \ +> This [`django-updown-ratings`][1] is forked from [`django-updown`][2] to support the newest django version. -[![Build Status](https://secure.travis-ci.org/weluse/django-updown.png?branch=master)](http://travis-ci.org/weluse/django-updown) +[![Build Status](https://secure.travis-ci.org/agusmakmun/django-updown-ratings.png?branch=master)][3] ## Install ``` -pip install django-updown +pip install django-updown-ratings ``` ## Usage -Add `"updown"` to your `INSTALLED_APPS`. Then just add a `RatingField` to -your existing model: +Add `"updown"` to your `INSTALLED_APPS`. Then just add a `RatingField` to your existing model: - from django.db import models - from updown.fields import RatingField +``` +from django.db import models +from updown.fields import RatingField - class Video(models.Model): - # ...other fields... - rating = RatingField() +class Post(models.Model): + # ...other fields... + rating = RatingField() +``` You can also allow the user to change his vote: - class Video(models.Model): - # ...other fields... - rating = RatingField(can_change_vote=True) +``` +class Post(models.Model): + # ...other fields... + rating = RatingField(can_change_vote=True) +``` Now you can write your own view to submit ratings or use the predefined: - from updown.views import AddRatingFromModel - - urlpatterns = patterns("", - url(r"^(?P\d+)/rate/(?P[\d\-]+)$", AddRatingFromModel(), { - 'app_label': 'video', - 'model': 'Video', - 'field_name': 'rating', - }, name="video_rating"), - ) +``` +from updown.views import AddRatingFromModel + +urlpatterns = [ + ... + path('/rate/', AddRatingFromModel(), { + 'app_label': 'post', + 'model': 'Post', + 'field_name': 'rating' + }, name='post_rating'), +] +``` -To submit a vote just go to ``video//rate/(1|-1)``. If you allowed users to +To submit a vote just go to ``post//rate/(1|-1)``. If you allowed users to change they're vote, they can do it with the same url. + + +[1]: https://github.com/agusmakmun/django-updown-ratings +[2]: https://github.com/weluse/django-updown +[3]: http://travis-ci.org/agusmakmun/django-updown-ratings diff --git a/setup.py b/setup.py index adaeb7d..80ebd16 100644 --- a/setup.py +++ b/setup.py @@ -17,13 +17,13 @@ def get_version(package): setup( - name='django-updown', + name='django-updown-ratings', version=version, description='Reusable Django application for youtube \ like up and down voting.', - author='Daniel Banck', + author='Daniel Banck, Agus Makmun', author_email='dbanck@weluse.de', - url='http://github.com/weluse/django-updown/tree/master', + url='http://github.com/agusmakmun/django-updown-ratings/tree/master', packages=find_packages(), zip_safe=False, classifiers=[ diff --git a/tests/test_model.py b/tests/test_model.py index 905714b..f7ebaaf 100644 --- a/tests/test_model.py +++ b/tests/test_model.py @@ -39,7 +39,7 @@ def test_basic_vote(self): self.instance.rating.add(SCORE_TYPES['LIKE'], self.user, '192.168.0.1') - self.assertEquals(self.instance.rating_likes, 1) + self.assertEqual(self.instance.rating_likes, 1) def test_change_vote(self): self.instance.rating.add(SCORE_TYPES['LIKE'], self.user, @@ -47,8 +47,8 @@ def test_change_vote(self): self.instance.rating.add(SCORE_TYPES['DISLIKE'], self.user, '192.168.0.1') - self.assertEquals(self.instance.rating_likes, 0) - self.assertEquals(self.instance.rating_dislikes, 1) + self.assertEqual(self.instance.rating_likes, 0) + self.assertEqual(self.instance.rating_dislikes, 1) def test_change_vote_disallowed(self): self.instance.rating2.add(SCORE_TYPES['LIKE'], self.user, diff --git a/updown/__init__.py b/updown/__init__.py index 6fd1fab..866c261 100644 --- a/updown/__init__.py +++ b/updown/__init__.py @@ -1,4 +1,4 @@ -__version__ = '1.0.2' +__version__ = '1.0.3' # Version synonym VERSION = __version__ diff --git a/updown/migrations/0001_initial.py b/updown/migrations/0001_initial.py index 219679c..a3dac08 100644 --- a/updown/migrations/0001_initial.py +++ b/updown/migrations/0001_initial.py @@ -17,7 +17,7 @@ class Migration(migrations.Migration): migrations.CreateModel( name='Vote', fields=[ - ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)), + ('id', models.BigAutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)), ('object_id', models.PositiveIntegerField()), ('key', models.CharField(max_length=32)), ('score', models.SmallIntegerField(choices=[(-1, 'DISLIKE'), (1, 'LIKE')])), diff --git a/updown/models.py b/updown/models.py index 00dc2e1..f3ee249 100644 --- a/updown/models.py +++ b/updown/models.py @@ -6,7 +6,6 @@ from django.db import models from django.contrib.contenttypes.models import ContentType from django.contrib.contenttypes.fields import GenericForeignKey -from django.utils.encoding import python_2_unicode_compatible from django.conf import settings from django.utils import timezone @@ -18,9 +17,8 @@ SCORE_TYPES = dict((value, key) for key, value in _SCORE_TYPE_CHOICES) -@python_2_unicode_compatible class Vote(models.Model): - content_type = models.ForeignKey(ContentType, related_name="updown_votes", + content_type = models.ForeignKey(ContentType, related_name="updown_votes", on_delete=models.CASCADE) object_id = models.PositiveIntegerField() key = models.CharField(max_length=32) From 2ed2b80f153e2ba85addaf6c86fb4b8d3295af9d Mon Sep 17 00:00:00 2001 From: agusmakmun Date: Thu, 17 Sep 2020 20:18:17 +0700 Subject: [PATCH 3/5] added demo, update travis, tox, setup --- .travis.yml | 6 +- README.md | 29 ++++-- setup.cfg | 4 +- setup.py | 7 +- tox.ini | 12 +-- updown/__init__.py | 2 +- updown/models.py | 1 + updown/views.py | 2 + updown_demo/.gitignore | 1 + updown_demo/app/__init__.py | 0 updown_demo/app/admin.py | 4 + updown_demo/app/apps.py | 5 + updown_demo/app/migrations/.gitignore | 2 + updown_demo/app/migrations/__init__.py | 0 updown_demo/app/models.py | 10 ++ updown_demo/app/urls.py | 10 ++ updown_demo/manage.py | 22 +++++ updown_demo/updown_demo/__init__.py | 0 updown_demo/updown_demo/asgi.py | 16 ++++ updown_demo/updown_demo/settings.py | 123 +++++++++++++++++++++++++ updown_demo/updown_demo/urls.py | 22 +++++ updown_demo/updown_demo/wsgi.py | 16 ++++ 22 files changed, 270 insertions(+), 24 deletions(-) create mode 100644 updown_demo/.gitignore create mode 100644 updown_demo/app/__init__.py create mode 100644 updown_demo/app/admin.py create mode 100644 updown_demo/app/apps.py create mode 100644 updown_demo/app/migrations/.gitignore create mode 100644 updown_demo/app/migrations/__init__.py create mode 100644 updown_demo/app/models.py create mode 100644 updown_demo/app/urls.py create mode 100755 updown_demo/manage.py create mode 100644 updown_demo/updown_demo/__init__.py create mode 100644 updown_demo/updown_demo/asgi.py create mode 100644 updown_demo/updown_demo/settings.py create mode 100644 updown_demo/updown_demo/urls.py create mode 100644 updown_demo/updown_demo/wsgi.py diff --git a/.travis.yml b/.travis.yml index 9df82ff..5f10afe 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,9 +11,9 @@ python: sudo: false env: - - DJANGO=2.0.* - - DJANGO=3.0.* - - DJANGO=3.1.* + - DJANGO=2.0 + - DJANGO=3.0 + - DJANGO=3.1 matrix: fast_finish: true diff --git a/README.md b/README.md index 52f11b9..7632686 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,9 @@ > Simple Django application for adding Youtube like up and down voting. \ > This [`django-updown-ratings`][1] is forked from [`django-updown`][2] to support the newest django version. -[![Build Status](https://secure.travis-ci.org/agusmakmun/django-updown-ratings.png?branch=master)][3] +[![build status][3]][4] +[![django version][5]][6] +[![python version][7]][8] ## Install @@ -38,19 +40,28 @@ Now you can write your own view to submit ratings or use the predefined: from updown.views import AddRatingFromModel urlpatterns = [ - ... - path('/rate/', AddRatingFromModel(), { - 'app_label': 'post', - 'model': 'Post', - 'field_name': 'rating' - }, name='post_rating'), + .... + + path('/rate/', AddRatingFromModel(), { + 'app_label': 'blogapp', + 'model': 'Post', + 'field_name': 'rating' + }, name='post_rating'), ] ``` -To submit a vote just go to ``post//rate/(1|-1)``. If you allowed users to +To submit a vote just go to `post//rate/(1|-1)`. If you allowed users to change they're vote, they can do it with the same url. [1]: https://github.com/agusmakmun/django-updown-ratings [2]: https://github.com/weluse/django-updown -[3]: http://travis-ci.org/agusmakmun/django-updown-ratings + +[3]: https://secure.travis-ci.org/agusmakmun/django-updown-ratings.png?branch=master +[4]: http://travis-ci.org/agusmakmun/django-updown-ratings + +[5]: https://img.shields.io/badge/Django-2.0%20%3E=%203.1-green.svg +[6]: https://www.djangoproject.com + +[7]: https://img.shields.io/pypi/pyversions/django-updown-ratings.svg +[8]: https://pypi.python.org/pypi/django-updown-ratings diff --git a/setup.cfg b/setup.cfg index 5e40900..b88034e 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,2 +1,2 @@ -[wheel] -universal = 1 +[metadata] +description-file = README.md diff --git a/setup.py b/setup.py index 80ebd16..33ea97a 100644 --- a/setup.py +++ b/setup.py @@ -19,12 +19,13 @@ def get_version(package): setup( name='django-updown-ratings', version=version, - description='Reusable Django application for youtube \ - like up and down voting.', + description='Reusable Django application for youtube like up and down voting.', + long_description=open('README.md').read(), + long_description_content_type='text/markdown', author='Daniel Banck, Agus Makmun', author_email='dbanck@weluse.de', url='http://github.com/agusmakmun/django-updown-ratings/tree/master', - packages=find_packages(), + packages=find_packages(exclude=["*demo"]), zip_safe=False, classifiers=[ 'Development Status :: 5 - Production/Stable', diff --git a/tox.ini b/tox.ini index 8b9744d..12ba6cb 100644 --- a/tox.ini +++ b/tox.ini @@ -3,15 +3,15 @@ addopts=--tb=short [tox] envlist = - {py27,py34,py35}-django110, - {py27,py34,py35,py36}-django111, {py34,py35,py36}-django20, + {py34,py35,py36,py37,py38}-django30, + {py34,py35,py36,py37,py38}-django31, [travis:env] DJANGO = - 1.10: django110 - 1.11: django111 2.0: django20 + 3.0: django30 + 3.1: django31 [testenv] commands = py.test tests/ @@ -20,8 +20,8 @@ setenv = PYTHONDONTWRITEBYTECODE=1 PYTHONWARNINGS=once deps = - django110: Django>=1.10,<1.11 - django111: Django>=1.11,<2.0 django20: Django>=2.0,<2.1 + django30: Django>=3.0,<3.1 + django31: Django>=3.1,<4.1 pytest pytest-django diff --git a/updown/__init__.py b/updown/__init__.py index 866c261..c5ba0f3 100644 --- a/updown/__init__.py +++ b/updown/__init__.py @@ -1,4 +1,4 @@ -__version__ = '1.0.3' +__version__ = '1.0.0' # Version synonym VERSION = __version__ diff --git a/updown/models.py b/updown/models.py index f3ee249..8cda71d 100644 --- a/updown/models.py +++ b/updown/models.py @@ -18,6 +18,7 @@ class Vote(models.Model): + id = models.BigAutoField(primary_key=True) content_type = models.ForeignKey(ContentType, related_name="updown_votes", on_delete=models.CASCADE) object_id = models.PositiveIntegerField() diff --git a/updown/views.py b/updown/views.py index fd726ea..650981a 100644 --- a/updown/views.py +++ b/updown/views.py @@ -11,6 +11,7 @@ class AddRatingView(object): + def __call__(self, request, content_type_id, object_id, field_name, score): """__call__(request, content_type_id, object_id, field_name, score) @@ -90,6 +91,7 @@ def get_instance(self, content_type_id, object_id): class AddRatingFromModel(AddRatingView): + def __call__(self, request, model, app_label, object_id, field_name, score, **kwargs): """__call__(request, model, app_label, object_id, field_name, score) diff --git a/updown_demo/.gitignore b/updown_demo/.gitignore new file mode 100644 index 0000000..49ef255 --- /dev/null +++ b/updown_demo/.gitignore @@ -0,0 +1 @@ +db.sqlite3 diff --git a/updown_demo/app/__init__.py b/updown_demo/app/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/updown_demo/app/admin.py b/updown_demo/app/admin.py new file mode 100644 index 0000000..a81e91f --- /dev/null +++ b/updown_demo/app/admin.py @@ -0,0 +1,4 @@ +from django.contrib import admin +from app.models import Post + +admin.site.register(Post) diff --git a/updown_demo/app/apps.py b/updown_demo/app/apps.py new file mode 100644 index 0000000..80b2c8d --- /dev/null +++ b/updown_demo/app/apps.py @@ -0,0 +1,5 @@ +from django.apps import AppConfig + + +class AppConfig(AppConfig): + name = 'app' diff --git a/updown_demo/app/migrations/.gitignore b/updown_demo/app/migrations/.gitignore new file mode 100644 index 0000000..d25fe16 --- /dev/null +++ b/updown_demo/app/migrations/.gitignore @@ -0,0 +1,2 @@ +[^.]* +!__init__.py diff --git a/updown_demo/app/migrations/__init__.py b/updown_demo/app/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/updown_demo/app/models.py b/updown_demo/app/models.py new file mode 100644 index 0000000..554a72d --- /dev/null +++ b/updown_demo/app/models.py @@ -0,0 +1,10 @@ +from django.db import models +from updown.fields import RatingField + + +class Post(models.Model): + title = models.CharField(max_length=200) + rating = RatingField(can_change_vote=True) + + def __str__(self): + return self.title diff --git a/updown_demo/app/urls.py b/updown_demo/app/urls.py new file mode 100644 index 0000000..7abcc0d --- /dev/null +++ b/updown_demo/app/urls.py @@ -0,0 +1,10 @@ +from django.urls import path +from updown.views import AddRatingFromModel + +urlpatterns = [ + path('post//rate/', AddRatingFromModel(), { + 'app_label': 'app', + 'model': 'Post', + 'field_name': 'rating' + }, name='post_rating'), +] diff --git a/updown_demo/manage.py b/updown_demo/manage.py new file mode 100755 index 0000000..7d3269d --- /dev/null +++ b/updown_demo/manage.py @@ -0,0 +1,22 @@ +#!/usr/bin/env python +"""Django's command-line utility for administrative tasks.""" +import os +import sys + + +def main(): + """Run administrative tasks.""" + os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'updown_demo.settings') + try: + from django.core.management import execute_from_command_line + except ImportError as exc: + raise ImportError( + "Couldn't import Django. Are you sure it's installed and " + "available on your PYTHONPATH environment variable? Did you " + "forget to activate a virtual environment?" + ) from exc + execute_from_command_line(sys.argv) + + +if __name__ == '__main__': + main() diff --git a/updown_demo/updown_demo/__init__.py b/updown_demo/updown_demo/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/updown_demo/updown_demo/asgi.py b/updown_demo/updown_demo/asgi.py new file mode 100644 index 0000000..f11db32 --- /dev/null +++ b/updown_demo/updown_demo/asgi.py @@ -0,0 +1,16 @@ +""" +ASGI config for updown_demo project. + +It exposes the ASGI callable as a module-level variable named ``application``. + +For more information on this file, see +https://docs.djangoproject.com/en/3.1/howto/deployment/asgi/ +""" + +import os + +from django.core.asgi import get_asgi_application + +os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'updown_demo.settings') + +application = get_asgi_application() diff --git a/updown_demo/updown_demo/settings.py b/updown_demo/updown_demo/settings.py new file mode 100644 index 0000000..df6dfaf --- /dev/null +++ b/updown_demo/updown_demo/settings.py @@ -0,0 +1,123 @@ +""" +Django settings for updown_demo project. + +Generated by 'django-admin startproject' using Django 3.1.1. + +For more information on this file, see +https://docs.djangoproject.com/en/3.1/topics/settings/ + +For the full list of settings and their values, see +https://docs.djangoproject.com/en/3.1/ref/settings/ +""" + +from pathlib import Path + +# Build paths inside the project like this: BASE_DIR / 'subdir'. +BASE_DIR = Path(__file__).resolve().parent.parent + + +# Quick-start development settings - unsuitable for production +# See https://docs.djangoproject.com/en/3.1/howto/deployment/checklist/ + +# SECURITY WARNING: keep the secret key used in production secret! +SECRET_KEY = '&*=y8v^y&83c&0n0e5b5pks-8#&*$12g!l-^_uma@=_!cf5$z-' + +# SECURITY WARNING: don't run with debug turned on in production! +DEBUG = True + +ALLOWED_HOSTS = ['*'] + + +# Application definition + +INSTALLED_APPS = [ + 'django.contrib.admin', + 'django.contrib.auth', + 'django.contrib.contenttypes', + 'django.contrib.sessions', + 'django.contrib.messages', + 'django.contrib.staticfiles', + + 'app', + 'updown', +] + +MIDDLEWARE = [ + 'django.middleware.security.SecurityMiddleware', + 'django.contrib.sessions.middleware.SessionMiddleware', + 'django.middleware.common.CommonMiddleware', + 'django.middleware.csrf.CsrfViewMiddleware', + 'django.contrib.auth.middleware.AuthenticationMiddleware', + 'django.contrib.messages.middleware.MessageMiddleware', + 'django.middleware.clickjacking.XFrameOptionsMiddleware', +] + +ROOT_URLCONF = 'updown_demo.urls' + +TEMPLATES = [ + { + 'BACKEND': 'django.template.backends.django.DjangoTemplates', + 'DIRS': [], + 'APP_DIRS': True, + 'OPTIONS': { + 'context_processors': [ + 'django.template.context_processors.debug', + 'django.template.context_processors.request', + 'django.contrib.auth.context_processors.auth', + 'django.contrib.messages.context_processors.messages', + ], + }, + }, +] + +WSGI_APPLICATION = 'updown_demo.wsgi.application' + + +# Database +# https://docs.djangoproject.com/en/3.1/ref/settings/#databases + +DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.sqlite3', + 'NAME': BASE_DIR / 'db.sqlite3', + } +} + + +# Password validation +# https://docs.djangoproject.com/en/3.1/ref/settings/#auth-password-validators + +AUTH_PASSWORD_VALIDATORS = [ + { + 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', + }, +] + + +# Internationalization +# https://docs.djangoproject.com/en/3.1/topics/i18n/ + +LANGUAGE_CODE = 'en-us' + +TIME_ZONE = 'UTC' + +USE_I18N = True + +USE_L10N = True + +USE_TZ = True + + +# Static files (CSS, JavaScript, Images) +# https://docs.djangoproject.com/en/3.1/howto/static-files/ + +STATIC_URL = '/static/' diff --git a/updown_demo/updown_demo/urls.py b/updown_demo/updown_demo/urls.py new file mode 100644 index 0000000..d776b6d --- /dev/null +++ b/updown_demo/updown_demo/urls.py @@ -0,0 +1,22 @@ +"""updown_demo URL Configuration + +The `urlpatterns` list routes URLs to views. For more information please see: + https://docs.djangoproject.com/en/3.1/topics/http/urls/ +Examples: +Function views + 1. Add an import: from my_app import views + 2. Add a URL to urlpatterns: path('', views.home, name='home') +Class-based views + 1. Add an import: from other_app.views import Home + 2. Add a URL to urlpatterns: path('', Home.as_view(), name='home') +Including another URLconf + 1. Import the include() function: from django.urls import include, path + 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) +""" +from django.contrib import admin +from django.urls import path, include + +urlpatterns = [ + path('admin/', admin.site.urls), + path('', include('app.urls')), +] diff --git a/updown_demo/updown_demo/wsgi.py b/updown_demo/updown_demo/wsgi.py new file mode 100644 index 0000000..59e8748 --- /dev/null +++ b/updown_demo/updown_demo/wsgi.py @@ -0,0 +1,16 @@ +""" +WSGI config for updown_demo project. + +It exposes the WSGI callable as a module-level variable named ``application``. + +For more information on this file, see +https://docs.djangoproject.com/en/3.1/howto/deployment/wsgi/ +""" + +import os + +from django.core.wsgi import get_wsgi_application + +os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'updown_demo.settings') + +application = get_wsgi_application() From aeed0ed4558562ef7a0d5dcca5106014a9aae5e4 Mon Sep 17 00:00:00 2001 From: agusmakmun Date: Thu, 17 Sep 2020 21:59:47 +0700 Subject: [PATCH 4/5] fixed the get_rating_for_user param, update setup, travis --- .travis.yml | 6 ++++++ setup.py | 6 +++++- updown/__init__.py | 2 +- updown/fields.py | 4 ++-- 4 files changed, 14 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index 5f10afe..f1f274a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -18,6 +18,12 @@ env: matrix: fast_finish: true + exclude: + - { python: "3.4", env: DJANGO=3.0 } + - { python: "3.4", env: DJANGO=3.1 } + - { python: "3.5", env: DJANGO=3.0 } + - { python: "3.5", env: DJANGO=3.1 } + install: - pip install tox tox-travis diff --git a/setup.py b/setup.py index 33ea97a..5e45d12 100644 --- a/setup.py +++ b/setup.py @@ -35,7 +35,11 @@ def get_version(package): 'License :: OSI Approved :: BSD License', 'Operating System :: OS Independent', 'Programming Language :: Python', - 'Programming Language :: Python :: 3', + 'Programming Language :: Python :: 3.4', + 'Programming Language :: Python :: 3.5', + 'Programming Language :: Python :: 3.6', + 'Programming Language :: Python :: 3.7', + 'Programming Language :: Python :: 3.8', 'Topic :: Internet :: WWW/HTTP', ] ) diff --git a/updown/__init__.py b/updown/__init__.py index c5ba0f3..20b1830 100644 --- a/updown/__init__.py +++ b/updown/__init__.py @@ -1,4 +1,4 @@ -__version__ = '1.0.0' +__version__ = '1.0.1' # Version synonym VERSION = __version__ diff --git a/updown/fields.py b/updown/fields.py index 0487d62..02e6163 100644 --- a/updown/fields.py +++ b/updown/fields.py @@ -2,6 +2,7 @@ Fields needed for the updown ratings """ from __future__ import unicode_literals +from django.contrib.contenttypes.models import ContentType from django.db.models import IntegerField, PositiveIntegerField from django.conf import settings @@ -15,7 +16,6 @@ raise ImportError("django-updown requires django.contrib.contenttypes " "in your INSTALLED_APPS") -from django.contrib.contenttypes.models import ContentType __all__ = ('Rating', 'RatingField', 'AnonymousRatingField') @@ -50,7 +50,7 @@ def is_authenticated(self, user): return user.is_authenticated() return user.is_authenticated - def get_rating_for_user(self, user, ip_address=None): + def get_rating_for_user(self, user=None, ip_address=None): kwargs = { 'content_type': self.get_content_type(), 'object_id': self.instance.pk, From c8ea4ec9c20cb5349ad93f73faf5b2fb70483fd3 Mon Sep 17 00:00:00 2001 From: agusmakmun Date: Thu, 17 Sep 2020 22:21:35 +0700 Subject: [PATCH 5/5] update readme: rating properties --- CHANGELOG.md | 39 --------------------------------------- README.md | 19 +++++++++++++++++++ 2 files changed, 19 insertions(+), 39 deletions(-) delete mode 100644 CHANGELOG.md diff --git a/CHANGELOG.md b/CHANGELOG.md deleted file mode 100644 index fc650ba..0000000 --- a/CHANGELOG.md +++ /dev/null @@ -1,39 +0,0 @@ -# Changelog - -## 1.0.2 - -- Replaced IPAddressField in migration (thanks to [baster33](https://github.com/baster33)) - -## 1.0.1 - -- Fixed IPAddressField error (thanks to [agusmakmun](https://github.com/agusmakmun)) - -## 1.0.0 - -- Dropped support for Python 2.6 -- Added Python 3 support -- Dropped support for Django < 1.8 -- Django 1.8 & Django 1.9 are now supported -- Tests are run using tox (for all Python and Django versions) -- Switched to more semantic versioning -- Removed old south migrations, added Django migrations -- Refactoring and cleanup - -## 0.5: - -- Fixed DateTimeField RuntimeWarning (thanks to [yurtaev](https://github.com/yurtaev)) -- Tests are using Django 1.4.10 now - -## 0.4: - -- Usage of `AUTH_USER_MODEL` instead of `auth.models.User` (thanks to [timbutler](https://github.com/timbutler)) - -## 0.3: - -- Removed south as dependency -- Small cleanups (thanks to [gwrtheyrn](https://github.com/gwrtheyrn>)) - -## 0.2: - -- Updated `related_name` to avoid namespace clashes -- Added south as dependency diff --git a/README.md b/README.md index 7632686..4213e45 100644 --- a/README.md +++ b/README.md @@ -53,6 +53,25 @@ urlpatterns = [ To submit a vote just go to `post//rate/(1|-1)`. If you allowed users to change they're vote, they can do it with the same url. +#### Template + +You can directly use this properties in the template, e.g: + +``` +{{ post.rating.likes }} +{{ post.rating.dislikes }} +{{ post.rating.get_difference }} +{{ post.rating.get_quotient }} +``` + +**Properties:** + +- `.likes` show total likes +- `.dislikes` show total dislikes +- `.get_difference` get diff between _likes_ and _dislikes_ (`likes - dislikes`). +- `.get_quotient` get quotient between _likes_ and _dislikes_ (`likes / max(dislikes)`). + + [1]: https://github.com/agusmakmun/django-updown-ratings [2]: https://github.com/weluse/django-updown