Exemple #1
0
def new_group_post (request):
	image_url=''
	viewer = request.user
	owner_user = request.user
	owner_user_role = UserProfile.objects.get( user_id = owner_user.id )
	if request.method == 'POST':
		eform = freeCrop(request.POST) # A form bound to the POST data
		if eform.is_valid(): # All validation rules pass
		    	new_event = eform.save()
		    	#return HttpResponseRedirect('/user/profile/'+request.user.username)
		    	#return HttpResponseRedirect('/file-upload/cicu-freecrop/?id='+str(new_event.id))
			a = new_event.id
			if uploadedImage.objects.get(id=a).image:
				image_url = "###uploaded_image###"+uploadedImage.objects.get(id=a).image.url+"##!uploaded_image!##"
		form = Group_Post_Form(request.POST)
		if form.is_valid():
			######## form values ###########
			content = form.cleaned_data['content']+image_url
			actor_name = form.cleaned_data['actor_name']
			group_id = form.cleaned_data['group_id']
			#####################			
			owner_user_role = UserProfile.objects.get( user_id = owner_user.id )
			org = Organization.objects.get( id = group_id )
			content = rendered_content (content,request)
			action.send(viewer, verb='posted', action_object = org, target= org,  post_content=content) # action creation
		else:
			print "ERROR IN VALIDATION"
			print form.errors		
	else:
		form = Group_Post_Form()

	return HttpResponseRedirect('/groups/'+group_id)
Exemple #2
0
def user_not_member(request,organization_pk):

	organization_ct = ContentType.objects.get(app_label="organizations", model="organization")
	wall_posts= Action.objects.filter( Q (target_object_id= organization_pk) & Q(verb='posted') & Q(target_content_type_id = organization_ct.id ))
	organization = Organization.objects.get(id = organization_pk )
	link = "/groups/"+str(organization_pk)+"/add/"+str(request.user.id)
	image_form = freeCrop(request.POST)
	
	return render(request, "organizations/organization_detail_visitor.html", {'wall_posts':wall_posts, 'organization':organization, 'link':link, 'image_form':image_form})
Exemple #3
0
	def get_context_data(self, **kwargs):
		context = super(BaseOrganizationDetail, self).get_context_data(**kwargs)
		context['organization_users'] = self.organization.organization_users.all()
		context['organization'] = self.organization
		organization_ct = ContentType.objects.get(app_label="organizations", model="organization")
		if not self.organization.is_admin(self.request.user) and not self.request.user.is_superuser:
			context['admin'] = False
		else:
			context['admin'] = True	
		context['link'] = "/groups/"+str(self.organization.id)+"/delete/"+str(self.request.user.id)
		context['image_form'] = freeCrop(self.request.POST)
		context['wall_posts'] = Action.objects.filter( Q (target_object_id= self.organization.id) & Q(verb='posted') & Q(target_content_type_id = organization_ct.id ))
		return context
Exemple #4
0
def user_not_member(request, organization_pk):

    organization_ct = ContentType.objects.get(app_label="organizations",
                                              model="organization")
    wall_posts = Action.objects.filter(
        Q(target_object_id=organization_pk) & Q(verb='posted')
        & Q(target_content_type_id=organization_ct.id))
    organization = Organization.objects.get(id=organization_pk)
    link = "/groups/" + str(organization_pk) + "/add/" + str(request.user.id)
    image_form = freeCrop(request.POST)

    return render(
        request, "organizations/organization_detail_visitor.html", {
            'wall_posts': wall_posts,
            'organization': organization,
            'link': link,
            'image_form': image_form
        })
Exemple #5
0
 def get_context_data(self, **kwargs):
     context = super(BaseOrganizationDetail,
                     self).get_context_data(**kwargs)
     context[
         'organization_users'] = self.organization.organization_users.all()
     context['organization'] = self.organization
     organization_ct = ContentType.objects.get(app_label="organizations",
                                               model="organization")
     if not self.organization.is_admin(
             self.request.user) and not self.request.user.is_superuser:
         context['admin'] = False
     else:
         context['admin'] = True
     context['link'] = "/groups/" + str(
         self.organization.id) + "/delete/" + str(self.request.user.id)
     context['image_form'] = freeCrop(self.request.POST)
     context['wall_posts'] = Action.objects.filter(
         Q(target_object_id=self.organization.id) & Q(verb='posted')
         & Q(target_content_type_id=organization_ct.id))
     return context
