Ejemplo n.º 1
0
def get_i_college_topic_count(user_id):
	us = UserSchool.objects.get(id=user_id)
	if us.college:
		sql=" select count(*) from user_school as us,topic as a where us.college = "+str(us.college)+" and a.user_id = us.id"
		result = custom_raw_sql(sql)
		if result:
			return result[0][0]
		else:
			return 0
Ejemplo n.º 2
0
def get_user_next_article(user_id,id):
	sql = "select id,title from article where user_id=%d and id < %d ORDER BY id desc limit 0,1"%(user_id,id)
	articles=custom_raw_sql(sql)
	if articles:
		one={}
		one['id']=articles[0][0]
		one['title']=articles[0][1]
		return one
	else:
		return None
Ejemplo n.º 3
0
def get_prev_article(id):
	
	sql = "select id,title from article where id > %d ORDER BY id asc limit 0,1"%(id)
	articles = custom_raw_sql(sql)

	if articles:
		one={}
		one['id']=articles[0][0]
		one['title']=articles[0][1]
		return one
	else:
		return None
Ejemplo n.º 4
0
def get_articles_by_i_college(user_id,start,end):
	us = UserSchool.objects.get(id=user_id)
	data=[]
	if us.college:
		sql = "select a.id,a.user_id,a.title,a.create_time,a.content from user_school us,article a where us.college="+str(us.college)+" and us.id = a.user_id order by create_time desc limit "+str(start)+","+str(end)+""
		articles=custom_raw_sql(sql)
		for a in articles:
			a_id,user_id,title,create_time,content=a
			article={}
			article['id']=a_id
			article['user_id']=user_id
			article['title']=title
			article['content']=content
			article['create_time']=create_time
			one = {}
			one['article']=article
			one['author']=User.objects.get(id=user_id)
			data.append(one)

	return data
Ejemplo n.º 5
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