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


Python Session.delete方法代码示例

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


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

示例1: delete

# 需要导入模块: from kazhal.model import Session [as 别名]
# 或者: from kazhal.model.Session import delete [as 别名]
    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,代码行数:14,代码来源:addgroup.py

示例2: delete

# 需要导入模块: from kazhal.model import Session [as 别名]
# 或者: from kazhal.model.Session import delete [as 别名]
    def delete(self, id):
        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)

        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"))

        if user.user_name == "admin":
            h.flash("Did u lost your mind?! deleting admin user will destroy ur program!")
            return redirect(came_from)

        if user.pending:
            conf = Session.query(UserConfirm).filter_by(user_id=user.id).one()
            Session.delete(conf)
            delcommons(user)
            Session.delete(user)
        else:
            invoices = Session.query(Invoice).filter_by(customer_id=user.id).filter_by(pending=False).all()
            if invoices == []:
                invoices = Session.query(Invoice).filter_by(customer_id=user.id).all()
                for invoice in invoices:
                    for invoice_item in invoice.invoice_items:
                        Session.delete(invoice_item)
                    Session.delete(invoice)
                delcommons(user)
                Session.delete(user)
                h.flash("user and all his/her pending orders were deleted")
            else:
                h.flash(
                    "you can not delete users permanently with confirmed orders from this site.instead this user has been marked as deleted and is unable to use his/her account anymore"
                )
                user.deleted = True
                Session.add(user)
        Session.commit()
        h.flash(_("User %s deleted!") % user.user_name)
        return redirect(came_from)
开发者ID:vickyi,项目名称:PylonsSimpleCMS,代码行数:50,代码来源:user.py

示例3: confirmuser

# 需要导入模块: from kazhal.model import Session [as 别名]
# 或者: from kazhal.model.Session import delete [as 别名]
    def confirmuser(self):
        confirmcode = request.GET.get("confirmcode", "")
        try:
            conf = Session.query(UserConfirm).filter_by(confirm_code=confirmcode).one()
        except:
            h.flash(_("Wrong confirmation code"))
            redirect(url(controller="home", action="index"))
        if conf.confirm_code[:3] != u"cu-":
            h.flash(_("Not a user confirmation"))
            redirect(url(controller="product", action="list"))

        user = conf.user
        user.pending = False
        Session.add(user)
        Session.delete(conf)
        Session.commit()

        h.flash(_("Confirmation ok. you can now login with your user name and password"))
        redirect(url(controller="home", action="index"))
开发者ID:vickyi,项目名称:PylonsSimpleCMS,代码行数:21,代码来源:user.py

示例4: delete

# 需要导入模块: from kazhal.model import Session [as 别名]
# 或者: from kazhal.model.Session import delete [as 别名]
    def delete(self):
        """
        TODO: hmmm. how should I return an error to the upload dialon in case of ... anything?
        """
        id = request.params.get("id")
        try:
            photo = Session.query(Photo).filter_by(id=id).one()
        except:
            return httpexceptions.HTTPConflict()
        if photo.products != []:
            return HTTPResourceInUse()
        else:
            file_path = os.path.join(config["pylons.paths"]["static_files"], "pics", photo.file_path)
            thumb_path = os.path.join(config["pylons.paths"]["static_files"], "pics", "thumbs", photo.file_path)
            if os.path.isfile(file_path) or os.path.isfile(thumb_path):
                try:
                    os.remove(thumb_path)
                    os.remove(file_path)
                except:
                    pass

            Session.delete(photo)
            Session.commit()
            return
开发者ID:vickyi,项目名称:PylonsSimpleCMS,代码行数:26,代码来源:photo.py

示例5: delcommons

# 需要导入模块: from kazhal.model import Session [as 别名]
# 或者: from kazhal.model.Session import delete [as 别名]
 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,代码行数:12,代码来源:user.py

示例6: _proccess_form

# 需要导入模块: from kazhal.model import Session [as 别名]
# 或者: from kazhal.model.Session import delete [as 别名]
    def _proccess_form(self, action, values, postto, id=-1, renderer=None):
        render_form = renderer
        if action.startswith(_("Add")):
            if action.endswith(_("Email")):
                return render_form(self.menu_items, action=postto, id=id, values=values, add_number_of_emails=1)

            elif action.endswith(_("Address")):
                return render_form(self.menu_items, action=postto, id=id, values=values, add_number_of_addresses=1)
            elif action.endswith(_("Phone")):
                return render_form(self.menu_items, action=postto, id=id, values=values, add_number_of_phones=1)
        elif action.startswith(_("Remove")):
            if action.count(_("Phone")) != 0:
                if id != -1 and values["phone-%i.id" % int(action.split(" ")[-1])] != "":
                    ph_idf = int(action.split(" ")[-1])
                    ph = values["phone-%i.id" % ph_idf]
                    phone = Session.query(Phone).filter_by(phone_number=ph).one()
                    Session.delete(phone)
                    Session.commit()
                new_values = remove_item(values, action, "phone")
                return render_form(self.menu_items, action=postto, id=id, values=new_values)

            elif action.count(_("Email")) != 0:
                if id != -1 and values["email-%i.email_address" % int(action.split(" ")[-1])] != "":
                    em_idf = int(action.split(" ")[-1])
                    em = values["email-%i.email_address" % em_idf]
                    email = Session.query(Email).filter_by(email_address=em).one()
                    Session.delete(email)
                    Session.commit()

                new_values = remove_item(values, action, "email")
                return render_form(self.menu_items, action="create", id=id, values=new_values)
            elif action.count(_("Address")) != 0:
                if id != -1 and values["address-%i.id" % int(action.split(" ")[-1])] != "":
                    add_idf = int(action.split(" ")[-1])
                    add_id = int(values["address-%i.id" % add_idf])
                    address = Session.query(Address).filter_by(id=add_id).one()
                    Session.delete(address)
                    Session.commit()
                new_values = remove_item(values, action, "address")
                return render_form(self.menu_items, action=postto, id=id, values=new_values)
        return False
