Esempio n. 1
0
def get_limit_questions(user_id=None,start=None,end=None,order=None,filter=None):

	if start>=0 and end>=start:
		if not user_id:
			data=[]
			if not order:
				questions= Question.objects.filter().order_by('-last_update_time','-create_time')[start:end]
			else:
				questions = Question.objects.filter().order_by(order,'-create_time')[start:end]

			if questions:
				for q in questions:
					one = {}
					one['q']=q
					one['u']=User.objects.get(id=q.user_id)
					one['s']=get_c_subjects(q.subject)
					one['t']=get_c_tags(q.tag)
					data.append(one)
			
			return data


		questions = Question.objects.filter(user_id=user_id)[start:end]

	else:
		questions = Question.objects.filter(user_id=user_id)

	return questions
Esempio n. 2
0
def view_blog(request,template_name=blog_template_prefix+'blog_view.html',id=None):
	try:

		s = request.GET.get('subject')
		people = request.GET.get('people')

		tags=[]
		subjects=[]
	
		if id and id.isdigit():
			id = int(id)
			article =  get_article(int(id))
			
			if not article:
				raise Http404()

			author = get_author(article.user_id)

			page_number = request.GET.get('page')
			comment_count = get_article_comments_count(article.id)
			paginator = Paginator(comment_count,10)

			if page_number and page_number.isdigit():
				try:
					page = paginator.page(int(page_number))
					pages = paginator.calculate_display_pages(int(page_number))
				except EmptyPage:
					page = paginator.page(1)
					pages = paginator.calculate_display_pages(1)
			else:
				page = paginator.page(1)
				pages = paginator.calculate_display_pages(1)
			
			less_than_certain_size = paginator.check_less_than_certain_size()

			if article.tag:
				tags = get_c_tags(article.tag)

			if article.subject:
				subjects = get_c_subjects(article.subject)

			comments = get_limit_comments(article.id,page.start,page.end)
			if s and s.isdigit():
				one = get_one_subject(int(s))
				if one:
					next_article = get_subject_next_article(int(s),id)
					prev_article = get_subject_prev_article(int(s),id)
				else:
					raise Http404()	
			else:
				next_article = get_next_article(id)
				prev_article = get_prev_article(id)
				one=None

			data={'article':article,'one':one,'comment_count':comment_count,'author':author,'tags':tags,'subjects':subjects,'page':page,'pages':pages,'less_than_certain_size':less_than_certain_size,'comments':comments,'next_article':next_article,'prev_article':prev_article}
			return render_to_response(template_name,data,context_instance=RequestContext(request))
		else:
			raise Http404()
	except Exception,e:
		raise
Esempio n. 3
0
def edit_blog(request,template_name=blog_template_prefix+'blog_edit.html',id=None):
	try:
		u = request.session['user']


		
		if id and id.isdigit():
			article = get_article(id,u.id)

			subjects = get_subjects()

			tag_list=[]
			subject_list=[]

			
			
			if article:
				if article.tag:
					tag_list = get_c_tags(article.tag)

				if article.subject:
					subject_list = get_c_subjects(article.subject)
					
				form = ArticleForm(user_id=u.id,initial=article.get_data(),auto_id='%s')
				time=article.create_time
				return render_to_response(template_name,{'form':form,'time':time,'subjects':subjects,'tag_list':tag_list,'subject_list':subject_list},context_instance=RequestContext(request))
			else:
				raise Http404()
		else:
			raise Http404()
	except Exception, e:
		raise
Esempio n. 4
0
def get_limit_topics(user_id=None,start=None,end=None):
	if not user_id:
		data=[]
		topics = Topic.objects.filter().order_by('-last_update_time','-create_time')[start:end]
		if topics:
			for t in topics:
				one={}
				one['s']=get_c_subjects(t.subject)
				one['t']=get_c_tags(t.tag)
				one['p']=t
				one['user']=User.objects.get(id=t.user_id)
				data.append(one)

		return data


	return Topic.objects.filter(user_id=user_id)[start:end].values('id','topic','create_time','comment_count')
