8000 Fixed bug in API serializers · FeverCode/GAwards@decaaf5 · GitHub
[go: up one dir, main page]

Skip to content

Commit decaaf5

Browse files
committed
Fixed bug in API serializers
1 parent 3ff69e0 commit decaaf5

11 files changed

+179
-34
lines changed

Procfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
web: gunicorn awards.wsgi

app/forms.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ class Meta:
7171
class ProfileUpdateForm(forms.ModelForm):
7272
class Meta:
7373
model = Profile
74-
fields = ['profile_photo', 'bio','location']
74+
fields = ['profile_photo','name', 'bio','location']
7575

7676

7777
class UserUpdateForm(forms.ModelForm):
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Generated by Django 3.2 on 2022-06-14 13:14
2+
3+
import cloudinary.models
4+
from django.db import migrations
5+
6+
7+
class Migration(migrations.Migration):
8+
9+
dependencies = [
10+
('app', '0001_initial'),
11+
]
12+
13+
operations = [
14+
migrations.AlterField(
15+
model_name='profile',
16+
name='profile_photo',
17+
field=cloudinary.models.CloudinaryField(default='http://res.cloudinary.com/dim8pysls/image/upload/v1639001486/x3mgnqmbi73lten4ewzv.png', max_length=255, verbose_name='image'),
18+
),
19+
]
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Generated by Django 3.2 on 2022-06-14 13:16
2+
3+
import cloudinary.models
4+
from django.db import migrations
5+
6+
7+
class Migration(migrations.Migration):
8+
9+
dependencies = [
10+
('app', '0002_alter_profile_profile_photo'),
11+
]
12+
13+
operations = [
14+
migrations.AlterField(
15+
model_name='profile',
16+
name='profile_photo',
17+
field=cloudinary.models.CloudinaryField(blank=True, default='http://res.cloudinary.com/dim8pysls/image/upload/v1639001486/x3mgnqmbi73lten4ewzv.png', max_length=255),
18+
),
19+
]
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Generated by Django 3.2 on 2022-06-14 13:18
2+
3+
import cloudinary.models
4+
from django.db import migrations
5+
6+
7+
class Migration(migrations.Migration):
8+
9+
dependencies = [
10+
('app', '0003_alter_profile_profile_photo'),
11+
]
12+
13+
operations = [
14+
migrations.AlterField(
15+
model_name='profile',
16+
name='profile_photo',
17+
field=cloudinary.models.CloudinaryField(default='default.png', max_length=255, verbose_name='image'),
18+
),
19+
]

app/serializer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class PostSerializer(serializers.ModelSerializer):
1717

1818
class Meta:
1919
model = Post
20-
fields = ['id', 'title', 'url', 'description', 'technologies', 'image', 'user', 'date']
20+
fields = ['id', 'title', 'url', 'description', 'technologies','photo', 'user', 'date']
2121

2222

2323
class UserSerializer(serializers.ModelSerializer):