开发者ID:vickyi,项目名称:PylonsSimpleCMS,代码行数:43,代码来源:user.py

示例7: createcustomer

# 需要导入模块: from kazhal.model import Session [as 别名]
# 或者: from kazhal.model.Session import delete [as 别名]
    def createcustomer(self):
        readsettings()
        values = dict(request.params)
        # create the pending user
        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"))
            c.came_from = values["came_from"]
            if request.GET.get("came_from", None):
                h.flash(_("After filling the from you will be sent back to your shopping cart"))
            html = render("/derived/user/new.html")
            return htmlfill.render(html, values, errors={"captcha": _("Invalid Captcha try again")})
        email = Email(email_address=self.form_result["email"], user=None)
        phone = Phone(None, str(self.form_result["phone"]), None)
        newcustormer = User(
            first_name=self.form_result["first_name"],
            last_name=self.form_result["last_name"],
            user_name=self.form_result["email"],
            password=self.form_result["password"],
            user_groups=[Session.query(Group).filter_by(group="customer").one()],
            SSN=None,
            birth_date=None,
            balance=0,
            photo=None,
            addresses=[],
            customer_invoices=[],
            staff_invoices=[],
            emails=[email],
            phones=[phone],
            deleted=False,
            pending=True,
        )
        # create the confirm link
        Session.add(newcustormer)

        # confurlcode = randint(10e40,10e49)
        confurlcode = str(uuid.uuid1())
        confurlcode = "cu-" + confurlcode

        conf = UserConfirm(newcustormer, confurlcode)
        Session.add(conf)

        newcustormer.confirmcode = [conf]
        Session.add(newcustormer)

        message = Message(
            session["site_settings"]["userconf"], self.form_result["email"], _("User registration"), encoding="utf-8"
        )
        plain = (
            "someone (hopefully you) registered an account with"
            + str(request.application_url)
            + "<br/>"
            + "for confirming your registration click the below link"
            + "<br/>"
            + unicode(request.application_url + url(controller="user", action="confirmuser", confirmcode=confurlcode))
            + "<br/>"
            + "After confirmation you can login with your Email address and password."
        )
        c.confurlcode = confurlcode
        registerHtml = render(_("/derived/emails/register.html"))
        message.plain = plain
        message.rich = registerHtml
        try:
            message.send()
        except:
            Session.delete(conf)
            Session.delete(phone)
            Session.delete(email)
            Session.delete(newcustormer)
            Session.rollback()
            h.flash(_("smtp error try again"))
            redirect(values["came_from"])

        Session.commit()
        h.flash(
            _(
                "Check your email and click the activation link after logging in you can continue with the purchuse in Shop online page"
            )
        )
        redirect(values["came_from"])
开发者ID:vickyi,项目名称:PylonsSimpleCMS,代码行数:87,代码来源:user.py

示例8: redirect

# 需要导入模块: from kazhal.model import Session [as 别名]
# 或者: from kazhal.model.Session import delete [as 别名]
            h.flash(_("wrong reset confirmation info."))
            return redirect(url(controller="home", action="index"))
        c.user = user
        c.confcode = userconf.confirm_code
        c.menu_items = h.top_menu(self.menu_items, _("Customers"))
        return render("/derived/user/resetpass.html")

    @ActionProtector(is_anonymous())
    def resetpassEmailaction(self):
        values = dict(request.params)
        user = Session.query(User).filter_by(id=values["userid"]).one()
        schema = ResetpassEmail()
        try:
            resutl = schema.to_python(values, c)
        except Invalid, e:
            c.user = user
            c.confcode = values["confcode"]
            c.menu_items = h.top_menu(self.menu_items, _("Customers"))
            html = render("/derived/user/resetpass.html")
            return htmlfill.render(
                html, values, errors=variabledecode.variable_encode(e.unpack_errors() or {}, add_repetitions=False)
            )

        userconf = Session.query(UserConfirm).filter_by(confirm_code=values["confcode"]).one()
        user._set_password(resutl["password"])
        Session.add(user)
        Session.delete(userconf)
        Session.commit()
        h.flash(_("password resert succeffuly."))
        return redirect(url(controller="account", action="login"))