Exemple #6
0
def profile_edit(request, username):
    owner_user = User.objects.get(username__exact = username)
    profile = owner_user.get_profile()
    

    image_form = freeCrop(request.POST) # A form bound to the POST data
    

    eform = UserEditProfileForm( initial={'displayName':profile.displayName,
                      'name':profile.name,
                      'aboutMe':profile.aboutMe,
                      'status':profile.status,
                      'location':profile.location,
		      'studies':profile.studies,
                      'activities':profile.activities,
                      'birthday':profile.birthday,
                      'favouriteFood':profile.favouriteFood,
                      'favouriteSport':profile.favouriteSport,
                      'gender':profile.gender,
                      'interests':profile.interests,
                      'role':profile.role,
		      'thumbnail':profile.thumbnailURL,
                    },
                 instance = profile, 
                 data = request.POST)    

    if request.method == "POST":
        
        if eform.is_valid():
            profile = eform.save(commit = False)
            profile.save()
	if image_form.is_valid(): # All validation rules pass
		new_event = image_form.save()
		a = new_event.id
		#if uploadedImage.objects.get(id=a).image:
			#image_url = "###uploaded_image###"+uploadedImage.objects.get(id=a).image.url+"##!uploaded_image!##"
    return render_to_response('userprofiles/profile_change.html', {
        'form': eform, 
	'image_form': image_form,
	'MEDIA_URL': settings.MEDIA_URL,
    },context_instance=RequestContext(request))
Exemple #7
0
def new_group_post(request):
    image_url = ''
    viewer = request.user
    owner_user = request.user
    owner_user_role = UserProfile.objects.get(user_id=owner_user.id)
    if request.method == 'POST':
        eform = freeCrop(request.POST)  # A form bound to the POST data
        if eform.is_valid():  # All validation rules pass
            new_event = eform.save()
            #return HttpResponseRedirect('/user/profile/'+request.user.username)
            #return HttpResponseRedirect('/file-upload/cicu-freecrop/?id='+str(new_event.id))
            a = new_event.id
            if uploadedImage.objects.get(id=a).image:
                image_url = "###uploaded_image###" + uploadedImage.objects.get(
                    id=a).image.url + "##!uploaded_image!##"
        form = Group_Post_Form(request.POST)
        if form.is_valid():
            ######## form values ###########
            content = form.cleaned_data['content'] + image_url
            actor_name = form.cleaned_data['actor_name']
            group_id = form.cleaned_data['group_id']
            #####################
            owner_user_role = UserProfile.objects.get(user_id=owner_user.id)
            org = Organization.objects.get(id=group_id)
            content = rendered_content(content, request)
            action.send(viewer,
                        verb='posted',
                        action_object=org,
                        target=org,
                        post_content=content)  # action creation
        else:
            print "ERROR IN VALIDATION"
            print form.errors
    else:
        form = Group_Post_Form()

    return HttpResponseRedirect('/groups/' + group_id)
