예제 #1
0
파일: classes.py 프로젝트: Cossacs/moto
    def attr(self, name):
        if name == 'url':
            r = self.doc.request
            query = dict(hl = self.hl, disc = r('disc'), adpr = r('adpr'), cdef = r('cdef'))
            if isfiche(self.source):
                return self.doc.geturl(self.param[:1] + self.param[2:], 
                                       query = query, view = self.view, addmod = False)
            else:
                return self.doc.geturl(self.param[:const.PRODUCT_URL_LEN] + [self.partno1], 
                                       query = query, addview = False, addmod = False)
        elif name == 'image':
            return self.doc.getimage(self.id_image, self, self.param)

        elif name == 'imagebig':
            if isproduct(self.source) and self.images:
                return self.images[0]

        elif name == 'images':
            q = sql.get_fval(['id_image'], 'image_deps', 'id_obj')
            q = sql.order(q, 'id')
            res = []
            i = 1
            for id in self.db.fetchvals(q, [self.id]):
                img = self.doc.getimage(id, self, self.param, i)
                res.append(img)
                i += 1
            return res

        elif name == 'stored':                	
            qstore = sql.get_fval('SUM(quantity)', 'store', 'id_product')
            return self.db.fetchval(qstore, [self.id])

        elif name == 'store':
            fields = ['SUM(s.quantity) AS quantity', 'pr.val1 AS eta', 'peta.name AS etaname']
            f = ['p.id = s.id_store', 'id_product = %s']
            f.append('pr.id_prop = p.id')
            f.append('pr.name = "ETA"')
            f.append('peta.translit = pr.val1')
            qstore = sql.get_f(fields, ['store s', 'prop p', 'param pr', 'prop peta'], f)
            qstore = sql.group(qstore, 'eta')
            qstore = sql.order(qstore, 'eta')
            res = Storage()
            res.data = self.db.fetchobj(qstore, [self.id])
            res.quantity = self.stored
            res.available = True if self.stored else False
            q = sql.get_f('p.*', ['param pr', 'prop p'], ['pr.id_prop = %s', 'pr.name = "ETA"', 'p.translit = pr.val1'])
            res.default = self.db.fetchrowobj(q, [self.view.id_cat])
            return res

        return None
예제 #2
0
파일: classes.py 프로젝트: Cossacs/moto
    def save(self, afields = None):
        if afields:
            fields = afields
        else:
            fields = self.table.fields

        key = self.keyfield
        tab = self.table.name
        exists = self.id and self.db.fetchval(sql.get_fval(key, tab, key), [self.id])
        db = self.db.self()
        try:
            # UPDATE
            if exists:
                self.mode = MOD_UPD
                q = sql.update(fields, tab, key)
                vals = map(lambda field: self.get(field, None), fields) + [self.id]
            # INSERT
            else:
                self.mode = MOD_INS
                self.newid(db)
                q = sql.insert(fields, tab)
                vals = map(lambda field: self.get(field, None), fields)
            db.execute(q, vals, commit = True)
        finally:
            pass
예제 #3
0
파일: interface.py 프로젝트: Cossacs/moto
 def __fastid(self, params):
     # deleting '/image' prefix
     param = self.request.url[6:]
     crc = getcrc(param)
     q = sql.get_fval(['id_image'], 'mem_image_crc', 'crc')
     id = db.fetchval(q, [crc])
     return id
예제 #4
0
파일: utils.py 프로젝트: Cossacs/moto
def img_addcrc(db, param, id):
    crc = getcrc(param)

    q = sql.get_fval('crc', 'mem_image_crc', 'crc')
    if not db.fetchval(q, [crc]):
        q = sql.insert(['crc', 'id_image'], 'mem_image_crc')
        db.execute(q, [crc, id])
