Example #1
0
def index():
    from shops import Shop
    from gluon.contrib.pysimplesoap.client import SoapClient
    import time
    Shop(db)
    shops = db((db.shop.id > 0) & (db.shop.user == auth.user_id)).select()
    form = None

    if not shops:
        from queuemail import Queuemail
        Queuemail(db)
        firstname = Field(
            'first_name',
            'string',
            length=128,
            notnull=True,
            requires=IS_NOT_EMPTY(
                error_message=
                'Para dirigirnos a usted y para los clientes en su tienda'))
        lastname = Field(
            'last_name',
            'string',
            length=128,
            notnull=True,
            requires=IS_NOT_EMPTY(
                error_message=
                'Para dirigirnos a usted y para los clientes en su tienda'))
        shopname = Field(
            'name',
            'string',
            length=80,
            notnull=True,
            unique=True,
            requires=[
                IS_NOT_EMPTY(
                    error_message='No olvide decirnos el nombre de su tienda'),
                IS_NOT_IN_DB(db,
                             'shop.name',
                             error_message="Este nombre ya está siendo usado")
            ])
        hostname = Field(
            'host',
            'string',
            length=45,
            notnull=True,
            unique=True,
            requires=[
                IS_MATCH(
                    '^\w+$',
                    'Sólo letras y números, ni espacios ni caracteres especiales'
                ),
                IS_NOT_EMPTY(
                    error_message=
                    'Más adelante podrás poner tu propio dominio, pero ahora es importante este dato'
                ),
                IS_NOT_IN_DB(db,
                             'shop.host',
                             error_message="Este nombre ya está siendo usado")
            ])
        form = SQLFORM.factory(firstname,
                               lastname,
                               shopname,
                               hostname,
                               submit_button='Crear Tienda')
        if form.validate():
            try:
                #almacena los datos
                dbdata = "%s" % str(time.time()).replace('.', '')
                shopid = db.shop.insert(
                    user=auth.user_id,
                    host=form.vars.host,
                    db_name="gex%s" % dbdata,
                    db_user="******" % dbdata,
                    name=form.vars.name,
                    email=auth.user.email,
                    first_name=form.vars.first_name,
                    last_name=form.vars.last_name,
                    country='es',
                    language='es',
                )
                db(db.auth_user.id == auth.user).update(
                    first_name=form.vars.first_name,
                    last_name=form.vars.last_name)

                client = SoapClient(
                    wsdl=
                    "http://localhost:8000/internalgexcommerce/default/call/soap?WSDL=None"
                )
                if client.addShopSite(auth.user_id, shopid)['result'] == "0":
                    db(db.shop.id == shopid).update(status="enabled")
                    db.commit()

                else:
                    db.rollback()
                    session.flash = "Ocurrió un error al generar la tienda."
                    redirect(URL('index'))

            except Exception as ex:
                logger.debug(ex)
                db.rollback()
                session.flash = "Ocurrió un error al generar la tienda."
                redirect(URL('index'))

            session.flash = "En unos minutos recibirá un correo con los datos de su nueva tienda"
            redirect(URL('index'))
        elif form.errors:
            response.flash = 'Revise los campos erróneos'

    return dict(shops=shops, form=form)
Example #2
0
def createmanualshop():
    if auth.has_membership('superadministradores') or auth.has_membership(
            'administradores'):
        from shops import Shop
        from gluon.contrib.pysimplesoap.client import SoapClient
        import time
        Shop(db)
        if request.args(0):
            firstname = Field(
                'first_name',
                'string',
                length=128,
                notnull=True,
                requires=IS_NOT_EMPTY(
                    error_message=
                    'Para configurar en la aplicación del Host el nombre del administrador'
                ))
            lastname = Field(
                'last_name',
                'string',
                length=128,
                notnull=True,
                requires=IS_NOT_EMPTY(
                    error_message=
                    'Para configurar en la aplicación del Host el nombre del administrador'
                ))
            applicationtitle = Field(
                'name',
                'string',
                length=80,
                notnull=True,
                unique=True,
                requires=[
                    IS_NOT_EMPTY(error_message='Nombre de la web o tienda'),
                    IS_NOT_IN_DB(
                        db,
                        'shop.name',
                        error_message="Este nombre ya está siendo usado")
                ])
            hostname = Field(
                'host',
                'string',
                length=45,
                notnull=True,
                unique=True,
                requires=[
                    IS_MATCH(
                        '^\w+$',
                        'Sólo letras y números, ni espacios ni caracteres especiales'
                    ),
                    IS_NOT_EMPTY(
                        error_message=
                        'Más adelante podrás poner tu propio dominio, pero ahora es importante este dato'
                    ),
                    IS_NOT_IN_DB(
                        db,
                        'shop.host',
                        error_message="Este nombre ya está siendo usado")
                ])
            form = SQLFORM.factory(firstname,
                                   lastname,
                                   applicationtitle,
                                   hostname,
                                   submit_button='Crear Tienda')
            if form.validate(keepvalues=True):
                try:
                    #almacena los datos
                    dbdata = "%s" % str(time.time()).replace('.', '')
                    shopid = db.shop.insert(
                        user=request.args(0),
                        host=form.vars.host,
                        db_name="gex%s" % dbdata,
                        db_user="******" % dbdata,
                        name=form.vars.name,
                        email=auth.user.email,
                        first_name=form.vars.first_name,
                        last_name=form.vars.last_name,
                        country='es',
                        language='es',
                    )
                    user = db.auth_user(request.args(0))
                    if not user.first_name or not user.last_name:
                        user.update_record(first_name=form.vars.first_name,
                                           last_name=form.vars.last_name)
                    client = SoapClient(
                        wsdl=
                        "http://localhost:8000/internalgexcommerce/default/call/soap?WSDL=None"
                    )
                    if client.addShopSite(request.args(0),
                                          shopid)['result'] == "0":
                        db(db.shop.id == shopid).update(status="enabled")
                        db.commit()
                    else:
                        db.rollback()
                        response.flash = "Ocurrió un error al generar la tienda."

                except Exception as ex:
                    logger.debug(ex)
                    db.rollback()
                    response.flash = "Ocurrió un error al generar la tienda."

            elif form.errors:
                response.flash = 'Revise los campos erróneos'

            return dict(form=form)

        else:

            redirect(URL(request.application, 'administrator', 'users'))
    else:
        redirect(URL(request.application, 'default', 'user/login'))
