예제 #1
0
 def post(self):
         detailedDescription = self.request.get("detailedDescription")
         
         count=int(self.request.get("count"))
         projectObject = Project()
         user=users.get_current_user()
         if user:
                 userid = user.user_id()
                 authenticationUser = User.query(User.userid==userid).fetch(1)
                 authenticationNGO = NGO.query(NGO.userid==userid).fetch(1)
                 if authenticationNGO:
                         ngo = projectObject.ngo
                         existingProject = Project.query(Project.ngo==userid).fetch(1)
                         if existingProject:
                                 projectObject.detailedDescription = detailedDescription
                                 while count>0:
                                         j=1
                                         Counter=str(count-count+j)
                                         taskTitle = self.request.get("taskTitle"+Counter)
                                         taskDescription = self.request.get("taskDescription"+Counter)
                                         taskFund = self.request.get("taskFund"+Counter)
                                         count=count-1
                                         j=j-1
                                         projectObject.tasks = [TaskList(taskTitle = taskTitle, taskDescription = taskDescription, taskFund = taskFund)]
                                 projectObject.put()
                                 self.redirect("/home")
                         else:
                                 self.redirect("/propose")
                 elif authenticationUser:
                         self.redirect("/home")
                 else:
                         self.redirect("/")
         else:
                 self.redirect("/login")
 def get(self):
     user = users.get_current_user()
     try:
         hitCount = HitCount.query().fetch(1)[0]
         hits = int(hitCount.hitCount) + 1
     except:
         hits = 0
         hitCount = HitCount()
     hitCount.hitCount = str(hits)
     hitCount.put()
     if user:
         userid = user.user_id()
         userAuthenticationQuery = User.query(
             User.userid == userid).fetch(1)
         NGOauthenticationQuery = NGO.query(NGO.userid == userid).fetch(1)
         if (not userAuthenticationQuery) and (not NGOauthenticationQuery):
             self.redirect("/signup/registration")
     projects = Project.query().fetch()
     randProjects = []
     try:
         for i in range(0, 4):
             randomInt = randint(0, len(projects) - 1)
             if projects[randomInt] not in randProjects:
                 randProjects.append(projects[randomInt])
     except:
         pass
     parameter = {"projects": randProjects, "hits": hits}
     self.render('frontPage.html', parameter)
예제 #3
0
	def get(self):
		user=users.get_current_user()
		if user:
			userid = user.user_id()
			userAuth = User.query(User.userid == userid).fetch(1)
			ngoAuth = NGO.query(NGO.userid == userid).fetch(1)
			if userAuth:
				userProj = []
				link = userAuth[0].projects
				for p in link:
					ngo, title = p[0].split("_")
					projects = ndb.gql("SELECT * FROM Project WHERE link = :1 AND ngo = :2", title,ngo).fetch(1)
					if projects:
						userProj.append((projects[0],p[1]));
						print userProj
				parameter = {"proj":userProj, "user": 1, "length":len(userProj)}
				self.render("/userProjects.html",parameter)
			elif ngoAuth:
				ngoProjects = []
				link = ngoAuth[0].projects
				for p in link:
					proj = Project.query(Project.ngo == p.userid).fetch(1)
					ngoProjects.append(proj[0]);
				parameter = {"projects":ngoProjects, "user": 0, "length":len(ngoProjects),"ngo":ngoAuth[0]}
				self.render("/ngoProjects.html",parameter)
		else:
			self.render("/login.html")
예제 #4
0
 def post(self):
         detailedDescription = self.request.get("detailedDescription")
         
         count=int(self.request.get("count"))
         projectObject = Project()
         user=users.get_current_user()
         if user:
                 userid = user.user_id()
                 authenticationUser = User.query(User.userid==userid).fetch(1)
                 authenticationNGO = NGO.query(NGO.userid==userid).fetch(1)
                 if authenticationNGO:
                         ngo = projectObject.ngo
                         existingProject = Project.query(Project.ngo==userid).fetch(1)
                         if existingProject:
                                 projectObject.detailedDescription = detailedDescription
                                 while count>0:
                                         j=1
                                         Counter=str(count-count+j)
                                         taskTitle = self.request.get("taskTitle"+Counter)
                                         taskDescription = self.request.get("taskDescription"+Counter)
                                         taskFund = self.request.get("taskFund"+Counter)
                                         count=count-1
                                         j=j-1
                                         projectObject.tasks = [TaskList(taskTitle = taskTitle, taskDescription = taskDescription, taskFund = taskFund)]
                                 projectObject.put()
                                 self.redirect("/home")
                         else:
                                 self.redirect("/propose")
                 elif authenticationUser:
                         self.redirect("/home")
                 else:
                         self.redirect("/")
         else:
                 self.redirect("/login")
