Example #1
0
def send(request):
    if request.method == 'POST':
        form = SendForm(request.POST)

        if form.is_valid():
            message = form.cleaned_data['message']
            comment = form.cleaned_data['comment']
            phone_n = form.cleaned_data['phone_n']

            item = QueueItem(phone_n=phone_n,
                             message=message,
                             comment=comment,
                             partner=Partner.objects.get(user=request.user.id),
                             status_message="ADDED TO QUEUE")
            item.save()

            result = SendSms.delay(item)

            SmsLog.objects.create(item=item, text='Added: %s; phone_n: %s; message: %s; task_id: %s' %
                                                  (request.user.id, phone_n, message, result.task_id))

            return response_json({'status': 0, 'id': item.id})
        else:
            return response_json({'status': 1, 'message': 'form is invalid', 'form_errors': form.errors})
    else:
        return HttpResponse(status=405) # method not allowed
def wallet(request, uuid):

    try:
        instawallet=InstaWallet.objects.get(uuid=uuid)
    except:
        return HttpResponseRedirect('/404')

    if request.method == 'POST': # If the form has been submitted...
        form = SendForm(request.POST) # A form bound to the POST data
        if form.is_valid(): # All validation rules pass
            # check if 
            if len(form.cleaned_data["address_to"])>30 \
                and len(form.cleaned_data["address_to"])<37:
                try:
                    instawallet.wallet.send_to_address(form.cleaned_data["address_to"], form.cleaned_data["amount"])
                    messages.add_message(request, messages.SUCCESS, \
                        _(u"Transaction successfully sent to bitcoin address "+form.cleaned_data["address_to"]))
                except:
                    messages.add_message(request, messages.ERROR, sys.exc_info()[0])
            else:
                otherwallets=InstaWallet.objects.filter(uuid__startswith=form.cleaned_data["address_to"])
                if len(otherwallets)==1:
                    instawallet.wallet.send_to_wallet(otherwallets[0].wallet, form.cleaned_data["amount"])
                    messages.add_message(request, messages.SUCCESS, \
                        _(u"Transaction successfully sent to another instawallet "+form.cleaned_data["address_to"]))
                else:
                    messages.add_message(request, messages.ERROR, _(u"Address not an valid bitcoin address or wallet uuid not found."))
    else:
        form = SendForm() # An unbound form

    return render_to_response("instawallet.html", {
        "instawallet": instawallet,
        "form": form,
        }, context_instance=RequestContext(request))
Example #3
0
def index():
    import tempfile
    form = SendForm()
    if form.validate_on_submit():
        srcfile = request.files['file']
        imgfile = request.files['img']
        password = request.form['pwd']
        uid = unique_id()
        dir = os.path.join(app.config['UPLOADED_FILES_DEST'], uid)
        if not os.path.exists(dir):
            os.makedirs(dir)
        if(srcfile.filename != imgfile.filename):
           tfn = os.path.join(dir, secure_filename(srcfile.filename))
        else:
            tfn = os.path.join(dir, secure_filename("0_" + srcfile.filename))
        filepath = os.path.join(dir, secure_filename(imgfile.filename))
        imgfile.save(filepath)
        srcfile.save(tfn)
        szip_out = Make7zJpeg(os.path.abspath(tfn), filepath, filepath, password)
        if __debug__:
            print(szip_out)
        os.remove(tfn)
        deltime = datetime.combine(date.today(), time()) + timedelta(days=30)
        rec = File(filepath = filepath, filename = imgfile.filename, filekey = uid, deletetime = deltime, from_ip = request.remote_addr)
        db.session.add(rec)
        db.session.commit()
        return redirect("/" + str(rec.id) + '/' + uid)
    return render_template("index.html", form = form)
