python

Setting model level permissions in code for Django admin panel

Hi All, Is there a way to implement the permissions for models through the code? I have a large set of models and I want some of the models to be just viewable by the admin and not the ability to add them. Please suggest. ...

How to get out of def ()

hello guys for example i have def Hello(): and here is the code def Hello(): F = 'Y' if F == 'Y': #here i want get out of the Hello() to Hey()! by how! ...

upload file not working in google app engine

it should works but hitting the submit button redirect my page to http://localhost:8082/sign (http://localhost:8082 being the path to my app). There's no such path in my application thus it return a link broken page. Is this a common problem? ...

This code for creating a QPolygon in Pyqt is stopping my application! Help?

HI all, The following code: self.painter = QtGui.QPainter(self) self.painter.setRenderHint(QPainter.Antialiasing) self.painter.translate(482,395) self.painter.scale(300,300) self.painter.save() needle = Qt.QPolygon([QPoint(30, 0), QPoint(-30, 0), QPoint(0, 200)]) self.painter.setBrush(Qt.cyan) self.painter.setPen(Qt.black) self.painter...

strange python behaviour with mixing globals/parameters and function named 'top'

The following code (not directly in an interpreter, but execute as file) def top(deck): pass def b(): global deck produces the error SyntaxError: name 'deck' is local and global on python2.6.4 and SyntaxError: name 'deck' is parameter and global on python 3.1 python2.4 seems to accept this code, so does the 2.6.4 inter...

why we need sys.setdefaultencoding("utf-8") in py scipt

I have seem a few script use this at top of py script,i curised when i need use it ? import sys reload(sys) sys.setdefaultencoding("utf-8") ...

Hide app from taskbar

I'm trying to get my application hidden to systray and the systray thing works fine, except my app won't disspaear from the taskbar. The icon seem to dissapear, but another icon pops up and when I click to show that window I get a windowframe but the contents aren't drawn. def hideEvent(self, event): self.trayIcon.show() self.hi...

how to do non blocking accept() in Python?

Hello I cannot use threads thus I want to write a server program that can be interrupted after a while: d = show_non_modal_dialog("serving clients") s = socket(...) s.bind(...) s.listen() while (!user_pressed_cancel()) { s.accept() # timed accept for like 1 second if timed_out: continue serve_client close_client_sock } hid...

Why is there no "compound method call statement", i.e. ".="?

Lots of programming languages already have the compound statements +=, -=, /=, etc. A relatively new style of programming is to "chain" method calls onto each other, e.g. in Linq, JQuery and Django's ORM. I sometimes, more often than I'd like, find the need to do this in Django: # Get all items whose description beginning with A items ...

Python DB-API: how to handle different paramstyles?

I'm implementing a Python ontology class that uses a database backend to store and query the ontology. The database schema is fixed (specified in advance), but I don't know what type of database engine is being used. However, I can rely on the fact that the Python interface of the database engine uses the Python DB-API 2.0 (PEP 249). A s...

How do I get some slot/function to be executed when a certain QTableWidgetItem is checked / unchecked in PyQt

I have a dynamically created table, that has N rows and M QTableWidgetItems (that are only used as checkboxes) per row - I need to run code that knows the row and the column whenever a checkbox is checked or unchecked. My CheckBox subclass looks like: class CheckBox(QTableWidgetItem): def __init__(self): QTableWidgetItem.__...

Problem with web code generator designer

I want to write a web-based code generator for a Python crawler. Its aim is to automatically generate code so a developer doesn't need to write it, but I've run into this problem: in one of my project's webpages, there are some checkboxes, buttons, etc. Each of them generates some Python code and writes it to a common textarea. However, ...

Django-Python: Generate XML file from model data

I need to write model data (CharFields only) to an XML file to contain the data for a flash file. I am new to this, and the process is a little unclear to me for doing this in django. I am creating an xml file, and then writing the text data to the file (as is done with the csv module, but to xml). A very simplified xml file should re...

Generating all 5 card poker hands

This problem sounds simple at first glance, but turns out to be a lot more complicated than it seems. It's got me stumped for the moment. There are 52c5 = 2,598,960 ways to choose 5 cards from a 52 card deck. However, since suits are interchangeable in poker, many of these are equivalent - the hand 2H 2C 3H 3S 4D is equivalent to 2D 2S ...

How to read pcks#7 personal digital certificates with python?

Hi everyone, is it possible to read personal digital certificates with extension Pcks#7 ( http://en.wikipedia.org/wiki/X.509#Certificate_filename_extensions ) with python? I have to develop an application using Django that authenticate its users by reading their certificate. In an initial step we are going to use an external services t...

Google appengine-db.key()

Hi am going through the docs of GAE and needed a small clarification. If I have my db model something like this:- class Phone(Model): phone_name = db.StringProperty() r = Phone(Nokia, key_name='first') r.put() Now if I have to retrieve this entity but I dont know the key, can I construct the key like this: k=db.Key('Phone','first'...

Assert that a method was called in a Python unit test

Suppose I have the following code in a Python unit test: aw = aps.Request("nv1") aw2 = aps.Request("nv2", aw) Is there an easy way to assert that a particular method (in my case aw.Clear()) was called during the second line of the test? e.g. is there something like this: #pseudocode: assertMethodIsCalled(aw.Clear, lambda: aps.Request...

adding a subpackage from a different path

I have a python package called zypp. It is generated via swig and the rpm package (called python-zypp) puts it in: rpm -ql python-zypp /usr/lib64/python2.6/site-packages/_zypp.so /usr/lib64/python2.6/site-packages/zypp.py Now, I have a different project which provides an additional sets of APIs. Pure python. Plus some scripts. The la...

Best way to change the value of "settings" from within a Python test case?

I'm writing unit tests in Python for the first time, for a Django app. I've struck a problem. In order to test a particular piece of functionality, I need to change the value of one of the app's settings. Here's my first attempt: def test_in_list(self): mango.settings.META_LISTS = ('tags',) tags = Document(filepath).meta['tags']...

Python, using os.system - Is there a way for Python script to move past this without waiting for call to finish?

I am trying to use Python (through Django framework) to make a Linux command line call and have tried both os.system and os.open but for both of these it seems that the Python script hangs after making the command line call as the call is for instantiating a server (so it never "finishes" as its meant to be long-running). I know for doin...