예제 #5
0
	def post(self,urlParameter):
		flag = 0;
		link = self.request.get("project")
		user=users.get_current_user()
		if user:
			userid = user.user_id()
			userAuth = User.query(User.userid == userid).fetch(1)
			if userAuth:
				funds = self.request.get("funds")
				ngo, title = link.split("_")
				print title
				q = ndb.gql("SELECT * FROM Project WHERE link = :1 AND ngo = :2", title,ngo).fetch(1)
				for p in userAuth[0].projects:
					if p[0] == link:
						p[1] = p[1] + funds
						flag = 1
				if(flag == 0):
					userAuth[0].projects.append([link,funds])
				userAuth[0].projects = sorted(userAuth[0].projects, key=lambda tup: tup[1])
				userAuth[0].put()
				q[0].funding.append((userid,funds))
				q[0].put()
				parameter = {"message":"You Have Successfully Funded a Project."}
			else:
				parameter = {"message":"You Are Not Authorized to Fund a Project."}
		else:
			parameter = {"message":"Please Login to Fund a Project."}
		self.render("message.html",parameter)
예제 #6
0
	def get(self):
		user=users.get_current_user()
		if user:
			userid = user.user_id()
			userAuth = User.query(User.userid == userid).fetch(1)
			ngoAuth = NGO.query(NGO.userid == userid).fetch(1)
			if userAuth:
				userProj = []
				link = userAuth[0].projects
				for p in link:
					ngo, title = p[0].split("_")
					projects = ndb.gql("SELECT * FROM Project WHERE link = :1 AND ngo = :2", title,ngo).fetch(1)
					if projects:
						userProj.append((projects[0],p[1]));
						print userProj
				parameter = {"proj":userProj, "user": 1, "length":len(userProj)}
				self.render("/userProjects.html",parameter)
			elif ngoAuth:
				ngoProjects = []
				ngoAuth
				for p in ngoAuth:
					proj = Project.query(Project.ngo == p.userid).fetch(1)
					ngoProjects.append(proj[0]);
				print ngoAuth[0]
				parameter = {"ngoProjects":ngoProjects, "user": 0, "length":len(ngoProjects),"ngo":ngoAuth[0]}
				self.render("/ngoProjects.html",parameter)
		else:
			self.render("/login.html")
예제 #7
0
	def get(self):
		user=users.get_current_user()
		try:
			hitCount = HitCount.query().fetch(1)[0]
			hits = int(hitCount.hitCount) + 1
		except:
			hits = 0
			hitCount = HitCount()
		hitCount.hitCount = str(hits)
		hitCount.put()
		if user:
			userid = user.user_id()
 	    		userAuthenticationQuery = User.query(User.userid == userid).fetch(1)	 	    	      
                        NGOauthenticationQuery = NGO.query(NGO.userid == userid).fetch(1)
                        if (not userAuthenticationQuery) and (not NGOauthenticationQuery) :
				self.redirect("/signup/registration")
		projects = Project.query().fetch()
		randProjects = []
		try:
			for i in range(0,4):
				randomInt = randint(0,len(projects)-1)
				if projects[randomInt] not in randProjects:
					randProjects.append(projects[randomInt])
		except:
			pass
		parameter = {"projects" : randProjects, "hits":hits}
		self.render('frontPage.html', parameter)        
