from django.shortcuts import render
from itsapp.models import  Clan, ClanMembership, UserProfile
from django.contrib.auth.models import User
from django import forms
import string
from itsapp.utils import *
import os
import base64


USER_FIELD_SEPARATOR = ","
MAX_GROUP_IMAGE_SIZE = 1000000


def search(request,term):
	tag=None
	photos=list()
	try:
		tag=Tag.objects.get(name=term.replace(" ","_"))
		tags=TagMembership.objects.filter(tag=tag,tag_type="1")
		for t in tags:
			permission = PermissionUtil(request.user, t.photo.gallery.identificator)		
			if(permission.checkReadPermission()):
				photos.append(t.photo)
	except:
		pass

	return render(request,'itsapp/search.html',{'term': term,'photos':photos})
