Ejemplo n.º 1
0
def get_msg(request):
    user_msg = "Thanks :)"
    form = NameForm()
    if request.method == "POST":
        form = NameForm(request.POST)
        if form.is_valid():
            # p = Person()
            user_msg = form.cleaned_data["msg"]
            print user_msg

    details = {}
    facebook_profile = request.user
    user = User.objects.filter(username=facebook_profile)
    access_token = (UserSocialAuth.objects.filter(
        user=user))[0].extra_data['access_token']

    url = "https://graph.facebook.com/me?fields=first_name,name,picture,birthday"
    parameters = {'access_token': access_token}
    detail = requests.get(url, params=parameters).json()

    details['name'] = detail['name']
    details['first_name'] = detail['first_name']
    details['picture'] = detail['picture']['data']['url']
    details['birthday'] = detail['birthday']

    bday = requests.get(url, params=parameters)
    bday = detail['birthday']
    bday_date = str(bday.split('/')[1])
    bday_nextdate = str(int(bday.split('/')[1]) + 1)
    bday_month = str(bday.split('/')[0])
    current_year = str(date.today().year)

    current_bday = bday_month + "/" + bday_date + "/" + current_year
    next_day = bday_month + "/" + bday_nextdate + "/" + current_year

    url = "https://graph.facebook.com/v2.4/me/feed?since=" + "08/17/2015" + "&until=" + "08/18/2015"
    # url = "https://graph.facebook.com/v2.4/me"
    parameters = {'access_token': access_token}
    related_list = requests.get(url, params=parameters)
    related_list = related_list.json()
    print related_list
    for msg in related_list['data']:
        try:
            print msg['id']
            url = "https://graph.facebook.com/" + msg['id']
            parameters = {'access_token': access_token}
            per_post = requests.get(url, params=parameters).json()
            print per_post
            bday_list = [
                "birthday", "birth", "bdae", "bday", "b'day", "janamdin",
                "janmdin", "returns", "day", "brth", "hbd", "hb", "happy",
                "day", "wish", "wishing"
            ]
            for txt in bday_list:
                if txt in per_post['message']:
                    thanks(per_post['id'], user_msg, access_token)
                    break
        except:
            print "Error"
    return render(request, 'index.html', {'details': details})
Ejemplo n.º 2
0
def	New(request):

    try:
	if CheckAccess(request,'23') != 'OK':
	    return render_to_response("mtmc/notaccess/mtmc.html")
    except:
	return HttpResponseRedirect('/')


    if request.method == 'POST':
	form = NameForm(request.POST)
	if form.is_valid():
	    name = form.cleaned_data['name']
	    result = NewEq(request,name)
	    if result:
		return HttpResponseRedirect('/mtmcedit/?eq_id=%s' % result)


    form = NameForm(None)



    c = RequestContext(request,{'form':form})
    c.update(csrf(request))
    return render_to_response("mtmc/new.html",c)
Ejemplo n.º 3
0
def get_name(request):
    form=NameForm()
    form1=UpdateForm()
    s8 = prediction_content.get_prediction_content()
    json_pre = json.dumps(s8)

    # if this is a POST request we need to process the form data
    if request.method == 'POST' and 'search' in request.POST:
        # create a form instance and populate it with data from the request:
        form = NameForm(request.POST)
        # check whether it's valid:
        if form.is_valid():
            #start of search processing time
            start_time=time.time()
            your_name = request.POST.get('your_name')
            your_name1=your_name
            s=search1.get_search_result(your_name1)
            s1=search1.get_file_name()
            s3=[]
            s4=search1.pre()
            s5=search1.get_knownerror()
            for i in s1:
                if i not in s3:
                    s3.append(i)
            s2=zip(s,s1,s4,s5)
            c=len(s)
            tim=time.time()-start_time
            tim=str(tim)+" sec"
            #end of search process time
            form=NameForm()

            return render(request,'myapp/thanks.html',{'name':your_name1,'file':s3,'filename':s2,'number':c,'result':s,'form':form,'form1':form1,'soln':s,'ti':tim,'json_pre':json_pre})

    if request.method == 'POST' and 'update' in request.POST:
        form1 = UpdateForm(request.POST)
        if form1.is_valid():
            question = request.POST.get('question')
            answer = request.POST.get('comment')
            pre = request.POST.get('pre')
            file_choice=request.POST.get('file_choice')
            print answer

            print question
            print file_choice
            form1 = UpdateForm()
            update.update(question,answer,pre,file_choice)

            return render(request, 'myapp/thanks.html',
                          {'form':form,'form1':form1,'json_pre':json_pre})
    else:
            form = NameForm()
            form1=UpdateForm()


    #template = loader.get_template("myapp/name.html")
    context = {'form': form,'form1':form1,'json_pre':json_pre}
    #return HttpResponse(template.render(context, request))
    return render(request, "myapp/name.html", context)