Example #4
0
def send(request):
    if request.method == 'POST':
        form = SendForm(request.POST)

        if form.is_valid():
            message = form.cleaned_data['message']
            comment = form.cleaned_data['comment']
            phone_n = form.cleaned_data['phone_n']

            item = QueueItem(phone_n=phone_n,
                             message=message,
                             comment=comment,
                             partner=request.user.get_profile(),
                             status_message="ADDED TO QUEUE")
            item.save()
            
            result = SendSms.delay(item)

            SmsLog.objects.create(item=item, text='Added: %s; phone_n: %s; message: %s; task_id: %s' %
                                                  (request.user.id, phone_n, message, result.task_id))

            return response_json({'status': 0, 'id': item.id})
        else:
            return response_json({'status': 1, 'message': 'form is invalid', 'form_errors': form.errors})
    else:
        return HttpResponse(status=405) # method not allowed
Example #5
0
def email_render():
    recipient_email = request.args.get('recipient_email')
    job_position = request.args.get('job_position')
    heard_about = request.args.get('heard_about')
    company_name = request.args.get('company_name')
    confirm_form = SendForm()
    if confirm_form.validate_on_submit():
        send_email(job_position, company_name, recipient_email, heard_about)
        ## Send email! 
    return render_template(r"template_email.html", heard_about = heard_about, job_position = job_position, company_name = company_name, recipient_email = recipient_email, form = confirm_form)
Example #6
0
def index():
    form = SendForm()
    if form.validate_on_submit():
        name = form.name.data
        last_name = form.lastname.data
        age = form.age.data
        txt = form.txt.data
        web_client = WebClient()
        web_client.create_attachment()
        web_client.upload(name, last_name, age, txt)
        return redirect('/send')
    return render_template("index.html", form=form)
Example #7
0
File: app.py Project: usennon/my_cv
def contact():
    form = SendForm()
    if request.method == 'POST' and form.validate_on_submit():
        name = request.form.get('name')
        email = request.form.get('email')
        subject = request.form.get('subject')
        body = request.form.get('body')
        with smtplib.SMTP('smtp.gmail.com') as connection:
            connection.starttls()
            connection.login(user=my_email, password=PASSWORD)
            msg = EmailMessage()
            msg['Subject'] = subject
            msg['From'] = my_email
            msg['To'] = '*****@*****.**'
            msg.set_content(name + '\n' + body + f'\nMy email is {email}')
            connection.send_message(msg)
            return redirect(url_for('contact'))
    return render_template('contact.html', form=form)
def wallet(request, uuid):

    try:
        instawallet = InstaWallet.objects.get(uuid=uuid)
    except:
        return HttpResponseRedirect('/404')

    if request.method == 'POST':  # If the form has been submitted...
        form = SendForm(request.POST)  # A form bound to the POST data
        if form.is_valid():  # All validation rules pass
            # check if
            if len(form.cleaned_data["address_to"])>30 \
                and len(form.cleaned_data["address_to"])<37:
                try:
                    instawallet.wallet.send_to_address(
                        form.cleaned_data["address_to"],
                        form.cleaned_data["amount"])
                    messages.add_message(request, messages.SUCCESS, \
                        _(u"Transaction successfully sent to bitcoin address "+form.cleaned_data["address_to"]))
                except:
                    messages.add_message(request, messages.ERROR,
                                         sys.exc_info()[0])
            else:
                otherwallets = InstaWallet.objects.filter(
                    uuid__startswith=form.cleaned_data["address_to"])
                if len(otherwallets) == 1:
                    instawallet.wallet.send_to_wallet(
                        otherwallets[0].wallet, form.cleaned_data["amount"])
                    messages.add_message(request, messages.SUCCESS, \
                        _(u"Transaction successfully sent to another instawallet "+form.cleaned_data["address_to"]))
                else:
                    messages.add_message(
                        request, messages.ERROR,
                        _(u"Address not an valid bitcoin address or wallet uuid not found."
                          ))
    else:
        form = SendForm()  # An unbound form

    return render_to_response("instawallet.html", {
        "instawallet": instawallet,
        "form": form,
    },
                              context_instance=RequestContext(request))
Example #9
0
def home(request):
    if request.method == 'GET':
        initial={
            'mails':'[email protected],[email protected],[email protected]',
            'tmail':1,
        }
        form = SendForm(initial=initial)
    else:
        form = SendForm(request.POST)
        if form.is_valid():
            send = form.save()
            total,success = send.do()
            msg = '%d 封邮件正在等待发送' % (total)
            messages.success(request,msg)
            return redirect('home')

    ctx = {'form':form}
    ctx['objs'] = m.Tmail.objects.all()
    return render(request,'home.html',ctx)
