Esempio n. 1
0
def ticker_detail(request, ticker_symbol):

	try:
		ticker = Ticker.objects.get(ticker_symbol=ticker_symbol)
	except:
		# if the ticker isn't found, redirect to the listing of all tickers
		return redirect('ticker_overview')

	if request.POST:
		form = TickerForm(request.POST, instance=ticker)

		if form.is_valid():
			model_instance = form.save(commit=True)

	form = TickerForm(instance=ticker)

	context = {
		'title_value': '%s (%s)' % (ticker.company_name, ticker.ticker_symbol),
		'form': form,
		'ticker':ticker
	}

	return render(request, 'satellite/ticker_detail.html', context)
Esempio n. 2
0
def coverage_detail(request, ticker_symbol):

	try:
		ticker = Ticker.objects.get(ticker_symbol=ticker_symbol)
	except:
		# if the ticker isn't found, redirect to the listing of all tickers
		return redirect('coverage_index')

	services_to_filter_by = None
	service_filter_description = None
	tickers_to_filter_by = None
	single_authors = get_authors_from_article_set()
	form = TickerForm(instance=ticker)

	if request.POST:

		form = TickerForm(request.POST, instance=ticker)
		if form.is_valid():
			model_instance = form.save(commit=True)

		if 'coverage' in request.POST:

			# delete records that are already there
			coverage_type_objects = CoverageType.objects.filter(ticker=ticker)
			print 'deleting existing CoverageType records for %s (%d)' % (ticker.ticker_symbol, len(coverage_type_objects))
			coverage_type_objects.delete()

			# replace them with the records passed along in POST
			# we expect the keys per selection to have this format: "cid_x__sid_y", where x is a content choice integer value, y is a service id
			selected_keys = [k for k in request.POST if k.startswith('author_')]
			for k in selected_keys:

				k = k.replace('author_','')
				print k, '---------------'
				choice_id, service_id = k.replace("cid_","").replace("sid_","").split('__')

				ct = CoverageType()
				ct.coverage_type = int(choice_id)
				ct.ticker = ticker
				ct.service = Service.objects.get(id=service_id)

				author_key = 'author_'+k

				print author_key

				if author_key in request.POST:
					ct.author = request.POST[author_key]

				ct.save()
				print 'added CoverageType record: %s %s %d %s' % (ct.service.pretty_name, ct.ticker.ticker_symbol, ct.coverage_type, ct.author)
		else:
			pass
		
	else:
		pass

	services = Service.objects.all()
	
	today = datetime.now()
	date_today = today.date()
	ninety_days_ago = (date_today - timedelta(days=90))

	articles = [a for a in Article.objects.filter(ticker=ticker).exclude(tags=None).exclude(tags='') if a.date_pub is not None and a.date_pub.date() >= ninety_days_ago]

	relevant_articles = set()
	ten_percent_promises = set()
	everlasting = set()
	analysis = set()
	featured = set()
	earnings = set()
	mission_log = set()
	buy_recommendations = set()
	five_and_three = set()
	best_buys_now = set()
	two_minute_drills = set()
	commentary = set()
	news = set()

	for a in articles:
		if '10 promise' in a.tags:
			ten_percent_promises.add(a)
		if 'everlasting' in a.tags:
			everlasting.add(a)
		if 'analysis' in a.tags:
			analysis.add(a)
		if 'featured' in a.tags:
			featured.add(a)
		if 'earnings' in a.tags:
			earnings.add(a)
		if 'mission_log' in a.tags:
			mission_log.add(a)
		if 'buy recommendation' in a.tags:
			buy_recommendations.add(a)
		if '5 and 3' in a.tags:
			five_and_three.add(a)
		if 'best buys now' in a.tags:
			best_buys_now.add(a)
		if '2 minute drill' in a.tags:
			two_minute_drills.add(a)
		if 'commentary' in a.tags:
			commentary.add(a)
		if 'news' in a.tags:
			news.add(a)

	dictionary_of_values = {
		'ticker': ticker,
		'form': form,
		'coverage_type_choices': COVERAGE_CHOICES,
		'services': services,
		'single_authors': single_authors,
		'title_value': '%s (%s)' % (ticker.company_name, ticker.ticker_symbol),
		'relevant_articles': relevant_articles,
		'ten_percent_promises': ten_percent_promises,
		'everlasting': everlasting,
		'featured': featured,
		'earnings': earnings,
		'mission_log': mission_log,
		'buy_recommendations': buy_recommendations,
		'five_and_three': five_and_three,
		'best_buys_now': best_buys_now,
		'two_minute_drills': two_minute_drills,
		'commentary': commentary,
		'news': news,
	}

	return render(request, 'satellite/coverage_detail.html', dictionary_of_values)