from django.shortcuts import render, redirect, get_object_or_404
from django.core.paginator import Paginator
from django.db.models import Q
from django.conf import settings
from .models import Categories, Courses, Partners, School, Wilayas, Testimonials
from blog.models import Articles
from . import forms

def home(request):
	schools = School.objects.all()[:8]
	partners = Partners.objects.all()[:6]
	wilayas = Wilayas.objects.all()[:6]
	testimonials = Testimonials.objects.all()
	articles = Articles.objects.all()[:3]
	return render(request, 'main/home.html', {'schools': schools, 'partners': partners, 'wilayas': wilayas, 'testimonials': testimonials, 'articles': articles})


def events(request):
	
	return render(request, 'main/events.html')

def about(request):
	
	return render(request, 'main/about.html')

def contact(request):
	
	form = forms.ContactForm()

	if request.method == 'POST':

		form = forms.ContactForm(request.POST)
		
		if form.is_valid():
			form.save()
			return redirect('main:thanks')

	return render(request, 'main/contact.html', {'form': form})

def thanks(request):
    return render(request, 'main/thanks.html')