Skip to content

Commit

Permalink
Formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
shacker committed Apr 12, 2019
1 parent 4a385bd commit befc7ad
Show file tree
Hide file tree
Showing 28 changed files with 254 additions and 312 deletions.
4 changes: 1 addition & 3 deletions base_urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,4 @@
to your site's urlconf.
"""

urlpatterns = [
path('lists/', include('todo.urls')),
]
urlpatterns = [path("lists/", include("todo.urls"))]
36 changes: 8 additions & 28 deletions test_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@

DEBUG = (True,)
BASE_DIR = os.path.dirname(os.path.dirname(__file__))
DATABASES = {
"default": {
"ENGINE": "django.db.backends.sqlite3"
}
}
DATABASES = {"default": {"ENGINE": "django.db.backends.sqlite3"}}

EMAIL_BACKEND = "django.core.mail.backends.console.EmailBackend"

Expand Down Expand Up @@ -65,28 +61,12 @@
]

LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'handlers': {
'console': {
'class': 'logging.StreamHandler',
},
},
'loggers': {
'': {
'handlers': ['console'],
'level': 'DEBUG',
'propagate': True,
},
'django': {
'handlers': ['console'],
'level': 'WARNING',
'propagate': True,
},
'django.request': {
'handlers': ['console'],
'level': 'DEBUG',
'propagate': True,
},
"version": 1,
"disable_existing_loggers": False,
"handlers": {"console": {"class": "logging.StreamHandler"}},
"loggers": {
"": {"handlers": ["console"], "level": "DEBUG", "propagate": True},
"django": {"handlers": ["console"], "level": "WARNING", "propagate": True},
"django.request": {"handlers": ["console"], "level": "DEBUG", "propagate": True},
},
}
10 changes: 5 additions & 5 deletions todo/__init__.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
"""
A multi-user, multi-group task management and assignment system for Django.
"""
__version__ = '2.4.6'
__version__ = "2.4.6"

__author__ = 'Scot Hacker'
__email__ = '[email protected]'
__author__ = "Scot Hacker"
__email__ = "[email protected]"

__url__ = 'https://github.com/shacker/django-todo'
__license__ = 'BSD License'
__url__ = "https://github.com/shacker/django-todo"
__license__ = "BSD License"

from . import check
6 changes: 2 additions & 4 deletions todo/check.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ def dal_check(app_configs, **kwargs):
return []

errors = []
missing_apps = {'dal', 'dal_select2'} - set(settings.INSTALLED_APPS)
missing_apps = {"dal", "dal_select2"} - set(settings.INSTALLED_APPS)
for missing_app in missing_apps:
errors.append(
Error('{} needs to be in INSTALLED_APPS'.format(missing_app))
)
errors.append(Error("{} needs to be in INSTALLED_APPS".format(missing_app)))
return errors
3 changes: 2 additions & 1 deletion todo/features.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@
HAS_TASK_MERGE = False
if HAS_AUTOCOMPLETE:
import dal.autocomplete
if getattr(dal.autocomplete, 'Select2QuerySetView', None) is not None:

if getattr(dal.autocomplete, "Select2QuerySetView", None) is not None:
HAS_TASK_MERGE = True
12 changes: 7 additions & 5 deletions todo/mail/delivery.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import importlib


def _declare_backend(backend_path):
backend_path = backend_path.split('.')
backend_module_name = '.'.join(backend_path[:-1])
backend_path = backend_path.split(".")
backend_module_name = ".".join(backend_path[:-1])
class_name = backend_path[-1]

def backend(*args, headers={}, from_address=None, **kwargs):
Expand All @@ -17,9 +18,10 @@ def _backend():
_backend.from_address = from_address
_backend.headers = headers
return _backend

return backend


smtp_backend = _declare_backend('django.core.mail.backends.smtp.EmailBackend')
console_backend = _declare_backend('django.core.mail.backends.console.EmailBackend')
locmem_backend = _declare_backend('django.core.mail.backends.locmem.EmailBackend')
smtp_backend = _declare_backend("django.core.mail.backends.smtp.EmailBackend")
console_backend = _declare_backend("django.core.mail.backends.console.EmailBackend")
locmem_backend = _declare_backend("django.core.mail.backends.locmem.EmailBackend")
6 changes: 2 additions & 4 deletions todo/mail/producers/imap.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,12 @@ def process_batch():
try:
yield message
except Exception:
logger.exception(
f"something went wrong while processing {message_uid}"
)
logger.exception(f"something went wrong while processing {message_uid}")
raise

if not preserve:
# tag the message for deletion
conn.store(message_uid, '+FLAGS', '\\Deleted')
conn.store(message_uid, "+FLAGS", "\\Deleted")
else:
logger.debug("did not receive any message")
finally:
Expand Down
40 changes: 23 additions & 17 deletions todo/management/commands/hopper.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def gen_title(tc=True):
# faker doesn't provide a way to generate headlines in Title Case, without periods, so make our own.
# With arg `tc=True`, Title Cases The Generated Text
fake = Faker()
thestr = fake.text(max_nb_chars=32).rstrip('.')
thestr = fake.text(max_nb_chars=32).rstrip(".")
if tc:
thestr = titlecase(thestr)

Expand All @@ -29,7 +29,7 @@ def gen_content():
# faker provides paragraphs as a list; convert with linebreaks
fake = Faker()
grafs = fake.paragraphs()
thestr = ''
thestr = ""
for g in grafs:
thestr += "{}\n\n".format(g)
return thestr
Expand All @@ -43,11 +43,12 @@ def add_arguments(self, parser):
"-d",
"--delete",
help="Wipe out existing content before generating new.",
action="store_true")
action="store_true",
)

def handle(self, *args, **options):

if options.get('delete'):
if options.get("delete"):
# Wipe out previous contents? Cascade deletes the Tasks from the TaskLists.
TaskList.objects.all().delete()
print("Content from previous run deleted.")
Expand All @@ -56,11 +57,11 @@ def handle(self, *args, **options):
fake = Faker() # Use to create user's names

# Create users and groups, add different users to different groups. Staff user is in both groups.
sd_group, created = Group.objects.get_or_create(name='Scuba Divers')
bw_group, created = Group.objects.get_or_create(name='Basket Weavers')
sd_group, created = Group.objects.get_or_create(name="Scuba Divers")
bw_group, created = Group.objects.get_or_create(name="Basket Weavers")

# Put user1 and user2 in one group, user3 and user4 in another
usernames = ['user1', 'user2', 'user3', 'user4', 'staffer']
usernames = ["user1", "user2", "user3", "user4", "staffer"]
for username in usernames:
if get_user_model().objects.filter(username=username).exists():
user = get_user_model().objects.get(username=username)
Expand All @@ -70,15 +71,16 @@ def handle(self, *args, **options):
first_name=fake.first_name(),
last_name=fake.last_name(),
email="{}@example.com".format(username),
password="todo")
password="todo",
)

if username in ['user1', 'user2']:
if username in ["user1", "user2"]:
user.groups.add(bw_group)

if username in ['user3', 'user4']:
if username in ["user3", "user4"]:
user.groups.add(sd_group)

if username == 'staffer':
if username == "staffer":
user.is_staff = True
user.first_name = fake.first_name()
user.last_name = fake.last_name()
Expand All @@ -91,7 +93,9 @@ def handle(self, *args, **options):
TaskListFactory.create_batch(5, group=sd_group)
TaskListFactory.create(name="Public Tickets", slug="tickets", group=bw_group)

print("For each of two groups, created fake tasks in each of {} fake lists.".format(num_lists))
print(
"For each of two groups, created fake tasks in each of {} fake lists.".format(num_lists)
)


class TaskListFactory(factory.django.DjangoModelFactory):
Expand Down Expand Up @@ -120,17 +124,19 @@ class Meta:
task_list = None # Pass this in
note = factory.LazyAttribute(lambda o: gen_content())
priority = factory.LazyAttribute(lambda o: random.randint(1, 100))
completed = factory.Faker('boolean', chance_of_getting_true=30)
created_by = factory.LazyAttribute(lambda o: get_user_model().objects.get(username='staffer')) # Randomized in post
created_date = factory.Faker('date_this_year')
completed = factory.Faker("boolean", chance_of_getting_true=30)
created_by = factory.LazyAttribute(
lambda o: get_user_model().objects.get(username="staffer")
) # Randomized in post
created_date = factory.Faker("date_this_year")

@factory.post_generation
def add_details(self, build, extracted, **kwargs):

fake = Faker() # Use to create user's names
taskgroup = self.task_list.group

self.created_by = taskgroup.user_set.all().order_by('?').first()
self.created_by = taskgroup.user_set.all().order_by("?").first()

if self.completed:
self.completed_date = fake.date_this_year()
Expand All @@ -141,6 +147,6 @@ def add_details(self, build, extracted, **kwargs):

# 1/3 of generated tasks are assigned to someone in this tasks's group
if random.randint(1, 3) == 1:
self.assigned_to = taskgroup.user_set.all().order_by('?').first()
self.assigned_to = taskgroup.user_set.all().order_by("?").first()

self.save()
5 changes: 1 addition & 4 deletions todo/management/commands/mail_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,7 @@ def handle(self, *args, **options):
worker_name = options["worker_name"]
tracker = settings.TODO_MAIL_TRACKERS.get(worker_name, None)
if tracker is None:
logger.error(
"couldn't find configuration for %r in TODO_MAIL_TRACKERS",
worker_name
)
logger.error("couldn't find configuration for %r in TODO_MAIL_TRACKERS", worker_name)
sys.exit(1)

# set the default socket timeout (imaplib doesn't enable configuring it)
Expand Down
105 changes: 64 additions & 41 deletions todo/migrations/0001_initial.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,70 +9,93 @@
class Migration(migrations.Migration):

dependencies = [
('auth', '0001_initial'),
("auth", "0001_initial"),
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
]

operations = [
migrations.CreateModel(
name='Comment',
name="Comment",
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('date', models.DateTimeField(default=datetime.datetime.now)),
('body', models.TextField(blank=True)),
('author', models.ForeignKey(to=settings.AUTH_USER_MODEL, on_delete=models.CASCADE)),
(
"id",
models.AutoField(
verbose_name="ID", serialize=False, auto_created=True, primary_key=True
),
),
("date", models.DateTimeField(default=datetime.datetime.now)),
("body", models.TextField(blank=True)),
(
"author",
models.ForeignKey(to=settings.AUTH_USER_MODEL, on_delete=models.CASCADE),
),
],
options={
},
options={},
bases=(models.Model,),
),
migrations.CreateModel(
name='Item',
name="Item",
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('title', models.CharField(max_length=140)),
('created_date', models.DateField(auto_now=True, auto_now_add=True)),
('due_date', models.DateField(null=True, blank=True)),
('completed', models.BooleanField(default=None)),
('completed_date', models.DateField(null=True, blank=True)),
('note', models.TextField(null=True, blank=True)),
('priority', models.PositiveIntegerField(max_length=3)),
('assigned_to', models.ForeignKey(related_name='todo_assigned_to', to=settings.AUTH_USER_MODEL, on_delete=models.CASCADE)),
('created_by', models.ForeignKey(related_name='todo_created_by', to=settings.AUTH_USER_MODEL, on_delete=models.CASCADE)),
(
"id",
models.AutoField(
verbose_name="ID", serialize=False, auto_created=True, primary_key=True
),
),
("title", models.CharField(max_length=140)),
("created_date", models.DateField(auto_now=True, auto_now_add=True)),
("due_date", models.DateField(null=True, blank=True)),
("completed", models.BooleanField(default=None)),
("completed_date", models.DateField(null=True, blank=True)),
("note", models.TextField(null=True, blank=True)),
("priority", models.PositiveIntegerField(max_length=3)),
(
"assigned_to",
models.ForeignKey(
related_name="todo_assigned_to",
to=settings.AUTH_USER_MODEL,
on_delete=models.CASCADE,
),
),
(
"created_by",
models.ForeignKey(
related_name="todo_created_by",
to=settings.AUTH_USER_MODEL,
on_delete=models.CASCADE,
),
),
],
options={
'ordering': ['priority'],
},
options={"ordering": ["priority"]},
bases=(models.Model,),
),
migrations.CreateModel(
name='List',
name="List",
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('name', models.CharField(max_length=60)),
('slug', models.SlugField(max_length=60, editable=False)),
('group', models.ForeignKey(to='auth.Group', on_delete=models.CASCADE)),
(
"id",
models.AutoField(
verbose_name="ID", serialize=False, auto_created=True, primary_key=True
),
),
("name", models.CharField(max_length=60)),
("slug", models.SlugField(max_length=60, editable=False)),
("group", models.ForeignKey(to="auth.Group", on_delete=models.CASCADE)),
],
options={
'ordering': ['name'],
'verbose_name_plural': 'Lists',
},
options={"ordering": ["name"], "verbose_name_plural": "Lists"},
bases=(models.Model,),
),
migrations.AlterUniqueTogether(
name='list',
unique_together=set([('group', 'slug')]),
),
migrations.AlterUniqueTogether(name="list", unique_together=set([("group", "slug")])),
migrations.AddField(
model_name='item',
name='list',
field=models.ForeignKey(to='todo.List', on_delete=models.CASCADE),
model_name="item",
name="list",
field=models.ForeignKey(to="todo.List", on_delete=models.CASCADE),
preserve_default=True,
),
migrations.AddField(
model_name='comment',
name='task',
field=models.ForeignKey(to='todo.Item', on_delete=models.CASCADE),
model_name="comment",
name="task",
field=models.ForeignKey(to="todo.Item", on_delete=models.CASCADE),
preserve_default=True,
),
]
Loading

0 comments on commit befc7ad

Please sign in to comment.