def test_was_published_recently_with_recent_new(self): """ was_published_recently() should return True for polls whose creation_date is within the last day """ recent_new = New(creation_date=timezone.now() - datetime.timedelta(hours=1)) self.assertEqual(recent_new.was_published_recently(), True)
def test_was_published_recently_with_future_new(self): """ was_published_recently() should return False for news whose creation_date is in the future """ future_new = New(creation_date=timezone.now() + datetime.timedelta(days=30)) self.assertEqual(future_new.was_published_recently(), False)
def test_was_published_recently_with_old_new(self): """ was_published_recently() should return False for polls whose creation_date is older than 1 day """ old_new = New(creation_date=timezone.now() - datetime.timedelta(days=30)) self.assertEqual(old_new.was_published_recently(), False)
def import_news(self, limit=10): entries = self.get_entries(self.get_content()) for entry in entries: data = self.parse_entry(entry) data = self.clean_data(data) new = New(**data) new.save()
def process_item(self, item, spider): new_item = New() new_item.unique_id = self.unique_id new_item.title = item['title'] new_item.writer = item['writer'] new_item.preview = item['preview'] new_item.save() return item
def add_new(request): """New Create View.""" context = {} if request.method == 'POST': title = request.POST.get('title', None) url = request.POST.get('url', None) text = request.POST.get('text', None) if title and url: new = New(title=title, url=url, user=request.user) new.save() return redirect('/') elif text: new = New(text=text, user=request.user) new.save() return redirect('/') return render(request, 'news/add.html', context)
def judge_alarm(left, right, top, bottom, center, video_id, name): if center[1] > left and center[1] < right and center[0] < bottom and center[0] > top: alarm = name + " be in dangerous area (" + str(left) + "," + str(right) + "," + str(bottom) + "," +str(top) + ")" + ' with '+'('+str(center[1])+ ','+str(center[0]) + ')' n = New(news_title = alarm, news_date = timezone.now(), news_type = video_id) n.save()
def test_new_get_unicode(self): """ Test unicode function of New class from model """ new = New(title="Novinka", date=timezone.now(), text="Text novinky") self.assertEqual(new.__unicode__(), "Novinka")