Ejemplo n.º 4
0
def get_msg(request):
	user_msg = "Thanks :)"
	form = NameForm()
	if request.method == "POST":
		form = NameForm(request.POST)
		if form.is_valid():
				# p = Person()
				user_msg = form.cleaned_data["msg"]
				print user_msg

	details = {}
	facebook_profile = request.user
	user = User.objects.filter(username = facebook_profile)
	access_token = (UserSocialAuth.objects.filter(user = user))[0].extra_data['access_token']

	url = "https://graph.facebook.com/me?fields=first_name,name,picture,birthday"
	parameters = {'access_token': access_token}
	detail = requests.get(url, params = parameters).json()

	details['name'] = detail['name']
	details['first_name'] = detail['first_name']
	details['picture']= detail['picture']['data']['url']
	details['birthday'] = detail['birthday']

	bday = requests.get(url, params = parameters)
	bday =  detail['birthday']
	bday_date = str(bday.split('/')[1])
	bday_nextdate = str(int(bday.split('/')[1])+1)
	bday_month = str(bday.split('/')[0])
	current_year = str(date.today().year)

	current_bday = bday_month+"/"+bday_date+"/"+current_year
	next_day = bday_month+"/"+bday_nextdate+"/"+current_year

	url = "https://graph.facebook.com/v2.4/me/feed?since="+"08/17/2015"+"&until="+"08/18/2015"
	# url = "https://graph.facebook.com/v2.4/me"
	parameters = {'access_token': access_token}
	related_list = requests.get(url, params = parameters)
	related_list = related_list.json()
	print related_list
	for msg in related_list['data']:
		try:
			print msg['id']
			url = "https://graph.facebook.com/"+msg['id']
			parameters = {'access_token': access_token}
			per_post = requests.get(url, params = parameters).json()
			print per_post
			bday_list = ["birthday", "birth", "bdae", "bday", "b'day", "janamdin", "janmdin", "returns", "day", "brth", "hbd", "hb", "happy", "day", "wish", "wishing"]
			for txt in bday_list:
				if txt in per_post['message']:
					thanks(per_post['id'], user_msg, access_token)
					break
		except:
			print "Error"
	return render(request, 'index.html',{ 'details' : details })
Ejemplo n.º 5
0
def form_edit(request,pk=id):
    if request.POST:
        form=NameForm(request.POST)
        if form.is_valid():
            form.save()
            return HttpResponseRedirect("/show/")
    else:
        form=NameForm()
        

    return render(request,"form.html",locals())
Ejemplo n.º 6
0
def profile(request):
    if request.method=="POST":
        form=NameForm(request.POST, request.FILES)
        if form.is_valid():
            name=form.cleaned_data['name']
            surname=form.cleaned_data['surname']
            email=form.cleaned_data['email']
            ssc=form.cleaned_data['ssc']
            inter=form.cleaned_data['inter']
            phone_number=form.cleaned_data['phone_number']
            highest_qualification=form.cleaned_data['highest_qualification']
            docfile=form.cleaned_data['docfile']
            p=Profile()
            p.name=name
            p.surname=surname
            p.email=email
            p.ssc=ssc
            p.inter=inter
            p.phone_number=phone_number
            p.highest_qualification=highest_qualification
            p.docfile=docfile
            p.save()
            print docfile
            from email.mime.text import MIMEText
            #attachment.add_header('Content-Disposition', 'attachment', filename=f) 
            success = "yes"
            subject="profile informayion"
            #url='http://127.0.0.1:8000/resetpwd/'
            url='http://127.0.0.1:8000/resetpwd/{0}'
            html_content='<a href="%s" > download</a>'% url
            body = preprocess_email_body(request,  html_content)
            email = EmailMessage(subject, body, to=[email])
            try:
              #email =EmailMultiAlternatives(subject,body,to=[email])
              email.attach(docfile.name, docfile.read(), docfile.content_type)
              content_subtype = "html"
              #email.attach_alternative(html_content, "text/html")
              #email.attach(attachment)
              email.send()
              #return render(request,"profile.html",locals())       
              success = "yes"
            except Exception as e:
              print e
             
            return render (request,"profile.html",locals())
        else:
            error = "yes"
            print "34233333434", form.errors
    else:
        form=NameForm()
    return render(request,"profile.html",{"form":form})