Exemple #8
0
def profile_view(request, username):
	SEX_CHOICES = (
		('male', 'Male'),
		('female', 'Female'),
	)
	ACTIVITY_CHOICES = (
		('art', 'Art'),
		('cooking', 'cooking'),
		('family', 'family'),
		('reading', 'Διάβασμα'),
		('trips', 'Ταξίδια'),
		('gym', 'Γυμναστήριο'),
		('walking', 'Περπάτημα'),
		('nature', 'Φύση'),
		('technology', 'Τεχνολογία'),
		('science', 'Επιστήμη'),
		('photography', 'Φωτογραφία'),
		('pets', 'Κατοικίδια'),
		('music', 'Μουσική'),
		('cinema', 'Κινηματογράφος'),
		('theater', 'Θέατρο'),
		('gardening', 'Κηπουρική'),
		('painting', 'Ζωγραφική'),
	)
	STATUS_CHOICES = (
		('single', 'Άγαμος'),
		('married', 'Έγγαμος'),
		('divorced-widowed', 'Διαζευγμένος-Χήρος'),
	)
	owner_user = User.objects.get(username__exact = username)
	owner_user_role = UserProfile.objects.get( user_id = owner_user.id )
	profile = owner_user.get_profile()
	wall_posts = get_actions_by_user( request.user , owner_user)
	user_relationships = []
	activities = []
	contacts = []
	if owner_user == request.user :
			user_relationships = RelationshipStatus.objects.all().filter( to_role_id = owner_user_role.role_id )
			for status in user_relationships:
				contacts.extend(request.user.relationships.get_related_to(status=status))
			
	form = freeCrop() # A form bound to the POST data

	
 
	context = {				  'otheruser':owner_user,
					  'username': owner_user.username,      
					  'displayName':profile.displayName,
					  'name':profile.name,
					  'aboutMe':profile.aboutMe,
					  'status':profile.status,
					  'location':profile.location,
					  'studies': profile.studies,
					  'activities':profile.activities.all,
					  'birthday':profile.birthday,
					  'favouriteFood':profile.favouriteFood,
					  'favouriteSport':profile.favouriteSport,
					  'gender':profile.gender,
					  'interests':profile.interests,
					  'role':profile.role,
					  'wall_posts' : wall_posts ,
					  'image_form': form,
					  'thumbnailURL': profile.thumbnailURL,
					  'MEDIA_URL': settings.MEDIA_URL,
					  'user_relationships' : user_relationships,
					  'contacts': contacts,}
	return render(request, 'userprofiles/profile.html', context)
