Beispiel #1
0
def new(request):
    c = {}
    c.update(csrf(request))

    if request.method == 'POST':
        currentuser = User.objects.get(id=request.user.id)
        print currentuser


        #Tags
        incommingtags=request.POST["tags"].replace(" ","")
        thetags=incommingtags.split(',')


        #Location
        incommingloca=request.POST["location"].replace(" ","")
        thelocations=incommingloca.split(',')

        #Saving articel
        articel=Post(title=request.POST['title'],auther=currentuser,location=thelocations,tags=thetags,text=request.POST["text"],page_views=0,page_rate=0)
        articel.save()
        UserInfo.objects.select_related().filter(username=currentuser).update(postscount=F('postscount')+1)

        return render_to_response('book/saved.html',context_instance=RequestContext(request))


    return render_to_response('book/new.html', c,context_instance=RequestContext(request))
Beispiel #2
0
def rate(request):
    '''
    Rate the articel
    '''
    if request.method == 'POST':
        if request.user.id:
            currentuser = User.objects.get(id=request.user.id)

            Post.objects(id=request.POST.get('articel')).update_one(inc__page_rate=int(request.POST.get('rate')))
            return render_to_response('book/rate_ok.html',context_instance=RequestContext(request))
        else:
            print "User not login"
            return render_to_response('book/rate_no.html',context_instance=RequestContext(request))
    return render_to_response('book/rate_no.html',context_instance=RequestContext(request))
Beispiel #3
0
def view_location_tags(request,location,tags):
	'''
	View and articel
	'''
	
	articels = Post.objects(Q(tags=tags) | Q(location=location))
	return render_to_response('book/list_articels.html',  {'articels': articels},context_instance=RequestContext(request))
Beispiel #4
0
def signup_mailchump(email):
	'''
	Sign upp new user to our mailchimp email service
	All new usere that sign up will get sign up to automatical
	'''
	chimp = chimpy.Connection('d784f29c89de4f56fc793d85a074623c-us8')
	chimp.list_subscribe('be2d53aa4d', email, {'FIRST': 'User', 'LAST': 'Asylguiden'}, double_optin=False)
	#No info
	info="no"
	#Updating user settingsglobal name 'request' is not defined
	if request.POST.get("user_settings"):
		user = User.objects.get(id=request.user.id)
		if request.POST.get('password1'):
			user.set_password(request.POST.get('password1'))
		if request.POST.get('email'):
			user.email = request.POST.get('email')
		user.save()
		info = "saved"
	#updating user details in mongodb	
	if request.POST.get("user_detial"):
		user = User.objects.get(id=request.user.id)
		update = UserInfo.objects.get(user=user)
		update.username = request.user.username
		update.first_name = request.POST.get('id_fname')
		update.last_name = request.POST.get('id_sname')
		update.address = request.POST.get('id_address')
		update.postnr = request.POST.get('id_postnr')
		update.cell = request.POST.get('id_cell')
		update.country = request.POST.get('id_country')
		update.language = request.POST.get('id_language')
		update.save()
		info = "saved"

	#Get user info fix for displying correct user email after update
	user_info = User.objects.get(id=request.user.id)
	userid   = request.user.id
	username = request.user.username
	useremail = user_info.email


	currentuser = UserInfo.objects(user=user_info)
	users_articel = Post.objects(auther=user_info)



	return render_to_response("users/mypage.html",{'user_id':str(hashlib.sha224(str(request.user.id)).hexdigest()),'username':username,'useremail':useremail,'userid':userid,'users_articel':users_articel,'info':info,'userinfo':currentuser},context_instance=RequestContext(request))
