from django.shortcuts import render
from django.http import HttpResponse, HttpResponseRedirect
from django.contrib import messages

from .models import Team, Job, Mentor, Meetup, Coworking, Post, Event
from .forms import ApplicationForm


def get_index(request):
    featured_posts = Post.objects.filter(is_featured=True)
    events = Event.objects.all()
    return render(request, 'main/index.html', {
        'featured_posts': featured_posts,
        'events': events,
    })

def get_about(request):
    return render(request, 'main/about.html', {
        'page_title': 'Σχετικά',
    })

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

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

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

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

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

def apply(request):
    if request.method == 'POST':
        form = ApplicationForm(request.POST)
        if form.is_valid():
            form.save()
            messages.info(request, 'Thank you for applying!')
            return HttpResponseRedirect('/apply')
        else:
            return HttpResponse('Application form submission is invalid.')
    else:
        form = ApplicationForm()
        return render(request, 'main/apply.html', {'form': form})

def contact(request):
    return HttpResponseRedirect('/')

@@ -28,17 +28,27 @@
 t render
+, redirect
 %0A
-
 from dja
@@ -133,16 +133,48 @@
 messages
+%0Afrom django.urls import reverse
 %0A%0Afrom .
@@ -619,32 +619,112 @@
 %CE%B5%CF%84%CE%B9%CE%BA%CE%AC',%0A    %7D)%0A%0A
+def program_redir(request):%0A    return redirect(reverse('main:program_teams'))%0A%0A
 def get_program(
@@ -722,16 +722,22 @@
 _program
+_teams
 (request
@@ -779,16 +779,202 @@
 /program
+-teams.html')%0A%0Adef get_program_mentors(request):%0A    return render(request, 'main/program-mentors.html')%0A%0Adef get_program_alumni(request):%0A    return render(request, 'main/program-alumni
 .html')%0A

add new program view methods