Exemple #9
0
def stream(request,
           template='actstream/actor.html',
           page_template='actstream/action.html'):
    """
	Index page for authenticated user's activity stream. (Eg: Your feed at
	github.com)
	"""
    viewer = request.user
    viewer_user_role = UserProfile.objects.get(user_id=viewer.id)
    posts_set = []
    posts_final = []
    posts_set_ids = []
    posts_set_ids_m = []
    posts_set_by_user = []
    posts_final_by_other_users = []
    posts_set_user_ids = []
    posts_final_mentioned_for_this_user = []
    group_actions_list = []

    user_ct = ContentType.objects.get(app_label="auth",
                                      model="user")  # User Content Type

    ######## posts by owner #########
    posts_set_user_distinct = list(
        Action.objects.filter(
            Q(verb='posted') & Q(actor_object_id=viewer.id)
            & Q(actor_content_type_id=user_ct.id)).values_list(
                'timestamp').distinct())
    for y in Action.objects.filter(verb='posted'):
        for x in posts_set_user_distinct:
            if y.timestamp == x[0]:
                posts_set_user_distinct.remove(x)
                posts_set_user_ids.append(y.id)

    for wp_id in posts_set_user_ids:
        posts_set_by_user.extend(Action.objects.filter(id=wp_id))

    relation_ct = ContentType.objects.get(
        app_label="relationships",
        model="relationshipstatus")  # User Content Type

    ##########posts by other related users ######
    for related_users in Relationship.objects.all().filter(
            from_user_id=viewer.id):
        print "RELATED"
        print related_users.to_user_id
        actions_list = Action.objects.filter(
            Q(verb='posted') & Q(actor_object_id=related_users.to_user_id)
            & Q(target_object_id=related_users.status_id)
            & Q(actor_content_type_id=user_ct.id)
            & Q(target_content_type_id=relation_ct.id))
        print actions_list
        posts_set_distinct = list(
            actions_list.values_list('timestamp').distinct())
        for y in Action.objects.filter(
                Q(verb='posted')
                & (Q(actor_object_id=related_users.to_user_id))
                & Q(target_object_id=related_users.status_id)
                & Q(actor_content_type_id=user_ct.id)
                & Q(target_content_type_id=relation_ct.id)):
            for x in posts_set_distinct:
                if y.timestamp == x[0]:
                    posts_set_distinct.remove(x)
                    posts_set_ids.append(y.id)

        for wp_id in posts_set_ids:
            posts_final_by_other_users.extend(Action.objects.filter(id=wp_id))

        posts_set_ids = []
    print "OTHER"
    print posts_final_by_other_users

    ##########posts mentioned to user ######
    posts_set_user_ids = []
    posts_set_for_mentioned_user_distinct = list(
        Action.objects.filter(
            Q(verb='posted') & Q(target_object_id=viewer.id)
            & Q(actor_content_type_id=user_ct.id)
            & Q(target_content_type_id=user_ct.id)).values_list(
                'timestamp').distinct())
    for y in Action.objects.filter(verb='posted'):
        for x in posts_set_for_mentioned_user_distinct:
            if y.timestamp == x[0]:
                posts_set_for_mentioned_user_distinct.remove(x)
                posts_set_user_ids.append(y.id)

    for wp_id in posts_set_user_ids:
        if not any(x.id == wp_id for x in posts_set_by_user
                   ):  #check for duplicate records in posts_set_by_user
            posts_final_mentioned_for_this_user.extend(
                Action.objects.filter(id=wp_id))

    ##########posts from groups ######
    organization_ct = ContentType.objects.get(app_label="organizations",
                                              model="organization")
    for related_groups in OrganizationUser.objects.all().filter(
            user_id=viewer.id):
        group_actions_list.extend(
            Action.objects.filter(
                Q(verb='posted') & ~Q(actor_object_id=viewer.id)
                & Q(target_object_id=related_groups.organization_id)
                & Q(actor_content_type_id=user_ct.id)
                & Q(target_content_type_id=organization_ct.id)))

    print "OTHER"
    print group_actions_list

    related_org = []
    for related_org_user in OrganizationUser.objects.all().filter(
            user_id=viewer.id):
        related_org.extend(Organization.objects.all().filter(
            id=related_org_user.organization_id))
    print "RELATED GROUPS"
    print related_org

    print "THIS POSTS"

    print posts_set_by_user
    print posts_final
    print posts_final_by_other_users
    print posts_final
    print posts_final_mentioned_for_this_user
    print posts_final
    print type(group_actions_list)

    posts_final = posts_final_by_other_users + posts_set_by_user + posts_final_mentioned_for_this_user + group_actions_list
    print posts_final
    posts_final.sort(key=lambda Action: Action.timestamp,
                     reverse=True)  # sort actions by timestamp

    users = User.objects.all()
    suggested_users = []
    contacts = []
    user_relationships = RelationshipStatus.objects.all().filter(
        to_role_id=request.user.profile.role.id)
    for status in user_relationships:
        contacts.extend(
            request.user.relationships.get_related_to(status=status))
    users = list(set(users) ^ set(contacts))
    for user in users:

        if not user.is_superuser and user != request.user:
            common_activities = list(
                set(user.profile.activities.all()).intersection(
                    request.user.profile.activities.all()))
            if len(common_activities) >= 3:
                suggested_users.append(user)
            else:
                if len(common_activities) == 2:
                    if user.profile.studies == request.user.profile.studies:
                        suggested_users.append(user)
                    else:
                        if user.profile.status == request.user.profile.status:
                            suggested_users.append(user)
                else:
                    if len(common_activities) == 1:
                        if user.profile.status == request.user.profile.status or user.profile.studies == request.user.profile.studies:
                            suggested_users.append(user)
    '''
	return render_to_response(('actstream/actor.html', 'activity/actor.html'), {
	'ctype': ContentType.objects.get_for_model(User),
	'actor': request.user, 'action_list': posts_final, 'related_groups':related_org, 'users':suggested_users, 'username':request.user.username
	}, context_instance=RequestContext(request))
	'''

    iform = freeCrop(request.POST)
    context = {
        'ctype': ContentType.objects.get_for_model(User),
        'actor': request.user,
        'action_list': posts_final,
        'related_groups': related_org,
        'page_template': page_template,
        'users': suggested_users,
        'image_form': iform,
        'username': request.user.username,
        'user_relationships': user_relationships,
        'contacts': contacts
    }

    if request.is_ajax():
        template = page_template
    return render_to_response(template,
                              context,
                              context_instance=RequestContext(request))