Esempio n. 5
0
def get_questions_by_subject(id,start=None,end=None):
	data=[]
	sql = "select id,user_id,question,answer_count,create_time,subject,tag,anonymity from question  where subject like %s or subject like %s limit "+str(start)+","+str(end)+""
	questions=execute_subject_query(id,sql=sql)
	for a in questions:
		q_id,user_id,question,answer_count,create_time,subject,tag,anonymity=a
		q={}
		q['id']=q_id
		q['user_id']=user_id
		q['question']=question
		q['answer_count']=answer_count
		q['create_time']=create_time
		q['anonymity']=anonymity
		one = {}
		one['q']=q
		one['u']=User.objects.get(id=user_id)
		one['s']=get_c_subjects(subject)
		one['t']=get_c_tags(tag)
		data.append(one)

	return data
Esempio n. 6
0
def get_limit_anonymity_questions(user_id=None,start=None,end=None,order='-answer_count'):

	if start>=0 and end>=start:
		if not user_id:
			data=[]
			questions = Question.objects.filter(anonymity=1).order_by(order,'-create_time')[start:end]
			if questions:
				for q in questions:
					one = {}
					one['q']=q
					one['s']=get_c_subjects(q.subject)
					one['t']=get_c_tags(q.tag)
					data.append(one)
			return data

		questions = Question.objects.filter(user_id=user_id)[start:end]

	else:
		questions = Question.objects.filter(user_id=user_id)

	return questions
Esempio n. 7
0
def get_i_college_limit_topics(user_id,start,end):
	us = UserSchool.objects.get(id=user_id)
	data=[]
	if us.college:
		sql = "select a.id,a.user_id,a.topic,a.create_time,a.comment_count,a.tag,a.subject from user_school us,topic a where us.college="+str(us.college)+" and us.id = a.user_id order by create_time desc,comment_count desc limit "+str(start)+","+str(end)+""
		topics=custom_raw_sql(sql)
		for a in topics:
			id,user_id,t,create_time,comment_count,tag,subject=a
			topic={}
			topic['id']=id
			topic['user_id']=user_id
			topic['topic']=t
			topic['comment_count']=comment_count
			topic['create_time']=create_time
			one={}
			one['s']=get_c_subjects(subject)
			one['t']=get_c_tags(tag)
			one['p']=topic
			one['user']=User.objects.get(id=user_id)
			data.append(one)

	return data
Esempio n. 8
0
def get_i_college_limit_questions(user_id,start,end):
	us = UserSchool.objects.get(id=user_id)
	data=[]
	if us.college:
		sql = "select a.id,a.user_id,a.question,a.create_time,a.answer_count,a.tag,a.subject from user_school us,question a where us.college="+str(us.college)+" and us.id = a.user_id order by create_time desc,answer_count desc limit "+str(start)+","+str(end)+""
		results=execute_sql(sql)
		for a in results:
			id,user_id,question,create_time,answer_count,tag,subject=a
			q={}
			q['id']=id
			q['user_id']=user_id
			q['topic']=question
			q['comment_count']=answer_count
			q['create_time']=create_time
			q['question']=question
			one={}
			one['s']=get_c_subjects(subject)
			one['t']=get_c_tags(tag)
			one['q']=q
			one['u']=User.objects.get(id=user_id)
			data.append(one)

	return data
Esempio n. 9
0
def topic_detail(request,template_name=topic_template_prefix+'topic_detail.html',id=None):
	try:
		u = request.session['user']
		if id and id.isdigit():
			topic = get_certain_one_topoc(int(id))

			tags=[]
			subjects=[]

			if topic['tag']:
				tags = get_c_tags(topic['tag'])

			if topic['subject']:
				subjects = get_c_subjects(topic['subject'])

			#开始对评论分页
			paginator = Paginator(topic['comment_count'],20)
			page_number = request.GET.get('page')
			if page_number and page_number.isdigit():
				try:
					page = paginator.page(int(page_number))
					pages = paginator.calculate_display_pages(int(page_number))
				except EmptyPage:
					page = paginator.page(1)
					pages = paginator.calculate_display_pages(1)
			else:
				page = paginator.page(1)
				pages = paginator.calculate_display_pages(1)
			less_than_certain_size = paginator.check_less_than_certain_size()
			comments = get_limit_topic_comments(int(id),page.start,page.end)
			data={'comments':comments,'topic_id':topic['id'],'tags':tags,'subjects':subjects,'t':topic,'page':page,'pages':pages,'less_than_certain_size':less_than_certain_size}
			return render_to_response(template_name,data,context_instance=RequestContext(request))
		else:
			raise Http404()
	except Exception, e:
		raise