def un_hdi_import():
    book = open_workbook('./data/un_hdi.xlsx')
    sheet = book.sheet_by_name('Table 2')

    connect(host=db)
    for row in range(7, sheet.nrows):
        name = sheet.cell(row, 1).value
        hdi_score = sheet.cell(row, 14).value
        hdi_rank = sheet.cell(row, 0).value

        Country.objects(name=name).update(hdi_score=hdi_score, hdi_rank=hdi_rank)
def happiness_import():
    book = open_workbook('./data/kaggle_happiness.xlsx')
    sheet = book.sheet_by_name('2017')

    connect(host=db)
    for row in range(1, sheet.nrows):
        name = sheet.cell(row, 0).value
        happiness_score = sheet.cell(row, 2).value
        happiness_rank = sheet.cell(row, 1).value

        Country.objects(name=name).update(
            happiness_score=happiness_score,
            happiness_rank=happiness_rank)
Exemple #3
0
def get_country(fields=[], lang='en'):
    items = []
    if lang == 'en':
        items = Country.objects().exclude("translation")
        items = items2dict(items)
        # items = json.dumps(items)
    elif lang:
        items = Country.objects(translation__language=lang).exclude(
            "name").exclude("language").order_by("translation__name")
        items = items2dict(items)

        items = translations_unify(items, lang)
    else:
        items = []
    return items
Exemple #4
0
def reg_supplier(userid):
    pool = Pool()
    pool_new(pool)
    uservalue = UserSignup.objects.get(id=userid)
    login_user(uservalue, remember=True)
    if current_user.usertype == 'Supplier':
        with regapp.app_context():
            form = SupplierForm()
        if request.method == 'POST' and form.validate():
            controler = SignUpControler()
            result = controler.regSupplierCotrl(request)
            if result == "Fail":
                logger.info('Failed to Supplier Registration ')
                return render_template('error.html',
                                       reportsof='Registration Failed')
            registeredUser = Reg_Supplier.objects(
                supplier_mail=current_user.email)
            if registeredUser.count() > 0:
                fo = open("./static/mailtemp/suppliermailtemp.html", "r+")
                htmlbody = fo.read()
                fo.close()
                urldata = "Your registration process is  in progress. Our marketing team will contact and update shortly. "
                htmlbody = htmlbody.replace("$$urldata$$", urldata)
                #sendMail(registeredUser[0].supplier_mail,'Supplier have registered successfully',htmlbody)
                pool.apply_async(sendMail, [
                    registeredUser[0].supplier_mail,
                    'Our marketing team is verifying the details. Will get back to you shortly',
                    htmlbody
                ])
                msg = "Your registration process is  in progress. Our marketing team will contact and update shortly. "
                #mobile='91'+registeredUser[0].supplier_mobile
                mobileList = []
                mobileList.append(registeredUser[0].supplier_isd +
                                  registeredUser[0].supplier_mobile)
                #SMS(msg,mobile)
                pool.apply_async(SMS, [msg, mobileList])
                logger.info('Supplier Registration Sucessfully')
                registeredUser1 = UserSignup.objects(usertype="Admin")
                fo = open("./static/mailtemp/suppliermailtemp.html", "r+")
                htmlbody = fo.read()
                fo.close()
                adminmail = registeredUser1[0].email
                #print adminmail
                urldata = 'New user ' + registeredUser[
                    0].supplier_name + ' is registered. Login and confirm the user details.'
                htmlbody = htmlbody.replace("$$urldata$$", urldata)
                #sendMail(email,'Supplier Verification & Approval',htmlbody)
                pool.apply_async(sendMail, [
                    adminmail, 'New user registration under review', htmlbody
                ])
                msg = 'New user ' + registeredUser[
                    0].supplier_name + ' is registered. Login and confirm the user details.'
                mobileList = []
                mobileList.append("91" + registeredUser1[0].mobile)
                #SMS(msg,mobileList)
                pool.apply_async(SMS, [msg, mobileList])
                return render_template(
                    'error.html',
                    form=form,
                    reportsof='Supplier have registered sucessfully',
                    msg="Thank you, <br> Please check your Email and Mobile.",
                    userinfo=current_user)
            else:
                form.email.errors.append("Email not available with us!")
                return render_template(
                    'error.html',
                    form=form,
                    reportsof='Email not available with us!')
        else:
            empDetails = UserSignup.objects.get(email=current_user.email)
            form.supplier_name.data = empDetails.username
            form.supplier_mail.data = empDetails.email
            form.supplier_mobile.data = empDetails.mobile
            form.supplier_email.data = empDetails.email
            country = Country.objects()
            #print i.country_std_isd
            return render_template('supplier-register.html',
                                   form=form,
                                   country=country)
    return render_template('error.html', reportsof='Unauthorized out ....')