예제 #1
0
	def get(self):
		# lookup user's auth info
		user_info = User.get_by_id(long(self.user_id))

		# setup channel to do page refresh
		channel_token = user_info.key.urlsafe()
		refresh_channel = channel.create_channel(channel_token)

		# check for url param or referer
		url = ""
		if 'url' in self.request.GET:
			url = urllib2.unquote(self.request.GET['url'])

		# if we have a URL, we deal with it
		if url:
			project = Project.get_by_url(url)
			if not project:
				# create a new project for this user
				self.form.url.data = url
				return self.post()
			else:
				# go to the existing project
				return self.redirect_to('account-projects-detail', project_id = project.key.id())

		# params build out
		params = {
			'refresh_channel': refresh_channel,
			'channel_token': channel_token 
		}

		return self.render_template('project/new.html', **params)
예제 #2
0
	def post(self):
		# lookup user's auth info
		user_info = User.get_by_id(long(self.user_id))

		# check what was returned from form validates     
		if not self.form.validate():
			for key, value in self.form.errors.iteritems():
				self.add_message("Fix the %s. %s" % (key, value[0]), "error")
			return self.get()

		# load form values
		url = self.form.url.data.strip()
		
		# check if we have it already
		if Project.get_by_url(url):
			self.add_message("A project with that URL already exists.", "error")
			return self.redirect_to('account-projects')		

		# get the basic repo data
		response = github.repo_base(url)
		if response['response'] == 'success':
			repo = response['result']['repo']
		else:
			repo = None
			self.add_message(response['result']['message'], 'error')
			return self.redirect_to('projects')

		# save the new project in our database
		project = Project()           
		project.url = url.lower().strip('/')
		project.name = repo['name'] # this one is editable later
		project.repo_name = repo['name'] # this one is not
		project.address = None
		project.amount = 0
		project.description = repo['description']
		project.owner = user_info.key
		project.public = False
		project.port = 80
		project.put()

		# give it a second
		time.sleep(1)

		# check if the repo has the utterio directory
		response = project.sync()

		# log to alert
		if response['response'] == "success":
			self.add_message("Project %s successfully added!" % project.name, "success")
		else:
			self.add_message("%s" % response['result']['message'], "fail")

		# redirect
		return self.redirect_to('account-projects-detail', project_id = project.key.id())
예제 #3
0
	def get(self):
		# check for referer (only works SSL to SSL site) or parameter in URL (for custom page)
		url = ""
		if 'url' in self.request.GET:
			url = urllib2.unquote(self.request.GET['url'])
		elif self.request.referer:
			if config.github_url in self.request.referer:
				url = urllib2.unquote(self.request.referer)

		# lowercase url and strip slashes
		url = url.lower().strip('/')

		# run regex to get base URL
		match = re.search('https://github.com/([\w]*)/([\w]*)', url)
		if match:
			# pull out the match
			url = match.group()

			# if we have a URL, we look it up
			if url:
				project = Project.get_by_url(url)

				if project:
					# go to the existing project
					return self.redirect_to('account-projects-view', project_id = project.key.id())
				else:
					# if user is logged in, redirect to the new page
					if self.user_id:
						params = {'url': url}
						return self.redirect_to('account-projects-new', **params)

		# load all public projects
		projects = Project.get_public()

		# params build out
		params = {
			'projects': projects
		}

		return self.render_template('site/projects.html', **params)