Example #10
0
def resolver_main():
    problem_id = request.args.get("problem_id")
    messages = []
    path = os.path.abspath(os.path.dirname(__file__))
    path = path + '/static/chats'
    send_form = SendForm()
    if send_form.validate_on_submit():
        now = datetime.datetime.now()
        chat_file = open(path + '/pr' + str(problem_id), 'a')
        chat_str = '\n' + str(now.date()) + '|' + str(
            now.strftime("%H:%M:%S")) + '|' + str(
                globals.user_id) + '|' + send_form.message.data + '|' + '---'
        print(chat_str)
        chat_file.write(chat_str)
        print('----button pressed')
        send_form.message.data = ''

    if problem_id == None:
        messages.append(["", "", "", "Choose the problem", "---", "center"])
    else:
        chat_file = open(path + '/pr' + str(problem_id), 'r')
        # url_for('static', filename = 'chats/')
        for line in chat_file:
            if line[-1] == '\n':
                line = line[:-1]
            message_params = line.split("|")
            if message_params[2] == str(globals.user_id):
                message_params.append("right")
            else:
                message_params.append("left")

            if message_params[4] != "---":
                message_params[4] = url_for('static',
                                            filename='chats/media' +
                                            str(problem_id) + "/" +
                                            message_params[4])
            messages.append(message_params)
        chat_file.close()

    return render_template('resolver_main.html',
                           messages=messages,
                           form=send_form)
Example #11
0
def index():
    form = SendForm()
    if form.validate_on_submit():
        name = form.name.data
        body = form.body.data

        if name != 'node0' and name in XBEE_ADDR:
            sendData(name, body)
            t = time.localtime()
            t1 = time.strftime('%Y_%m_%d', t)
            t2 = time.strftime('%H:%M:%S', t)
            with open('Send_' + t1 + '.txt', 'a+') as f:
                f.write('Send to %s : %s  at %s\n' % (name, body, t2))
            flash('Send to %s : %s at %s Successfully !' % (name, body, t2))
        else:
            flash('Target Node Error')

        return redirect(url_for('index'))

    return render_template('index.html', form=form)
Example #12
0
def contact():
    form = SendForm()
    if request.method == 'POST':

        from_name = request.form['Name']
        from_addr = request.form['email']
        subject = request.form['Subject']
        msg = request.form['comments']
        send_email(from_name, from_addr, subject, msg)
        flash('MESSAGE SENT')
        return redirect(url_for('home'))
    """Render the website's contact page."""
    return render_template('contact.html', form=form)
Example #13
0
def send_face_data():
    form = SendForm()
    ws = websocket.create_connection(
        "ws://192.168.9.208:19101/FACE-DETECT-WS/websck")
    face_unid_unique = int(21234)
    face_refid_unique = int(25678)
    event_refid = int(21357)
    time = session.get('time')
    print time
    print type(time)
    for i in range(19999, 19999 + int(time)):
        data = {
            "type":
            "request",
            "id":
            face_unid_unique,
            "command":
            "send_face_events",
            "params": [{
                "face_refid":
                face_refid_unique,
                "event_refid":
                "anmeifang",
                "event_dt":
                '2017-10-17T08:30:39.028',
                #"pic_url":"http://192.168.9.208:7788//LINDASceneAlarm/20171017/16/" + str(picname+1) + ".jpg",
                "pic_url":
                "http://192.168.9.208:7788//LINDASceneAlarm/20171017/16/" +
                str(i) + ".jpg",
                "accord_event_refid":
                "DF452E44-B458-446D-9273-35472618DE73}-20171011160011826",
                "accord_similarity":
                90,
                "camera_refid":
                "0557fc08-565d-449d-82b9-22ad08e6bc54",
                "sex":
                "1",
                "age":
                29,
            }],
        }
        try:
            ws.send(json.dumps(data))
            result = ws.recv()
            print result
        except socket.error, e:
            render_template('404.html')
        face_unid_unique = face_unid_unique + 1
        face_refid_unique = face_refid_unique + 1
        event_refid = event_refid + 1