Skip to content

Commit

Permalink
[feat] created users, team members fetch api and frontend utils
Browse files Browse the repository at this point in the history
  • Loading branch information
pranav-iitr committed Aug 8, 2023
1 parent 36c844f commit dd4fa70
Show file tree
Hide file tree
Showing 22 changed files with 602 additions and 3 deletions.
10 changes: 10 additions & 0 deletions backend/Aries/settings/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ class Common(Configuration):
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
# packages
'oauth2_provider',
'rest_framework',
# apps
'user',

]

MIDDLEWARE = [
Expand Down Expand Up @@ -115,3 +121,7 @@ class Common(Configuration):

DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'

AUTH_USER_MODEL = 'user.User'



9 changes: 6 additions & 3 deletions backend/Aries/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,12 @@
1. Import the include() function: from django.urls import include, path
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""
from django.conf import settings
from django.conf.urls.static import static
from django.contrib import admin
from django.urls import path

from django.urls import path , include
from user import urls as user_urls
urlpatterns = [
path('admin/', admin.site.urls),
]
path('user/', include(user_urls)),
]+ static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
18 changes: 18 additions & 0 deletions backend/Aries/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from oauth2_provider.models import Application
from rest_framework.exceptions import ParseError
import utils.errors as em
from rest_framework.views import APIView

class ApplicationBaseView(APIView):
def initial(self, request, *args, **kwargs):
super().initial(request, *args, **kwargs)
data = request.data
client_id = data.get('client_id', None)
client_secret = data.get('client_secret', None)
if not client_secret or not client_secret:
raise ParseError(em.EMPTY_FIELD('Client ID or Client secret'))
try:
app = Application.objects.get(client_id=client_id, client_secret=client_secret)
except:
raise ParseError(em.INVALID_FIELD_PARAMETER('Client ID or Client secret'))
request.app = app
Empty file added backend/__init__.py
Empty file.
Empty file added backend/user/__init__.py
Empty file.
5 changes: 5 additions & 0 deletions backend/user/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from django.contrib import admin
from .models import Team_Member

admin.site.register(Team_Member)
# Register your models here.
6 changes: 6 additions & 0 deletions backend/user/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from django.apps import AppConfig


class UserConfig(AppConfig):
default_auto_field = "django.db.models.BigAutoField"
name = "user"
34 changes: 34 additions & 0 deletions backend/user/managers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
from django.contrib.auth.base_user import BaseUserManager
from django.utils.translation import gettext_lazy as _


class UserManager(BaseUserManager):
"""
Custom user model manager where email is the unique identifiers
for authentication instead of usernames.
"""
def create_user(self, email, password, **extra_fields):
"""
Create and save a user with the given email and password.
"""
if not email:
raise ValueError(_("The Email must be set"))
email = self.normalize_email(email)
user = self.model(email=email, **extra_fields)
user.set_password(password)
user.save()
return user

def create_superuser(self, email, password, **extra_fields):
"""
Create and save a SuperUser with the given email and password.
"""
extra_fields.setdefault("is_staff", True)
extra_fields.setdefault("is_superuser", True)
extra_fields.setdefault("is_active", True)

if extra_fields.get("is_staff") is not True:
raise ValueError(_("Superuser must have is_staff=True."))
if extra_fields.get("is_superuser") is not True:
raise ValueError(_("Superuser must have is_superuser=True."))
return self.create_user(email, password, **extra_fields)
185 changes: 185 additions & 0 deletions backend/user/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,185 @@
# Generated by Django 4.2.4 on 2023-08-08 11:51

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


class Migration(migrations.Migration):
initial = True

dependencies = [
("auth", "0012_alter_user_first_name_max_length"),
]

