Python Daily
2.57K subscribers
1.48K photos
53 videos
2 files
38.9K links
Daily Python News
Question, Tips and Tricks, Best Practices on Python Programming Language
Find more reddit channels over at @r_channels
Download Telegram
Do you even log? Questions about your logging habbits considering web apps...

Hey Flask Users,

I am interested in what you are logging in your web apps.
E.g.

+ User activities
+ Http Headers
+ Authentications
+ Errors/Warnings
+ ...

How do you log these things:

+ In a database
+ Files
+ Mails
+ Do you summarize your logs automatically?

And which technology/place you use:

+ Flask
+ Webserver
+ Frontend/js

At the moment I am just logging Python and Flask errors and warnings in a text file using Flask. Additionaly I use the standard logs of Apache Webserver (basic information about single requests and web server errors). But as I am planning to make one of my apps public I probably increase and improve my logging habbits to ensure a stable and safe service for my users...

/r/flask
https://redd.it/6xyxyk
# 1
# 2
# 3
# 4
[AF] Help with combining two Flask-SqlAlchemy queries into one

I have looked myself blind on this issue. Is anybody familiar with SqlAlchemy and can help me in the right direction with combining the following two queries into one query, giving a total count?

unread_count1 = models.MessageThread.query.join(models.AppReg, models.MessageThread.source_app)\
.filter(and_(models.MessageThread.source_read == 0, models.MessageThread.source_archived == 0))\
.filter(models.AppReg.user_UID == g._user.uid)\
.count()

unread_count2 = models.MessageThread.query.join(models.AppReg, models.MessageThread.target_app)\
.filter(and_(models.MessageThread.target_read == 0, models.MessageThread.target_archived == 0))\
.filter(models.AppReg.user_UID == g._user.uid)\
.count()

/r/flask
https://redd.it/6y3agr
Best way to do dynamic models? (or any other solution?)

Hi all,
I want to implement the following:
A "document" is a collection of different "components" that can be just about anything (text, images, dates, links, output of custom scripts, whatever).
Each component can get status (draft, validated, disabled..), comments, history, validation etc.
We only know at runtime what kind of components a specific document will have, and how many.
I'm a bit lost on how to even get started. I saw some things about dynamic forms, but I can't really get how to relate this with a model.
Any suggestions on how to achieve that using Django? Or maybe it's not the right framework for what I want?
Thanks a lot!

/r/django
https://redd.it/6y78ih
What's everyone working on this week?

Tell /r/python what you're working on this week! You can be bragging, grousing, sharing your passion, or explaining your pain. Talk about your current project or your pet project; whatever you want to share.


/r/Python
https://redd.it/6y87sb
I want to make a minimal Mezzanine site. How do I start from "scratch?"

I've set up a virtual environment using `virtualenv` command. Then I ran these commands:

# Install from PyPI
$ pip install mezzanine

# Create a project
$ mezzanine-project myproject
$ cd myproject

# Create a database
$ python manage.py createdb

# Run the web server
$ python manage.py runserver

When I go to `localhost:8080`, I get the standard, basic Mezzanine site. But I want to make a minimal homepage with two main sections: A navbar up top and a big main section below.

It seems like a lot of work to change the basic Mezzanine theme to match what I want.

So what do I do if I want to start a Mezzanine website/page from scratch?

/r/django
https://redd.it/6y9cqc
PyData Conference

I am relatively new to python (can do the basics, but have few big projects). However, I am debating trying to transition my job from academia to data analyst around May.

My questions for this community:
1) Both in terms of learning new things and interacting with potential employers, is the upcoming PyData conference in New York something that I would benefit from attending?

2) Has anybody attended in the past? What was your experience like?

3) If I decide to attend, how should I prepare?

I should also mention that my college will pay between 50-75% of my total expenses.

I appreciate any thoughts!


/r/pystats
https://redd.it/6xuh5x
What is considered to be the definitive Python bible, so far as books go?

I've been doing software development for 20+ years, and I'm not looking for a beginners Python programming book. I'm looking for something more akin to Perl's Camel book - a definitive reference, that covers all aspects of the language.

Many thanks!

/r/Python
https://redd.it/6y8i05
[AF] Strange problem with output compounding if the a form is submitted within a short timeframe

This one has me stumped.

I have a WTForm that I'm using like so:

form = UserForm()
if form.validate_on_submit():
session['form'] = form.data
return redirect('/analysis')

and then on my analysis function in views.py:

@app.route('/analysis', methods=['GET', 'POST'])
def analysis_results(text=None):
image, answers = main(session.get('form', None))
uniques = answers['uniques']
del answers['uniques']
session['form'] = None # a hack...didn't actually help.
if answers == False:
flash('No viable schedules are possible with these settings. Revise your parameters and submit again.')
return render_template('analysis.html',
title='Analysis',
image=image,
schedules=uniques,
mutations=answers)

So as you can see, I'm calling my backend program (main), which receives the session cookie that has the form data. The problem is that if I go to my analysis page, its great the first time. But, if I go back to the form quickly enough and just submit the same info (or different) in a 30 second window, it processes the whole thing, and then it looks like the 'answers' output (a dict) contains more keys than it should, and these end up getting printed to the analysis page.

Thing is, if I wait more than 30 seconds, no problem.

Thing is, if I try to print the form data, it looks the same no matter what. Or I'm crazy. One of the two.

How the heck could my front end be jacking up my back end if the input form data seemingly stays the same? And its not a problem if I just wait a little? I'm very confused.

This probably wouldn't be an issue for 90% of my users, but if someone did encounter this problem, it would make them lose confidence in my project. Help appreciated.

/r/flask
https://redd.it/6yc6a1