Exemple #10
0
def new_wall_post(request):
    image_url = ""
    viewer = request.user
    owner_user = request.user
    owner_user_role = UserProfile.objects.get(user_id=owner_user.id)
    if request.method == 'POST':
        form = freeCrop(request.POST)  # A form bound to the POST data
        if form.is_valid():  # All validation rules pass
            new_event = form.save()
            #return HttpResponseRedirect('/user/profile/'+request.user.username)
            #return HttpResponseRedirect('/file-upload/cicu-freecrop/?id='+str(new_event.id))
            a = new_event.id
            if uploadedImage.objects.get(id=a).image:
                image_url = "###uploaded_image###" + uploadedImage.objects.get(
                    id=a).image.url + "##!uploaded_image!##"

        form = Wall_Post_Form(request.POST)
        if form.is_valid():
            content = form.cleaned_data['content']
            if content != "" or image_url != "":
                content = content + image_url
                actor_name = form.cleaned_data['actor_name']
                post_target = form.cleaned_data['target']
                print post_target
                #####################
                owner_user = User.objects.get(
                    username__exact=actor_name)  # user creation
                owner_user_role = UserProfile.objects.get(
                    user_id=owner_user.id)
                #relationships =  [relationship for relationship in RelationshipStatus.objects.all().filter (to_role_id = user_role.role_id)]

                content = rendered_content(content, request)

                if post_target == "Private":
                    print "Private target"
                    action.send(viewer,
                                verb='posted',
                                action_object=owner_user,
                                target=viewer,
                                post_content=content)  # action creation
                elif post_target == "Public":
                    print "public target"
                    print owner_user_role.role_id
                    if (RelationshipStatus.objects.all().filter(
                            to_role_id=owner_user_role.role_id).count() == 0):
                        print " No relationship found "
                        if (RelationshipStatus.objects.all().filter(
                                to_role_id__isnull=True).count() >= 0):
                            for relationship in RelationshipStatus.objects.all(
                            ).filter(to_role_id__isnull=True):
                                action.send(viewer,
                                            verb='posted',
                                            action_object=owner_user,
                                            target=relationship,
                                            post_content=content)
                    else:
                        for relationship in RelationshipStatus.objects.all(
                        ).filter(to_role_id=owner_user_role.role_id):
                            action.send(
                                viewer,
                                verb='posted',
                                action_object=owner_user,
                                target=relationship,
                                post_content=content)  # action creation
                        if (RelationshipStatus.objects.all().filter(
                                to_role_id__isnull=True).count() >= 0):
                            for relationship in RelationshipStatus.objects.all(
                            ).filter(to_role_id__isnull=True):
                                action.send(viewer,
                                            verb='posted',
                                            action_object=owner_user,
                                            target=relationship,
                                            post_content=content)
                else:
                    for relationship in RelationshipStatus.objects.all(
                    ).filter(
                            Q(to_role_id=owner_user_role.role_id)
                            & Q(name=post_target)):
                        action.send(viewer,
                                    verb='posted',
                                    action_object=owner_user,
                                    target=relationship,
                                    post_content=content)  # action creation

                # notification NOT USED
                '''
				if request.user.id != user.id:
					print user.id
					notify.send(request.user,  recipient=user, verb='wall_post' )
				'''
        else:
            print "ERROR IN VALIDATION"
            print form.errors
    else:
        form = Wall_Post_Form()

    return HttpResponseRedirect('/user/profile/' + request.user.username)
