Skip to content

Commit

Permalink
Merge 367de95 into ab52303
Browse files Browse the repository at this point in the history
  • Loading branch information
norkans7 committed Aug 1, 2018
2 parents ab52303 + 367de95 commit 4d017d3
Show file tree
Hide file tree
Showing 112 changed files with 399 additions and 340 deletions.
19 changes: 15 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,25 +1,36 @@
language: python
sudo: false
python:
- "2.7"
- "3.5"
- "3.6"
addons:
postgresql: "9.6"
env:
- DJANGO_VERSION=1.10.4
- DJANGO_VERSION=1.11.2
- DJANGO_VERSION=1.11.14
- DJANGO_VERSION=2.0.7
- DJANGO_VERSION=2.0.8
- DJANGO_VERSION=2.1
services:
- redis-server
install:
- pip install pip --upgrade
- pip install -q -rrequirements/base.txt
- pip install -q -rrequirements/tests.txt
- pip install -q Django==$DJANGO_VERSION
- pip install coveralls
before_script:
- createdb -E UTF-8 dash -U postgres -O $USER
script:
- coverage run manage.py test --settings=dash_test_runner.settings_travis
# any non-zero error code should be treated as an immediate failure
- set -e

# test PEP8 compliance on both Python 2 and 3
- flake8

# check for model changes not reflected in a migration
- python manage.py makemigrations --dry-run | grep 'No changes detected' || (echo 'There are changes which require migrations.' && exit 1)

- coverage run manage.py test --settings=dash_test_runner.settings_travis

after_success:
- coveralls
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ Support library for building dashboards applications for [RapidPro](https://gith

* Provides an organization app to support multi-tenant sites
* Reusable user management views
* Supports Python 2 and 3
* Supports Django 1.9 and 1.10
* Supports Python 3 only
* Supports Django 1.11 and 2.0
2 changes: 0 additions & 2 deletions dash/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
from __future__ import unicode_literals

__version__ = "1.3.7"
1 change: 0 additions & 1 deletion dash/categories/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
from __future__ import unicode_literals
20 changes: 14 additions & 6 deletions dash/categories/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.conf import settings
from django.db import migrations, models

Expand Down Expand Up @@ -38,14 +35,25 @@ class Migration(migrations.Migration):
(
"created_by",
models.ForeignKey(
help_text="The user which originally created this item", to=settings.AUTH_USER_MODEL
help_text="The user which originally created this item",
on_delete=models.PROTECT,
to=settings.AUTH_USER_MODEL,
),
),
(
"modified_by",
models.ForeignKey(help_text="The user which last modified this item", to=settings.AUTH_USER_MODEL),
models.ForeignKey(
help_text="The user which last modified this item",
on_delete=models.PROTECT,
to=settings.AUTH_USER_MODEL,
),
),
(
"org",
models.ForeignKey(
help_text="The organization this category applies to", on_delete=models.PROTECT, to="orgs.Org"
),
),
("org", models.ForeignKey(help_text="The organization this category applies to", to="orgs.Org")),
],
options={"verbose_name_plural": "Categories"},
bases=(models.Model,),
Expand Down
3 changes: 0 additions & 3 deletions dash/categories/migrations/0002_auto_20140820_1415.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import migrations, models


Expand Down
19 changes: 13 additions & 6 deletions dash/categories/migrations/0003_categoryimage.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.conf import settings
from django.db import migrations, models

Expand Down Expand Up @@ -32,17 +29,27 @@ class Migration(migrations.Migration):
("image", models.ImageField(help_text="The image file to use", upload_to="categories")),
(
"category",
models.ForeignKey(help_text="The category this image represents", to="categories.Category"),
models.ForeignKey(
help_text="The category this image represents",
on_delete=models.PROTECT,
to="categories.Category",
),
),
(
"created_by",
models.ForeignKey(
help_text="The user which originally created this item", to=settings.AUTH_USER_MODEL
help_text="The user which originally created this item",
on_delete=models.PROTECT,
to=settings.AUTH_USER_MODEL,
),
),
(
"modified_by",
models.ForeignKey(help_text="The user which last modified this item", to=settings.AUTH_USER_MODEL),
models.ForeignKey(
help_text="The user which last modified this item",
on_delete=models.PROTECT,
to=settings.AUTH_USER_MODEL,
),
),
],
options={"abstract": False},
Expand Down
3 changes: 0 additions & 3 deletions dash/categories/migrations/0004_auto_20140904_0927.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import migrations, models


Expand Down
12 changes: 8 additions & 4 deletions dash/categories/migrations/0005_auto_20140922_1514.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.conf import settings
from django.db import migrations, models