app/templates/awards.html

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ <h1 class="display-3">GAwards</h1>
88
{%for post in posts%}
99
<article class="postcard dark blue" data-bs-toggle="modal" data-bs-target="#exampleModal{{post.id}}>
1010
11-
<a class=" postcard__img_link" href="{% url 'project' post.title %}">
11+
<a class="postcard__img_link" href="{% url 'project' post.title %}">
1212
<img class="postcard__img" src="{{post.photo.url}}" alt="Image Title" />
1313
</a>
1414
<div class="postcard__text">
@@ -19,15 +19,14 @@ <h1 class="postcard__title blue"><a href="{% url 'project' post.title %}">{{post
1919
<div class="postcard__bar"></div>
2020
<div class="postcard__preview-txt">{{post.description}}</div>
2121
<ul class="postcard__tagbox">
22-
<a href="{% url 'user-profile' %}">
23-
<li class="tag__item"> <img class="rounded-circle nav-img" src="{{user.profile.profile_photo.url }}"
24-
alt="" width="30"> By {{post.user.username}}</li>
22+
<a href="{% url 'user-profile'%}">
23+
<li class="tag__item"> <img class="rounded-circle nav-img" src="{{post.user.profile.profile_photo.url }}" alt="" width="30"> By {{post.user.username}}</li>
2524
</a>
2625

27-
<li class="tag__item"><i class="fas fa-tag mr-2"></i>{{post.technologies}}</li>
26+
<li class="tag__item"> <i class="fas fa-tag mr-2"></i>{{post.technologies}}</li>
2827

2928
<li class="tag__item play blue">
30-
<a href="{{post.url}}"><i class="fas fa-play mr-2"></i>View Site</a>
29+
<a href="{{post.url}}" target="_blank"><i class="fa fa-link" aria-hidden="true"></i>View Site</a>
3130
</li>
3231
<li class="tag__item play blue">
3332
<a href="{% url 'project' post.title %}"><i class="fa fa-star-o" aria-hidden="true"></i>Rate</a>

app/templates/base.html

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,13 @@
4747
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.2.0-beta1/dist/js/bootstrap.bundle.min.js" integrity="sha384-pprn3073KE6tl6bjs2QrFaJGz5/SUsLqktiwsUTF55Jfv3qYSDhgCecCxMW52nD2" crossorigin="anonymous"></script>
4848
{% bootstrap_javascript %}
4949
{% endblock %}
50-
50+
<script>
51+
if('serviceWorker' in navigator) {
52+
window.addEventListener('load', function() {
53+
navigator.serviceWorker.register('/sw.js');
54+
});
55+
}
56+
</script>
5157

5258
</body>
5359

awards/settings.py

Lines changed: 52 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -14,24 +14,18 @@
1414
import cloudinary
1515
import cloudinary.uploader
1616
import cloudinary.api
17-
from decouple import config
17+
from decouple import config, Csv
1818
from django import conf
19+
import django_heroku
20+
import dj_database_url
1921

2022
# Build paths inside the project like this: BASE_DIR / 'subdir'.
21-
BASE_DIR = Path(__file__).resolve().parent.parent
23+
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
2224

2325

2426
# Quick-start development settings - unsuitable for production
2527
# See https://docs.djangoproject.com/en/3.2/howto/deployment/checklist/
2628

27-
# SECURITY WARNING: keep the secret key used in production secret!
28-
SECRET_KEY = 'django-insecure-5&(fdvbeeu#6=62f=+fkw1zsjbjf40+slyz+*9a0*)!-z0$ts1'
29-
30-
# SECURITY WARNING: don't run with debug turned on in production!
31-
DEBUG = True
32-
33-
ALLOWED_HOSTS = []
34-
3529

3630
# Application definition
3731

@@ -62,6 +56,7 @@
6256
}
6357

6458
MIDDLEWARE = [
59+
'whitenoise.middleware.WhiteNoiseMiddleware',
6560
'django.middleware.security.SecurityMiddleware',
6661
'django.contrib.sessions.middleware.SessionMiddleware',
6762
'django.middleware.common.CommonMiddleware',
@@ -100,15 +95,34 @@
10095
# Database
10196
# https://docs.djangoproject.com/en/3.2/ref/settings/#databases
10297

103-
DATABASES = {
104-
'default': {
105-
'ENGINE': 'django.db.backends.postgresql_psycopg2',
106-
'NAME': 'awards',
107-
'USER': 'moringa',
108-
'PASSWORD': 'Access',
109-
}
110-
}
111-
98+
MODE = config("MODE", default="dev")
99+
SECRET_KEY = config('SECRET_KEY')
100+
DEBUG = config('DEBUG', default=False, cast=bool)
101+
# development
102+
if config('MODE') == "dev":
103+
DATABASES = {
104+
'default': {
105+
'ENGINE': 'django.db.backends.postgresql_psycopg2',
106+
'NAME': config('DB_NAME'),
107+
'USER': config('DB_USER'),
108+
'PASSWORD': config('DB_PASSWORD'),
109+
'HOST': config('DB_HOST'),
110+
'PORT': '',
111+
}
112+
113+
}
114+
# production
115+
else:
116+
DATABASES = {
117+
'default': dj_database_url.config(
118+
default=config('DATABASE_URL')
119+
)
120+
}
121+
122+
db_from_env = dj_database_url.config(conn_max_age=500)
123+
DATABASES['default'].update(db_from_env)
124+
125+
ALLOWED_HOSTS = config('ALLOWED_HOSTS', cast=Csv())
112126

113127
# Password validation
114128
# https://docs.djangoproject.com/en/3.2/ref/settings/#auth-password-validators
@@ -143,7 +157,7 @@
143157

144158
LANGUAGE_CODE = 'en-us'
145159

146-
TIME_ZONE = 'UTC'
160+
TIME_ZONE = 'Africa/Nairobi'
147161

148162
USE_I18N = True
149163

@@ -153,12 +167,22 @@
153167

154168

155169
# Static files (CSS, JavaScript, Images)
156-
# https://docs.djangoproject.com/en/3.2/howto/static-files/
157-
170+
# https://docs.djangoproject.com/en/1.9/howto/static-files/
171+
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
158172
STATIC_URL = '/static/'
159-
STATICFILES_DIRS = [
160-
os.path.join(BASE_DIR, "static"),
161-
]
173+
174+
# Extra places for collectstatic to find static files.
175+
STATICFILES_DIRS = (
176+
os.path.join(BASE_DIR, 'static'),
177+
)
178+
179+
180+
# Simplified static file serving.
181+
# https://warehouse.python.org/project/whitenoise/
182+
183+
STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'
184+
185+
162186

163187
cloudinary.config(
164188
cloud_name=config('CD_NAME'),
@@ -209,3 +233,6 @@
209233
# https://docs.djangoproject.com/en/3.2/ref/settings/#default-auto-field
210234

211235
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
236+
237+
# Configure Django App for Heroku.
238+
django_heroku.settings(locals())

requirements.txt

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
anyio==3.6.1
2+
asgiref==3.5.2
3+
autopep8==1.6.0
4+
beautifulsoup4==4.11.1
5+
certifi==2022.5.18.1
6+
cffi==1.15.0
7+
charset-normalizer==2.0.12
8+
cloudinary==1.29.0
9+
cryptography==37.0.2
10+
defusedxml==0.7.1
11+
dj-database-url==0.5.0
12+
Django==3.2
13+
django-appconf==1.0.5
14+
django-bootstrap-v5==1.0.11
15+
django-compressor==4.0
16+
django-crispy-forms==1.14.0
17+
django-heroku==0.3.1
18+
django-sass-processor==1.2
19+
djangorestframework==3.13.1
20+
dnspython==2.2.1
21+
email-validator==1.2.1
22+
gunicorn==20.1.0
23+
h11==0.12.0
24+
httpcore==0.13.7
25+
httpx==0.18.2
26+
idna==3.3
27+
libsass==0.21.0
28+
oauthlib==3.2.0
29+
Pillow==9.1.1
30+
psycopg2==2.9.3
31+
pycodestyle==2.8.0
32+
pycparser==2.21
33+
pydantic==1.9.1
34+
PyJWT==2.4.0
35+
python-dateutil==2.8.2
36+
python-decouple==3.6
37+
python3-openid==3.2.0
38+
pytz==2021.3
39+
pyuploadcare==3.0.0
40+
rcssmin==1.1.0
41+
requests==2.28.0
42+
requests-oauthlib==1.3.1
43+
rfc3986==1.5.0
44+
rjsmin==1.2.0
45+
six==1.16.0
46+
sniffio==1.2.0
47+
social-auth-app-django==5.0.0
48+
social-auth-core==4.2.0
49+
soupsieve==2.3.2.post1
50+
sqlparse==0.4.2
51+
toml==0.10.2
52+
typing-extensions==3.10.0.2
53+
urllib3==1.26.9
54+
whitenoise==6.2.0

0 commit comments

Comments
 (0)
0