예제 #5
0
파일: interface.py 프로젝트: Cossacs/moto
    def __slowid(self, params):
        img = self.request.img
        url = self.request.url

        p = self.request.params
        # IMAGE - Property
        if len(p) == 1:
            q = sql.get_fval('id_image', 'prop', 'translit')
            id = db.fetchval(q, p[0])
            # Prop image by num
            if not id:
                mo = re.search(r'\-([a-z0-9])$', p[0])
                if mo:
                    f = ['p.id = id.id_obj', 'p.translit = %s', 'id.num = %s']
                    q = sql.get_f('id.id_image', ['image_deps id', 'prop p'], f)
                    plist = [p[0][:-len(mo.group(0))], mo.group(1)]
                    id = db.fetchval(q, plist)
            if id:
                url = url[6:]
        # IMAGE - Product
        else:
            pid = None
            if len(p) == const.IMAGE_URL_LEN + 1:
                pid = db.fetchval(sql.get_fval('id', 'product', 'partno1'), params[-1])
                if pid:
                    params.pop()
            DocCatalog.params(self, params)
            if not pid:
                pid = self.getpid()

            # Full Image
            if isint(img):
                q = sql.get_fval(['id_image'], 'image_deps', 'id_obj')
                q = sql.order(q, 'id_obj')
                idl = db.fetchvals(q, [pid])
                if (img > 0) and img <= len(idl):
                     id = idl[img - 1]
                else:
                     self.NotFound('Image Index %d out of range' % img)
            # Preview
            else:
                q = sql.get_fval(['id_image'], self.tproduct, 'id')
                id = db.fetchval(q, [pid])
        img_addcrc(db, url, id)
        return id
예제 #6
0
파일: database.py 프로젝트: Cossacs/moto
 def fetchobject(self, table, id, field = 'id'):
     if type(table) == list:
         t = table[0]
         f = map(lambda t2: '%s.%s = %s.%s' % (t, field, t2, field), table[1:])
         f.append('%s.%s = %s' % (t, field, '%s'))            
         q = sql.get_f(['*'], sql.joiner(table), f)
     else:
         q = sql.get_fval(['*'], table, field)
     return self.fetchrowobj(q, [id])
예제 #7
0
파일: classes.py 프로젝트: Cossacs/moto
    def load(self):
        Prop.load(self)

        if not 'source' in self:
            q = sql.get_fval(['prod_source'], 'cat', 'id')
            self.source = self.db.fetchval(q, [self.id])

        if self.source == None:
            self.doc.NotFound("Category prod_source is None")

        self.isproduct = isproduct(self.source)
        self.isfiche   = isfiche(self.source)
        self.isprice   = isprice(self.source)
예제 #8
0
파일: interface.py 프로젝트: Cossacs/moto
    def prodlist(self, doc, qsort):
        q = doc.sqlpids(doc.view.pview, self.ppair)
        pid = db.fetchvals(q)
        if not pid:
            self.NotFound('Fiche not found')
        pid = pid[0]

        k = doc.kseries
        modellist = map(lambda k: k.name, (k[1], k[3], k[2]))
        translist = map(lambda k: k.translit, doc.kseries)

        fiche = db.fetchobject(doc.tproduct, pid)
        fiche.model = '%s %s %s' % tuple(modellist)
        fiche.img   = doc.geturl(translist, ext = 'gif')
        fiche.imgs  = doc.geturl(translist, img ='preview', ext = 'gif')
        img_addcrc(db, fiche.img, fiche.id_image)
        img_addcrc(db, fiche.imgs, fiche.id_image)
        self.add(fiche = fiche)

        q = sql.get_fval(['*'], doc.tprice, 'id_product')
        if qsort[0][0] == 'name':
            qsort[0] = ('CAST(num AS UNSIGNED)', 'ASC')

        q = sql.group(q, 'num, name')
        q = sql.order(q, qsort)
        prices = db.fetchobj(q, [pid])
        log.t_trace('DOCatFiche.Prepare.Price requested')
        for row in prices:
            row.price = float(row.price) * float(site.config("CURRENCY", 2))
            row.price = doc.getprice(row.price, True, row.currency)
            row.code  = formatnumber(row.id, 9)
            row.req = row.req or ''
        log.t_trace('DOCatFiche.Price formatted')

        self.add(show_all = True)
        self.ppg = site.config('PROD_PER_PAGE', 2)
        self.prodcount = len(prices)

        i = self.ppg * (self.page - 1)
        prices = prices[i:i + self.ppg]

        log.t_trace('DOCatFiche.Prepare.Before return')
        return prices
