Skip to content

Commit

Permalink
Merge branch 'main' into read_title_tweak
Browse files Browse the repository at this point in the history
  • Loading branch information
rowanseymour committed Aug 15, 2023
2 parents 9366590 + 4f1470d commit ddc8004
Show file tree
Hide file tree
Showing 29 changed files with 41 additions and 80 deletions.
6 changes: 2 additions & 4 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ packages = [
repository = "http://github.com/nyaruka/smartmin"

[tool.poetry.dependencies]
python = "^3.9"
python = "^3.10"
Django = ">= 4.0, < 5.0"
celery = ">= 5.1"
pytz = "*"
Expand All @@ -42,7 +42,7 @@ Pillow = "^9.3.0"
colorama = "^0.4.6"

[tool.black]
line-length = 119
line-length = 120

[tool.ruff]
line-length = 120
Expand All @@ -53,7 +53,7 @@ fix = true
[tool.isort]
multi_line_output = 3
force_grid_wrap = 0
line_length = 119
line_length = 120
include_trailing_comma = true
combine_as_imports = true
sections = ["FUTURE", "STDLIB", "THIRDPARTY", "DJANGO", "FIRSTPARTY", "LOCALFOLDER"]
Expand Down
1 change: 0 additions & 1 deletion smartmin/csv_imports/migrations/0001_initial.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@


class Migration(migrations.Migration):

dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
]
Expand Down
1 change: 0 additions & 1 deletion smartmin/csv_imports/migrations/0002_auto_20161118_1920.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@


class Migration(migrations.Migration):

