当前位置: 首页>>代码示例>>Python>>正文


Python model.Session类代码示例

本文整理汇总了Python中kazhal.model.Session的典型用法代码示例。如果您正苦于以下问题:Python Session类的具体用法?Python Session怎么用?Python Session使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Session类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: list

    def list(self,id=None,page=1): 
        if "repoze.who.identity" in request.environ:
            user = request.environ.get('repoze.who.identity')['user']
            wholesale_tag = Session.query(UserTag).filter_by(tag='wholesale').one()
            if wholesale_tag in user.tags:
                c.wholesale=True
        c.tags = Session.query(ProductTag).all()
        c.menu_items = h.top_menu(self.menu_items,_('Shop online'))

        if session.has_key('product_querystr'):
            if session.has_key('paliasedtags'):
                for item in session['paliasedtags']:
                    exec(item)
            products = eval(session['product_querystr']+".filter(Product.deleted==False)")
            c.paginator = paginate.Page(products,
                                        page=int(request.params.get('page', page)),
                                        items_per_page = 10)
            html = render('/derived/product/list.html')
            return htmlfill.render(html,defaults=session['product_search_values'])
        else:
            products = Session.query(Product).filter_by(deleted=False)
            c.paginator = paginate.Page(products,
                                        page=int(request.params.get('page', page)),
                                        items_per_page = 10)
            return render('/derived/product/list.html')
开发者ID:vickyi,项目名称:PylonsSimpleCMS,代码行数:25,代码来源:product.py

示例2: createbasket

    def createbasket(self):
        came_from = str(request.GET.get('came_from', ''))
        values = dict(request.params)
        for item in values:
            if item.startswith('product_id.'):
                id = int(item.split('.')[-1])
                try:
                    product = Session.query(Product).filter_by(id=id).one()
                except:
                    h.flash(_('No product exist with ID: %s')%id)
                    redirect(url(controller='product',action='list'))
        if values['quant']!='':
            quantity = int(values['quant'])
        else:
            quantity =1        

        if session.has_key('basket'):
            session['basket'][id]=quantity
        else:
            session['basket']={id:quantity}
        product = Session.query(Product).filter_by(id=id).one()
        h.flash(_('%s of product %s added to basket')%(quantity,product.name))
        if came_from !='':            
            return redirect(came_from)
        redirect(url(controller='product',action='list'))
开发者ID:vickyi,项目名称:PylonsSimpleCMS,代码行数:25,代码来源:product.py

示例3: edit2

 def edit2(self,id):
     product = Session.query(Product).filter_by(id=int(id)).one()
     jd = jcal.gregorian_to_jd(product.buy_date.year, product.buy_date.month, product.buy_date.day)
     jalali = jcal.jd_to_jalali(jd)
     jalali = str(jalali[0])+'/'+str(jalali[1])+'/'+str(jalali[2])
     values={
         'code':product.code,
         'name':product.name,
         'brand':product.brand,
         'quantity':product.quantity,
         'description':product.description,
         'buy_price':product.buy_price,
         'sell_price':product.sell_price,
         'wholesale_price':product.wholesale_price,
         'buy_date':jalali,            
     }
     tags = Session.query(ProductTag).all()
     for i,tag in enumerate(tags):
         for ptag in product.tags:
             if ptag.tag == tag.tag:
                 values['tag-%i.%i'%(i,tag.id)]=1
     return render_edit2_form(
         self.menu_items,
         values,
         number_of_photos=number_of_photos(values),
         id=product.id,
         photos=product.photos)
开发者ID:vickyi,项目名称:PylonsSimpleCMS,代码行数:27,代码来源:product.py

示例4: create

 def create(self):
     values = dict(request.params)
     producttag = ProductTag(values['producttag'])
     Session.add(producttag)
     Session.commit()
     h.flash(_("Product tag %s created successfully")%values['producttag'])
     return redirect(url(controller='producttag',action='index'))
开发者ID:vickyi,项目名称:PylonsSimpleCMS,代码行数:7,代码来源:producttag.py

示例5: create

 def create(self):
     values = dict(request.params)
     usertag = UserTag(values['usertag'])
     Session.add(usertag)
     Session.commit()
     h.flash(_("User tag %s created successfully")%values['usertag'])
     return redirect(url(controller='usertag',action='index'))
开发者ID:vickyi,项目名称:PylonsSimpleCMS,代码行数:7,代码来源:usertag.py

示例6: update

 def update(self,id):
     values = dict(request.params)
     producttag = Session.query(ProductTag).filter_by(id=id).one()
     producttag.tag = values['producttag']
     Session.add(producttag)
     Session.commit()
     h.flash(_("Tag %s edited successfully")%producttag.tag)
     return redirect(url(controller='producttag',action='index'))