Beispiel #5
0
def post(request, method="POST"):
	# LATEST ALGORITHM
	if request.method == "POST":
		# post details
		#create post instance
		post_data = Post(request.POST)

		new_post = post_data.save(commit=False)
		new_post.what = post_data.get("what")
		new_post.where = post_data.get("where")
		new_post.profession = post_data.get("where")
		new_post.setting = post_data.get("setting")
		new_post.incentives = post_data.get("incentives", None)
		new_post.incentives_date = post_data.get("incentives_date", None)
		new_post.salary_date = post_data.get("salary_date")
		new_post.requirements = post_data.get("requirements", None)
		new_post.patients_number = post_data.get("patients_number")
		new_post.person_to_look_for = post_data.get("person_to_look_for")
		new_post.others = post_data.get("others", None)
		new_post.save()
		# determine if it's for several vs similar professionals or similar 
		type_of_post = post_data.get("post_type")
		# if for different professionals
		if type_of_post == "different_professionals":
			# get NUMBER OF POSTS
			number_of_posts = post_data.get("number_of_posts")
			# iterate thru number of posts

			for i in number_of_posts + 1: 
			#access post details by indexing
				post_details = Date()
				post_details.post = new_post
				post_details.start_date = post_data.get("start_date")[i]
				post_details.end_date = post_data.get("end_date")[i]
				post_details.start_time = post_data.get("start_time")[i]
				post_details.end_time = post_data.get("end_time")[i]
				post_details.total_hours = post_data.get("total_hours")[i]
				post_details.net_rate = post_data.get("net_salary")[i]

				# total number of posts
				total_posts = post_data.get("total_posts")[i]
				# determine if it's AND or OR
				determinant = post_data.get("determinant")[i]
				# get the no. of males needed
				male = post_data.get("male")[i]
				# get the no. of females needed
				female = post_data.get("female")[i]

				if total_posts != 0:
				# if AND
					if determinant == "AND":
						
						if male != 0:

							post_details.sex_of_professional = "Male"
							post_details.is_taken = False
							post_details.save()

							for i in male + 1:
								#create post
								post_details.pk = None
								post_details.sex_of_professional = "Male"
								post_details.is_taken = False
								post_details.save()

								#redirect to the posts page
							# use for loop to iterate thru female
							for i in female + 1:
								#create post
								post_details.pk = None
								post_details.sex_of_professional = "Female"
								post_details.is_taken = False
								post_details.save()

						elif female != 0:

							post_details.sex_of_professional = "Female"
							post_details.is_taken = False
							post_details.save()

							for i in female + 1:
								#create post
								post_details.pk = None
								post_details.sex_of_professional = "Female"
								post_details.is_taken = False
								post_details.save()

						#if 0 male and 0 female
						else:
							#return error message
							return render(request, 'book/post2.html')


					# else if OR
					elif determinant == "OR":
					# CREATE AN INITIAL POST FIRST TO BE COPIED LATER


						post_details.sex_of_professional = "Male"
						post_details.is_taken = False
						post_details.save()

						post_details.pk = None
						post_details.sex_of_professional = "Female"
						post_details.is_taken = False
						post_details.save()

					# use for loop to iterate thru male ONLY
						for i in total_posts:
						#create post
							post_details.pk = None
							post_details.sex_of_professional = "Male"
							post_details.is_taken = False
							post_details.save()

							post_details.pk = None
							post_details.sex_of_professional = "Female"
							post_details.is_taken = False
							post_details.save()

		# else for same professionals 
		elif type_of_post == "same_professionals":
			number_of_posts = post_data.get("number_of_posts")

			determinant = post_data.get("determinant")
			# get the no. of males needed
			male = post_data.get("male")
			# get the no. of females needed
			female = post_data.get("female")
			# iterate thru number of posts
			for i in number_of_posts + 1:
				#access post details by indexing
			# iterate thru number of posts
				#access post details by indexing
					post_details = Date.save(commit=False)
					post_details.post = new_post
					post_details.start_date = post_data.get("start_date")[i]
					post_details.end_date = post_data.get("end_date")[i]
					post_details.start_time = post_data.get("start_time")[i]
					post_details.end_time = post_data.get("end_time")[i]
					post_details.total_hours = post_data.get("total_hours")[i]
					post_details.net_rate = post_data.get("net_salary")[i]

			
					# determine if it's AND or OR
					determinant = post_data.get()
					# get the no. of males needed
					male = post_data.get("male")
					# get the no. of females needed
					female = post_data.get("female")

					# if AND
					if determinant == "AND":
						
						if male != 0:

							post_details.sex_of_professional = "Male"
							post_details.is_taken = False
							post_details.save()

							for i in male:
								#create post
								post_details.pk = None
								post_details.sex_of_professional = "Male"
								post_details.is_taken = False
								post_details.save()

						elif female != 0:

							post_details.sex_of_professional = "Female"
							post_details.is_taken = False
							post_details.save()

							for i in female:
								#create post
								post_details.pk = None
								post_details.sex_of_professional = "Female"
								post_details.is_taken = False
								post_details.save()

						#if 0 male and 0 female
						else:
							return render(request, 'book/post2.html')

							#return error message

					elif determinant == "OR":
					# CREATE AN INITIAL POST FIRST TO BE COPIED LATER

						if male != 0:
							post_details.sex_of_professional = "Male"
							post_details.is_taken = False
							post_details.save()

							post_details.pk = None
							post_details.sex_of_professional = "Female"
							post_details.is_taken = False
							post_details.save()
					
					# use for loop to iterate thru male ONLY
							for i in male:
								#create post
								post_details.pk = None
								post_details.sex_of_professional = "Male"
								post_details.is_taken = False
								post_details.save()

								post_details.pk = None
								post_details.sex_of_professional = "Female"
								post_details.is_taken = False
								post_details.save()

	
	else: 
		return render(request, 'book/post2.html')