Expand All @@ -16,6 +13,7 @@ class Migration(migrations.Migration):
field=models.ForeignKey(
related_name="categories_category_creations",
to=settings.AUTH_USER_MODEL,
on_delete=models.PROTECT,
help_text="The user which originally created this item",
),
),
Expand All @@ -25,14 +23,18 @@ class Migration(migrations.Migration):
field=models.ForeignKey(
related_name="categories_category_modifications",
to=settings.AUTH_USER_MODEL,
on_delete=models.PROTECT,
help_text="The user which last modified this item",
),
),
migrations.AlterField(
model_name="categoryimage",
name="category",
field=models.ForeignKey(
related_name="images", to="categories.Category", help_text="The category this image represents"
related_name="images",
on_delete=models.PROTECT,
to="categories.Category",
help_text="The category this image represents",
),
),
migrations.AlterField(
Expand All @@ -41,6 +43,7 @@ class Migration(migrations.Migration):
field=models.ForeignKey(
related_name="categories_categoryimage_creations",
to=settings.AUTH_USER_MODEL,
on_delete=models.PROTECT,
help_text="The user which originally created this item",
),
),
Expand All @@ -50,6 +53,7 @@ class Migration(migrations.Migration):
field=models.ForeignKey(
related_name="categories_categoryimage_modifications",
to=settings.AUTH_USER_MODEL,
on_delete=models.PROTECT,
help_text="The user which last modified this item",
),
),
Expand Down
8 changes: 4 additions & 4 deletions dash/categories/migrations/0006_auto_20141008_1955.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import migrations, models


Expand All @@ -13,7 +10,10 @@ class Migration(migrations.Migration):
model_name="category",
name="org",
field=models.ForeignKey(
related_name="categories", to="orgs.Org", help_text="The organization this category applies to"
related_name="categories",
to="orgs.Org",
on_delete=models.PROTECT,
help_text="The organization this category applies to",
),
)
]
4 changes: 0 additions & 4 deletions dash/categories/migrations/0007_auto_20170301_0914.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.10.5 on 2017-03-01 09:14
from __future__ import unicode_literals

import django.utils.timezone
from django.db import migrations, models

Expand Down
22 changes: 13 additions & 9 deletions dash/categories/models.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

import six
from smartmin.models import SmartModel

from dash.orgs.models import Org
from django.db import models
from django.utils.encoding import python_2_unicode_compatible
from django.utils.translation import ugettext_lazy as _
from smartmin.models import SmartModel

from dash.orgs.models import Org


@python_2_unicode_compatible
Expand All @@ -23,7 +20,12 @@ class Category(SmartModel):
upload_to="categories", null=True, blank=True, help_text=_("An optional image that can describe this category")
)

org = models.ForeignKey(Org, related_name="categories", help_text=_("The organization this category applies to"))
org = models.ForeignKey(
Org,
on_delete=models.PROTECT,
related_name="categories",
help_text=_("The organization this category applies to"),
)

def get_first_image(self):
cat_images = self.images.filter(is_active=True).exclude(image="")
Expand All @@ -32,7 +34,7 @@ def get_first_image(self):

def get_label_from_instance(self):
label = str(self)
if isinstance(label, six.binary_type):
if isinstance(label, bytes):
label = label.decode("utf-8")

if not self.is_active:
Expand All @@ -51,7 +53,9 @@ class Meta:
class CategoryImage(SmartModel):
name = models.CharField(max_length=64, help_text=_("The name to describe this image"))

category = models.ForeignKey(Category, related_name="images", help_text=_("The category this image represents"))
category = models.ForeignKey(
Category, on_delete=models.PROTECT, related_name="images", help_text=_("The category this image represents")
)

image = models.ImageField(upload_to="categories", help_text=_("The image file to use"))

Expand Down
2 changes: 0 additions & 2 deletions dash/categories/urls.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import unicode_literals

from . import views

urlpatterns = views.CategoryCRUDL().as_urlpatterns()
Expand Down
9 changes: 6 additions & 3 deletions dash/categories/views.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from __future__ import unicode_literals
from smartmin.views import SmartCreateView, SmartCRUDL, SmartListView, SmartUpdateView

from django import forms

from dash.categories.fields import CategoryChoiceField
from dash.orgs.views import OrgObjPermsMixin, OrgPermsMixin
from django import forms
from smartmin.views import SmartCreateView, SmartCRUDL, SmartListView, SmartUpdateView

from .models import Category, CategoryImage

Expand Down Expand Up @@ -31,6 +31,8 @@ class Update(OrgObjPermsMixin, SmartUpdateView):
fields = ("is_active", "name")

class List(OrgPermsMixin, SmartListView):
ordering = ("name",)

def derive_fields(self):
if self.request.user.is_superuser:
return ("name", "modified_on", "created_on", "org")
Expand Down Expand Up @@ -77,6 +79,7 @@ def get_form_kwargs(self):

class List(OrgPermsMixin, SmartListView):
fields = ("name", "category", "modified_on", "created_on")
ordering = ("name", "category")

def get_queryset(self, **kwargs):
queryset = super(CategoryImageCRUDL.List, self).get_queryset(**kwargs)
Expand Down
2 changes: 0 additions & 2 deletions dash/context_processors.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import unicode_literals

from django.conf import settings


Expand Down
1 change: 0 additions & 1 deletion dash/dashblocks/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
from __future__ import unicode_literals

0 comments on commit 4d017d3

Please sign in to comment.