from django.contrib import messages
from django.shortcuts import render, redirect
from web.models import MailingList



def index(request):
    return render(request, 'index.html')


def album(request):
    return render(request, 'album.html')


def socials(request):
    return render(request, 'socials.html')


def mailing_list(request):
    if request.method == 'POST':
        referer = request.META['HTTP_REFERER'][:-1].split('/')[-1].split('.')[0]
        email = request.POST.get('email')

        if email:
            exists = MailingList.objects.filter(email=email).first()
            if not exists:
                m = MailingList(
                    email=email
                )
                m.save()
                messages.add_message(request, messages.INFO, "Nice! Thanks for joining our mailing list!")
    return redirect('index')
