Пример #1
0
def new_source_from_url(request):
	message = None
	if request.method == 'POST':
		form = URLForm(request.POST)
		if form.is_valid():
			url = form.cleaned_data['url']
			source_type = form.cleaned_data['source_type']
			
			if source_type == "HTML":
				title,text = getTextFromURL(url)
				if text is not None and title is not None:
					s = Source(creator=request.user.get_profile(),url=url,title=title,content=text)
					s.save()
					return HttpResponseRedirect(reverse('source_detail',args=[s.id])) # Redirect after POST
				else:
					message = "Error obtaining text from URL.  Please use the manual text entry form or try a different URL."
			elif source_type=='RSS':
				f = RSSFeed(url=url)
				f.save()
				f.watchers.add(request.user.get_profile())
				return HttpResponseRedirect(reverse('rss_detail',args=[f.id]))
	else:
		form = URLForm()
	
	actionurl = reverse('new_url')
	return render_to_response('wikilink/newsource.html',{'form':form,'action':actionurl,'message':message,},context_instance=RequestContext(request))
Пример #2
0
	def update(self):
		title,text = getTextFromURL(self.url)
		if text is not None and title is not None:
			self.title=title
			self.content=text
			self.save()
		else:
			message = "Error obtaining text from URL.  Please use the manual text entry form or try a different URL."
Пример #3
0
	def update(self):
		parsed = feedparser.parse(self.url)
		self.name = unicode(parsed.feed.title)
		self.link = parsed.feed.link
		self.lastUpdate = datetime.datetime.now()
		self.save()
		rssUser = User.objects.get(username="******").get_profile()
		
		for s in parsed.entries[:10]:
			title = unicode(s.title).encode("UTF-8")
			published = datetime.datetime(*s.updated_parsed[:6])
			url = s.link
			
			try:
				source=Source.objects.get(url=url)
			except Source.DoesNotExist:
				content = getTextFromURL(url)[1]
				source = Source(title=title,url=url,published=published,creator=rssUser,content=content)
				source.save()
				self.sources.add(source)
			else:
				self.sources.add(source)
				print source.title ,"already exists in DB."