Example #3
0
def newshop():
    # if settings.prelaunch==True and not (auth.has_membership('administradores') or auth.has_membership('superadministradores')):
    # 	redirect(URL(request.application, 'communications','prelaunch'))

    from shops import Shop, DomainShop
    from gluon.contrib.pysimplesoap.client import SoapClient
    import time
    Shop(db), DomainShop(db)
    lenshops = db((db.shop.id > 0) & (db.shop.user == auth.user_id)).count()
    count = db.domainshops.id.count()
    countsdomainshops = int(
        db((db.shop.id > 0) & (db.shop.user == auth.user_id)
           & (db.domainshops.shop == db.shop.id)).select(
               count,
               left=[db.domainshops.on(db.domainshops.shop == db.shop.id)
                     ]).first()['COUNT(domainshops.id)'])
    shopid = None
    if lenshops <= 10 + countsdomainshops:
        form = None
        from queuemail import Queuemail
        Queuemail(db)
        firstname = Field(
            'first_name',
            'string',
            length=128,
            notnull=True,
            requires=IS_NOT_EMPTY(
                error_message=
                'Para dirigirnos a usted y para los clientes en su tienda'))
        lastname = Field(
            'last_name',
            'string',
            length=128,
            notnull=True,
            requires=IS_NOT_EMPTY(
                error_message=
                'Para dirigirnos a usted y para los clientes en su tienda'))
        shopname = Field(
            'name',
            'string',
            length=80,
            notnull=True,
            unique=True,
            requires=[
                IS_NOT_EMPTY(
                    error_message='No olvide decirnos el nombre de su tienda'),
                IS_NOT_IN_DB(db,
                             'shop.name',
                             error_message="Este nombre ya está siendo usado")
            ])
        hostname = Field(
            'host',
            'string',
            length=45,
            notnull=True,
            unique=True,
            requires=[
                IS_MATCH(
                    '^\w+$',
                    'Sólo letras y números, ni espacios ni caracteres especiales'
                ),
                IS_NOT_EMPTY(
                    error_message=
                    'Más adelante podrás poner tu propio dominio, pero ahora es importante este dato'
                ),
                IS_NOT_IN_DB(db,
                             'shop.host',
                             error_message="Este nombre ya está siendo usado")
            ])
        form = SQLFORM.factory(firstname,
                               lastname,
                               shopname,
                               hostname,
                               submit_button=T('Create new store'))
        if form.validate():
            try:
                #almacena los datos
                dbdata = "%s" % str(time.time()).replace('.', '')
                shopid = db.shop.insert(
                    user=auth.user_id,
                    host=form.vars.host,
                    db_name="gex%s" % dbdata,
                    db_user="******" % dbdata,
                    name=form.vars.name,
                    email=auth.user.email,
                    first_name=form.vars.first_name,
                    last_name=form.vars.last_name,
                    country='es',
                    language='es',
                    ip=__get_ip_address('wlan0'),
                )

                client = SoapClient(
                    wsdl=
                    "http://localhost:8000/internalgexcommerce/default/call/soap?WSDL=None"
                )
                if client.addShopSite(auth.user_id, shopid)['result'] == "0":
                    db(db.shop.id == shopid).update(status="enabled")
                    db.commit()
                else:
                    db.rollback()
                    response.flash = "Ocurrió un error al generar la tienda."

                session.shopname = form.vars.host
            except Exception as ex:
                logger.debug(ex)
                db.rollback()
                response.flash = "Ocurrió un error al generar la tienda."

            session.flash = "En unos minutos recibirá un correo con los datos de su nueva instancia de tienda"
            redirect(URL('account', 'index'))
            # if request.vars.priceplan:
            # 	plan=db.priceplans(request.vars.priceplan)
            # 	if plan.paymode=='free':
            # 		redirect(URL('index'))
            # 	else:
            # 		redirect(URL('setdomain', vars=dict(plan=request.vars.priceplan, shop=shopid)))
            # else:
            # 	redirect(URL('plans'))
        elif form.errors:
            response.flash = 'Revise los campos erróneos'
    else:
        session.flash = "Ńo puede crear más tiendas. Contrate alguno de los planes de pago"

    return dict(form=form, domainshops=countsdomainshops)