예제 #8
0
	def post(self,urlParameter):
		flag = 0;
		link = self.request.get("project")
		user=users.get_current_user()
		if user:
			userid = user.user_id()
			userAuth = User.query(User.userid == userid).fetch(1)
			if userAuth:
				funds = self.request.get("funds")
				ngo, title = link.split("_")
				print title
				q = ndb.gql("SELECT * FROM Project WHERE link = :1 AND ngo = :2", title,ngo).fetch(1)
				for p in userAuth[0].projects:
					if p[0] == link:
						p[1] = p[1] + funds
						flag = 1
				if(flag == 0):
					userAuth[0].projects.append([link,funds])
				userAuth[0].projects = sorted(userAuth[0].projects, key=lambda tup: tup[1])
				userAuth[0].put()
				q[0].funding.append((userid,funds))
				q[0].put()
				parameter = {"message":"You Have Successfully Funded a Project.","title":"Successfully Funded"}
			else:
				parameter = {"message":"You Are Not Authorized to Fund a Project.","title":"Error"}
		else:
			parameter = {"message":"Please Login to Fund a Project.","title":"Error"}
		self.render("message.html",parameter)
예제 #9
0
	def get(self):
		user=users.get_current_user()
		if user:
			userid = user.user_id()
 	    		authenticationQuery = User.query(User.userid == userid).fetch(1)	 	    	      
			if not authenticationQuery:
				self.redirect("/signup/registration")    
		self.render('frontPage.html')        
예제 #10
0
 def get(self):
     user = users.get_current_user()
     if user:
         userid = user.user_id()
         authenticationQuery = User.query(User.userid == userid).fetch(1)
         if not authenticationQuery:
             self.redirect("/signup/registration")
     self.render('frontPage.html')
예제 #11
0
	def post(self):
		user= users.get_current_user()
		if user:
			userid = user.user_id()
			authenticationUser = User.query(User.userid == userid).fetch(1)
			authenticationNgo = NGO.query(NGO.userid == userid).fetch(1)
			if authenticationUser or authenticationNgo:
				self.redirect("/home")
			else:
				name = self.request.get("name")	
				email = user.email()
				description = self.request.get("description")
				pancardNumber = self.request.get("pancardNumber")
				chiefFunctionary = self.request.get("chiefFunctionary")
				chairman = self.request.get("chairman")
				sectorOfOperation = self.request.get("sectorOfOperation")
				stateOfOperation = self.request.get("stateOfOperation")
				email = self.request.get("email")
				website = self.request.get("website")
				registrationNumber = self.request.get("registrationNumber")
				dateOfRegistration = self.request.get("dateOfRegistration")
				stateOfRegistration = self.request.get("stateOfRegistration")
				telephone = self.request.get("telephone")	
				address = self.request.get("address")
				dateOfRegistration  =  self.date(dateOfRegistration)
				ngo = NGO()
				ngo.userid = userid
				ngo.name = name
				ngo.credibility = False
				ngo.description = description
				ngo.pancardNumber = pancardNumber
				ngo.email = email
				ngo.website = website
				ngo.chiefFunctionary = chiefFunctionary
				ngo.chairman = chairman
				ngo.sectorOfOperation = sectorOfOperation
				ngo.stateOfOperation = stateOfOperation
				ngo.registrationNumber = registrationNumber
				ngo.dateOfRegistration = dateOfRegistration
				ngo.stateOfRegistration = stateOfRegistration 
				ngo.telephone = telephone 
				ngo.projects = []
				ngo.address = address 
				ngo.email = email
				ngo.put()

				index = search.Index(name = "NGO")		
				document = search.Document(doc_id = userid, fields = [ search.TextField(name = "name", value = name ),
								       search.TextField(name = "description", value = description),
								       search.TextField(name = "state", value = stateOfRegistration)])
				try:
					index.put(document)
				except search.Error:
					logging.exception("Put Failed")
				sleep(5) #cheap trick but none the less it works!
				self.redirect("/home")	
		else:
			self.redirect("/login") 
예제 #12
0
 def get(self):
     user = users.get_current_user()
     if user:
         userid = user.user_id()
         authenticationUser = User.query(User.userid == userid).fetch(1)
         if not authenticationUser:
             self.render("userRegistration.html")
         else:
             self.redirect("/home")
     else:
         self.redirect("/signup")
