from django import forms
from django.contrib.auth.forms import UserCreationForm, authenticate
from django.contrib.auth import login, authenticate
from django.http import HttpResponseRedirect
from django.shortcuts import render
from django.views.generic import ListView, DetailView
from django.contrib import auth
from django.contrib.auth.models import User
from . forms import MyUserCreationForm

from core.models import Post


class Home(ListView):
    model = Post
    template_name = 'home.html'
    context_object_name = 'posts'
    paginate_by = 2


class PostDetail(DetailView):
    model = Post
    template_name = 'post_detail.html'
    context_object_name = 'post'


class Fiksi(ListView):
    queryset = Post.objects.filter(category='Fiksi')
    template_name = 'fiksi.html'
    paginate_by = 2
    context_object_name = 'posts'


class Berita(ListView):
    queryset = Post.objects.filter(category='Berita')
    template_name = 'berita.html'
    paginate_by = 2
    context_object_name = 'posts'

class Olahraga(ListView):
    queryset = Post.objects.filter(category='Olahraga')
    template_name = 'olahraga.html'
    paginate_by = 2
    context_object_name = 'posts'

class Teknologi(ListView):
    queryset = Post.objects.filter(category='Teknologi')
    template_name = 'teknologi.html'
    paginate_by = 2
    context_object_name = 'posts'

def register(request):
    if request.method == 'POST':
        form = MyUserCreationForm(request.POST)
        if form.is_valid():
            #new_user = form.save()
            username = form.cleaned_data.get('username')
            password = form.cleaned_data.get('password1')
            user = authenticate(username=username, password=password)
            login(request, user)
            return HttpResponseRedirect("/admin")
    else:
        form = MyUserCreationForm()
    return render(request, 'register.html', {
        'form': form,
    })

#def redirect_to_home(request):
    #return HttpResponseRedirect(Home.as_view)


c401eb2770618fbc4132bffb54ccf21f85172eb0
<mask token>


class Berita(ListView):
    queryset = Post.objects.filter(category='Berita')
    template_name = 'berita.html'
    paginate_by = 2
    context_object_name = 'posts'


class Olahraga(ListView):
    queryset = Post.objects.filter(category='Olahraga')
    template_name = 'olahraga.html'
    paginate_by = 2
    context_object_name = 'posts'


class Teknologi(ListView):
    queryset = Post.objects.filter(category='Teknologi')
    template_name = 'teknologi.html'
    paginate_by = 2
    context_object_name = 'posts'


<mask token>

<mask token>


class Fiksi(ListView):
    <mask token>
    <mask token>
    <mask token>
    <mask token>


class Berita(ListView):
    queryset = Post.objects.filter(category='Berita')
    template_name = 'berita.html'
    paginate_by = 2
    context_object_name = 'posts'


class Olahraga(ListView):
    queryset = Post.objects.filter(category='Olahraga')
    template_name = 'olahraga.html'
    paginate_by = 2
    context_object_name = 'posts'


class Teknologi(ListView):
    queryset = Post.objects.filter(category='Teknologi')
    template_name = 'teknologi.html'
    paginate_by = 2
    context_object_name = 'posts'


<mask token>

<mask token>


class PostDetail(DetailView):
    <mask token>
    <mask token>
    <mask token>


class Fiksi(ListView):
    queryset = Post.objects.filter(category='Fiksi')
    template_name = 'fiksi.html'
    paginate_by = 2
    context_object_name = 'posts'


class Berita(ListView):
    queryset = Post.objects.filter(category='Berita')
    template_name = 'berita.html'
    paginate_by = 2
    context_object_name = 'posts'


class Olahraga(ListView):
    queryset = Post.objects.filter(category='Olahraga')
    template_name = 'olahraga.html'
    paginate_by = 2
    context_object_name = 'posts'


class Teknologi(ListView):
    queryset = Post.objects.filter(category='Teknologi')
    template_name = 'teknologi.html'
    paginate_by = 2
    context_object_name = 'posts'


<mask token>

<mask token>


class Home(ListView):
    <mask token>
    <mask token>
    <mask token>
    <mask token>


class PostDetail(DetailView):
    model = Post
    template_name = 'post_detail.html'
    context_object_name = 'post'


class Fiksi(ListView):
    queryset = Post.objects.filter(category='Fiksi')
    template_name = 'fiksi.html'
    paginate_by = 2
    context_object_name = 'posts'


class Berita(ListView):
    queryset = Post.objects.filter(category='Berita')
    template_name = 'berita.html'
    paginate_by = 2
    context_object_name = 'posts'


class Olahraga(ListView):
    queryset = Post.objects.filter(category='Olahraga')
    template_name = 'olahraga.html'
    paginate_by = 2
    context_object_name = 'posts'


class Teknologi(ListView):
    queryset = Post.objects.filter(category='Teknologi')
    template_name = 'teknologi.html'
    paginate_by = 2
    context_object_name = 'posts'


<mask token>

from django import forms
from django.contrib.auth.forms import UserCreationForm, authenticate
from django.contrib.auth import login, authenticate
from django.http import HttpResponseRedirect
from django.shortcuts import render
from django.views.generic import ListView, DetailView
from django.contrib import auth
from django.contrib.auth.models import User
from . forms import MyUserCreationForm

from core.models import Post


class Home(ListView):
    model = Post
    template_name = 'home.html'
    context_object_name = 'posts'
    paginate_by = 2


class PostDetail(DetailView):
    model = Post
    template_name = 'post_detail.html'
    context_object_name = 'post'


class Fiksi(ListView):
    queryset = Post.objects.filter(category='Fiksi')
    template_name = 'fiksi.html'
    paginate_by = 2
    context_object_name = 'posts'


class Berita(ListView):
    queryset = Post.objects.filter(category='Berita')
    template_name = 'berita.html'
    paginate_by = 2
    context_object_name = 'posts'

class Olahraga(ListView):
    queryset = Post.objects.filter(category='Olahraga')
    template_name = 'olahraga.html'
    paginate_by = 2
    context_object_name = 'posts'

class Teknologi(ListView):
    queryset = Post.objects.filter(category='Teknologi')
    template_name = 'teknologi.html'
    paginate_by = 2
    context_object_name = 'posts'

def register(request):
    if request.method == 'POST':
        form = MyUserCreationForm(request.POST)
        if form.is_valid():
            #new_user = form.save()
            username = form.cleaned_data.get('username')
            password = form.cleaned_data.get('password1')
            user = authenticate(username=username, password=password)
            login(request, user)
            return HttpResponseRedirect("/admin")
    else:
        form = MyUserCreationForm()
    return render(request, 'register.html', {
        'form': form,
    })

#def redirect_to_home(request):
    #return HttpResponseRedirect(Home.as_view)