开发者ID:vickyi,项目名称:PylonsSimpleCMS,代码行数:8,代码来源:producttag.py

示例7: create

 def create(self):        
     #if Session.query(Group).filter_by(group=request.POST['group']).one() != None:
         #abort(404)
     newgroup = Group(request.POST['group'])
     newgroup.permissions = self.form_result['permissions']         
     Session.add(newgroup)
     Session.commit()
     h.flash(_('Group successfully Created.'))
     redirect(url(controller='addgroup', action='list'))
开发者ID:vickyi,项目名称:PylonsSimpleCMS,代码行数:9,代码来源:addgroup.py

示例8: delete

    def delete(self,id):
        if id is None:
            abort(404)
        group = Session.query(Group).filter_by(id=id).one()
        if group is None:
            abort(404)
        h.flash(_('Group successfully deleted.'))

        Session.delete(group)
        Session.commit()
        redirect(url(controller='addgroup', action='list'))
        return "Group Deleted"
开发者ID:vickyi,项目名称:PylonsSimpleCMS,代码行数:12,代码来源:addgroup.py

示例9: undelete

 def undelete(self, id):
     came_from = str(request.GET.get("came_from", "")) or url(controller="user", action="admin")
     try:
         user = Session.query(User).filter_by(id=id).one()
     except:
         h.flash(_("No user with ID:%s to delete" % id))
         return redirect(h.url(controller="user", action="index"))
     user.deleted = False
     Session.add(user)
     Session.commit()
     h.flash(_("User %s undeleted!") % user.user_name)
     return redirect(came_from)
开发者ID:vickyi,项目名称:PylonsSimpleCMS,代码行数:12,代码来源:user.py

示例10: save

 def save(self,id):
     if id is None:
         abort(404)
     group = self.form_result['group']
     del self.form_result['group']
     for k,v in self.form_result.items():
         if getattr(group, k) != v:
             setattr(group, k, v)        
     Session.add(group)
     Session.commit()
     response.status_int = 302
     response.headers['location'] = url(controller='addgroup', action='list')
     return "Moved temporarily"
开发者ID:vickyi,项目名称:PylonsSimpleCMS,代码行数:13,代码来源:addgroup.py

示例11: upload

    def upload(self):
        values = dict(request.params)
        overwrite = False
        if "files[]" in values:
            picfile = values["files[]"]
            fname = picfile.filename.replace(os.sep, "_")
            file_path = os.path.join(config["pylons.paths"]["static_files"], "pics", fname)
            if os.path.isfile(file_path):
                overwrite = True
            thumb_path = os.path.join(config["pylons.paths"]["static_files"], "pics", "thumbs", fname)
            watermark_path = os.path.join(config["pylons.paths"]["static_files"], "pics", "watermark2.PNG")
            permanent_file = open(file_path, "wb")
            shutil.copyfileobj(picfile.file, permanent_file)
            picfile.file.close()
            fsize = os.fstat(permanent_file.fileno())[6]
            if not overwrite:
                photo = Photo(fname)
                Session.add(photo)
                Session.commit()
            else:
                photo = Session.query(Photo).filter_by(file_path=fname).one()
            permanent_file.close()
            # use image magic to resize and water mark the photo
            call(["convert", file_path, "-strip", file_path])
            # convert "prepared/$i" -colorspace RGB "prepared/$i"
            call(["convert", file_path, "-colorspace", "RGB", file_path])
            # convert -resize 300x300 -quality 70% $img $img
            call(["convert", "-resize", "300x300", "-quality", "70%%", file_path, file_path])
            # convert -define jpeg:size=200x200 "$i" -thumbnail '69x69>' "thumbs/$i
            call(["convert", "-define", "jpeg:size=200x200", file_path, "-thumbnail", "69x69>", thumb_path])
            # composite -dissolve 6 -tile watermark2.PNG $img $img
            call(["composite", "-dissolve", "6", "-tile", watermark_path, file_path, file_path])

            session["photos"]["files"].append({"name": fname, "size": fsize, "id": photo.id})
            session.save()
        retval = []
        for item in session["photos"]["files"]:
            retdict = dict()
            retdict["name"] = item["name"]
            retdict["size"] = item["size"]
            retdict["id"] = item["id"]
            retdict["type"] = ("image\/jpeg",)
            retdict["url"] = "/pics/%s" % item["name"]
            retdict["thumbnail_url"] = "/pics/thumbs/%s" % item["name"]
            retdict["delete_url"] = "/photo/delete?id=%s" % item["id"]
            retdict["delete_type"] = "DELETE"
            if overwrite:
                retdict["info"] = "File over writen on photo with id %s" % item["id"]
            retval.append(retdict)

        return retval
