-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
426 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,6 @@ | |
import re | ||
from .models import User | ||
|
||
import os | ||
|
||
from django.shortcuts import get_object_or_404 | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
|
||
|
||
default_app_config = 'authors.apps.profiles.apps.MyAppConfig' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
from django.apps import AppConfig | ||
|
||
|
||
class MyAppConfig(AppConfig): | ||
name = 'authors.apps.profiles' | ||
|
||
def ready(self): | ||
import authors.apps.profiles.signals | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
from rest_framework.exceptions import APIException | ||
|
||
|
||
class UserProfileDoesNotExist(APIException): | ||
status_code = 400 | ||
default_detail = "The requested profile does not exist" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# Generated by Django 2.1 on 2018-09-12 18:34 | ||
|
||
from django.conf import settings | ||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
initial = True | ||
|
||
dependencies = [ | ||
migrations.swappable_dependency(settings.AUTH_USER_MODEL), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='UserProfile', | ||
fields=[ | ||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('bio', models.TextField(blank=True, null=True)), | ||
('avatar', models.URLField(blank=True, null=True)), | ||
('first_name', models.CharField(blank=True, max_length=50, null=True)), | ||
('last_name', models.CharField(blank=True, max_length=50, null=True)), | ||
('created_at', models.DateTimeField(auto_now_add=True)), | ||
('birth_date', models.DateField(blank=True, null=True)), | ||
('location', models.CharField(blank=True, max_length=100, null=True)), | ||
('updated_at', models.DateTimeField(auto_now=True)), | ||
('user', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)), | ||
], | ||
), | ||
] |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
from django.db import models | ||
from authors.apps.authentication.models import User | ||
|
||
|
||
class UserProfile(models.Model): | ||
user = models.OneToOneField(User, on_delete=models.CASCADE) | ||
bio = models.TextField(blank=True, null=True) | ||
avatar = models.URLField(blank=True, null=True) | ||
first_name = models.CharField(max_length=50, blank=True, null=True) | ||
last_name = models.CharField(max_length=50, blank=True, null=True) | ||
|
||
# A timestamp representing when this object was created. | ||
created_at = models.DateTimeField(auto_now_add=True) | ||
birth_date = models.DateField(null=True, blank=True) | ||
location = models.CharField(max_length=100, null=True, blank=True) | ||
|
||
# A timestamp representing when this object was last updated. | ||
updated_at = models.DateTimeField(auto_now=True) | ||
|
||
def __str__(self): | ||
return self.first_name | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
|
||
import json | ||
from datetime import datetime | ||
|
||
from django.conf.global_settings import DATETIME_FORMAT | ||
from rest_framework.renderers import JSONRenderer | ||
|
||
|
||
class AHJSONRenderer(JSONRenderer): | ||
charset = 'utf-8' | ||
object_label = 'object' | ||
|
||
def render(self, data, media_type=None, renderer_context=None): | ||
|
||
return json.dumps({ | ||
self.object_label: data | ||
}) | ||
|
||
|
||
class ProfileJSONRenderer(AHJSONRenderer): | ||
object_label = 'profile' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
from rest_framework import serializers | ||
|
||
from authors.apps.profiles.models import UserProfile | ||
|
||
|
||
class RetrieveUserProfileSerializer(serializers.ModelSerializer): | ||
|
||
username = serializers.CharField(source='user.username') | ||
bio = serializers.CharField(allow_blank=True, required=False) | ||
first_name = serializers.CharField(allow_blank=True, required=False) | ||
last_name = serializers.CharField(allow_blank=True, required=False) | ||
location = serializers.CharField(allow_blank=True, required='False') | ||
|
||
class Meta: | ||
model = UserProfile | ||
fields = ('username', 'bio', 'first_name', 'last_name', 'location') | ||
read_only_fields = ('username',) | ||
extra_kwargs = {'token': {'read_only': True}} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
from django.dispatch import receiver | ||
from django.db.models.signals import post_save | ||
|
||
from .models import * | ||
|
||
|
||
@receiver(post_save, sender=User) | ||
def build_profile_on_user_creation(sender, instance, created, **kwargs): | ||
if created: | ||
""" Check if user is created """ | ||
profile = UserProfile(user=instance) | ||
profile.save() |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
""" | ||
This module contains data used by other test modules | ||
""" | ||
|
||
|
||
class BaseTest(): | ||
""" | ||
This class contains data required for testing by test classes. | ||
""" | ||
|
||
def __init__(self): | ||
self.user_name = "iroq" | ||
self.user_email = "iroq@sims.andela" | ||
self.password = "teamiroq1" | ||
self.superuser_name = "iroquois" | ||
self.superuser_email = "iroq@sims1.andela" | ||
self.superuserpassword = "teamiroq" | ||
self.user_data = {"user": {"username": self.user_name, "email": self.user_email, | ||
"password": self.password, | ||
} | ||
} | ||
self.login_data = {"user": {"email": self.user_email, "password": self.password, | ||
} | ||
} | ||
|
||
self.second_user = {"user": {"username": "second_user", "email": "second@exists.com", | ||
"password": self.password, | ||
} | ||
} | ||
|
||
|
Oops, something went wrong.