예제 #1
0
파일: views.py 프로젝트: jneighbs/newsfeed
def createFeed(request, feed_id=None):
	context = RequestContext(request, {'user': request.user})
	print "ID: ", request.user.id, " Name: ", request.user.username, request.user.is_anonymous()
	#print dir(request.user)

	if (not request.user) or request.user.is_anonymous():
		#return HttpResponseRedirect("/event/" + str(event_id))
		print "bad user! not logged in! not your event!"

	if feed_id:
		print "got an id"
		feed = get_object_or_404(NewsFeed, pk=feed_id)
		
		if request.user.id != feed.owner_id:
			print "not your event, kiddo"
			#return HttpResponseRedirect("/event/" + str(event_id))
	else:

		if (not request.user) or request.user.is_anonymous():
			#return HttpResponseRedirect("/event/" + str(event_id))
			print "bad user! not logged in! not your event!"

		print "ain't got no event id"
		feed = NewsFeed(owner_id=request.user.id)
		feed.save()
	#return HttpResponse("So you wanna create an event, eh?")
	all_sources = NewsSource.objects.all()
	return render(request, 'create_feed.html', {'all_sources': all_sources, 'feed':feed })
예제 #2
0
     def post(self):
         text = cgi.escape(self.request.get('text'))
         url = cgi.escape(self.request.get('url'))
         f = NewsFeed(url=url, name=name)
         f.put()
         
         taskqueue.add(queue_name='fetch-news-queue', url='/admin/feeds/fetch/', params={'key':f.key})

         self.redirect('/admin/feeds/')
예제 #3
0
 def post(self):
     key = self.request.get('key')
     feed = NewsFeed.get_by_key_name(key)
     # FIXME check if feed was retrieved
     result = urlfetch.fetch(feed.url)
     if result.status_code == 200:
         rssfeed = feedparser.parse(result.content)
         for i in rssfeed.entries:
             item = NewsItem(key_name=i.guid)
             item.url = i.link
             item.title = i.title
             item.text = i.summary
             item.date = datetime.datetime(*i.date_parsed[:6])
             item.orderdate = datetime.datetime(*i.date_parsed[:6])
             item.source = feed
             item.put()
         feed.last_fetch = datetime.datetime.now() 
         feed.put() 
         taskqueue.add(queue_name='fetch-news-queue', url='/admin/feeds/fetch/', params={'key':feed.key})
         self.response.out.write('feed pulled')
     else:  
         self.error(500)
예제 #4
0
 def test_slugify_on_save(self):
     feed = NewsFeed(title="My Special Feed")
     feed.save()
     self.assertEquals(feed.slug, 'my-special-feed')
예제 #5
0
 def test_slugify_on_save(self):
     feed = NewsFeed(title="My Special Feed")
     feed.save()
     self.assertEquals(feed.slug, 'my-special-feed')
예제 #6
0
 def setUp(self):
     create_news_items(is_sticky=False, amount=7)
     feed = NewsFeed(title='second feed')
     feed.save()
     self.widget = NewsWidget()