예제 #1
0
	def post(self, code):
		self.init_session()
		if self.do_redirect(): return
		
		old_code = cgi.escape(self.request.get('old_code'))
		
		old_paste = Paste.get_by_code(old_code)
		if old_paste is None:
			logger.error("PASTE "+old_code+" NOT FOUND")
			self.redirect('/404')
			return
		
		user = self.get_key('user')
		paste = old_paste.start_fork(user)
		paste.name = cgi.escape(self.request.get('name'))
		paste.content = cgi.escape(self.request.get('content'))
		paste.hidden = (cgi.escape(self.request.get('hidden'))=="on")
		paste.format = cgi.escape(self.request.get('format'))
		paste.parsed_content = formatting.highlight_with_longname(
								self.request.get('content'), paste.format)
		paste.parent_diff = "".join(difflib.unified_diff(
			old_paste.content.split('\n'),
			paste.content.split('\n')
		))
		paste.parsed_parent_diff = formatting.highlight_with_shortname(paste.parent_diff, 'diff')
		paste.save_new(cgi.escape(self.request.get('password')))
		
		self.session['flash'] = 'Forked successfully.'
		self.redirect('/paste/'+paste.pastecode)
예제 #2
0
def home(request):
    # session = sessions.Session(request)
    # if session.do_redirect(): return
    template_values = {}

    pastes = Paste.get_most_recent_public()

    template_values.update({"explain": True, "formats": formatting.formats_ordered, "pastes": pastes})
    return render_to_response("index.html", template_values)
예제 #3
0
	def post(self):
		self.init_session()
		if self.do_redirect(): return
		
		paste = Paste()
		paste.usercode = self.get_key('usercode')
		paste.name = cgi.escape(self.request.get('name'))
		paste.content = cgi.escape(self.request.get('content'))
		paste.format = cgi.escape(self.request.get('format'))
		paste.hidden = (self.request.get('hidden')=="on")
		paste.parsed_content = formatting.highlight_with_longname(
								self.request.get('content'), paste.format)
		
		paste.save_new(cgi.escape(self.request.get('password')))
		
		self.session['flash'] = 'Pasted sucessfully.'
		self.redirect('/paste/'+paste.pastecode)
예제 #4
0
	def get(self):
		self.init_session()
		if self.do_redirect(): return
		
		user = self.get_key('user')
		#pastes_query = Paste.gql("WHERE owner=:owner ORDER BY date_created DESC",
		#							owner=user)
		#pastes = pastes_query.fetch(10)
		pastes = Paste.get_most_recent_public().fetch(10)
		
		self.template_values.update({
			'explain': True,
			'formats': formatting.formats_ordered,
			'pastes': pastes
		})
		path = get_template_path('index.html')
		self.response.out.write(template.render(path, self.template_values, debug=True))
예제 #5
0
	def get(self, code):
		self.init_session()
		if self.do_redirect(): return
		
		paste = Paste.get_by_code(cgi.escape(code))
		if paste is None:
			logger.error("PASTE "+code+" NOT FOUND")
			self.redirect('/404')
			return
			
		self.template_values.update({
			'paste': paste,
			'paste_url': paste.get_url()
		})
		
		path = get_template_path('view_paste.html')
		self.response.out.write(template.render(path, self.template_values, debug=True))
예제 #6
0
	def get(self, code, filename=None):
		self.init_session()
		if self.do_redirect(): return
		
		paste = Paste.get_by_code(code)
		if paste is None:
			logger.error("PASTE "+code+" NOT FOUND")
			self.redirect('/404')
			return
		
		if filename is None:
			filename = make_filename(paste.name)
			if not has_extension(filename):
				filename += formatting.formats[paste.format]['extension']
			self.redirect('/paste/'+code+'/download/'+filename)
			return
		elif filename[0] == '/':
			filename = filename[1:]
		
		self.response.headers['Content-type'] = formatting.formats[paste.format]['mimetype']
		path = get_template_path('file_out')
		self.response.out.write(template.render(path, {'content':paste.content}, debug=True))
예제 #7
0
	def get(self, usercode=None):
		self.init_session()
		if self.do_redirect(): return
		
		if usercode is None:
			usercode = self.get_key('usercode')
			if usercode is None:
				self.redirect('/login')
				return
			else:
				self.redirect('/profile/'+usercode)
				return
		elif usercode[0] == '/':
			usercode = usercode[1:]
		
		my_usercode = self.get_key('usercode')
		your_profile = (usercode == self.get_key('usercode'))

		if not your_profile:
			userdata = UserData.get_by_code(usercode)
			if not (my_usercode is None):
				are_friends = Friend.already_present(my_usercode, usercode)
				if not are_friends:
					
					if not userdata.friends_hidden_by_default:
						list_link = '/friends/'+usercode
					else:
						list_link = None
					
					if FriendRequest.already_present(my_usercode, usercode):
						#print "AWAITING REPLY"
						awaiting_reply = True
						approve_link = reject_link = None
						friend_link = unfriend_link = None
					elif FriendRequest.already_present(usercode, my_usercode):
						#print "APPROVE REJECT"
						awaiting_reply = False
						approve_link = '/friends/approve/'+usercode
						reject_link = '/friends/reject/'+usercode
						friend_link = unfriend_link = None
					else:
						friend_link = '/friends/request/'+usercode
						unfriend_link = None
						approve_link = reject_link = awaiting_reply = None
				else:
					friend_link = None
					unfriend_link = '/friends/remove/'+usercode
					list_link = '/friends/'+usercode
					approve_link = reject_link = awaiting_reply = None
			else:
				are_friends = False
				approve_link = reject_link = awaiting_reply = None
				friend_link = unfriend_link = list_link = None
			pastes = Paste.get_public_by_usercode(usercode)
			self.template_values.update({ 
				'prof_nickname': userdata.nickname,
				'prof_usercode': usercode,
				'profile_link': '/profile/'+usercode,
				'pastes': pastes,
				'num_pastes': pastes.count(),
				'are_friends': are_friends,
				'your_profile': your_profile,
				'friend_link': friend_link,
				'unfriend_link': unfriend_link,
				'list_link': list_link,
				'approve_link': approve_link,
				'reject_link': reject_link,
				'awaiting_reply': awaiting_reply
			})
		else:
			pastes = Paste.get_all_by_usercode(usercode)	
			self.template_values.update({	
				'prof_nickname': self.session['nickname'],
				'prof_usercode': usercode, 
				'profile_link': '/profile/'+usercode,
				'pastes': pastes,
				'num_pastes': pastes.count(),
				'your_profile': your_profile
			})
			
		path = get_template_path('profile.html')
		self.response.out.write(template.render(path, self.template_values, debug=True))