Exemple #11
0
def stream(request, template='actstream/actor.html', page_template='actstream/action.html'):
	"""
	Index page for authenticated user's activity stream. (Eg: Your feed at
	github.com)
	"""
	viewer = request.user
	viewer_user_role = UserProfile.objects.get( user_id = viewer.id )
	posts_set =[]
	posts_final = []
	posts_set_ids = []
	posts_set_ids_m =[]
	posts_set_by_user =[]
	posts_final_by_other_users = []
	posts_set_user_ids = []
	posts_final_mentioned_for_this_user =[]
	group_actions_list = []
	
	user_ct = ContentType.objects.get(app_label="auth", model="user") # User Content Type
	
	######## posts by owner #########
	posts_set_user_distinct = list (Action.objects.filter( Q(verb='posted' ) & Q(actor_object_id = viewer.id) & Q(actor_content_type_id = user_ct.id) ).values_list('timestamp').distinct())
	for y in Action.objects.filter(verb='posted'):
			for x in posts_set_user_distinct:
				if y.timestamp ==x[0]:
					posts_set_user_distinct.remove(x)
					posts_set_user_ids.append(y.id)
				
	for wp_id in posts_set_user_ids:
		posts_set_by_user.extend(Action.objects.filter( id = wp_id ) )
		
	relation_ct = ContentType.objects.get(app_label="relationships", model="relationshipstatus") # User Content Type
	
	##########posts by other related users ######
	for related_users in Relationship.objects.all().filter(from_user_id = viewer.id ):
		print "RELATED"
		print related_users.to_user_id
		actions_list = Action.objects.filter( Q(verb='posted' ) & Q(actor_object_id = related_users.to_user_id )  & Q(target_object_id = related_users.status_id) & Q(actor_content_type_id = user_ct.id) & Q(target_content_type_id = relation_ct.id))
		print actions_list
		posts_set_distinct = list ( actions_list.values_list('timestamp').distinct())
		for y in Action.objects.filter( Q(verb='posted' ) &  ( Q(actor_object_id = related_users.to_user_id) ) & Q(target_object_id = related_users.status_id) & Q(actor_content_type_id = user_ct.id) & Q(target_content_type_id = relation_ct.id) ):
			for x in posts_set_distinct:
				if y.timestamp ==x[0]:
					posts_set_distinct.remove(x)
					posts_set_ids.append(y.id)
					
		for wp_id in posts_set_ids:
			posts_final_by_other_users.extend(Action.objects.filter( id = wp_id ) )
			
		posts_set_ids =[]
	print "OTHER"
	print posts_final_by_other_users
			
	##########posts mentioned to user ######
	posts_set_user_ids = []
	posts_set_for_mentioned_user_distinct = list (Action.objects.filter( Q(verb='posted' ) & Q(target_object_id = viewer.id) & Q(actor_content_type_id = user_ct.id) & Q(target_content_type_id = user_ct.id) ).values_list('timestamp').distinct())
	for y in Action.objects.filter(verb='posted'):
			for x in posts_set_for_mentioned_user_distinct:
				if y.timestamp ==x[0]:
					posts_set_for_mentioned_user_distinct.remove(x)
					posts_set_user_ids.append(y.id)
				
	for wp_id in posts_set_user_ids:
		if not any(x.id == wp_id for x in posts_set_by_user): #check for duplicate records in posts_set_by_user
			posts_final_mentioned_for_this_user.extend(Action.objects.filter( id = wp_id ) )
		
		
	##########posts from groups ######
	organization_ct = ContentType.objects.get(app_label="organizations", model="organization")	
	for related_groups in OrganizationUser.objects.all().filter(user_id = viewer.id ):
		group_actions_list.extend (Action.objects.filter( Q(verb='posted' ) & ~Q(actor_object_id = viewer.id )  & Q(target_object_id = related_groups.organization_id) & Q(actor_content_type_id = user_ct.id) & Q(target_content_type_id = organization_ct.id)))
		
	print "OTHER"
	print group_actions_list
	
	related_org =[]
	for related_org_user in OrganizationUser.objects.all().filter(user_id = viewer.id ):
		related_org.extend(Organization.objects.all().filter(id = related_org_user.organization_id ))
	print "RELATED GROUPS"
	print related_org
	
	print "THIS POSTS"
	
	print posts_set_by_user
	print posts_final
	print posts_final_by_other_users
	print posts_final
	print posts_final_mentioned_for_this_user
	print posts_final
	print type(group_actions_list)
	
	posts_final = posts_final_by_other_users+ posts_set_by_user + posts_final_mentioned_for_this_user + group_actions_list
	print posts_final
	posts_final.sort(key=lambda Action	: Action.timestamp, reverse= True)# sort actions by timestamp


	users = User.objects.all()
	suggested_users = []
	contacts = []
	user_relationships = RelationshipStatus.objects.all().filter( to_role_id = request.user.profile.role.id )
	for status in user_relationships:
		contacts.extend(request.user.relationships.get_related_to(status=status))
	users = list(set(users)^set(contacts))
	for user in users:
		
		if not user.is_superuser and user != request.user:
			common_activities = list(set(user.profile.activities.all()).intersection(request.user.profile.activities.all()))
			if len(common_activities) >= 3:
				suggested_users.append(user)
			else:
				if len(common_activities) == 2:
					if user.profile.studies == request.user.profile.studies:					
						suggested_users.append(user)
					else:
						if user.profile.status == request.user.profile.status:
							suggested_users.append(user)
				else:
					if len(common_activities) == 1:
						if user.profile.status == request.user.profile.status or user.profile.studies == request.user.profile.studies:
							suggested_users.append(user)


	'''
	return render_to_response(('actstream/actor.html', 'activity/actor.html'), {
	'ctype': ContentType.objects.get_for_model(User),
	'actor': request.user, 'action_list': posts_final, 'related_groups':related_org, 'users':suggested_users, 'username':request.user.username
	}, context_instance=RequestContext(request))
	'''

	iform = freeCrop(request.POST)
	context =  {
	'ctype': ContentType.objects.get_for_model(User),
	'actor': request.user, 
	'action_list': posts_final, 
	'related_groups':related_org,
	'page_template': page_template,
	'users':suggested_users,
	'image_form':iform,
	'username':request.user.username,
	'user_relationships' : user_relationships,
	'contacts':contacts
	}
	
	if request.is_ajax():
		template = page_template
	return render_to_response(template, context, context_instance=RequestContext(request))	