开发者ID:vickyi,项目名称:PylonsSimpleCMS,代码行数:32,代码来源:user.py

示例9: delete

# 需要导入模块: from kazhal.model import Session [as 别名]
# 或者: from kazhal.model.Session import delete [as 别名]
 def delete(self,id):
     producttag = Session.query(ProductTag).filter_by(id=id).one()
     h.flash(_('Tag %s deleted')%producttag.tag)
     Session.delete(producttag)
     Session.commit()
     return redirect(url(controller='producttag',action='index'))
开发者ID:vickyi,项目名称:PylonsSimpleCMS,代码行数:8,代码来源:producttag.py

示例10: redirect

# 需要导入模块: from kazhal.model import Session [as 别名]
# 或者: from kazhal.model.Session import delete [as 别名]
                    invoice_items.append(invoice_item)
                    totalprice += invoice_item.total_price
                else:
                    delitem = invoice_item
                if invoice.pending is False:                            
                    product = invoice_item.product
                    product.quantity += invoice_item.quantity                
                    customer.balance += invoice_item.total_price
                    #send mail to customer about returning founds?
                    Session.add(customer)
                    Session.add(product)                

            invoice.invoice_items= invoice_items
            invoice.total_price = totalprice
            Session.add(invoice)
            Session.delete(delitem)                                
            Session.commit()
            return redirect(url(controller='invoice',action='edit',id=invoice.id))

        elif action.startswith('Delete invoice'):
            return self._delete(invoice)

        elif action == 'recalc price':
            totalprice=0
            for item in result['items']:
                quantity = item['quantity']
                unitprice = item['unitprice']
                for invoice_item in invoice.invoice_items:            
                    if invoice_item.id == item['id']:
                        if invoice_item.quantity != quantity or invoice_item.unitprice != unitprice:
                            price = unitprice*quantity                        
开发者ID:vickyi,项目名称:PylonsSimpleCMS,代码行数:33,代码来源:invoice.py

示例11: save

# 需要导入模块: from kazhal.model import Session [as 别名]
# 或者: from kazhal.model.Session import delete [as 别名]
    def save(self):
        values = dict(request.params)
        photos_inform=[]
        for item in values:
            if item.startswith('product_id'):
                product_id = item.split('.')[-1]
            if item.startswith('oldphoto'):
                photos_inform.append(int(item.split('-')[-1]))                    
        product = Session.query(Product).filter_by(id=product_id).one()
        
        action = request.params.getone('action')        
        del values['action']      

        if action.startswith('Delete Photo'):                        
            photos = []
            photo_id = int(action.split(' ')[-1])
            for photo in product.photos:
                if photo.id != photo_id and photo.id in photos_inform:
                    photos.append(photo)
            #delte photo_id from disk and data base too
            for photo in product.photos:
                if photo.id == photo_id:
                    path = os.path.join(config['here'],'kazhal','public','pics',photo.file_path)
                    os.remove(path)
                    Session.delete(photo)
                    Session.commit()
            #end of delete procedure

            product.photos = photos
            Session.add(product)
            Session.commit()

            new_values = remove_item(values,action,'oldphoto')              
            return render_edit_form(self.menu_items,
                                    new_values,
                                    id=product_id,
                                    number_of_photos=number_of_photos(new_values),
                                    photos=photos)

        elif action.startswith(_('Remove photo')):
            new_values = remove_item(values,action,'photo')                
            return render_edit_form(
                self.menu_items,
                values=new_values,
                id=product_id,
                number_of_photos = number_of_photos(new_values),
                photos = product.photos
            )

        elif action == _('Add Photo'):
            return render_edit_form(
                self.menu_items,
                values=values,
                id=product_id,
                number_of_photos = number_of_photos(values)+1,
                photos = product.photos
            )
        else: #action is save
            schema = NewProductForm()
            try:
                result = schema.to_python(dict(request.params), c)
            except Invalid, e:
                return render_edit_form(
                    self.menu_items,
                    values=values,
                    id=product.id,
                    errors=variabledecode.variable_encode(
                        e.unpack_errors() or {},
                        add_repetitions=False
                        ),
                    number_of_photos=number_of_photos(values),
                    photos = product.photos
                )
            else:  
开发者ID:vickyi,项目名称:PylonsSimpleCMS,代码行数:76,代码来源:product.py

示例12: delete

# 需要导入模块: from kazhal.model import Session [as 别名]
# 或者: from kazhal.model.Session import delete [as 别名]
 def delete(self,id):
     usertag = Session.query(UserTag).filter_by(id=id).one()
     h.flash(_('Tag %s deleted')%usertag.tag)
     Session.delete(usertag)
     Session.commit()
     return redirect(url(controller='usertag',action='index'))
开发者ID:vickyi,项目名称:PylonsSimpleCMS,代码行数:8,代码来源:usertag.py


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