예제 #13
0
	def get(self):
		user=users.get_current_user()
		if user:
			userid = user.user_id()
 	    		userAuthenticationQuery = User.query(User.userid == userid).fetch(1)	 	    	      
                        NGOauthenticationQuery = NGO.query(NGO.userid == userid).fetch(1)
                        if (not userAuthenticationQuery) and (not NGOauthenticationQuery) :
				self.redirect("/signup/registration")
		projects = Project.query().fetch(3)
		parameter = {"projects" : projects }
		self.render('frontPage.html', parameter)        
예제 #14
0
	def get(self):
		user=users.get_current_user()
		if user:
			userid = user.user_id()
 			authenticationUser = User.query(User.userid == userid).fetch(1)
			if  not authenticationUser:
				self.render("userRegistration.html")
			else:
				self.redirect("/home")
		else:
			self.redirect("/signup")
예제 #15
0
	def post(self):
		user= users.get_current_user()
		if user:
			userid = user.user_id()
			authenticationUser = User.query(User.userid == userid).fetch(1)
			authenticationNgo = NGO.query(NGO.userid == userid).fetch(1)
			if authenticationUser or authenticationNgo:
				self.redirect("/home")
			else:
				name = self.request.get("name")	
				email = user.email()
				description = self.request.get("description")
				pancardNumber = self.request.get("pancardNumber")
				chiefFunctionary = self.request.get("chiefFunctionary")
				chairman = self.request.get("chairman")
				sectorOfOperation = self.request.get("sectorOfOperation")
				stateOfOperation = self.request.get("stateOfOperation")
				registrationNumber = self.request.get("registrationNumber")
				dateOfRegistration = self.request.get("dateOfRegistration")
				stateOfRegistration = self.request.get("stateOfRegistration")
				telephone = self.request.get("telephone")	
				address = self.request.get("address")
				dateOfRegistration  =  self.date(dateOfRegistration)
				ngo = NGO()
				ngo.userid = userid
				ngo.name = name
				ngo.credibility = False
				ngo.description = description
				ngo.pancardNumber = pancardNumber
				ngo.chiefFunctionary = chiefFunctionary
				ngo.chairman = chairman
				ngo.sectorOfOperation = sectorOfOperation
				ngo.stateOfOperation = stateOfOperation
				ngo.registrationNumber = registrationNumber
				ngo.dateOfRegistration = dateOfRegistration
				ngo.stateOfRegistration = stateOfRegistration 
				ngo.telephone = telephone 
				ngo.projects = []
				ngo.address = address 
				ngo.email = email
				ngo.put()

				index = search.Index(name = "NGO")		
				document = search.Document(doc_id = userid, fields = [ search.AtomField(name = "name", value = name ),
								       search.TextField(name = "description", value = description)])
				try:
					index.put(document)
				except search.Error:
					logging.exception("Put Failed")
				sleep(5) #cheap trick but none the less it works!
				self.redirect("/signup/ngoRegistration/proofOfRegistration")	
		else:
			self.redirect("/login") 
 def get(self, urlParameter):
     print urlParameter
     ngo, title = urlParameter.split("_")
     q = ndb.gql("SELECT * FROM Project WHERE link = :1 AND ngo = :2",
                 title, ngo).fetch(1)
     funds = 0
     print q
     if q:
         parameters = {}
         for p in q:
             parameters["project"] = p
             ngoP = NGO.query(NGO.userid == p.ngo).fetch(1)
             parameters["ngo"] = ngoP[0]
         for task in parameters["project"].tasks:
             funds = funds + int(task[2])
         i = 0
         parameters["collected"] = 0
         parameters["funding"] = []
         while i < len(parameters["project"].funding):
             user = User.query(User.userid ==
                               parameters["project"].funding[i][0]).fetch(1)
             parameters["collected"] = parameters["collected"] + int(
                 parameters["project"].funding[i][1])
             parameters["funding"].append(
                 (user[0], parameters["project"].funding[i][1]))
             i = i + 1
         parameters["funding"].reverse()
         print parameters["project"].funding
         parameters["support"] = i
         print parameters["support"]
         projects = Project.query(
             Project.category == parameters["project"].category).fetch()
         closeProjects = []
         try:
             for i in range(0, 4):
                 randomInt = randint(0, len(projects) - 1)
                 if (projects[randomInt] not in closeProjects
                         and projects[randomInt] != parameters["project"]):
                     closeProjects.append(projects[randomInt])
         except:
             pass
         parameters["closeProjects"] = closeProjects
         parameters["funds"] = funds
         self.render("projectPage.html", parameters)
