Rewrite "fix: super(BaseTask) [all tests pass]" and remove Black fixes

This commit is contained in:
Adrien Lemaire 2019-04-24 12:30:57 +09:00
parent 7d54cff939
commit dd9dec0d29

View file

@ -40,18 +40,13 @@ class LockedAtomicTransaction(Atomic):
super(LockedAtomicTransaction, self).__enter__() super(LockedAtomicTransaction, self).__enter__()
# Make sure not to lock, when sqlite is used, or you'll run into problems while running tests!!! # Make sure not to lock, when sqlite is used, or you'll run into problems while running tests!!!
if ( if settings.DATABASES[self.using]["ENGINE"] != "django.db.backends.sqlite3":
settings.DATABASES[self.using]["ENGINE"]
!= "django.db.backends.sqlite3"
):
cursor = None cursor = None
try: try:
cursor = get_connection(self.using).cursor() cursor = get_connection(self.using).cursor()
for model in self.models: for model in self.models:
cursor.execute( cursor.execute(
"LOCK TABLE {table_name}".format( "LOCK TABLE {table_name}".format(table_name=model._meta.db_table)
table_name=model._meta.db_table
)
) )
finally: finally:
if cursor and not cursor.closed: if cursor and not cursor.closed:
@ -76,12 +71,8 @@ class TaskList(models.Model):
class BaseTask(models.Model): class BaseTask(models.Model):
title = models.CharField(max_length=140) title = models.CharField(max_length=140)
task_list = models.ForeignKey( task_list = models.ForeignKey(TaskList, on_delete=models.CASCADE, null=True)
TaskList, on_delete=models.CASCADE, null=True created_date = models.DateField(default=timezone.now, blank=True, null=True)
)
created_date = models.DateField(
default=timezone.now, blank=True, null=True
)
due_date = models.DateField(blank=True, null=True) due_date = models.DateField(blank=True, null=True)
completed = models.BooleanField(default=False) completed = models.BooleanField(default=False)
completed_date = models.DateField(blank=True, null=True) completed_date = models.DateField(blank=True, null=True)
@ -147,10 +138,7 @@ class Comment(models.Model):
""" """
author = models.ForeignKey( author = models.ForeignKey(
settings.AUTH_USER_MODEL, settings.AUTH_USER_MODEL, on_delete=models.CASCADE, blank=True, null=True
on_delete=models.CASCADE,
blank=True,
null=True,
) )
task = models.ForeignKey(Task, on_delete=models.CASCADE) task = models.ForeignKey(Task, on_delete=models.CASCADE)
date = models.DateTimeField(default=datetime.datetime.now) date = models.DateTimeField(default=datetime.datetime.now)
@ -175,9 +163,7 @@ class Comment(models.Model):
def snippet(self): def snippet(self):
body_snippet = textwrap.shorten(self.body, width=35, placeholder="...") body_snippet = textwrap.shorten(self.body, width=35, placeholder="...")
# Define here rather than in __str__ so we can use it in the admin list_display # Define here rather than in __str__ so we can use it in the admin list_display
return "{author} - {snippet}...".format( return "{author} - {snippet}...".format(author=self.author_text, snippet=body_snippet)
author=self.author_text, snippet=body_snippet
)
def __str__(self): def __str__(self):
return self.snippet return self.snippet
@ -189,13 +175,9 @@ class Attachment(models.Model):
""" """
task = models.ForeignKey(Task, on_delete=models.CASCADE) task = models.ForeignKey(Task, on_delete=models.CASCADE)
added_by = models.ForeignKey( added_by = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE)
settings.AUTH_USER_MODEL, on_delete=models.CASCADE
)
timestamp = models.DateTimeField(default=datetime.datetime.now) timestamp = models.DateTimeField(default=datetime.datetime.now)
file = models.FileField( file = models.FileField(upload_to=get_attachment_upload_dir, max_length=255)
upload_to=get_attachment_upload_dir, max_length=255
)
def filename(self): def filename(self):
return os.path.basename(self.file.name) return os.path.basename(self.file.name)