コード例 #1
0
ファイル: views.py プロジェクト: naved92/testsharethis
def spread(request,post_id):
    """
    Spreads the post of a user within the range
    :param request:The HTMLRequest
    :param post_id: the post id
    :return:  if the user is not logged in,it redirects to the index page
             else if the user is not verified,it redirects to 'verification.html'
             else if the requesting user is blocked by the requested user or has blocked requested user,an error page is shown
            else spreads the post and redirects to newsfeed page

    """
    context = RequestContext(request)
    user_profile = request.user.userprofile
    if user_profile.verification_status == 'p':
        return HttpResponseRedirect(reverse('verification'))
    else:
        spreadedpost=Post.objects.get(pk=post_id)
        spreadedpost.post_sharecount+=1
        spreadedpost.save()

        req_loc_dict=get_location(get_ip_address(request))
        if str(req_loc_dict['region_name'])== '':
            req_loc_dict['region_name']=req_loc_dict['country_name']

        req_loc= Location(location_name=str(req_loc_dict['region_name']),location_lat=req_loc_dict['latitude'],location_long=req_loc_dict['longitude'])
        req_loc.save()
        newpost=Post()
        newpost.post_location=req_loc
        print(newpost.post_location.location_name)
        newpost.post_maker=UserProfile.objects.get(user=request.user)
        newpost.post_text=spreadedpost.post_text
        newpost.post_photo=spreadedpost.post_photo
        newpost.post_sharecount=0
        newpost.post_sharedfrom=spreadedpost
        newpost.post_time=datetime.now()

        newpost.save()
        return HttpResponseRedirect(reverse('newsfeed'))