Ejemplo n.º 7
0
def edit_speaker_profile(request):
    profile = Speaker.objects.get(user = request.user)
    done = False
    if request.method == 'POST':
        name_form = NameForm(request.POST, instance=request.user)
        speaker_form = SpeakerProfile(request.POST, instance=profile)
        if name_form.is_valid() and speaker_form.is_valid():
            name_form.save()
            speaker_form.save()
            done = True
    else:
        name_form = NameForm(instance=request.user)
        speaker_form = SpeakerProfile(instance=profile)

    return render(request, 'access/edit_profile.html',
            {'title': u"Editar Perfil", 'name_form': name_form, 'speaker_form': speaker_form, 'done': done } )
Ejemplo n.º 8
0
def form(request):
    if request.method == 'POST':
        form=NameForm(request.POST)
        if form.is_valid():
            name=form.cleaned_data['name']
            city=form.cleaned_data['city']
            m=Metro()
            m.name=name
            m.city=city
            m.save()
            return HttpResponseRedirect("/show/")

    else:
        form=NameForm()
        

    return render(request,"form.html",locals())
Ejemplo n.º 9
0
def get_name(request):
    # if this is a POST request we need to process the form data
    if request.method == 'POST':
        # create a form instance and populate it with data from the request:
        form = NameForm(request.POST)
        # check whether it's valid:
        if form.is_valid():
            # process the data in form.cleaned_data as required
            # ...
            # redirect to a new URL:
            #return HttpResponseRedirect('app2/name.html')
            return render(request, 'app2/name.html', {'form': form})

    # if a GET (or any other method) we'll create a blank form
    else:
        form = NameForm()

    return render(request, 'app2/name.html', {'form': form})
Ejemplo n.º 10
0
def home_forms(request):
    print 'welcome to my forms'

    if request.method == 'POST':

        form = NameForm(request.POST)

        if form.is_valid():

            return HttpResponseRedirect('/thanks/')

    else:

        form = NameForm()

    context = {'form': form}

    return render(request, 'blogs/forms.html', context)
Ejemplo n.º 11
0
def get_name(request):
    # if this is a POST request we need to process the form data
    if request.method == 'POST':
        # create a form instance and populate it with data from the request:
        form = NameForm(request.POST)
        # check whether it's valid:
        if form.is_valid():
            p = models.Person()
            p.your_name = request.POST['your_name']
            p.pub_date = timezone.now()
            p.save()
            # redirect to a new URL:
            return HttpResponseRedirect('/thanks/')

    # if a GET (or any other method) we'll create a blank form
    else:
        form = NameForm()

        return render(request, 'forms/name.html', {'form': form})
Ejemplo n.º 12
0
def home_forms(request):
	print 'welcome to my forms'

	if request.method == 'POST':

		form = NameForm(request.POST)

		if form.is_valid():

			return HttpResponseRedirect('/thanks/')

	else:

		form = NameForm()


	context = {
		'form' : form
	}

	return render(request, 'blogs/forms.html', context)
Ejemplo n.º 13
0
def	Edit(request):

    try:
	if CheckAccess(request,'23') != 'OK':
	    return render_to_response("mtmc/notaccess/mtmc.html")
    except:
	return HttpResponseRedirect('/')

    try:
	eq_id = request.GET['eq_id']
	request.session['eq_id'] = eq_id
    except:
	pass

    try:
	eq_id = request.session['eq_id']
    except:
	return HttpResponseRedirect('/mtmc')
	

    if request.method == 'POST':
	form = NameForm(request.POST)
	if form.is_valid():
	    name = form.cleaned_data['name']
	    EditName(eq_id,name)

    eq = GetEq(eq_id)

    form = NameForm(None)
    form.fields['name'].initial = eq['name']
    
    field = DateTimeField()
    create = field._to_python(eq['create'])
    author = eq['author_name'].split()[1]+' '+eq['author_name'].split()[0]

    c = RequestContext(request,{'form':form,'eq':eq,'create':create,'author':author,'tmc':TmcUrl(eq)})
    c.update(csrf(request))
    return render_to_response("mtmc/edit.html",c)
Ejemplo n.º 14
0
def extraction(request):
    if request.method == 'POST':
        form = NameForm(request.POST)

        if form.is_valid():
            data = form.cleaned_data
            extracted_data = data['news_link']
            link, news, title = manual_extract(extracted_data)

            #
            # If you want to save the input news
            oldlinks = rssdata.objects.values_list('link', flat=True)

            if link not in oldlinks:
                id = extract(link, news, title)
                return render(
                    request, 'extraction.html', {
                        'form': form,
                        'news_id': id,
                        'article': rssdata.objects.get(pk=id)
                    })
            else:
                id = 5
                return render(
                    request, 'extraction.html', {
                        'form': form,
                        'news_id': id,
                        'article': rssdata.objects.get(link=link)
                    })

        # #

        #

    else:
        form = NameForm()

    return render(request, 'extraction.html', {'form': form})