Ejemplo n.º 1
0
def reply(request, id):
	if request.method == 'POST':
		m = Microblog()
		form = PostForm(request.POST)
		if form.is_valid():
			if request.META.get('HTTP_CONTEXT_URL'):
				try:
					geolocation = {
						'lat': float(request.META['HTTP_CONTEXT_GEO_LAT']),
						'lon': float(request.META['HTTP_CONTEXT_GEO_LON'])
					}
				except:
					geolocation = {
						'lat': 0.0,
						'lon': 0.0
					}
				try:
					url = request.META['HTTP_CONTEXT_URL']
					result = re.search('\/course\/(?P<slug>[a-zA-Z0-9-_]+)\/', url)
					course_slug = result.group('slug')
				except:
					course_slug = None
			else:
				geolocation = {
                    'lat': float(request.POST['context_geo_lat']),
                    'lon': float(request.POST['context_geo_lon'])
                }
				course_slug = None

			extra = {
				'geolocation': geolocation,
				'course_slug': course_slug
			}
			m.save_reply(id, request.user.id, request.user.first_name, request.user.last_name, request.user.username, "https:" + gravatar_for_email(request.user.email), form.cleaned_data['postText'],extra)
			return HttpResponseRedirect("/user/posts")
Ejemplo n.º 2
0
def profile_posts_search(request, query, hashtag=False, api=False):
	m = Microblog()
	if(not request.user.id):
		return HttpResponseRedirect("/auth/login")
	id = request.user.id
	user = request.user

	if request.method == 'POST':
		form = PostForm(request.POST)
		if form.is_valid():
			if request.META.get('HTTP_CONTEXT_URL'):
				try:
					geolocation = {
						'lat': float(request.META['HTTP_CONTEXT_GEO_LAT']),
						'lon': float(request.META['HTTP_CONTEXT_GEO_LON'])
					}
				except:
					geolocation = {
						'lat': 0.0,
						'lon': 0.0
					}
				try:
					url = request.META['HTTP_CONTEXT_URL']
					result = re.search('\/course\/(?P<slug>[a-zA-Z0-9-_]+)\/', url)
					course_slug = result.group('slug')
				except:
					course_slug = None
			else:
				geolocation = {
                    'lat': float(request.POST['context_geo_lat']),
                    'lon': float(request.POST['context_geo_lon'])
                }
				course_slug = None

			extra = {
				'geolocation': geolocation,
				'course_slug': course_slug
			}
			m.insert_post(request.user.id, request.user.first_name, request.user.last_name, request.user.username, "https:" + gravatar_for_email(request.user.email), form.cleaned_data['postText'], extra)
			return HttpResponseRedirect("/user/posts")

	else:
		case = _getCase(request,id)

		blog_user = m.get_blog_user(request.user.id)
		if(blog_user and id in blog_user["following"]):
			following = "true"
		else:
			following = "false"

		followingCount = 0
		if(request.user.id != id):
			blog_user = m.get_blog_user(id)
			if(blog_user):
				followingCount = len(blog_user["following"])
		elif(blog_user):
			followingCount = len(blog_user["following"])

		if hashtag:
			search_query = '#%s' % (query)
		else:
			search_query = query
		listPost = m.search_posts(search_query, 0)

		if not api:
			return render_to_response('profile/posts_search.html', {
				"id":id,
				"badges": get_db().get_collection('badge').find({"id_user": id}).count(),
				# "email":"@" + request.user.email.split("@")[0],
				'request': request,
				'form': PostForm(),
				'totalPost': m.count_posts(id),
				'posts': listPost,
				'case': case,
				"user_view_profile": user,
				"following": following,
				"followingCount": followingCount,
				"followerCount": m.get_num_followers(id),
				"query": query,
				"is_hashtag": hashtag,
				}, context_instance=RequestContext(request))
		else:
			response = {
				"query": query,
				"is_hashtag": hashtag,
				"posts": listPost
			}
			return HttpResponse(json_util.dumps(response), mimetype='application/json')