what is the current state of user authentication? is it good to go with openid or another alternative, or we still have to write our own user/password?
I need to throw ValidationError containing anchor.
if not profile.activated():
raise ValidationError('Your profile is not activated. <a href="{% url resend_activation_key %}">Resend activation key</a>.')
What I need to modify to make this work?
I would like to iterate a calculation over a column of values in a MySQL database. I wondered if Django had any built-in functionality for doing this. Previously, I have just used the following to store each column as a list of tuples with the name table_column:
import MySQLdb
import sys
try:
conn = MySQLdb.connect (host = "localhost",
user = "user",
passwd="passwd",
db="db")
except MySQLdb.Error, e:
print "Error %d: %s" % (e.args[0], e.args[1])
sys.exit (1)
cursor = conn.cursor()
for table in ['foo', 'bar']:
for column in ['foobar1', 'foobar2']:
cursor.execute('select %s from %s' % (column, table))
exec "%s_%s = cursor.fetchall()" % (table, column)
cursor.close()
conn.commit()
conn.close()
Is there any functionality built into Django to more conveniently iterate through the values of a column in a database table? I'm dealing with millions of rows so speed of execution is important.
I have an IronPython script that looks for current running processes using WMI. The code looks like this:
import clr
clr.AddReference('System.Management')
from System.Management import ManagementClass
from System import Array
mc = ManagementClass('Win32_Processes')
procs = mc.GetInstances()
That last line where I call the GetInstances() method raises the following error:
Traceback (most recent call first):
File "<stdin>", line 1, in <module>
SystemError: Not Found
I am not understanding what's not being found?!? I believe that I may need to pass an instance of ManagementOperationObserver and of EnumerationOptions to GetInstance() however, I don't understand why that is, since the method with the signature Getinstance() is available in ManagementClass.
I have to send out letters to certain clients and I have a standard letter that I need to use. I want to replace some of the text inside the body of the message with variables.
Here is my maturity_letter models.py
class MaturityLetter(models.Model):
default = models.BooleanField(default=False, blank=True)
body = models.TextField(blank=True)
footer = models.TextField(blank=True)
Now the body has a value of this:
Dear [primary-firstname],
AN IMPORTANT REMINDER…
You have a [product] that is maturing on [maturity_date] with [financial institution].
etc
Now I would like to replace everything in brackets with my template variables.
This is what I have in my views.py so far:
context = {}
if request.POST:
start_form = MaturityLetterSetupForm(request.POST)
if start_form.is_valid():
agent = request.session['agent']
start_date = start_form.cleaned_data['start_date']
end_date = start_form.cleaned_data['end_date']
investments = Investment.objects.all().filter(maturity_date__range=(start_date, end_date), plan__profile__agent=agent).order_by('maturity_date')
inv_form = MaturityLetterInvestments(investments, request.POST)
if inv_form.is_valid():
sel_inv = inv_form.cleaned_data['investments']
context['sel_inv'] = sel_inv
maturity_letter = MaturityLetter.objects.get(id=1)
context['mat_letter'] = maturity_letter
context['inv_form'] = inv_form
context['agent'] = agent
context['show_report'] = True
Now if I loop through the sel_inv I get access to sel_inv.maturity_date, etc but I am lost in how to replace the text.
On my template, all I have so far is:
{% if show_letter %}
{{ mat_letter.body }} <br/>
{{ mat_letter.footer }}
{% endif %}
Much appreciated.
I am working on large numpy arrays, and some native numpy operations are too slow for my needs (for example simple operations such as "bitwise" A&B).
I started looking into writing C extensions to try and improve performance. As a test case, I tried the example given here, implementing a simple trace calculation. I was able to get it to work, but was surprised by the performance: for a (1000,1000) numpy array, numpy.trace() was about 1000 times faster than the C extension!
This happens whether I run it once or many times. Is this expected? Is the C extension overhead that bad? Any ideas how to speed things up?
A minimal example:
class MainWindow(QtGui.QMainWindow):
def __init__(self, parent = None):
QtGui.QMainWindow.__init__(self, parent)
winWidth = 683
winHeight = 784
screen = QtGui.QDesktopWidget().availableGeometry()
screenCenterX = (screen.width() - winWidth) / 2
screenCenterY = (screen.height() - winHeight) / 2
self.setGeometry(screenCenterX, screenCenterY, winWidth, winHeight)
layout = QtGui.QVBoxLayout()
layout.addWidget(FormA())
mainWidget = QtGui.QWidget()
mainWidget.setLayout(layout)
self.setCentralWidget(mainWidget)
FormA is a QFrame with a VBoxLayout that can expand to an arbitrary number of entries.
In the code posted above, if the entries in the forms can't fit in the window then the window itself grows. I'd prefer for the window to become scrollable. I've also tried the following...
replacing
mainWidget = QtGui.QWidget()
mainWidget.setLayout(layout)
self.setCentralWidget(mainWidget)
with
mainWidget = QtGui.QScrollArea()
mainWidget.setLayout(layout)
self.setCentralWidget(mainWidget)
results in the forms and entries shrinking if they can't fit in the window.
Replacing it with
mainWidget = QtGui.QWidget()
mainWidget.setLayout(layout)
scrollWidget = QtGui.QScrollArea()
scrollWidget.setWidget(mainWidget)
self.setCentralWidget(scrollWidget)
results in the mainwidget (composed of the forms) being scrunched in the top left corner of the window, leaving large blank areas on the right and bottom of it, and still isn't scrollable.
I can't set a limit on the size of the window because I wish for it to be resizable.
How can I make this window scrollable?
Write an iterative program that finds the largest number of McNuggets that cannot be bought in exact quantity. Your program should print the answer in the following format (where the correct number is provided in place of n):
"Largest number of McNuggets that cannot be bought in exact quantity: n"
I have an application in Django 1.2.
Language is selectable (I18N and Locale = True)
When I select the english lang. in the site, the admin works OK. But when I change to any other language this is what happens with date inputs (spanish example):
Correctly, the input accepts the spanish format %d/%m/%Y (Even selecting from the calendar, the date inserts as expected). But when I save the form and load it again, the date shows in the english form: %Y-%m-%d
The real problem is that when I load the form to change any other text field and try to save it I get an error telling me to enter a valid date, so I have to write all dates again or change the language in the site to use the admin.
I haven't specified anything for DATE_INPUT_FORMATS in settings nor have I overridden forms or models.
Surely I am missing something but I can't find it. Can anybody give me a hint?
i have a file having around 1 lakh lists and have a another file with again a list of around an average of 50..
I want to compare 2nd item of list in second file with the 2nd element of 1st file and repeat this for each of the 50 lists in 2nd file and get the result of all the matching element.
I have written the code for all this,but this is taking a lot of time as it need to check the whole the 1lakh list some 50 times..i want to improve the speed...
please tell me how can i do this....
i cant not post my code as it is part of big code and will be difficult to infer anything from that...
please tell what can be done to improve the speed??
thank u,
There are plenty of question asking Which Programming Language Should I Learn? but I have not found an answer yet to the question what really motivates people to learn a specific new language?.
There are the people who think they should learn a new language every year for educational purpose. How do they decide on the languages to be learned?
Then I guess there are people who learn a new language because people around them told it is a fun language and they can build nice things with it.
Of course if the current job requires it people would learn a new language but I think if the language seems to have a potential to earn money (e.g. There are plenty of jobs in Java or ObjectiveC can be used to write apps for the iPhone and make money).
So why are you learning a new language or why have you learned the languages you know?
On my local machine the script runs fine but in the cloud it 500 all the time. This is a cron task so I don't really mind if it takes 5min...
:
Any idea whether it's possible to increase the timeout?
Thanks,
rui
I have created an array thusly:
import numpy as np
data = np.zeros( (512,512,3), dtype=np.uint8)
data[256,256] = [255,0,0]
What I want this to do is display a single red dot in the center of a 512x512 image. (At least to begin with... I think I can figure out the rest from there)
Hi all
I dont know if its a django bug or a feature but i have a strange ORM behaviour with MySQL.
class Status(models.Model):
name = models.CharField(max_length = 50)
class Article(models.Model)
status = models.ForeignKey(status, blank = True, null=True)
filters = Q(status__in =[0, 1,2] ) | Q(status=None)
items = Article.objects.filter(filters)
this returns Article items but some have other status than requested [0,1,2,None]
looking at the sql query :
SELECT [..] FROM `app_article` LEFT OUTER JOIN `app_status` ON (`app_article`.`status_id` = `app_status`.`id`) WHERE (`app_article`.`status_id` IN (1, 2) OR `app_status`.`id` IS NULL) ORDER BY [...]
the OR app_status.id IS NULL part seems to be the cause. if i change it to OR app_article.status_id IS NULL it works correctly.
How to deal with this ?
Thanx.
my model is :
class MyUser(db.Model):
user = db.UserProperty()
password = db.StringProperty(default=UNUSABLE_PASSWORD)
email = db.StringProperty()
nickname = db.StringProperty(indexed=False)
and my method which want to get all username is :
s=[]
a=MyUser.all().fetch(10000)
for i in a:
s.append(i.username)
and the error is :
AttributeError: 'MyUser' object has no attribute 'username'
so how can i get all 'username',
which is the simplest way .
thanks
a = 7
for a in range(10):
if a == 7:
pass
if a == 8:
pass
if a == 9:
pass
else:
print "yes"
how to write it shortly?
#like this or... help
if a ?????[7,8,9]:
pass
I want to make Waf generate a beep when it finishes the execution of any command that took more than 10 seconds.
I don't know how do add this and assure that the code executes when Waf exits.
This should run for any Waf command not only build.
I checked the Waf book but I wasn't able to find any indication about how should I do this.
Hi, I am stumped...
I am trying to get the following output until a certain condition is met.
test_1.jpg
test_2.jpg
..
test_50.jpg
The solution (if you could remotely call it that) that I have is
fileCount = 0
while (os.path.exists(dstPath)):
fileCount += 1
parts = os.path.splitext(dstPath)
dstPath = "%s_%d%s" % (parts[0], fileCount, parts[1])
however...this produces the following output.
test_1.jpg
test_1_2.jpg
test_1_2_3.jpg
.....etc
The Question: How do I get change the number in its current place (without appending numbers to the end)?
Ps. I'm using this for a file renaming tool.
im using sqlalchemy, and i have a few polymorphic tables, and i want to sort by a column in one of the relationship.
i have tables a,b,c,d, with relationship a to b, b to c, c to d.
a to b is one-to-many
b to c and c to d are one-to-one, but polymorphic.
given an item in table a, i will have a list of items b, c, d (all one to one). how do i use sqlalchemy to sort them by a column in table d?
How to identify which server side script language was used with a web site?
Asp.Net? PHP? RoR? Java? or other?
For example, Which server side script language was used with stackoverflow.com?
Ok, so I've written some code that, for all intents and purposes, should work:
def checkComments(comments):
for comment in comments:
print comment.body
checkComments(comment.replies)
def processSub(sub):
sub.replace_more_comments(limit=None, threshold=0)
checkComments(sub.comments)
#login and subreddit init stuff here
subs = mysubreddit.get_hot(limit=50)
for sub in subs:
processSub(sub)
However, given a submission that has 50 nested replies like so:
root comment
-> 1st reply
-> 2nd reply
-> 3rd reply
...
-> 50th reply
The above code only prints:
root comment
1st reply
2nd reply
3rd reply
4th reply
5th reply
6th reply
7th reply
8th reply
9th reply
Any idea how I can get the remaining 41 levels of replies? Or is this a praw limitation?
hi people, i wanna make change in css class every 3 loop. In the first three i want to use the CSS class A, in the next three i want to use the CSS class B, in the next three i want to use the CSS class A again and so on.
can anyone help? Thanks
As an experiment, I did this:
letters=['a','b','c','d','e','f','g','h','i','j','k','l']
for i in letters:
letters.remove(i)
print letters
The last print shows that not all items were removed ? (every other was).
IDLE 2.6.2
>>> ================================ RESTART ================================
>>>
['b', 'd', 'f', 'h', 'j', 'l']
>>>
What's the explanation for this ? How it could this be re-written to remove every item ?