Skip to content

Commit

Permalink
Merge fe3e8c6 into e707163
Browse files Browse the repository at this point in the history
  • Loading branch information
bibangamba committed Dec 20, 2018
2 parents e707163 + fe3e8c6 commit 8b0b544
Show file tree
Hide file tree
Showing 22 changed files with 1,067 additions and 90 deletions.
1 change: 1 addition & 0 deletions Procfile
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
release: ./manage makemigrations&&./manage.py migrate --noinput
web: gunicorn authors.wsgi --log-file -
113 changes: 69 additions & 44 deletions app.json
Original file line number Diff line number Diff line change
@@ -1,45 +1,70 @@
{
"name": "ah-backend-athena",
"description": "Backend of a social platform for the creative at heart",
"repository": "https://github.com/andela/ah-backend-athena",
"keywords": ["python", "django", "authors", "haven", "social", "api"],
"env": {
"DB_NAME": {
"required": true
},
"DB_PASSWORD": {
"required": true
},
"DB_USER": {
"required": true
},
"DISABLE_COLLECTSTATIC": {
"required": true
},
"HOST": {
"required": true
},
"PORT": {
"required": true
},
"SECRET_KEY": {
"required": true
}
},
"formation": {
"web": {
"quantity": 1
}
},
"addons": [
"heroku-postgresql"
],
"scripts": {
"postdeploy": "python manage.py migrate --noinput"
},
"buildpacks":[
{
"url": "heroku/python"
}
]
}
"name": "ah-backend-athena",
"description": "Backend of a social platform for the creative at heart",
"repository": "https://github.com/andela/ah-backend-athena",
"keywords": ["python", "django", "authors", "haven", "social", "api"],
"env": {
"DB_NAME": {
"required": true
},
"DB_PASSWORD": {
"required": true
},
"DB_USER": {
"required": true
},
"DISABLE_COLLECTSTATIC": {
"required": true
},
"HOST": {
"required": true
},
"PORT": {
"required": true
},
"DEBUG": {
"required": true
},
"SECRET_KEY": {
"required": true
},
"EMAIL": {
"required": true
},
"EMAIL_PASSWORD": {
"required": true
},
"TLS": {
"required": true
},
"EMAIL_PORT": {
"required": true
},
"TWITTER_CONSUMER_KEY": {
"required": true
},
"TWITTER_CONSUMER_SECRET": {
"required": true
},
"GOOGLE_CLIENT_ID": {
"required": true
},
"GOOGLE_SECRET_ID": {
"required": true
}
},
"formation": {
"web": {
"quantity": 1
}
},
"addons": [
"heroku-postgresql"
],
"scripts": {
"postdeploy": "./manage makemigrations&&./manage.py migrate --noinput"
},
"buildpacks": [{
"url": "heroku/python"
}]
}
85 changes: 84 additions & 1 deletion authors/apps/articles/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,95 @@
"""
from rest_framework.exceptions import APIException


class PermisionDenied(APIException):
status_code = 403
default_detail = 'You dont have permission to perform this action'


class CommentDoesNotExist(APIException):
status_code = 404
default_detail = "Failed, comment or article does not exist"



class MissingAccessTokenInRequestException(APIException):
"""
exception class for a missing access token
"""
status_code = 400
default_detail = "Missing access_token parameter in the request body, it is required"


class MissingTwitterTokensInRequestException(APIException):
"""
exception class for a missing tokens param
"""
status_code = 400
default_detail = "Missing tokens parameter in the request body, it is required"


class MissingEmailInRequestBodyException(APIException):
"""
exception class for a missing emails
"""
status_code = 400
default_detail = "Missing 'send_to' (Email address to share to)" +\
" parameter in the request body, it is required"


class InvalidEmailAddress(APIException):
"""
exception class for a invalid email
"""
status_code = 400
default_detail = "The email string provided is invalid"


class FailedToSendEmailException(APIException):
"""
exception class for a invalid email
"""
status_code = 500
default_detail = "Something bad happened and we were unable to send the email, try again later."

@classmethod
def change_error_message(cls, message):
"""
This method changes the outputted error message
depending on the exception met during send mail
"""
cls.default_detail = message


class InvalidAccessToken(APIException):
"""
exception class for a missing access token
"""
status_code = 400
default_detail = "The access_token provided is invalid"


class TwitterTokenInputsFormatError(APIException):
"""
exception class for a invalid formatting of twitter tokens
"""
status_code = 400
default_detail = "Invalid format supplied twitter credentials. " + \
"Correct format is: '<access_token_key> <access_token_secret>'"


class TwitterExceptionRaised(APIException):
"""
This class handles twitter error messages
"""
status_code = 400
default_detail = "Something bad happened with the twitter API"

@classmethod
def problem_occured(cls, message):
"""
This method returns a dynamic error message passed in from
the TwitterError that occured
"""
cls.status_code = 400
cls.default_detail = message
78 changes: 78 additions & 0 deletions authors/apps/articles/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
# Generated by Django 2.1.3 on 2018-12-18 13:06

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


class Migration(migrations.Migration):

initial = True

dependencies = [
]

operations = [
migrations.CreateModel(
name='Article',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('title', models.CharField(db_index=True, max_length=255)),
('body', models.TextField(db_index=True)),
('description', models.CharField(db_index=True, max_length=255, null=True)),
('slug', models.SlugField(max_length=255, unique=True)),
('published', models.BooleanField(default=False)),
('created_at', models.DateTimeField(auto_now_add=True)),
('updated_at', models.DateTimeField(auto_now=True)),
('favourited', models.BooleanField(default=False)),
('favouriteCount', models.IntegerField(default=0)),
('likes_count', models.IntegerField(default=0)),
],
options={
'ordering': ['-created_at', '-updated_at'],
},
),
migrations.CreateModel(
name='ArticleImg',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('image_url', models.URLField(blank=True, null=True)),
('description', models.CharField(db_index=True, max_length=255)),
('position_in_body_before', models.IntegerField(null=True)),
],
),
migrations.CreateModel(
name='Comments',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('comment_body', models.TextField()),
('created_at', models.DateTimeField(auto_now_add=True)),
('updated_at', models.DateTimeField(auto_now_add=True)),
],
options={
'get_latest_by': ['created_at'],
},
),
migrations.CreateModel(
name='Favourites',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('favourite', models.BooleanField(default=False)),
],
),
migrations.CreateModel(
name='Likes',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('like', models.BooleanField()),
('article', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='articles.Article')),
],
),
migrations.CreateModel(
name='Tag',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('tag', models.CharField(max_length=255)),
('slug', models.SlugField(unique=True)),
],
),
]
64 changes: 64 additions & 0 deletions authors/apps/articles/migrations/0002_auto_20181218_1306.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# Generated by Django 2.1.3 on 2018-12-18 13:06

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


class Migration(migrations.Migration):

initial = True

dependencies = [
('articles', '0001_initial'),
('profiles', '0001_initial'),
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
]

operations = [
migrations.AddField(
model_name='likes',
name='profile',
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, to='profiles.Profile'),
),
migrations.AddField(
model_name='favourites',
name='article',
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, related_name='article_id', to='articles.Article'),
),
migrations.AddField(
model_name='favourites',
name='profile',
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, to='profiles.Profile'),
),
migrations.AddField(
model_name='comments',
name='article',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='articles.Article'),
),
migrations.AddField(
model_name='comments',
name='author',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL),
),
migrations.AddField(
model_name='comments',
name='parent',
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='articles.Comments'),
),
migrations.AddField(
model_name='articleimg',
name='article',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='articles.Article'),
),
migrations.AddField(
model_name='article',
name='author',
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, to='profiles.Profile'),
),
migrations.AddField(
model_name='article',
name='tags',
field=models.ManyToManyField(related_name='articles', to='articles.Tag'),
),
]
Loading

0 comments on commit 8b0b544

Please sign in to comment.