from django.db import models
import time
import datetime
import os
from django import forms
import glob
from django.utils.text import slugify
from django_cryptography.fields import encrypt
from django.core.validators import EmailValidator

def filepath(request, filename):
	cwd = os.getcwd()
	path = filename
	checkpath = os.getcwd()
	for files in glob.glob(checkpath + "*"):
		x = checkpath + filename
		if x == files:
			os.remove(x)
	return path


# Create your models here.
class Event(models.Model):
	eventid = models.IntegerField(blank=True, default=0)
	title = models.CharField(max_length=250) #Title
	date = models.CharField(max_length=250, default="")
	location = models.CharField(max_length=250, default="")
	description = models.TextField(blank=True, max_length=2000)
	link = models.URLField(max_length=500, blank=True)
	image = models.ImageField(upload_to=filepath, null = True, blank = True) #Image File
	banner = models.ImageField(upload_to=filepath, null = True, blank = True) #Image File
	embed_video = models.TextField(blank=True)
	nextevent = models.BooleanField(default=True) #Whetever it is displayed on the mainpage
	online = models.BooleanField(default=False) #Whetever it is displayed on the mainpage
	slug = models.SlugField(max_length=255, editable = False, blank=True)

	def __str__(self):
		return self.title

	def save(self, *args, **kwargs):
		if not self.slug:
			self.slug = slugify(self.title)
		super(Event, self).save(*args, **kwargs)

class Kooperation(models.Model):
	koopid = models.IntegerField(blank=True, default=0)
	image = models.ImageField(upload_to=filepath, null = True, blank = True) #Image File
	link = models.URLField(max_length=500, blank=True)