Exemple #12
0
def new_wall_post (request):
	image_url = ""
	viewer = request.user
	owner_user = request.user
	owner_user_role = UserProfile.objects.get( user_id = owner_user.id )
	if request.method == 'POST':
		form = freeCrop(request.POST) # A form bound to the POST data
		if form.is_valid(): # All validation rules pass
		    	new_event = form.save()
		    	#return HttpResponseRedirect('/user/profile/'+request.user.username)
		    	#return HttpResponseRedirect('/file-upload/cicu-freecrop/?id='+str(new_event.id))
			a = new_event.id
			if uploadedImage.objects.get(id=a).image:
				image_url = "###uploaded_image###"+uploadedImage.objects.get(id=a).image.url+"##!uploaded_image!##"
			
		form = Wall_Post_Form(request.POST)
		if form.is_valid():
			content = form.cleaned_data['content']
			if content != "" or image_url!="":
				content = content + image_url
				actor_name = form.cleaned_data['actor_name']
				post_target = form.cleaned_data['target']
				print post_target
				#####################
				owner_user = User.objects.get(username__exact = actor_name) # user creation
				owner_user_role = UserProfile.objects.get( user_id = owner_user.id )
				#relationships =  [relationship for relationship in RelationshipStatus.objects.all().filter (to_role_id = user_role.role_id)]
			
				content = rendered_content (content,request)
			
			
				if post_target == "Private":
					print "Private target"
					action.send(viewer, verb='posted', action_object = owner_user, target= viewer,  post_content=content) # action creation
				elif post_target == "Public":
					print "public target"
					print owner_user_role.role_id
					if  (RelationshipStatus.objects.all().filter (to_role_id = owner_user_role.role_id).count() == 0 ):
						print " No relationship found "
						if  (RelationshipStatus.objects.all().filter (to_role_id__isnull=True ).count() >= 0 ):
							for relationship in RelationshipStatus.objects.all().filter (to_role_id__isnull=True):
								action.send(viewer, verb='posted', action_object = owner_user, target=relationship,  post_content=content)
					else:
						for relationship in RelationshipStatus.objects.all().filter (to_role_id = owner_user_role.role_id):
							action.send(viewer, verb='posted', action_object = owner_user, target=relationship,  post_content=content) # action creation
						if  (RelationshipStatus.objects.all().filter (to_role_id__isnull=True ).count() >= 0 ):
							for relationship in RelationshipStatus.objects.all().filter (to_role_id__isnull=True):
								action.send(viewer, verb='posted', action_object = owner_user, target=relationship,  post_content=content)
				else:
					for relationship in RelationshipStatus.objects.all().filter (Q(to_role_id = owner_user_role.role_id) & Q(name = post_target )):
						action.send(viewer, verb='posted', action_object = owner_user, target=relationship,  post_content=content) # action creation
			
				# notification NOT USED
				'''
				if request.user.id != user.id:
					print user.id
					notify.send(request.user,  recipient=user, verb='wall_post' )
				'''
		else:
			print "ERROR IN VALIDATION"
			print form.errors		
	else:
		form = Wall_Post_Form()
		
	return HttpResponseRedirect('/user/profile/'+request.user.username)