Pyramid+SQLAlchemy: create filter with multiple OR conditions

…my first step with Python…

When you add filter with multiple criterion conditions joined by AND, you simply put all conditions one after one separated by comma:

query = DBSession.query(SomeTable).filter(
                SomeTable.name.contains(search_str),
                SomeTable.description.contains(search_str),
                SomeTable.another_field.contains(search_str)
        )

But in case you need to join filter conditions with OR, the way is more tricky… I found this approach working for me:

Add import:

from sqlalchemy import or_

And then, your filter should look like this:

query = DBSession.query(SomeTable).filter(
            or_(
                SomeTable.name.contains(search_str),
                SomeTable.name.contains(search_string2),
                SomeTable.description.contains(search_str),
                SomeTable.another_field.contains(search_str)
            )
        )

Enjoy!





Why my code doesn’t work?!

Why my code doesn’t work?!

Maven: Everybody Knows Something

Maven: the global knowledge marketplace - connect, consult, profit.

Maven is a global network of professionals and thought leaders who seek to connect with others to share their knowledge. Maven’s proprietary “micro-consulting” platform allows its members to profit from their knowledge by participating in paid interactions with researchers, including short Telephone Consultations and Electronic Surveys.

Did you know that you are already a consultant?

Have you given someone advice on which product or service to choose? Answered a question about how you do your job? Explained a key technical term or concept? Described an accounting standard or law in “layman’s terms”? Shared your opinion on the future of your industry?

Think about it – when was the last time a friend, colleague, customer, or other acquaintance asked you to help them to better understand a topic or to make a more informed decision? Happens all the time, right?

That’s microconsulting – short bursts of knowledge, perspective, insight, and opinion that help others make better decisions.

So, how to profit from what you know?

  1. Sign up: becoming part of Maven‘s microconsulting network is quick, easy, and free. Simply select an hourly consulting rate and describe your background and knowledge, and Maven will handle the rest. It only takes a few minutes.
  2. Consult: when you are identified as potential match for a microconsulting opportunity, you will receive a notification from Maven. If you are qualified, accept the invitation to participate in a Telephone Consultation or Electronic Survey.
  3. Earn: you will be paid for your time spent on the phone during Telephone Consultations or a flat fee for responding to an Electronic Survey.

That’s all!





The advantages of the newly developed Windows 8

With the new Windows 8, the aim is to make connectivity as easy as possible, by eliminating any problems that it may have previously had. One specific improvement that Windows 8 will feature, is mobile broadband functionality that has been integrated into the OS. This will hopefully have been done without specialized applications from the hardware provider having been used, which will make everything a lot more simple than before.

Any uncertainty regarding locating and installing device drivers for mobile broadband will be removed, as has been explained by group program manager on Microsoft’s devices and networking team, Billy Anders. If this is a success, then users will be able to spend more time relaxing and chatting to friends or playing partypoker online, instead of searching for instructions and having to guess what to do when installing mobile broadband devices. The company have been able to do this as they have been working with their partners in mobile broadband and mobile operating across the industry.
Read the rest of this entry »

OS X: how to upgrade to Snow Leopard from local drive

This post is dedicated to people who like me have OS X 10.6 (Snow Leopard) disk image and have no DVD disk or 6Gb flash drive and want to upgrade from OS X 10.5 :)

I’m a total OS X newbie, but this way works for me and probably will help to someone. If you decided to try the way described below, you are doing this on your own risk!
Read the rest of this entry »





How to setup Apache/PHP/MySQL under OS X

A nice step-by-step guidelines about setting up Apache/PHP/MySQL on OS X for such Mac newbies like me…

:)

Nobody cares I produce messy HTML





How to run Windows under VirtualBox on Fedora Core

Recently I needed to install Windows XP under VirtualBox on my Fedora Core 9 mashine.

After a successfull VirtualBox installation, I got an error when trying to install Windows from .iso image:

VirtualBox can’t operate in VMX root mode. Please disable the KVM kernel extension, recompile your kernel and reboot (VERR_VMX_IN_VMX_ROOT_MODE).

The error message means your kernel has loaded kvm module which conflicts with VirtualBox.

How to fix the problem?
Read the rest of this entry »

L’viv photos in my brother’s blog

My brother took nice photos of L’viv – city where I live all my life. You may see more photos in his blog.

L'viv photo




Internet Explorer limits number of external CSS files to 32

Do you know IE has a limit of 32 external CSS files? Do you know each file should be up to 288Kb to get parsed?

I didn’t know and found this just a little bit of time ago. As Google says IE has a bug (well, someone names this a limitation which makes sense): number of external CSS files you can import is 32, everything beyond the 32th file will be ignored. In addition to this – CSS file size cannot exceed 288Kb, otherwise it will be ignored as well. This limit is present in Internet Explorer 6/7 and 8.

Seems IE is the only browser with such a limit, other browsers worked well for me with 33 external style sheets (Firefox, Opera, Safari, Google Chrome, Konqueror).

Solution: aggregate multiple CSS files in bigger ones. As my experience shows – most files are 5-20Kb in size, and one 40Kb file is faster than 8x5Kb.