Skip to content

Commit

Permalink
insercao MembroEquipeModel
Browse files Browse the repository at this point in the history
  • Loading branch information
bolzanMGB committed Nov 24, 2024
1 parent c52a18c commit dcbc493
Show file tree
Hide file tree
Showing 34 changed files with 254 additions and 20 deletions.
Empty file added mamutes/Users/__init__.py
Empty file.
Binary file added mamutes/Users/__pycache__/__init__.cpython-312.pyc
Binary file not shown.
Binary file added mamutes/Users/__pycache__/admin.cpython-312.pyc
Binary file not shown.
Binary file added mamutes/Users/__pycache__/apps.cpython-312.pyc
Binary file not shown.
Binary file added mamutes/Users/__pycache__/forms.cpython-312.pyc
Binary file not shown.
Binary file added mamutes/Users/__pycache__/models.cpython-312.pyc
Binary file not shown.
Binary file added mamutes/Users/__pycache__/views.cpython-312.pyc
Binary file not shown.
27 changes: 27 additions & 0 deletions mamutes/Users/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
from django.contrib import admin
from django.contrib.auth.admin import UserAdmin
from .forms import *
from .models import *

class MembroEquipeAdmin(UserAdmin):
add_form = MembroEquipeCreationForm # Use o formulário de criação personalizado
form = MembroEquipeChangeForm # Formulário de alteração personalizado
model = MembroEquipe

list_display = ('username', 'fullname', 'email') ## Lista principal na aba users
search_fields = ('username', 'email')
ordering = ('username',)

## O que aparece quando edita um usuario
fieldsets = (
(None, {'fields': ('username', 'fullname', 'phone', 'email')}),
)

## O que aparece quando adiciona um usuario
add_fieldsets = (
(None, {
'fields': ('username', 'fullname', 'phone', 'email', 'password1', 'password2')
}),
)

admin.site.register(MembroEquipe, MembroEquipeAdmin)
5 changes: 5 additions & 0 deletions mamutes/Users/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from django.apps import AppConfig

class UsersConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'Users'
12 changes: 12 additions & 0 deletions mamutes/Users/forms.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from django.contrib.auth.forms import UserCreationForm, UserChangeForm
from .models import *

class MembroEquipeCreationForm(UserCreationForm):
class Meta:
model = MembroEquipe
fields = ('username', 'fullname', 'email', 'phone', 'password1', 'password2')

class MembroEquipeChangeForm(UserChangeForm):
class Meta:
model = MembroEquipe
fields = ('username', 'email', 'phone', 'fullname', )
45 changes: 45 additions & 0 deletions mamutes/Users/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Generated by Django 5.1 on 2024-11-23 22:33

import django.contrib.auth.models
import django.contrib.auth.validators
import django.utils.timezone
from django.db import migrations, models


class Migration(migrations.Migration):

initial = True

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

operations = [
migrations.CreateModel(
name='MembroEquipe',
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')),
('username', models.CharField(error_messages={'unique': 'A user with that username already exists.'}, help_text='Required. 150 characters or fewer. Letters, digits and @/./+/-/_ only.', max_length=150, unique=True, validators=[django.contrib.auth.validators.UnicodeUsernameValidator()], verbose_name='username')),
('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')),
('email', models.EmailField(blank=True, max_length=254, verbose_name='email address')),
('is_staff', models.BooleanField(default=False, help_text='Designates whether the user can log into this admin site.', verbose_name='staff status')),
('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')),
('phone', models.CharField(max_length=20)),
('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,
},
managers=[
('objects', django.contrib.auth.models.UserManager()),
],
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Generated by Django 5.1 on 2024-11-23 23:05

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('Users', '0001_initial'),
]

