Skip to content

Commit 0d82077

Browse files
Code refactoring
1 parent ae8fb18 commit 0d82077

File tree

6 files changed

+22
-17
lines changed

6 files changed

+22
-17
lines changed

config/settings.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@
114114
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
115115

116116
# Location where we will store our static files
117-
STATICFILES_DIRS = [ os.path.join(BASE_DIR, 'static') ]
117+
STATICFILES_DIRS = [os.path.join(BASE_DIR, 'static')]
118118

119119
MEDIA_URL = '/media/'
120120
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')

portfolio/models.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,22 +21,22 @@ def __str__(self):
2121
class About(models.Model):
2222
title = models.CharField(max_length=50)
2323
description = models.CharField(max_length=250)
24-
icon = models.CharField(max_length=30) # Material Icon name
25-
24+
icon = models.CharField(max_length=30) # Material Icon name
25+
2626
class Meta:
2727
verbose_name = 'About'
2828
verbose_name_plural = 'About'
29-
29+
3030
def __str__(self):
3131
return self.title
3232

3333

3434
class Tag(models.Model):
3535
name = models.CharField(max_length=30)
36-
36+
3737
def __str__(self):
3838
return self.name
39-
39+
4040

4141
class Project(models.Model):
4242
name = models.CharField(max_length=100)
@@ -45,13 +45,13 @@ class Project(models.Model):
4545
image = models.ImageField()
4646
tags = models.ManyToManyField(Tag)
4747

48-
# override the save method and
49-
# use the Image class of the PIL package
48+
# override the save method and
49+
# use the Image class of the PIL package
5050
# to convert it to JPEG
5151
def save(self, *args, **kwargs):
5252
if self.image:
5353
filename = "%s.jpg" % self.image.name.split('.')[0]
54-
54+
5555
image = Image.open(self.image)
5656
# for PNG images discard the alpha channel and fill it with some color
5757
if image.mode in ('RGBA', 'LA'):
@@ -60,7 +60,7 @@ def save(self, *args, **kwargs):
6060
image = background
6161
image_io = BytesIO()
6262
image.save(image_io, format='JPEG', quality=100)
63-
63+
6464
# change the image field value to be the newly modified image value
6565
self.image.save(filename, ContentFile(image_io.getvalue()), save=False)
6666
super(Project, self).save(*args, **kwargs)
@@ -73,18 +73,18 @@ class Contact(models.Model):
7373
address = models.CharField(max_length=250)
7474
email = models.CharField(max_length=150)
7575
phone = models.CharField(max_length=20)
76-
76+
7777
class Meta:
7878
verbose_name = 'Contact'
7979
verbose_name_plural = 'Contact'
80-
80+
8181
def __str__(self):
8282
return self.email
8383

8484

8585
class Footer(models.Model):
8686
copyright = models.CharField(max_length=200)
87-
87+
8888
class Meta:
8989
verbose_name = 'Footer'
9090
verbose_name_plural = 'Footer'

portfolio/tests.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ def setUp(self):
88
self.hero = Hero.objects.create(
99
title='Lorem ipsum dolor sit amet',
1010
subtitle='Sed tincidunt quis odio id molestie',
11-
description='Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed tincidunt quis odio id molestie.',
11+
description='Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed tincidunt quis odio id.',
1212
image=tempfile.NamedTemporaryFile(suffix='.jpg').name
1313
)
1414

1515
def test_hero_model(self):
1616
data = self.hero
17-
self.assertIsInstance(data, Hero)
17+
self.assertIsInstance(data, Hero)

portfolio/urls.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33

44
urlpatterns = [
55
path('', IndexPageView.as_view()),
6-
]
6+
]

portfolio/views.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
from django.views.generic.base import TemplateView
22
from .models import Hero, About, Project, Contact, Footer
33

4+
45
class IndexPageView(TemplateView):
56
template_name = 'index.html'
6-
7+
78
def get_context_data(self, **kwargs):
89
context = super().get_context_data(**kwargs)
910
context['hero_data'] = Hero.objects.all()

setup.cfg

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[flake8]
2+
exclude = .git,*migrations*,*venv*
3+
max-line-length = 119
4+
indent-size = 2

0 commit comments

Comments
 (0)