dependencies = [
("csv_imports", "0001_initial"),
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@


class Migration(migrations.Migration):

dependencies = [
("csv_imports", "0002_auto_20161118_1920"),
]
Expand Down
1 change: 0 additions & 1 deletion smartmin/csv_imports/migrations/0004_auto_20170223_0917.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@


class Migration(migrations.Migration):

dependencies = [
("csv_imports", "0003_importtask_task_status"),
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@


class Migration(migrations.Migration):

dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
("csv_imports", "0004_auto_20170223_0917"),
Expand Down
1 change: 0 additions & 1 deletion smartmin/csv_imports/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@


def generate_file_path(instance, filename):

file_path_prefix = "csv_imports/"

name, extension = os.path.splitext(filename)
Expand Down
4 changes: 1 addition & 3 deletions smartmin/management/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,7 @@ def check_role_permissions(role, permissions, current_permissions):

# if this is a wildcard, then query our database for all the permissions that exist on this object
if action == "*":
for perm in Permission.objects.filter(
codename__startswith="%s_" % object, content_type__app_label=app
):
for perm in Permission.objects.filter(codename__startswith="%s_" % object, content_type__app_label=app):
codenames.append(perm.codename)
# otherwise, this is an error, continue
else:
Expand Down
9 changes: 3 additions & 6 deletions smartmin/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@ class SmartModel(models.Model):
dates.
"""

is_active = models.BooleanField(
default=True, help_text="Whether this item is active, use this instead of deleting"
)
is_active = models.BooleanField(default=True, help_text="Whether this item is active, use this instead of deleting")

created_by = models.ForeignKey(
settings.AUTH_USER_MODEL,
Expand Down Expand Up @@ -81,7 +79,6 @@ def get_import_file_headers(cls, csv_file):
workbook = open_workbook(filename.name, "rb")

for sheet in workbook.sheets():

# read our header
header = []
for col in range(sheet.ncols):
Expand Down Expand Up @@ -109,7 +106,7 @@ def get_import_file_headers(cls, csv_file):
break
reader.close()

reader = open(filename.name, "rU", encoding="utf-8-sig")
reader = open(filename.name, "r", encoding="utf-8-sig")

def unicode_csv_reader(utf8_data, dialect=csv.excel, **kwargs):
csv_reader = csv.reader(utf8_data, dialect=dialect, **kwargs)
Expand Down Expand Up @@ -309,7 +306,7 @@ def import_raw_csv(cls, filename, user, import_params, log=None, import_results=
break
reader.close()

reader = open(filename.name, "rU", encoding="utf-8-sig")
reader = open(filename.name, "r", encoding="utf-8-sig")

def unicode_csv_reader(utf8_data, dialect=csv.excel, **kwargs):
csv_reader = csv.reader(utf8_data, dialect=dialect, **kwargs)
Expand Down
1 change: 0 additions & 1 deletion smartmin/pdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ class PDFMixin(object):
"""

def render_to_response(self, context, **response_kwargs):

response = super(PDFMixin, self).render_to_response(context, **response_kwargs)

# do the actual rendering
Expand Down
1 change: 0 additions & 1 deletion smartmin/users/migrations/0001_initial.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@


class Migration(migrations.Migration):

dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
]
Expand Down
1 change: 0 additions & 1 deletion smartmin/users/migrations/0002_remove_failed_logins.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ def noop(apps, schema_editor): # pragma: no cover


class Migration(migrations.Migration):

dependencies = [
("users", "0001_initial"),
]
Expand Down
1 change: 0 additions & 1 deletion smartmin/users/migrations/0003_auto_20210219_1548.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@


class Migration(migrations.Migration):

dependencies = [
("users", "0002_remove_failed_logins"),
]
Expand Down
20 changes: 4 additions & 16 deletions smartmin/users/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,7 @@ def clean_new_password(self):
# if they specified a new password
if password and not is_password_complex(password):
raise forms.ValidationError(
_(
"Passwords must have at least 8 characters, including one uppercase, "
"one lowercase and one number"
)
_("Passwords must have at least 8 characters, including one uppercase, " "one lowercase and one number")
)

return password
Expand Down Expand Up @@ -76,10 +73,7 @@ def clean_new_password(self):

if password and not is_password_complex(password):
raise forms.ValidationError(
_(
"Passwords must have at least 8 characters, including one uppercase, "
"one lowercase and one number"
)
_("Passwords must have at least 8 characters, including one uppercase, " "one lowercase and one number")
)

if password and PasswordHistory.is_password_repeat(self.instance, password):
Expand Down Expand Up @@ -118,10 +112,7 @@ def clean_confirm_new_password(self):
password = self.cleaned_data["new_password"]
if password and not is_password_complex(password):
raise forms.ValidationError(
_(
"Passwords must have at least 8 characters, including one uppercase, "
"one lowercase and one number"
)
_("Passwords must have at least 8 characters, including one uppercase, " "one lowercase and one number")
)

if password and PasswordHistory.is_password_repeat(self.instance, password):
Expand Down Expand Up @@ -195,10 +186,7 @@ def clean_confirm_new_password(self):
password = self.cleaned_data["new_password"]
if password and not is_password_complex(password):
raise forms.ValidationError(
_(
"Passwords must have at least 8 characters, including one uppercase, "
"one lowercase and one number"
)
_("Passwords must have at least 8 characters, including one uppercase, " "one lowercase and one number")
)

if password and PasswordHistory.is_password_repeat(self.instance, password):
Expand Down
3 changes: 1 addition & 2 deletions test_runner/blog/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
from django.db import models, migrations
from django.conf import settings
from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
]
Expand Down
4 changes: 2 additions & 2 deletions test_runner/blog/migrations/0002_post_uuid.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from django.db import migrations, models
import uuid

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("blog", "0001_initial"),
]
Expand Down
3 changes: 1 addition & 2 deletions test_runner/blog/migrations/0003_auto_20170223_0917.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
from django.db import migrations, models
import django.utils.timezone
from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("blog", "0002_post_uuid"),
]
Expand Down
6 changes: 3 additions & 3 deletions test_runner/blog/migrations/0004_auto_20170609_0743.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from django.db import migrations, models
import django.utils.timezone
import uuid

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


class Migration(migrations.Migration):

dependencies = [
("blog", "0003_auto_20170223_0917"),
]
Expand Down
3 changes: 1 addition & 2 deletions test_runner/blog/migrations/0005_auto_20180615_2036.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import django.db.models.deletion
from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

dependencies = [
("blog", "0004_auto_20170609_0743"),
]
Expand Down
1 change: 0 additions & 1 deletion test_runner/blog/migrations/0006_post_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@


class Migration(migrations.Migration):