예제 #9
0
파일: search.py 프로젝트: Cossacs/moto
    def SearchProduct(self, res, doc):
        db = self._db
        val = res.text.replace(' ', '').upper()
        val = real_translit(val)

        def getpid(field, value):
            q = sql.get_fval('id', 'product', field)
            return db.fetchval(q, [value])

        pid = None

        if isint(val, False):
            pid = pid or getpid('id', toint(val))
        pid = pid or getpid('partno1', val)
        pid = pid or getpid('partno2', val)
        if pid:
            res.fillprod(pid, 'N')
            return True

        def getfid(field, value):
            t = 'fiche_price pc, fiche_prop_set ps'
            f = ['pc.id_product = ps.id_product']
            f.append('ps.id_prop2 = %s')
            f.append('pc.%s = ' % field + '%s')
            q = sql.get_f('pc.id_product, ps.id, pc.id', t, f)
            return db.fetchrow(q, [idbb, value])

        q = sql.get_fval('id', 'prop', 'translit')
        idbb = db.fetchval(q, 'bikebandit')
        if isint(val, False):
            pid = pid or getfid('id', toint(val))
        pid = pid or getfid('partno1', val)
        pid = pid or getfid('partno2', val)
        if pid:
            res.fillprod(pid[0], 'F', pid[1], pid[2])
            return True
        return False
예제 #10
0
파일: search.py 프로젝트: Cossacs/moto
 def getpid(field, value):
     q = sql.get_fval('id', 'product', field)
     return db.fetchval(q, [value])
예제 #11
0
파일: classes.py 프로젝트: Cossacs/moto
 def load(self):
     q = sql.get_fval(['name', 'val1', 'val2', 'val3', 'val4'], 'param', 'id_prop')
     self.data = self.site.db.fetchobj(q, [self.idp]) or []
예제 #12
0
파일: classes.py 프로젝트: Cossacs/moto
 def getgroup(id):
     q = sql.get_fval(['name'], 'prop_group', 'id')
     return self.db.fetchval(q, [id])
예제 #13
0
파일: classes.py 프로젝트: Cossacs/moto
 def __loadmap(self):
     q = 'pview_map pm LEFT JOIN prop_group pg ON pg.id = pm.id_group'
     q = sql.get_fval(['pg.name', 'pm.*'], q, 'pm.id_pview')
     q = sql.order(q, 'pm.num')
     self.map = self.db.fetchobj(q, [self.id])
예제 #14
0
파일: interface.py 프로젝트: Cossacs/moto
    def params(self, params):
        log.t_trace('dyna.params.start')
        if len(params) == 0:
            self.NotFound("Params length = 0")

        ptranslit = None
        if len(params) > 1:
            q = ['pv.id_cat = p.id', 'p.translit = %s', 'pv.translit = %s']
            q = sql.get_f('pv.translit', 'pview pv, prop p', q)
            ptranslit = db.fetchval(q, params[:2])
            if ptranslit:
                params.pop(1)


        self.opt.check = False
        self.k = self.getk(params)
        self.cat = classes.Cat(self, self.k[0])

        self.__settables()       
        self.__tryproduct(params)
        self.checkk(self.opt.dk, params)

        # Fetching view's information
        q = sql.get_fval(['*'], 'pview', 'id_cat')
        q = sql.order(q, 'num')
        log.t_trace('dyna.params.check3')

        self.view = None
        self.view0 = None
        self.views = []
        for row in db.fetchobj(q, [self.cat.id]):
            view = classes.View(self, row)

            self.views.append(view)
            
            if self.opt.pid:
                if view.main:
                    self.view = view
            elif ptranslit:
                if row.translit == ptranslit:
                    self.view = view
            else:
                if row.num == 1:
                    self.view = view

            if not self.view0 and (view.main or (self.cat.isfiche)):
                self.view0 = view

        if not self.view:
            self.NotFound("View is None (not found)")

        if not self.view0:
            self.NotFound("Default view is None (not found)")

        self.view.putk()
        self.view.parsemap()
        self.__markers()

        tlist = []
        exc = eval(self.cat.params('EXC_%s_HINTS' % self.view.pview) or '[]')
        for i in xrange(len(self.k)):
            if i in exc:
                continue
            tlist.append(self.k[i])
        self.title = formatname(tlist, lambda s: s.fname)

        plist = {}
        for k in self.kseries:
            p = k.params
            for row in p.data:
                plist[str(row.name)] = p(row.name, 1)
        self.addshared(**plist)

        self.add(price_min = parse_price_def(self.site.config, self('price_min')))
        self.add(price_max = parse_price_def(self.site.config, self('price_max')))

        self.savelist('show_store', 'price_min', 'price_max', 'list_view')
        log.t_trace('dyna.params.end')
예제 #15
0
파일: kernel.py 프로젝트: Cossacs/moto
 def load(self):
     self.idp = db.propbytr("sparams")
     q = sql.get_fval(['name', 'val1', 'val2', 'val3', 'val4'], 'param', 'id_prop')
     self.__data = site.db.fetchdic(q, 'name', [self.idp])