operations = [
migrations.AddField(
model_name='membroequipe',
name='fullname',
field=models.CharField(default='phon', max_length=100),
preserve_default=False,
),
migrations.AlterField(
model_name='membroequipe',
name='email',
field=models.EmailField(max_length=200),
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Generated by Django 5.1 on 2024-11-23 23:37

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('Users', '0002_membroequipe_fullname_alter_membroequipe_email'),
]

operations = [
migrations.AddField(
model_name='membroequipe',
name='area',
field=models.CharField(default='a', max_length=100),
preserve_default=False,
),
migrations.AddField(
model_name='membroequipe',
name='funcao',
field=models.CharField(default='a', max_length=100),
preserve_default=False,
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Generated by Django 5.1 on 2024-11-23 23:39

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('Users', '0003_membroequipe_area_membroequipe_funcao'),
]

operations = [
migrations.RemoveField(
model_name='membroequipe',
name='area',
),
migrations.RemoveField(
model_name='membroequipe',
name='funcao',
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Generated by Django 5.1 on 2024-11-24 00:47

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('Users', '0004_remove_membroequipe_area_remove_membroequipe_funcao'),
]

operations = [
migrations.CreateModel(
name='Area',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=100)),
],
),
migrations.CreateModel(
name='Function',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=100)),
],
),
migrations.AddField(
model_name='membroequipe',
name='areas',
field=models.ManyToManyField(blank=True, related_name='membros', to='Users.area'),
),
migrations.AddField(
model_name='membroequipe',
name='functions',
field=models.ManyToManyField(blank=True, related_name='membros', to='Users.function'),
),
]
Empty file.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
26 changes: 26 additions & 0 deletions mamutes/Users/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
from django.db import models
from django.contrib.auth.models import AbstractUser

class Area(models.Model):
name = models.CharField(max_length=100)

def __str__(self):
return self.name

class Function(models.Model):
name = models.CharField(max_length=100)

def __str__(self):
return self.name

class MembroEquipe(AbstractUser):
fullname = models.CharField(max_length=100, blank=False, null=False)
email = models.EmailField (max_length=200, blank=False, null=False)
phone = models.CharField(max_length=20, blank=False, null=False)

areas = models.ManyToManyField(Area, related_name='membros', blank=True)
functions = models.ManyToManyField(Function, related_name='membros', blank=True)

def __str__(self):
return self.phone

Empty file.
3 changes: 3 additions & 0 deletions mamutes/Users/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.
23 changes: 23 additions & 0 deletions mamutes/Users/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
from django.shortcuts import render
from django.http import HttpResponse
from django.shortcuts import render
from django.contrib.auth import authenticate, login as login_django
from .models import *
from .forms import *

def login (request):
if request.method == 'GET':
return render (request, 'cadastro/login.html')
else:
username = request.POST.get('username')
senha = request.POST.get('senha')

user = authenticate(username=username, password=senha)

if user is not None:
login_django (request, user)
return render(request, 'templates/login.html')

else:
return HttpResponse("Credenciais inválidas.")

Binary file modified mamutes/db.sqlite3
Binary file not shown.
Binary file added mamutes/mamutes/__pycache__/__init__.cpython-312.pyc
Binary file not shown.
Binary file not shown.
Binary file added mamutes/mamutes/__pycache__/urls.cpython-312.pyc
Binary file not shown.
Binary file added mamutes/mamutes/__pycache__/wsgi.cpython-312.pyc
Binary file not shown.
3 changes: 3 additions & 0 deletions mamutes/mamutes/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'Users',
'django.contrib.staticfiles',
]

Expand Down Expand Up @@ -121,3 +122,5 @@
# https://docs.djangoproject.com/en/5.1/ref/settings/#default-auto-field

DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'

AUTH_USER_MODEL = 'Users.MembroEquipe'
20 changes: 3 additions & 17 deletions mamutes/mamutes/urls.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,8 @@
"""
URL configuration for mamutes project.
The `urlpatterns` list routes URLs to views. For more information please see:
https://docs.djangoproject.com/en/5.1/topics/http/urls/
Examples:
Function views
1. Add an import: from my_app import views
2. Add a URL to urlpatterns: path('', views.home, name='home')
Class-based views
1. Add an import: from other_app.views import Home
2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
Including another URLconf
1. Import the include() function: from django.urls import include, path
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""
from django.contrib import admin
from django.urls import path

from Users import views
urlpatterns = [
path('admin/', admin.site.urls),
path ('login/', views.login, name = 'login'),

]
3 changes: 0 additions & 3 deletions mamutes/manage.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
#!/usr/bin/env python
"""Django's command-line utility for administrative tasks."""
import os
import sys


def main():
"""Run administrative tasks."""
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'mamutes.settings')
try:
from django.core.management import execute_from_command_line
Expand Down

0 comments on commit dcbc493

Please sign in to comment.