예제 #17
0
 def get(self):
     user = users.get_current_user()
     if user:
         userid = user.user_id()
         userAuthentication = User.query(User.userid == userid).fetch(1)
         ngoAuthentication = NGO.query(NGO.userid == userid).fetch(1)
         if userAuthentication:
             parameter = {}
             ngos = NGO.query().fetch(4)
             userObject = userAuthentication[0]
             userProjects = []
             for p in userObject.projects:
                 ngo, title = p[0].split("_")
                 print p[0]
                 proj = ndb.gql(
                     "SELECT * FROM Project WHERE link = :1 AND ngo = :2",
                     title, ngo).fetch(1)
                 if proj:
                     userProjects.append(proj[0])
             projects = Project.query().fetch(100)
             print userObject.projects
             closeProjects = []
             decorated = [(project,
                           project.distance(userAuthentication[0].lat,
                                            userAuthentication[0].lng))
                          for project in projects]
             closeProjects = sorted(decorated, key=lambda tup: tup[1])[0:4]
             parameter["projects"] = closeProjects
             parameter["userProjects"] = userProjects
             parameter["ngos"] = ngos
             parameter["currUser"] = userAuthentication[0]
             self.render("userHomePage.html", parameter)
         elif ngoAuthentication:
             parameter = {}
             proj = Project.query(
                 Project.ngo == ngoAuthentication[0].userid).fetch()
             parameter["ngoProjects"] = proj
             parameter["length"] = len(proj)
             parameter["ngo"] = ngoAuthentication[0]
             self.render("ngoHomePage.html", parameter)
         else:
             self.redirect("/signup/registration")
     else:
         self.redirect("/")
예제 #18
0
 def get(self):
     user = users.get_current_user()
     if user:
         userid = user.user_id()
         userAuthentication = User.query(User.userid == userid).fetch(1)
         if userAuthentication:
             parameter = {}
             userObject = userAuthentication[0]
             projectsIdentifier = userObject.projects[:10]
             projects = []
             for projectIdentifier in projectsIdentifier:
                 key = ndb.Key("Project", projectIdentifier)
                 projects.append(key.get())
             parameter["projects"] = projects
             self.render("projectUpdate.html", parameter)
         else:
             self.redirect("/")
     else:
         self.redirect("/login")
예제 #19
0
	def get(self):
		user = users.get_current_user()
                if user:
                        userid = user.user_id()
                        userAuthentication =  User.query(User.userid == userid).fetch(1)
                        if userAuthentication:
				parameter = {}
				userObject = userAuthentication[0]
				projectsIdentifier = userObject.projects[:10]
				projects = []
				for projectIdentifier in projectsIdentifier:
					key = ndb.Key("Project", projectIdentifier)
					projects.append(key.get())
				parameter["projects"] = projects
                                self.render("projectUpdate.html", parameter)
                        else:
                                self.redirect("/")
                else:   
                        self.redirect("/login")
