Skip to content

Instantly share code, notes, and snippets.

View richellyitalo's full-sized avatar
🏹
Exploring RemixJs

Richelly Italo richellyitalo

🏹
Exploring RemixJs
View GitHub Profile
@richellyitalo
richellyitalo / CreateProfile.js
Last active September 27, 2018 04:08
O necessário para realizar um post e tratar seus erros
// src/Components/create-profile/CreateProfile.js
// importações
// Importando ação que realizará o envio
import { connect } from 'react-redux'
import { withRouter } from 'react-router-dom'
import { createProfile } from '../actions/profileActions'
class CreateProfile extends Component {
// Estado

Sequência Django

  • Iniciando projeto:
    • django-admin startproject NOME_DO_PROJETO
  • Adicionando módulos:
    • django-admin startapp NOME_DO_MODULO
  • Instalado o djangorestframework
    • pip install djangorestframework
  • Adiciona os módulos ao projeto (nome_projeto/settings.py)
  • Cria as migrations
  • py manage.py makemigrations
@richellyitalo
richellyitalo / sobrescrevendo-tema-admin.md
Last active January 29, 2019 00:14
Sobrescrevendo áreas padrão do template admin do Django.

templates/admin/base_site.html

{% extends 'admin/base.html' %}
{%load static %}

{% block branding %}
<h1 id="head"><img src="{% static 'img/logo.png' %}"/></h1>
{% endblock %}

{% block extrastyle %}

doc.: https://docs.djangoproject.com/en/2.1/topics/forms/modelforms

Formulário (forms.py)

class AddressForm(forms.ModelForm):
    class Meta:
        model = Address
        # fields = '__all__'
        fields = ('address', 'address_complement', 'city', 'state', 'country')
        widgets = {
            'address': forms.TextInput(attrs={'class': 'form-control'}),

Nos settings do projeto 'settings.py'

# Configuração static
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
STATIC_URL = '/static/'
STATICFILES_DIRS = [
    os.path.join(BASE_DIR, 'PASTA_APP/static/')
]

Cria o serializers dentro do app

# app/serializers.py
from rest_framework import serializers
from .models import Category


class CategorySerializer(serializers.ModelSerializer):
    class Meta:
 model = Category
from django.contrib.auth.models import User
from rest_framework import serializers
from .models import Category, Product


class UserSerializer(serializers.ModelSerializer):
    class Meta:
        model = User
        fields = ('first_name', 'last_name', 'email')

Configura o rest em 'settings.py'

REST_FRAMEWORK = {
    # ...
    'DEFAULT_PERMISSION_CLASSES': (
        'rest_framework.permissions.IsAuthenticated',
    ),
    'DEFAULT_AUTHENTICATION_CLASSES': (
        'rest_framework.authentication.SessionAuthentication',
        'rest_framework.authentication.TokenAuthentication', # Necessário adicionar 'rest_framework.authtoken' ao INSTALLED_APPS
from django.contrib.auth.decorators import login_required
from django.utils.decorators import method_decorator
from django.views.generic import RedirectView

# 301 - permanente (browser salva como cache destino)
# 302 - temporário
class LogoutRedirectView(RedirectView):
    url = '/login/'