Skip to content

Commit b00dd69

Browse files
Django Rest avanzando
1 parent a6112c1 commit b00dd69

File tree

6,682 files changed

+770229
-1
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

6,682 files changed

+770229
-1
lines changed

Images/Django-REST-Framework.png

71.8 KB
Loading

README.md

+24-1
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,18 @@
106106
---
107107

108108

109+
## Django API Rest Framework Avanzando
110+
111+
Creación y consumo de APIs con Django REST Framework.
112+
113+
| Numeration | Check | Topic | Quantization | Edit Gitpot | Downloads | link |
114+
|:------------:|:------:|:------------:|:----------------:|:----------------:|:----------------:|:--------:|
115+
| C1 |:heavy_check_mark: | [REST API avanzado](#REST-API-avanzado) | <img src="https://media.giphy.com/media/f8W1VYgiA6gBEfEPPl/giphy.gif" width="25px"> | <img src="https://media.giphy.com/media/cNYPz37tVqWA1UJtBf/giphy.gif" width="25px"> | 💾 | [ ⬅️ Atras](https://github.com/BrianMarquez3) |
116+
117+
118+
119+
---
120+
109121
## Que es Django
110122

111123
Django es un framework de desarrollo web de código abierto, escrito en Python, que respeta el patrón de diseño conocido como MVC (Modelo–Vista–Controlador). Fue desarrollado en origen para gestionar varias páginas orientadas a noticias de la World Company de Lawrence, Kansas, y fue liberada al público bajo una licencia BSD en julio de 2005; el framework fue nombrado en alusión al guitarrista de jazz gitano Django Reinhardt. En junio de 2008 fue anunciado que la recién formada Django Software Foundation se haría cargo de Django en el futuro.
@@ -771,12 +783,23 @@ Documentacion [Django Api REST Framework ](https://www.django-rest-framework.org
771783

772784
## filtrarUsuarios
773785

774-
|B7| [filtrarUsuarios]() | ✔️ | yes | yes | ✔️ | ✔️ | [⬅️Atras](#Django-API-Rest-Framework) |
786+
|B7| [filtrarUsuarios](https://github.com/BrianMarquez3/Python-Django/tree/master/filtrarUsuarios) | ✔️ | yes | yes | ✔️ | ✔️ | [⬅️Atras](#Django-API-Rest-Framework) |
775787

776788

777789

790+
---
791+
792+
<table align="center">
793+
<tr>
794+
<td align="center" style="padding=0;width=50%;">
795+
<img align="center" style="padding=0;" src="./Images/Django-REST-Framework.png" />
796+
</td>
797+
</tr>
798+
</table>
778799

800+
## REST_API_avanzado
779801

802+
|C1| [REST API avanzado]() | ✔️ | yes | yes | ✔️ | ✔️ | [⬅️Atras](#Django-API-Rest-Framework) |
780803

781804

782805

REST_API_avanzado/REST_API_avanzando/app/__init__.py

Whitespace-only changes.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
"""
2+
ASGI config for app project.
3+
4+
It exposes the ASGI callable as a module-level variable named ``application``.
5+
6+
For more information on this file, see
7+
https://docs.djangoproject.com/en/3.2/howto/deployment/asgi/
8+
"""
9+
10+
import os
11+
12+
from django.core.asgi import get_asgi_application
13+
14+
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'app.settings')
15+
16+
application = get_asgi_application()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
"""
2+
Django settings for app project.
3+
4+
Generated by 'django-admin startproject' using Django 3.2.8.
5+
6+
For more information on this file, see
7+
https://docs.djangoproject.com/en/3.2/topics/settings/
8+
9+
For the full list of settings and their values, see
10+
https://docs.djangoproject.com/en/3.2/ref/settings/
11+
"""
12+
13+
from pathlib import Path
14+
15+
# Build paths inside the project like this: BASE_DIR / 'subdir'.
16+
BASE_DIR = Path(__file__).resolve().parent.parent
17+
18+
19+
# Quick-start development settings - unsuitable for production
20+
# See https://docs.djangoproject.com/en/3.2/howto/deployment/checklist/
21+
22+
# SECURITY WARNING: keep the secret key used in production secret!
23+
SECRET_KEY = 'django-insecure-(t0voz3)xo6m)$_7u9##jbpkt7c649392=s7hbtra*9l@61gj#'
24+
25+
# SECURITY WARNING: don't run with debug turned on in production!
26+
DEBUG = True
27+
28+
ALLOWED_HOSTS = []
29+
30+
31+
# Application definition
32+
33+
INSTALLED_APPS = [
34+
'django.contrib.admin',
35+
'django.contrib.auth',
36+
'django.contrib.contenttypes',
37+
'django.contrib.sessions',
38+
'django.contrib.messages',
39+
'django.contrib.staticfiles',
40+
'core',
41+
]
42+
43+
MIDDLEWARE = [
44+
'django.middleware.security.SecurityMiddleware',
45+
'django.contrib.sessions.middleware.SessionMiddleware',
46+
'django.middleware.common.CommonMiddleware',
47+
'django.middleware.csrf.CsrfViewMiddleware',
48+
'django.contrib.auth.middleware.AuthenticationMiddleware',
49+
'django.contrib.messages.middleware.MessageMiddleware',
50+
'django.middleware.clickjacking.XFrameOptionsMiddleware',
51+
]
52+
53+
ROOT_URLCONF = 'app.urls'
54+
55+
TEMPLATES = [
56+
{
57+
'BACKEND': 'django.template.backends.django.DjangoTemplates',
58+
'DIRS': [],
59+
'APP_DIRS': True,
60+
'OPTIONS': {
61+
'context_processors': [
62+
'django.template.context_processors.debug',
63+
'django.template.context_processors.request',
64+
'django.contrib.auth.context_processors.auth',
65+
'django.contrib.messages.context_processors.messages',
66+
],
67+
},
68+
},
69+
]
70+
71+
WSGI_APPLICATION = 'app.wsgi.application'
72+
73+
74+
# Database
75+
# https://docs.djangoproject.com/en/3.2/ref/settings/#databases
76+
77+
DATABASES = {
78+
'default': {
79+
'ENGINE': 'django.db.backends.sqlite3',
80+
'NAME': BASE_DIR / 'db.sqlite3',
81+
}
82+
}
83+
84+
85+
# Password validation
86+
# https://docs.djangoproject.com/en/3.2/ref/settings/#auth-password-validators
87+
88+
AUTH_PASSWORD_VALIDATORS = [
89+
{
90+
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
91+
},
92+
{
93+
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
94+
},
95+
{
96+
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
97+
},
98+
{
99+
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
100+
},
101+
]
102+
103+
104+
# Internationalization
105+
# https://docs.djangoproject.com/en/3.2/topics/i18n/
106+
107+
LANGUAGE_CODE = 'en-us'
108+
109+
TIME_ZONE = 'UTC'
110+
111+
USE_I18N = True
112+
113+
USE_L10N = True
114+
115+
USE_TZ = True
116+
117+
118+
# Static files (CSS, JavaScript, Images)
119+
# https://docs.djangoproject.com/en/3.2/howto/static-files/
120+
121+
STATIC_URL = '/static/'
122+
123+
# Default primary key field type
124+
# https://docs.djangoproject.com/en/3.2/ref/settings/#default-auto-field
125+
126+
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
127+
128+
AUTH_USER_MODEL = 'core.User'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
"""app URL Configuration
2+
3+
The `urlpatterns` list routes URLs to views. For more information please see:
4+
https://docs.djangoproject.com/en/3.2/topics/http/urls/
5+
Examples:
6+
Function views
7+
1. Add an import: from my_app import views
8+
2. Add a URL to urlpatterns: path('', views.home, name='home')
9+
Class-based views
10+
1. Add an import: from other_app.views import Home
11+
2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
12+
Including another URLconf
13+
1. Import the include() function: from django.urls import include, path
14+
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
15+
"""
16+
from django.contrib import admin
17+
from django.urls import path
18+
19+
urlpatterns = [
20+
path('admin/', admin.site.urls),
21+
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
"""
2+
WSGI config for app project.
3+
4+
It exposes the WSGI callable as a module-level variable named ``application``.
5+
6+
For more information on this file, see
7+
https://docs.djangoproject.com/en/3.2/howto/deployment/wsgi/
8+
"""
9+
10+
import os
11+
12+
from django.core.wsgi import get_wsgi_application
13+
14+
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'app.settings')
15+
16+
application = get_wsgi_application()

REST_API_avanzado/REST_API_avanzando/core/__init__.py

Whitespace-only changes.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from django.contrib import admin
2+
3+
# Register your models here.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
from django.apps import AppConfig
2+
3+
4+
class CoreConfig(AppConfig):
5+
default_auto_field = 'django.db.models.BigAutoField'
6+
name = 'core'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Generated by Django 3.2.8 on 2021-10-22 14:54
2+
3+
from django.db import migrations, models
4+
import django.db.models.manager
5+
6+
7+
class Migration(migrations.Migration):
8+
9+
initial = True
10+
11+
dependencies = [
12+
('auth', '0012_alter_user_first_name_max_length'),
13+
]
14+
15+
operations = [
16+
migrations.CreateModel(
17+
name='User',
18+
fields=[
19+
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
20+
('password', models.CharField(max_length=128, verbose_name='password')),
21+
('last_login', models.DateTimeField(blank=True, null=True, verbose_name='last login')),
22+
('is_superuser', models.BooleanField(default=False, help_text='Designates that this user has all permissions without explicitly assigning them.', verbose_name='superuser status')),
23+
('email', models.EmailField(max_length=255, unique=True)),
24+
('name', models.CharField(max_length=255)),
25+
('is_active', models.BooleanField(default=True)),
26+
('is_staff', models.BooleanField(default=False)),
27+
('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')),
28+
('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')),
29+
],
30+
options={
31+
'abstract': False,
32+
},
33+
managers=[
34+
('object', django.db.models.manager.Manager()),
35+
],
36+
),
37+
]

REST_API_avanzado/REST_API_avanzando/core/migrations/__init__.py

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
from django.contrib.auth import base_user
2+
from django.db import models
3+
from django.contrib.auth.models import AbstractBaseUser, BaseUserManager, PermissionsMixin
4+
5+
class UserManager(BaseUserManager):
6+
7+
def create_user(self, email, password=None, **extra_fields):
8+
9+
if not email:
10+
raise ValueError ('Users mst hace an email')
11+
12+
user = self.model(email=self.normalize_email(email), **extra_fields)
13+
user.set_password(password)
14+
user.save(using=self._db)
15+
16+
return user
17+
18+
class User(AbstractBaseUser, PermissionsMixin):
19+
""" Modelo personalisado de usuario que sorporta hacer login con Email en ves de Usuario """
20+
email = models.EmailField(max_length=255, unique=True)
21+
name = models.CharField(max_length=255)
22+
is_active = models.BooleanField(default=True)
23+
is_staff = models.BooleanField(default=False)
24+
25+
objects = UserManager()
26+
27+
USERNAME_FIELD = 'email'
28+
29+
30+
31+

REST_API_avanzado/REST_API_avanzando/core/tests/__init__.py

Whitespace-only changes.
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
from django.test import TestCase
2+
from django.contrib.auth import get_user_model
3+
4+
class ModelTest(TestCase):
5+
6+
def test_create_user_with_email_succesful(self):
7+
"""Porbar cerando un nvo usuario con un Email email correctamente"""
8+
9+
10+
password = 'Testpass123'
11+
12+
user = get_user_model().objects.create_user(
13+
email=email,
14+
password=password
15+
)
16+
17+
self.assertEqual(user.email, email)
18+
self.assertTrue(user.check_password(password))
19+
20+
21+
""" normalisar """
22+
def test_new_user_email_normalized(self):
23+
"""Testea email para nuero usuario normalizado"""
24+
25+
26+
user = get_user_model().objects.create_user(email, 'Testpass123')
27+
28+
self.assertEqual(user.email, email.lower())
29+
30+
def test_new_user_invalid_email(self):
31+
""" nuevo usuario email invalido """
32+
with self.assertRaises(ValueError):
33+
get_user_model().objects.create_user(None, 'Testpass123')
34+
35+
36+
37+
38+
39+
40+
41+
42+
43+
44+
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/usr/bin/env python
2+
"""Django's command-line utility for administrative tasks."""
3+
import os
4+
import sys
5+
6+
7+
def main():
8+
"""Run administrative tasks."""
9+
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'app.settings')
10+
try:
11+
from django.core.management import execute_from_command_line
12+
except ImportError as exc:
13+
raise ImportError(
14+
"Couldn't import Django. Are you sure it's installed and "
15+
"available on your PYTHONPATH environment variable? Did you "
16+
"forget to activate a virtual environment?"
17+
) from exc
18+
execute_from_command_line(sys.argv)
19+
20+
21+
if __name__ == '__main__':
22+
main()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
django==3.2.8
2+
djangorestframework==3.12.4
3+
django-environ==0.8.0
4+
environs==9.3.4
5+
psycopg2==2.8.6
6+
dj-database-url==0.5.0
7+
sqlparse==0.4.1
8+
six==1.15.0
9+
PyJWT==2.0.1

0 commit comments

Comments
 (0)