operations = [
migrations.CreateModel(
name="User",
fields=[
(
"id",
models.BigAutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
("password", models.CharField(max_length=128, verbose_name="password")),
(
"last_login",
models.DateTimeField(
blank=True, null=True, verbose_name="last login"
),
),
(
"is_superuser",
models.BooleanField(
default=False,
help_text="Designates that this user has all permissions without explicitly assigning them.",
verbose_name="superuser status",
),
),
(
"first_name",
models.CharField(
blank=True, max_length=150, verbose_name="first name"
),
),
(
"last_name",
models.CharField(
blank=True, max_length=150, verbose_name="last name"
),
),
(
"is_active",
models.BooleanField(
default=True,
help_text="Designates whether this user should be treated as active. Unselect this instead of deleting accounts.",
verbose_name="active",
),
),
(
"date_joined",
models.DateTimeField(
default=django.utils.timezone.now, verbose_name="date joined"
),
),
(
"email",
models.EmailField(
max_length=254, unique=True, verbose_name="email address"
),
),
("is_staff", models.BooleanField(default=False)),
("blocked", models.BooleanField(default=False)),
(
"groups",
models.ManyToManyField(
blank=True,
help_text="The groups this user belongs to. A user will get all permissions granted to each of their groups.",
related_name="user_set",
related_query_name="user",
to="auth.group",
verbose_name="groups",
),
),
(
"user_permissions",
models.ManyToManyField(
blank=True,
help_text="Specific permissions for this user.",
related_name="user_set",
related_query_name="user",
to="auth.permission",
verbose_name="user permissions",
),
),
],
options={
"verbose_name": "user",
"verbose_name_plural": "users",
"abstract": False,
},
),
migrations.CreateModel(
name="Team_Member",
fields=[
(
"id",
models.BigAutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
("created_at", models.DateTimeField(auto_now_add=True)),
("updated_at", models.DateTimeField(auto_now=True)),
("json_field", models.JSONField(blank=True, default=dict, null=True)),
("first_name", models.CharField(max_length=50)),
("last_name", models.CharField(max_length=50)),
("phone_number", models.CharField(max_length=20)),
(
"profile_pic",
models.ImageField(blank=True, upload_to="profile_pics/"),
),
("github", models.URLField(blank=True, null=True)),
("linkdin", models.URLField(blank=True, null=True)),
("additional_url", models.URLField(blank=True, null=True)),
(
"user",
models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE,
related_name="team",
to=settings.AUTH_USER_MODEL,
),
),
],
options={
"verbose_name": "Team Member",
"verbose_name_plural": "Team Members",
},
),
migrations.CreateModel(
name="Alum",
fields=[
(
"id",
models.BigAutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
("created_at", models.DateTimeField(auto_now_add=True)),
("updated_at", models.DateTimeField(auto_now=True)),
("json_field", models.JSONField(blank=True, default=dict, null=True)),
("first_name", models.CharField(max_length=50)),
("last_name", models.CharField(max_length=50)),
("phone_number", models.CharField(max_length=20)),
(
"profile_pic",
models.ImageField(blank=True, upload_to="profile_pics/"),
),
("linkdin", models.URLField(blank=True, null=True)),
("facebook_url", models.URLField(blank=True, null=True)),
("additional_url", models.URLField(blank=True, null=True)),
(
"user",
models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE,
related_name="alum",
to=settings.AUTH_USER_MODEL,
),
),
],
options={
"verbose_name": "Alum",
"verbose_name_plural": "Alums",
},
),
]
Empty file.
61 changes: 61 additions & 0 deletions backend/user/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
from django.contrib.auth.models import AbstractUser
from django.db import models
from django.utils.translation import gettext_lazy as _

from utils.mixins import JsonModel, TimestampedModel
from utils.path import get_profile_pics_path

from .managers import UserManager


class User(AbstractUser):
username = None
email = models.EmailField(_("email address"), unique=True)
is_staff = models.BooleanField(default=False)
blocked = models.BooleanField(default=False)
USERNAME_FIELD = "email"
REQUIRED_FIELDS = []
objects = UserManager()

def __str__(self):
return self.email


class Team_Member(JsonModel, TimestampedModel):
user = models.ForeignKey(User, on_delete=models.CASCADE, related_name="team")
first_name = models.CharField(max_length=50)
last_name = models.CharField(max_length=50)
phone_number = models.CharField(max_length=20)
profile_pic = models.ImageField(upload_to=get_profile_pics_path(), blank=True)
github = models.URLField(null=True,blank=True)
linkdin = models.URLField(null=True,blank=True)
additional_url = models.URLField(null=True,blank=True)

class Meta:
verbose_name = "Team Member"
verbose_name_plural = "Team Members"



def __str__(self):
return f"{self.first_name} {self.last_name} {self.user.email}"





class Alum(JsonModel, TimestampedModel):
user = models.ForeignKey(User, on_delete=models.CASCADE, related_name="alum")
first_name = models.CharField(max_length=50)
last_name = models.CharField(max_length=50)
phone_number = models.CharField(max_length=20)
profile_pic = models.ImageField(upload_to=get_profile_pics_path(), blank=True)
linkdin = models.URLField(null=True,blank=True)
facebook_url = models.URLField(null=True,blank=True)
additional_url = models.URLField(null=True,blank=True)
def __str__(self):
return f"{self.first_name} {self.last_name} {self.user.email}"
class Meta:
verbose_name = "Alum"
verbose_name_plural = "Alums"

15 changes: 15 additions & 0 deletions backend/user/serilizers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from rest_framework import serializers

from .models import Alum, Team_Member

class TeamMemberSerializer(serializers.ModelSerializer):
class Meta:
model = Team_Member
fields = "__all__"

class AlumSerializer(serializers.ModelSerializer):
class Meta:
model = Alum
fields = "__all__"


3 changes: 3 additions & 0 deletions backend/user/tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.test import TestCase

# Create your tests here.
6 changes: 6 additions & 0 deletions backend/user/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from django.urls import path
from .views import TeamMemberView

urlpatterns = [
path('team/', TeamMemberView.as_view()),
]
Loading

0 comments on commit dd4fa70

Please sign in to comment.