예제 #20
0
	def get(self):
		user = users.get_current_user()
		if user:
			userid = user.user_id()
			userAuthentication =  User.query(User.userid == userid).fetch(1)
			ngoAuthentication = NGO.query(NGO.userid == userid).fetch(1)
			if userAuthentication:
				parameter = {}
				ngos = NGO.query().fetch(4)
				userObject = userAuthentication[0]
				userProjects = []
				for p in userObject.projects:
					ngo, title = p[0].split("_")
					print p[0]
					proj = ndb.gql("SELECT * FROM Project WHERE link = :1 AND ngo = :2", title,ngo).fetch(1)
					if proj:
						userProjects.append(proj[0]);
				projects = Project.query().fetch(100)
				print userObject.projects
				cProjects = []
				decorated = [(project,project.distance(userAuthentication[0].lat,userAuthentication[0].lng)) for project in projects if project.distance(userAuthentication[0].lat,userAuthentication[0].lng)<50]
				print decorated
				cProjects = sorted(decorated, key=lambda tup: tup[1])[0:4] 
				parameter["cProjects"] = cProjects
				parameter["userProjects"] = userProjects 
				parameter["ngos"] = ngos
				parameter["currUser"] = userAuthentication[0]
				self.render("userHomePage.html", parameter)
			elif ngoAuthentication:
				parameter={}
				proj = Project.query(Project.ngo == ngoAuthentication[0].userid).fetch()
                                parameter["ngoProjects"] = proj
                                parameter["length"] = len(proj)
                                parameter["ngo"]=ngoAuthentication[0]
				self.render("ngoHomePage.html", parameter)
			else:
				self.redirect("/signup/registration")
		else:
			self.redirect("/")
예제 #21
0
    def get(self,urlParameter):
		print urlParameter
		ngo, title = urlParameter.split("_")
		q = ndb.gql("SELECT * FROM Project WHERE link = :1 AND ngo = :2", title,ngo).fetch(1)
		funds = 0
		print q
		if q:
			parameters = {}
			for p in q:
				parameters["project"] = p
				ngoP = NGO.query(NGO.userid == p.ngo).fetch(1)
				parameters["ngo"] = ngoP[0]
			for task in parameters["project"].tasks:
				funds = funds + int(task[2]);
			i=0
			parameters["collected"] = 0
			parameters["funding"] = []
			while i < len(parameters["project"].funding):
				user = User.query(User.userid == parameters["project"].funding[i][0]).fetch(1)
				parameters["collected"] = parameters["collected"] + int(parameters["project"].funding[i][1])
				parameters["funding"].append((user[0], parameters["project"].funding[i][1]))
				i=i+1
			parameters["funding"].reverse()
			print parameters["project"].funding
			parameters["support"]=i
			print parameters["support"]
			projects = Project.query(Project.category == parameters["project"].category).fetch()
			closeProjects = []
			try:
				for i in range(0,4):
					randomInt = randint(0,len(projects)-1)
					if(projects[randomInt] not in closeProjects and projects[randomInt] != parameters["project"]):
						closeProjects.append(projects[randomInt])
			except:
				pass
			parameters["closeProjects"] = closeProjects
			parameters["funds"] = funds
			self.render("projectPage.html", parameters)
예제 #22
0
	def get(self):
		user = users.get_current_user()
		if user:
			userid = user.user_id()
			userAuthentication =  User.query(User.userid == userid).fetch(1)
			ngoAuthentication = NGO.query(NGO.userid == userid).fetch(1)
			if userAuthentication:
				parameter = {}
				ngos = NGO.query().fetch(3)
				userObject = userAuthentication[0]
                                projectsIdentifier = userObject.projects[:3]
                                userProjects = []
                                for projectIdentifier in projectsIdentifier:
                                        key = ndb.Key("Project", projectIdentifier)
                                        userProjects.append(key.get())
				projects = Project.query().fetch(3)
                                parameter["projects"] = projects
				parameter["userProjects"] = userProjects 
				parameter["ngos"] = ngos
				self.render("userHomePage.html", parameter)
			elif ngoAuthentication:
				parameter={}
                                ngo = ngoAuthentication[0]
                                projectsIdentifierList = ngo.projects
                                ngoProjects = []
				if projectsIdentifierList:
                             		for projectIdentifier in projectsIdentifierList:
                                	        ngo, title = self.stripProjectIdentifier(projectIdentifier)
                                       	        projectObject = Project.query(Project.ngo == ngo, Project.title == title).fetch(1)[0]
                                        	ngoProjects.append(projectObject)
                                parameter["ngoProjects"] = ngoProjects
				self.render("ngoHomePage.html", parameter)
			else:
				self.redirect("/signup/registration")
		else:
			self.redirect("/")