开发者ID:vickyi,项目名称:PylonsSimpleCMS,代码行数:51,代码来源:photo.py

示例12: delcommons

 def delcommons(user):
     phones = Session.query(Phone).filter_by(user_id=user.id).all()
     addresses = Session.query(Address).filter_by(user_id=user.id).all()
     emails = Session.query(Email).filter_by(user_id=user.id).all()
     for phone in phones:
         Session.delete(phone)
     for address in addresses:
         Session.delete(address)
     for email in emails:
         Session.delete(email)
开发者ID:vickyi,项目名称:PylonsSimpleCMS,代码行数:10,代码来源:user.py

示例13: edit

    def edit(self,id):     
        values={}
        group = Session.query(Group).filter_by(id=id).one()
        values['group']= group.group

        c.permissions = Session.query(Permission).all()
        for i,perm in enumerate(c.permissions):
            for permission in group.permissions:
                if permission.name == perm.name:
                    values['permissions-%i.%i'%(i,perm.id)]= 1                

        c.menu_items = h.top_menu(self.menu_items,_('Customers'))
        html = render('/derived/group/edit.html')
        return htmlfill.render(html, defaults=values)
开发者ID:vickyi,项目名称:PylonsSimpleCMS,代码行数:14,代码来源:addgroup.py

示例14: forgotaction

    def forgotaction(self):
        values = dict(request.params)
        del values["action"]
        msg = ""
        settingsf = file(config["settings_file"], "rb")
        session["site_settings"] = pickle.load(settingsf)
        settingsf.close()
        session.save()

        captchres = h.captcha.submit(
            values["recaptcha_challenge_field"],
            values["recaptcha_response_field"],
            "6LepGccSAAAAAMfzDtmvyRjJ7-A1FWuJa5qUTxX2",
            session["site_settings"]["ip_address"],
        )
        if not captchres.is_valid:
            c.menu_items = h.top_menu(self.menu_items, _("Customers"))
            html = render("/derived/user/forgot.html")
            return htmlfill.render(html, values, errors={"captcha": _("Invalid Captcha try again")})

        user = Session.query(User).join(User.emails).filter(Email.email_address == values["email"]).one()
        confcode = str(uuid.uuid1())
        uconf = UserConfirm(user, confcode)
        Session.add(uconf)
        Session.commit()

        message = Message(
            session["site_settings"]["forgotpass"],
            user.emails[0].email_address,
            _("Kazhal trading Reset password"),
            encoding="utf-8",
        )
        msg += _("If you requested a password reset click the below link\n")
        ##msg += "%s%s"%(request.application_url,h.url(controller='user',action='resetpassEmail',id=user.id,confcode=confcode))
        msg += "%s%s" % (
            request.application_url,
            url(controller="user", action="resetpassEmail", id=user.id, confcode=confcode),
        )
        c.contents = msg
        msgHtml = render(_("/derived/emails/forgotpass.html"))
        message.rich = msgHtml
        message.plain = msg
        message.send()
        h.flash(
            _(
                "An email has been sent to your address.To reset your password check your email and  click on the confirm link."
            )
        )
        return redirect(url(controller="user", action="forgot"))
开发者ID:vickyi,项目名称:PylonsSimpleCMS,代码行数:49,代码来源:user.py

示例15: render_edit_form_admin

def render_edit_form_admin(menu_items,values=None, errors=None, id=None):    
    if "repoze.who.identity" in request.environ:
        user = request.environ.get('repoze.who.identity')['user']
        wholesale_tag = Session.query(UserTag).filter_by(tag='wholesale').one()
        if wholesale_tag in user.tags:
            c.wholesale = True
    c.menu_items = h.top_menu(menu_items,_('Shop online'))
    invoice = Session.query(Invoice).filter_by(id=int(id)).one()
    invoice_items = Session.query(Invoice_item).filter_by(invoice_id=invoice.id).order_by(Invoice_item.product_id).all()
    c.invoice_items = invoice_items
    c.invoice = invoice    
    if values is None:
        return render('/derived/invoice/staff/edit.html')
    else :
        html = render('/derived/invoice/staff/edit.html')
        return  htmlfill.render(html, defaults=values, errors=errors)
开发者ID:vickyi,项目名称:PylonsSimpleCMS,代码行数:16,代码来源:invoice.py


注:本文中的kazhal.model.Session类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。