dependencies = [
("blog", "0005_auto_20180615_2036"),
]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
# Generated by Django 4.0.1 on 2022-01-12 15:47

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


class Migration(migrations.Migration):

dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
("blog", "0006_post_image"),
Expand Down
2 changes: 1 addition & 1 deletion test_runner/blog/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from django.db import models
from django.utils.timezone import now

from smartmin.models import SmartModel, ActiveManager
from smartmin.models import ActiveManager, SmartModel


class Post(SmartModel):
Expand Down
28 changes: 12 additions & 16 deletions test_runner/blog/tests.py
Original file line number Diff line number Diff line change
@@ -1,29 +1,30 @@
import json
import pytz
from datetime import datetime, timedelta
from unittest.mock import patch

from datetime import datetime, timedelta
import pytz

from django.conf import settings
from django.contrib.auth.models import User, Group
from django.contrib.auth.models import Group, User
from django.core import mail
from django.core.files.uploadedfile import SimpleUploadedFile
from django.urls import reverse
from django.test import TestCase, override_settings
from django.test.client import Client
from django.test.utils import override_settings
from django.urls import reverse
from django.utils import timezone

import smartmin
from smartmin.csv_imports.models import ImportTask
from smartmin.management import check_role_permissions
from smartmin.models import SmartImportRowError
from smartmin.templatetags.smartmin import view_as_json, get_value_from_view, get, user_as_string
from smartmin.templatetags.smartmin import get, get_value_from_view, user_as_string, view_as_json
from smartmin.tests import SmartminTest
from smartmin.users.models import FailedLogin, RecoveryToken, PasswordHistory, is_password_complex
from smartmin.users.models import FailedLogin, PasswordHistory, RecoveryToken, is_password_complex
from smartmin.views import smart_url
from smartmin.widgets import DatePickerWidget, ImageThumbnailWidget
from test_runner.blog.models import Category, Post

from test_runner.blog.models import Post, Category
from .views import PostCRUDL


Expand Down Expand Up @@ -64,9 +65,7 @@ def assertNoAccess(self, user, url):
def assertHasAccess(self, user, url):
self.client.login(username=user.username, password=user.username)
response = self.client.get(url)
self.assertEquals(
200, response.status_code, "User '%s' does not have access to URL: %s" % (user.username, url)
)
self.assertEquals(200, response.status_code, "User '%s' does not have access to URL: %s" % (user.username, url))

def assertIsLogin(self, response):
self.assertRedirect(response, reverse("users.user_login"))
Expand All @@ -78,9 +77,7 @@ def test_crudl_urls(self):
self.assertEqual(reverse("blog.post_delete", args=[self.post.id]), "/blog/post/delete/%d/" % self.post.id)
self.assertEqual(reverse("blog.post_list"), "/blog/post/")
self.assertEqual(reverse("blog.post_author"), "/blog/post/author/")
self.assertEqual(
reverse("blog.post_by_uuid", args=[self.post.uuid]), "/blog/post/by_uuid/%s/" % self.post.uuid
)
self.assertEqual(reverse("blog.post_by_uuid", args=[self.post.uuid]), "/blog/post/by_uuid/%s/" % self.post.uuid)

def test_smart_url(self):
self.assertEqual(smart_url("@blog.post_create"), "/blog/post/create/")
Expand Down Expand Up @@ -946,9 +943,7 @@ def test_token(self):
self.assertIsNotNone(recovery_token.token)

self.assertTrue("https://nyaruka.com/users/user/recover/%s" % recovery_token.token in sent_email.body)
self.assertFalse(
"https://nyaruka.com//users/user/recover/%s" % recovery_token.token in sent_email.body
)
self.assertFalse("https://nyaruka.com//users/user/recover/%s" % recovery_token.token in sent_email.body)

# delete the recovery tokens we have
RecoveryToken.objects.all().delete()
Expand Down Expand Up @@ -1172,6 +1167,7 @@ def test_map(self):

def test_gmail_time(self):
import pytz

from smartmin.templatetags.smartmin import gmail_time

# given the time as now, should display "Hour:Minutes AM|PM" eg. "5:05 pm"
Expand Down
Loading

0 comments on commit ddc8004

Please sign in to comment.