From Kevin.Stone at jax.org Mon Feb 1 15:55:42 2016 From: Kevin.Stone at jax.org (Kevin Stone) Date: Mon, 1 Feb 2016 20:55:42 +0000 Subject: [Flask] User specific log files Message-ID: <1454360142384.38911@jax.org> ?Hi, I am not the most familiar with the python logging framework, and I think I need some help on developing an approach for creating user specific log files in Flask. It would be even better if someone has already done this before and could share their pattern. The problem I want to solve is this: 1) user1 and user2 both log in to the app 2) user1's activity is logged in "user1.log". user2's activity is logged in "user2.log". 3) No other user's activity should appear in that user's log file. Ideally, I would like to tap into existing loggers that I have (e.g. the app logger and the SQLAlchemy logger), but I don't know if that is possible. My first naive attempt simply registers additional handlers at login time to the app.logger. This created the appropriate log files, but they had all activity from all users writing to them. Any help or advice would be appreciated. Thanks, -Kevin The information in this email, including attachments, may be confidential and is intended solely for the addressee(s). If you believe you received this email by mistake, please notify the sender by return email as soon as possible. -------------- next part -------------- An HTML attachment was scrubbed... URL: From robertlagrant at gmail.com Mon Feb 1 17:26:48 2016 From: robertlagrant at gmail.com (Robert Grant) Date: Mon, 1 Feb 2016 22:26:48 +0000 Subject: [Flask] User specific log files In-Reply-To: <1454360142384.38911@jax.org> References: <1454360142384.38911@jax.org> Message-ID: Hi Kevin Just a couple of quick questions: 1) Do you have enough users to just log to a database and record a username with each log line? Just a suggestion to consider. 2) Can you post a minimal, verifiable and complete example of your first attempt to give people something solid to critique? Thanks Rob On Mon, Feb 1, 2016 at 8:55 PM, Kevin Stone wrote: > ?Hi, > > > I am not the most familiar with the python logging framework, and I think > I need some help on developing an approach for creating user specific log > files in Flask. It would be even better if someone has already done this > before and could share their pattern. > > > > The problem I want to solve is this: > > 1) user1 and user2 both log in to the app > > 2) user1's activity is logged in "user1.log". user2's activity is logged > in "user2.log". > > 3) No other user's activity should appear in that user's log file. > > > > Ideally, I would like to tap into existing loggers that I have (e.g. the > app logger and the SQLAlchemy logger), but I don't know if that is > possible. My first naive attempt simply registers additional handlers at > login time to the app.logger. This created the appropriate log files, but > they had all activity from all users writing to them. > > > > Any help or advice would be appreciated. > > Thanks, > > -Kevin > > The information in this email, including attachments, may be confidential > and is intended solely for the addressee(s). If you believe you received > this email by mistake, please notify the sender by return email as soon as > possible. > > _______________________________________________ > Flask mailing list > Flask at python.org > https://mail.python.org/mailman/listinfo/flask > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From kelvin.malyar at gmail.com Tue Feb 2 10:12:54 2016 From: kelvin.malyar at gmail.com (Kelvin M) Date: Tue, 2 Feb 2016 10:12:54 -0500 Subject: [Flask] User specific log files In-Reply-To: References: <1454360142384.38911@jax.org> Message-ID: Hi Kevin, What are you trying to accomplish with multiple log files? In the past, the approach that I/we've taken is to just use a log aggregator. Either, Splunk or ELK (ElasticSearch, LogStash, Kibana). With both, you index all log messages and can then create reports or views for users independently. I know that ELK is really easy to set up and free. Would something like that work for you? Regards, Kelvin On Mon, Feb 1, 2016 at 5:26 PM, Robert Grant wrote: > Hi Kevin > > Just a couple of quick questions: > > 1) Do you have enough users to just log to a database and record a > username with each log line? Just a suggestion to consider. > 2) Can you post a minimal, verifiable and complete example of your first > attempt to give people something solid to critique? > > Thanks > > > Rob > > On Mon, Feb 1, 2016 at 8:55 PM, Kevin Stone wrote: > >> ?Hi, >> >> >> I am not the most familiar with the python logging framework, and I think >> I need some help on developing an approach for creating user specific log >> files in Flask. It would be even better if someone has already done this >> before and could share their pattern. >> >> >> >> The problem I want to solve is this: >> >> 1) user1 and user2 both log in to the app >> >> 2) user1's activity is logged in "user1.log". user2's activity is logged >> in "user2.log". >> >> 3) No other user's activity should appear in that user's log file. >> >> >> >> Ideally, I would like to tap into existing loggers that I have (e.g. the >> app logger and the SQLAlchemy logger), but I don't know if that is >> possible. My first naive attempt simply registers additional handlers at >> login time to the app.logger. This created the appropriate log files, but >> they had all activity from all users writing to them. >> >> >> >> Any help or advice would be appreciated. >> >> Thanks, >> >> -Kevin >> >> The information in this email, including attachments, may be confidential >> and is intended solely for the addressee(s). If you believe you received >> this email by mistake, please notify the sender by return email as soon as >> possible. >> >> _______________________________________________ >> Flask mailing list >> Flask at python.org >> https://mail.python.org/mailman/listinfo/flask >> >> > > _______________________________________________ > Flask mailing list > Flask at python.org > https://mail.python.org/mailman/listinfo/flask > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From unai at sysbible.org Tue Feb 2 10:17:53 2016 From: unai at sysbible.org (Unai Rodriguez) Date: Tue, 02 Feb 2016 23:17:53 +0800 Subject: [Flask] How to handle sent data through a form (post request) Flask-{Admin, Security} In-Reply-To: <1453825661.970402.503069506.75DBBA4D@webmail.messagingengine.com> References: <1453825661.970402.503069506.75DBBA4D@webmail.messagingengine.com> Message-ID: <1454426273.3944066.509688114.00FD79E2@webmail.messagingengine.com> Dear All, I guess my email was too lengthy. Apologies for that. If anyone else is interested in this topic I have been able to make great progress thanks to this fantastic write-up[1]. Thank you -- unai On Wed, Jan 27, 2016, at 12:27 AM, Unai Rodriguez wrote: > Dear List, > > I am trying to build a simple web admin interface where users will be > able to register and login to see some details of their account, etc. > > I have started by modifying the following Flask-Security example which > basically makes it easy to have all typical views: register, login, > forgot password, etc... > > https://github.com/flask-admin/Flask-Admin/tree/master/examples/auth > > I am having a hard time implementing the register page since it needs > to be integrated with a payment gateway that requires that the server > submits some information to their servers once the user has entered > the data. The idea is simple: a user enters basic information > including some credit card details on the register form which all gets > sent to our server through a post request. The thing is we will > probably not store the credit card details on the database but use > this information to create a transaction on the payment gateway. So I > need a way of having access to the data sent by this post request and > not to store it on the database (and perform some other actions). > > This is how my form class has been defined: > > class ExtendedRegisterForm(RegisterForm):??? # Fields??? plan = > SelectField('Plan', choices=[('alpha','alpha ($6.99)'),('gamma','gamma > ($14.99)'),('beta','beta ($29.99)')])??? cc_number = StringField('Card > number', render_kw={'maxlength':'19'})??? cc_name = StringField('Name > on card', render_kw={'maxlength':'50'})??? cc_exp_month = > StringField('month', [InputRequired(), Length(min=2, max=2)], > render_kw={'maxlength':'2'})??? cc_exp_year = StringField('year', > render_kw={'maxlength':'4'})??? cc_cvv = StringField('cvv', > render_kw={'maxlength':'4'}) > > How can I handle the post request? I've tried this but doesn't seem > to work: > > @app.route('/admin/register', methods=['POST']) def register(): > return render_template('thanks.html') > > Is it worth using this Flask-{Admin,Security} modules for what I'm > trying to do or you'd rather just do it from scratch? > > Thank you so much > > > -- unai > > _________________________________________________ > Flask mailing list Flask at python.org > https://mail.python.org/mailman/listinfo/flask Links: 1. https://www.reddit.com/r/learnpython/comments/2ooq1t/im_trying_to_learn_flask_i_want_to_make_a_web_app/ -------------- next part -------------- An HTML attachment was scrubbed... URL: From Kevin.Stone at jax.org Tue Feb 2 10:21:36 2016 From: Kevin.Stone at jax.org (Kevin Stone) Date: Tue, 2 Feb 2016 15:21:36 +0000 Subject: [Flask] User specific log files In-Reply-To: References: <1454360142384.38911@jax.org> , Message-ID: <1454426498458.63267@jax.org> We have a simple internal application for editing our database. There are about 20-30 users. We primarily want to see the user actions and SQL generated by the app, sometimes in realtime. ? ? When a user logs in and creates a session, I would like to be able to append a filehandler for that user to the main app logger. What I can't grasp in my head is that the app logger is global, but I only want this filehandler to act on that user's session. That's why when I tried it it logged all user actions to every log file. ________________________________ From: Kelvin M Sent: Tuesday, February 2, 2016 10:12 AM To: Robert Grant Cc: Kevin Stone; flask at python.org Subject: Re: [Flask] User specific log files Hi Kevin, What are you trying to accomplish with multiple log files? In the past, the approach that I/we've taken is to just use a log aggregator. Either, Splunk or ELK (ElasticSearch, LogStash, Kibana). With both, you index all log messages and can then create reports or views for users independently. I know that ELK is really easy to set up and free. Would something like that work for you? Regards, Kelvin On Mon, Feb 1, 2016 at 5:26 PM, Robert Grant > wrote: Hi Kevin Just a couple of quick questions: 1) Do you have enough users to just log to a database and record a username with each log line? Just a suggestion to consider. 2) Can you post a minimal, verifiable and complete example of your first attempt to give people something solid to critique? Thanks Rob On Mon, Feb 1, 2016 at 8:55 PM, Kevin Stone > wrote: ?Hi, I am not the most familiar with the python logging framework, and I think I need some help on developing an approach for creating user specific log files in Flask. It would be even better if someone has already done this before and could share their pattern. The problem I want to solve is this: 1) user1 and user2 both log in to the app 2) user1's activity is logged in "user1.log". user2's activity is logged in "user2.log". 3) No other user's activity should appear in that user's log file. Ideally, I would like to tap into existing loggers that I have (e.g. the app logger and the SQLAlchemy logger), but I don't know if that is possible. My first naive attempt simply registers additional handlers at login time to the app.logger. This created the appropriate log files, but they had all activity from all users writing to them. Any help or advice would be appreciated. Thanks, -Kevin The information in this email, including attachments, may be confidential and is intended solely for the addressee(s). If you believe you received this email by mistake, please notify the sender by return email as soon as possible. _______________________________________________ Flask mailing list Flask at python.org https://mail.python.org/mailman/listinfo/flask _______________________________________________ Flask mailing list Flask at python.org https://mail.python.org/mailman/listinfo/flask The information in this email, including attachments, may be confidential and is intended solely for the addressee(s). If you believe you received this email by mistake, please notify the sender by return email as soon as possible. -------------- next part -------------- An HTML attachment was scrubbed... URL: From Kevin.Stone at jax.org Tue Feb 2 11:35:27 2016 From: Kevin.Stone at jax.org (Kevin Stone) Date: Tue, 2 Feb 2016 16:35:27 +0000 Subject: [Flask] User specific log files In-Reply-To: <1454426498458.63267@jax.org> References: <1454360142384.38911@jax.org> , , <1454426498458.63267@jax.org> Message-ID: <1454430929144.83414@jax.org> I have done some research and experimenting. There is a whole lot you can do with the python logging framework that I am unfamiliar with. I think I found something that will work for us, although maybe it's not the best solution. I was able to create a filehandler on user login that I attach a filter to. This filter tells the handler to only work when that user is logged into the session. Here is the filter code. class UserLoggingFilter(logging.Filter): """ Create a filter to only log the current user to its handler """ def __init__(self, user): self.user = user def filter(self, record): if 'user' in session and session['user'] == self.user: return True return False And here is more or less what the handler code is like. file_handler = FileHandler(user_log_file) file_handler.addFilter(UserLoggingFilter(user)) app.logger.addHandler(file_handler) ? This seems to work just great. I appreciate the help, and welcome any alternative suggestions, but at least I have one way that works. -Kevin ________________________________ From: Kevin Stone Sent: Tuesday, February 2, 2016 10:21 AM To: Kelvin M; Robert Grant Cc: flask at python.org Subject: Re: [Flask] User specific log files We have a simple internal application for editing our database. There are about 20-30 users. We primarily want to see the user actions and SQL generated by the app, sometimes in realtime. ? ? When a user logs in and creates a session, I would like to be able to append a filehandler for that user to the main app logger. What I can't grasp in my head is that the app logger is global, but I only want this filehandler to act on that user's session. That's why when I tried it it logged all user actions to every log file. ________________________________ From: Kelvin M Sent: Tuesday, February 2, 2016 10:12 AM To: Robert Grant Cc: Kevin Stone; flask at python.org Subject: Re: [Flask] User specific log files Hi Kevin, What are you trying to accomplish with multiple log files? In the past, the approach that I/we've taken is to just use a log aggregator. Either, Splunk or ELK (ElasticSearch, LogStash, Kibana). With both, you index all log messages and can then create reports or views for users independently. I know that ELK is really easy to set up and free. Would something like that work for you? Regards, Kelvin On Mon, Feb 1, 2016 at 5:26 PM, Robert Grant > wrote: Hi Kevin Just a couple of quick questions: 1) Do you have enough users to just log to a database and record a username with each log line? Just a suggestion to consider. 2) Can you post a minimal, verifiable and complete example of your first attempt to give people something solid to critique? Thanks Rob On Mon, Feb 1, 2016 at 8:55 PM, Kevin Stone > wrote: ?Hi, I am not the most familiar with the python logging framework, and I think I need some help on developing an approach for creating user specific log files in Flask. It would be even better if someone has already done this before and could share their pattern. The problem I want to solve is this: 1) user1 and user2 both log in to the app 2) user1's activity is logged in "user1.log". user2's activity is logged in "user2.log". 3) No other user's activity should appear in that user's log file. Ideally, I would like to tap into existing loggers that I have (e.g. the app logger and the SQLAlchemy logger), but I don't know if that is possible. My first naive attempt simply registers additional handlers at login time to the app.logger. This created the appropriate log files, but they had all activity from all users writing to them. Any help or advice would be appreciated. Thanks, -Kevin The information in this email, including attachments, may be confidential and is intended solely for the addressee(s). If you believe you received this email by mistake, please notify the sender by return email as soon as possible. _______________________________________________ Flask mailing list Flask at python.org https://mail.python.org/mailman/listinfo/flask _______________________________________________ Flask mailing list Flask at python.org https://mail.python.org/mailman/listinfo/flask The information in this email, including attachments, may be confidential and is intended solely for the addressee(s). If you believe you received this email by mistake, please notify the sender by return email as soon as possible. -------------- next part -------------- An HTML attachment was scrubbed... URL: From xancorreu at gmail.com Wed Feb 3 05:53:13 2016 From: xancorreu at gmail.com (Xan) Date: Wed, 3 Feb 2016 11:53:13 +0100 Subject: [Flask] Passing dict instead of Context in render_template Message-ID: <20160203115313.4d153d2b6f09bcbb6f8456de@gmail.com> Hi, I just want to know if I can do something like render_template(template, {'foo': 2, 'baa': 3}) instead of render_template(template, foo=2, baa=3). I want to pass a variable list of assignment. So I think that dict is the only solution. If I have: a = {'foo': 2, 'baa': 3, ...} How can I do, render_template(template, a)? (a has variable value) Thanks a lot, Xan PS: I asked in stackoverflow with a missunderstanding http://stackoverflow.com/questions/35117821/pass-a-list-of-assignments-in-a-template-in-a-flask From alejoar at gmail.com Wed Feb 3 06:09:33 2016 From: alejoar at gmail.com (Alejo Arias) Date: Wed, 3 Feb 2016 12:09:33 +0100 Subject: [Flask] Passing dict instead of Context in render_template In-Reply-To: <20160203115313.4d153d2b6f09bcbb6f8456de@gmail.com> References: <20160203115313.4d153d2b6f09bcbb6f8456de@gmail.com> Message-ID: Hi Xan, Did you try render_template(template, a=a)? You can then access your dict values from the template like so: {{ a['foo'] }} If 'foo' is a key that might not exist, you can use {{ a.get('foo', 'default result') }}. This will print 'default result' if foo doesn't exist. Regards, Alejo On 3 February 2016 at 11:53, Xan wrote: > Hi, > > I just want to know if I can do something like render_template(template, > {'foo': 2, 'baa': 3}) instead of render_template(template, foo=2, baa=3). I > want to pass a variable list of assignment. So I think that dict is the > only solution. > > If I have: > > a = {'foo': 2, 'baa': 3, ...} > > How can I do, render_template(template, a)? (a has variable value) > > > Thanks a lot, > Xan > > PS: I asked in stackoverflow with a missunderstanding > http://stackoverflow.com/questions/35117821/pass-a-list-of-assignments-in-a-template-in-a-flask > _______________________________________________ > Flask mailing list > Flask at python.org > https://mail.python.org/mailman/listinfo/flask > -------------- next part -------------- An HTML attachment was scrubbed... URL: From david at davidbaumgold.com Wed Feb 3 07:05:56 2016 From: david at davidbaumgold.com (David Baumgold) Date: Wed, 3 Feb 2016 07:05:56 -0500 Subject: [Flask] Passing dict instead of Context in render_template In-Reply-To: References: <20160203115313.4d153d2b6f09bcbb6f8456de@gmail.com> Message-ID: It would be simpler to use Python?s built-in argument list unpacking:?https://docs.python.org/2/tutorial/controlflow.html#tut-unpacking-arguments You can do something like this: context = {?foo?: 2, ?baa?: 3} return render_template(template, **context) On February 3, 2016 at 6:10:25 AM, Alejo Arias (alejoar at gmail.com) wrote: Hi Xan, Did you try?render_template(template, a=a)? You can then access your dict values from the template like so: {{ a['foo'] }} If 'foo' is a key that might not exist, you can use {{ a.get('foo', 'default result') }}. This will print 'default result' if foo doesn't exist. Regards, Alejo On 3 February 2016 at 11:53, Xan wrote: Hi, I just want to know if I can do something like render_template(template, {'foo': 2, 'baa': 3}) instead of render_template(template, foo=2, baa=3). I want to pass a variable list of assignment. So I think that dict is the only solution. If I have: a = {'foo': 2, 'baa': 3, ...} How can I do, render_template(template, a)? (a has variable value) Thanks a lot, Xan PS: I asked in stackoverflow with a missunderstanding http://stackoverflow.com/questions/35117821/pass-a-list-of-assignments-in-a-template-in-a-flask _______________________________________________ Flask mailing list Flask at python.org https://mail.python.org/mailman/listinfo/flask _______________________________________________ Flask mailing list Flask at python.org https://mail.python.org/mailman/listinfo/flask -------------- next part -------------- An HTML attachment was scrubbed... URL: From xancorreu at gmail.com Wed Feb 3 08:01:17 2016 From: xancorreu at gmail.com (Xan) Date: Wed, 3 Feb 2016 14:01:17 +0100 Subject: [Flask] Passing dict instead of Context in render_template In-Reply-To: References: <20160203115313.4d153d2b6f09bcbb6f8456de@gmail.com> Message-ID: <20160203140117.2d58616b6474bc18b0b8e4b5@gmail.com> Oh!!! Thanks a lot. To all of you. Ridiculous simple! ;-) On Wed, 3 Feb 2016 07:05:56 -0500 David Baumgold ha escrit: > It would be simpler to use Python?s built-in argument list unpacking:?https://docs.python.org/2/tutorial/controlflow.html#tut-unpacking-arguments > > You can do something like this: > > context = {?foo?: 2, ?baa?: 3} > return render_template(template, **context) > > On February 3, 2016 at 6:10:25 AM, Alejo Arias (alejoar at gmail.com) wrote: > > Hi Xan, > > Did you try?render_template(template, a=a)? > > You can then access your dict values from the template like so: {{ a['foo'] }} > > If 'foo' is a key that might not exist, you can use {{ a.get('foo', 'default result') }}. This will print 'default result' if foo doesn't exist. > > Regards, > Alejo > > On 3 February 2016 at 11:53, Xan wrote: > Hi, > > I just want to know if I can do something like render_template(template, {'foo': 2, 'baa': 3}) instead of render_template(template, foo=2, baa=3). I want to pass a variable list of assignment. So I think that dict is the only solution. > > If I have: > > a = {'foo': 2, 'baa': 3, ...} > > How can I do, render_template(template, a)? (a has variable value) > > > Thanks a lot, > Xan > > PS: I asked in stackoverflow with a missunderstanding http://stackoverflow.com/questions/35117821/pass-a-list-of-assignments-in-a-template-in-a-flask > _______________________________________________ > Flask mailing list > Flask at python.org > https://mail.python.org/mailman/listinfo/flask > > _______________________________________________ > Flask mailing list > Flask at python.org > https://mail.python.org/mailman/listinfo/flask From hsysinfo at gmail.com Wed Feb 3 10:15:54 2016 From: hsysinfo at gmail.com (Chukwudi Nwachukwu) Date: Wed, 3 Feb 2016 16:15:54 +0100 Subject: [Flask] Flask Digest, Vol 8, Issue 2 In-Reply-To: References: Message-ID: @Kelvin I had the issue once and I solved it. See what you can glean from here first: https://github.com/yandex-sysmon/elog/blob/master/elog/handlers.py I think you should be able to do it. iChux? http://bit.ly/iscrape *Behind every no entry sign, there is a door.* On 2 February 2016 at 17:35, wrote: > Send Flask mailing list submissions to > flask at python.org > > To subscribe or unsubscribe via the World Wide Web, visit > https://mail.python.org/mailman/listinfo/flask > or, via email, send a message with subject or body 'help' to > flask-request at python.org > > You can reach the person managing the list at > flask-owner at python.org > > When replying, please edit your Subject line so it is more specific > than "Re: Contents of Flask digest..." > > > Today's Topics: > > 1. Re: User specific log files (Kevin Stone) > 2. Re: User specific log files (Kevin Stone) > > > ---------------------------------------------------------------------- > > Message: 1 > Date: Tue, 2 Feb 2016 15:21:36 +0000 > From: Kevin Stone > To: Kelvin M , Robert Grant > > Cc: "flask at python.org" > Subject: Re: [Flask] User specific log files > Message-ID: <1454426498458.63267 at jax.org> > Content-Type: text/plain; charset="iso-8859-1" > > We have a simple internal application for editing our database. There are > about 20-30 users. We primarily want to see the user actions and SQL > generated by the app, sometimes in realtime. ? > > ? > > When a user logs in and creates a session, I would like to be able to > append a filehandler for that user to the main app logger. What I can't > grasp in my head is that the app logger is global, but I only want this > filehandler to act on that user's session. That's why when I tried it it > logged all user actions to every log file. > > > ________________________________ > From: Kelvin M > Sent: Tuesday, February 2, 2016 10:12 AM > To: Robert Grant > Cc: Kevin Stone; flask at python.org > Subject: Re: [Flask] User specific log files > > Hi Kevin, > > What are you trying to accomplish with multiple log files? In the past, > the approach that I/we've taken is to just use a log aggregator. Either, > Splunk or ELK (ElasticSearch, LogStash, Kibana). > > With both, you index all log messages and can then create reports or views > for users independently. > > I know that ELK is really easy to set up and free. > > Would something like that work for you? > > Regards, > Kelvin > > On Mon, Feb 1, 2016 at 5:26 PM, Robert Grant > wrote: > Hi Kevin > > Just a couple of quick questions: > > 1) Do you have enough users to just log to a database and record a > username with each log line? Just a suggestion to consider. > 2) Can you post a minimal, verifiable and complete example of your first > attempt to give people something solid to critique? > > Thanks > > > Rob > > On Mon, Feb 1, 2016 at 8:55 PM, Kevin Stone Kevin.Stone at jax.org>> wrote: > > ?Hi, > > > I am not the most familiar with the python logging framework, and I think > I need some help on developing an approach for creating user specific log > files in Flask. It would be even better if someone has already done this > before and could share their pattern. > > > > The problem I want to solve is this: > > 1) user1 and user2 both log in to the app > > 2) user1's activity is logged in "user1.log". user2's activity is logged > in "user2.log". > > 3) No other user's activity should appear in that user's log file. > > > > Ideally, I would like to tap into existing loggers that I have (e.g. the > app logger and the SQLAlchemy logger), but I don't know if that is > possible. My first naive attempt simply registers additional handlers at > login time to the app.logger. This created the appropriate log files, but > they had all activity from all users writing to them. > > > > Any help or advice would be appreciated. > > Thanks, > > -Kevin > > The information in this email, including attachments, may be confidential > and is intended solely for the addressee(s). If you believe you received > this email by mistake, please notify the sender by return email as soon as > possible. > > _______________________________________________ > Flask mailing list > Flask at python.org > https://mail.python.org/mailman/listinfo/flask > > > > _______________________________________________ > Flask mailing list > Flask at python.org > https://mail.python.org/mailman/listinfo/flask > > > > The information in this email, including attachments, may be confidential > and is intended solely for the addressee(s). If you believe you received > this email by mistake, please notify the sender by return email as soon as > possible. > -------------- next part -------------- > An HTML attachment was scrubbed... > URL: < > http://mail.python.org/pipermail/flask/attachments/20160202/415b3aab/attachment-0001.html > > > > ------------------------------ > > Message: 2 > Date: Tue, 2 Feb 2016 16:35:27 +0000 > From: Kevin Stone > To: Kelvin M , Robert Grant > > Cc: "flask at python.org" > Subject: Re: [Flask] User specific log files > Message-ID: <1454430929144.83414 at jax.org> > Content-Type: text/plain; charset="utf-8" > > I have done some research and experimenting. There is a whole lot you can > do with the python logging framework that I am unfamiliar with. I think I > found something that will work for us, although maybe it's not the best > solution. > > > I was able to create a filehandler on user login that I attach a filter > to. This filter tells the handler to only work when that user is logged > into the session. Here is the filter code. > > > > class UserLoggingFilter(logging.Filter): > > """ > > Create a filter to only log the current user > > to its handler > > """ > > > > def __init__(self, user): > > self.user = user > > > > def filter(self, record): > > if 'user' in session and session['user'] == self.user: > > return True > > return False > > > > And here is more or less what the handler code is like. > > > > file_handler = FileHandler(user_log_file) > > file_handler.addFilter(UserLoggingFilter(user)) > > app.logger.addHandler(file_handler) > > ? > > > This seems to work just great. I appreciate the help, and welcome any > alternative suggestions, but at least I have one way that works. > > > -Kevin > > > ________________________________ > From: Kevin Stone > Sent: Tuesday, February 2, 2016 10:21 AM > To: Kelvin M; Robert Grant > Cc: flask at python.org > Subject: Re: [Flask] User specific log files > > > We have a simple internal application for editing our database. There are > about 20-30 users. We primarily want to see the user actions and SQL > generated by the app, sometimes in realtime. ? > > ? > > When a user logs in and creates a session, I would like to be able to > append a filehandler for that user to the main app logger. What I can't > grasp in my head is that the app logger is global, but I only want this > filehandler to act on that user's session. That's why when I tried it it > logged all user actions to every log file. > > > ________________________________ > From: Kelvin M > Sent: Tuesday, February 2, 2016 10:12 AM > To: Robert Grant > Cc: Kevin Stone; flask at python.org > Subject: Re: [Flask] User specific log files > > Hi Kevin, > > What are you trying to accomplish with multiple log files? In the past, > the approach that I/we've taken is to just use a log aggregator. Either, > Splunk or ELK (ElasticSearch, LogStash, Kibana). > > With both, you index all log messages and can then create reports or views > for users independently. > > I know that ELK is really easy to set up and free. > > Would something like that work for you? > > Regards, > Kelvin > > On Mon, Feb 1, 2016 at 5:26 PM, Robert Grant > wrote: > Hi Kevin > > Just a couple of quick questions: > > 1) Do you have enough users to just log to a database and record a > username with each log line? Just a suggestion to consider. > 2) Can you post a minimal, verifiable and complete example of your first > attempt to give people something solid to critique? > > Thanks > > > Rob > > On Mon, Feb 1, 2016 at 8:55 PM, Kevin Stone Kevin.Stone at jax.org>> wrote: > > ?Hi, > > > I am not the most familiar with the python logging framework, and I think > I need some help on developing an approach for creating user specific log > files in Flask. It would be even better if someone has already done this > before and could share their pattern. > > > > The problem I want to solve is this: > > 1) user1 and user2 both log in to the app > > 2) user1's activity is logged in "user1.log". user2's activity is logged > in "user2.log". > > 3) No other user's activity should appear in that user's log file. > > > > Ideally, I would like to tap into existing loggers that I have (e.g. the > app logger and the SQLAlchemy logger), but I don't know if that is > possible. My first naive attempt simply registers additional handlers at > login time to the app.logger. This created the appropriate log files, but > they had all activity from all users writing to them. > > > > Any help or advice would be appreciated. > > Thanks, > > -Kevin > > The information in this email, including attachments, may be confidential > and is intended solely for the addressee(s). If you believe you received > this email by mistake, please notify the sender by return email as soon as > possible. > > _______________________________________________ > Flask mailing list > Flask at python.org > https://mail.python.org/mailman/listinfo/flask > > > > _______________________________________________ > Flask mailing list > Flask at python.org > https://mail.python.org/mailman/listinfo/flask > > > > The information in this email, including attachments, may be confidential > and is intended solely for the addressee(s). If you believe you received > this email by mistake, please notify the sender by return email as soon as > possible. > -------------- next part -------------- > An HTML attachment was scrubbed... > URL: < > http://mail.python.org/pipermail/flask/attachments/20160202/8bc80018/attachment.html > > > > ------------------------------ > > Subject: Digest Footer > > _______________________________________________ > Flask mailing list > Flask at python.org > https://mail.python.org/mailman/listinfo/flask > > > ------------------------------ > > End of Flask Digest, Vol 8, Issue 2 > *********************************** > -------------- next part -------------- An HTML attachment was scrubbed... URL: From kingkong88 at gmail.com Sat Feb 6 10:58:30 2016 From: kingkong88 at gmail.com (King Kong) Date: Sat, 6 Feb 2016 23:58:30 +0800 Subject: [Flask] Fwd: Need help deploying using mod_wsgi (Apache) In-Reply-To: References: Message-ID: I am trying to deploy a simple test app on a Raspberry Pi by following the instructions at http://flask.pocoo.org/docs/0.10/deploying/mod_wsgi/. I need help in what should be in the *yourapplication.wsgi* file. Does this file contain Python code? My project folder is /Z/flask and it runs fine in the development server, ie http://localhost:5000. */Z/flask/app.py* contains: #!/usr/bin/python3 from flask import Flask, jsonify, session, g, render_template app = Flask(__name__) from views import general app.register_blueprint(general.mod) if __name__ == '__main__': app.run(host='0.0.0.0',debug=True) */Z/flask/views/general.py* contains: from flask import Blueprint, render_template, session, redirect, url_for, \ request, flash, g, jsonify, abort mod = Blueprint('general', __name__) @mod.route('/') def index(): return "

Who are you?

" @mod.route('/test') def text(): return "

Testing...

" */Z/flask/views/__init__.py* is an empty file What should be in *yourapplication.wsgi*? Also, what does this paragraph in that documentation page mean: "If you don?t have a factory function for application creation but a singleton instance you can directly import that one as application." The folder /Z/flask is owned by user *pi*. I think apache2 runs using user *www-data*. Thanks. -------------- next part -------------- An HTML attachment was scrubbed... URL: From klawlor419 at gmail.com Sat Feb 6 14:33:02 2016 From: klawlor419 at gmail.com (Kyle Lawlor) Date: Sat, 6 Feb 2016 14:33:02 -0500 Subject: [Flask] flask-wtf form and server-side validation Message-ID: Is there a way to directly pass json data from a form, using request.get_json() into a wtform object at instantiation? Basically what I want would be something like: validation_form = MyForm(json_form_data = request.get_json()) validation_form.validate() ... do stuff depending on validation ... Details: I'm trying to get the data from a form to server-side in order to validate it with wtforms. (I pass the data via AJAX from a wtform inheriting the flask-wtf Form object.) I am using $("#targetForm").serializeArray() and passing that as the data: attribute in the ajax call. I pass it to the server as "application/json" type and retrieve it in the Flask view function with request.get_json(). Thus far, I am able to validate the form with something like: validation_form = create_modal_form(item, for_validation = True, csrf_token = form_data['csrf_token'], sides = form_data['sides']) Sparing some of the details, create_modal_form does basically this: def create_modal_form(item_object, prefix_string = '', for_validation = False, **kwargs): class ModalForm(Form): ... functionally declare a bunch of fields dependent upon item_object properties ... if not for_validation: return ModalForm(prefix=prefix_string) else: return ModalForm(formdata=None, **kwargs) The important thing is that when I am looking to validate, I pass in the data to the wtform object instantiation as *kwargs. (Like csrf_token and sides in the call above and it works.) Any advice and comments appreciated! -------------- next part -------------- An HTML attachment was scrubbed... URL: From lps at chireiden.net Sun Feb 7 05:33:01 2016 From: lps at chireiden.net (Lars Peter =?UTF-8?B?U8O4bmRlcmdhYXJk?=) Date: Sun, 7 Feb 2016 11:33:01 +0100 Subject: [Flask] Fwd: Need help deploying using mod_wsgi (Apache) In-Reply-To: References: Message-ID: <20160207113301.5d7a89f6@ikarus.ikarus> On Sat, 6 Feb 2016 23:58:30 +0800 King Kong wrote: > I am trying to deploy a simple test app on a Raspberry Pi by > following the instructions at > http://flask.pocoo.org/docs/0.10/deploying/mod_wsgi/. > > I need help in what should be in the *yourapplication.wsgi* file. > Does this file contain Python code? > > My project folder is /Z/flask and it runs fine in the development > server, ie http://localhost:5000. > > > */Z/flask/app.py* contains: > > > #!/usr/bin/python3 If you use python3, you'll probably want to install libapache2-mod-wsgi-py3 instead. Though I do not know what python3 version it uses on your machine, if it happens to be anything below python3.3, you'll probably have bad luck with your deployment. [...] > > */Z/flask/views/general.py* contains: [...] > > */Z/flask/views/__init__.py* is an empty file > > What should be in *yourapplication.wsgi*? Also, what does this > paragraph in that documentation page mean: > > "If you don?t have a factory function for application creation but a > singleton instance you can directly import that one as application." > > > The folder /Z/flask is owned by user *pi*. I think apache2 runs > using user *www-data*. > > Thanks. In the case of flask, you just want to import your "app" from your app.py file, and name it "application" I usually just call the file "wsgi.py", because well, it's supposed to be a python file. But that shouldn't actually matter to much. That file should be located in /Z/flask/ and probably contain something like: from app import app as application That's pretty much all. -- nitori -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 819 bytes Desc: OpenPGP digital signature URL: From miserlou at gmail.com Tue Feb 9 09:40:07 2016 From: miserlou at gmail.com (Rich Jones) Date: Tue, 9 Feb 2016 15:40:07 +0100 Subject: [Flask] Architecting flask-zappa Message-ID: Hey all! I recently published a new library called Zappa[1][2] that allows for incredibly easy deployment of WSGI applications on AWS Lambda + API Gateway. This is totally different way of running apps that comes with some major advantages in terms of cost, ease, and scalability. I've already written a client library for Django [3], and now I'd like it if there were a Flask client as well. But, I'm a Django developer, not usually a Flask developer, so I don't know necessary know what the Flask best practices are. For instance, is there a way to run management commands, ala Django's "python manage.py deploy dev"? So, I'd love it if somebody here could either a) write and maintain a Flask client library for Zappa (shouldn't take more than an afternoon or two) or b) architect/design the client library so that I can then write it. Would anybody out there be interested in helping with this? I think it'll be a huge win for the Flask community to be able to deploy their applications in a super cheap, super easy and incredibly scalable way! Thanks!, Rich Jones == [1] https://github.com/Miserlou/Zappa [2] https://gun.io/blog/announcing-zappa-serverless-python-aws-lambda/ [3] https://github.com/Miserlou/django-zappa -------------- next part -------------- An HTML attachment was scrubbed... URL: From philippe at ppmt.org Tue Feb 9 17:00:49 2016 From: philippe at ppmt.org (Philippe Le Toquin) Date: Tue, 9 Feb 2016 22:00:49 +0000 Subject: [Flask] Populate form with multiple item from database In-Reply-To: <56BA603B.6090003@ppmt.org> References: <56BA603B.6090003@ppmt.org> Message-ID: <56BA6191.3070208@ppmt.org> Hi, Very new to this mailing and first post so not sure if I am in the right place for my question. If it is not appropriate or if pasting so much code is wrong, I apologise in advance! And would appreciate if you could redirect me to a better place. I am trying to write an application for entering recipe. I am not expert in Python but by reading and with lots of trial and errors, I normally get the result I need. But lately I have been stuck on a problem which I believe is beyond my understanding of programming. I have a form which I use to add ingredient to a recipe Since it can have more than one ingredient I use some javascript code to clone the form for each additional ingredient. Once submitted it is then saved in a table. That part is working even though I am sure the code would scare most of you. Where I am stuck is that when I want to edit the ingredient list. I can't find a way to populate the form with the list of ingredient that are already in the table for that recipe. Instead it starts the form as if there is no ingredient. I have tried various way and search the web for similar case but cant find anything Here is the form I use: class IngredientListTemplate(Form): """ Template to add a new ingredient to a recipe The 2 input are prefilled with the date from the query_factory """ category = QuerySelectField(query_factory=categorylist, get_label=u'category', allow_blank=False) ingredient = QuerySelectField(query_factory=ingredientlist, get_label=u'ingredient', allow_blank=False) #it removes the CSRF token missing error def __init__(self, *args, **kwargs): kwargs['csrf_enabled'] = False super(IngredientListTemplate, self).__init__(*args, **kwargs) class IngredientListForm(Form): """ Display the template """ ingredient_list = FieldList(FormField(IngredientListTemplate), min_entries=1) and the function I use to edit the recipe: @mod.route('/ingredients_selection/', methods=['GET', 'POST']) def ingredient_selection(recipe_id): """ This is where you can select ingredients for a specific recipe It also stores them in a database for that recipe. It is accessed from /ingredients """ recipe = Recipeingredients.query.get(recipe_id) print recipe.ingredient_id #returns [5, 6, 9, 10, 19, 21, 23] being the id of each ingredients form = IngredientListForm() form.ingredient_list[0]['ingredient'].data=9 # this is my attempt at trying to force a some data in the form form.ingredient_list[0]['category'].data=1 # but it doesn't work. I still end up with the default form print form.data # Section to refresh the ingredient when the category is changed # if filters the ingredient based on the chosen category # it is buggy and sometime it just won't work :( if request.is_xhr: ## each line is numbered like this : ingredient_list-x-category ## x is the number of the line (each time you press clone it will step key = list(request.args.keys())[0] ## extract the line number form_cat = request.args.get(key) ## get the value chosen (ie the category id) ## Then query the ingredient and filter them by the category selected ingredients = Ingredientlist.query.filter_by(category_id=form_cat) result = dict() for ingredient in ingredients: #print ingredient.ingredient result[ingredient.ingredient] = ingredient.id print result return jsonify(result=result) # ingredients name and id for the clicked category # Section when we validate the form if form.validate_on_submit(): print form.data """ Return a dictionary in the form of : {'ingredient_list': [ {'category': Flour - Grain, 'ingredient': ingredient_id }, {'category': Flour - Grain, 'ingredient': ingredient_id } ] } """ #remove potential duplicate ingredients_list=[] for i in form.data['ingredient_list']: if i not in ingredients_list: ingredients_list.append(i) #Let's store it in the Recipeingredients table #We are just interested in storing the id of the ingredients since the rest can #be deducted from there. # First we create the list of ingredient id ing_list = [] for ingredient in ingredients_list: ing_list.append(ingredient['ingredient']) # Then we update the table with the updated ingredient recipe.ingredient_id = ing_list db.session.add(recipe) db.session.commit() # Now we can return to displaying the ingredients list return redirect(url_for('.ingredients_display',recipe_id=recipe_id)) # Default display of the form ## TODO: We need to read the recipe being edited and preload it with ## pre existing ingredient if they exist or a "clear form" if not return render_template("ingredients_selection.html", action = 'Save', title='List of Ingredients', form = form, recipe_id=recipe_id ) and finally the template I use {% extends "bootstrap/base.html" %} {% import "bootstrap/wtf.html" as wtf %} {% include "mybase.html" %} {% block content %}

{{ title }}

In this section you will select the ingredient that will be the base of the recipe

{{ form.hidden_tag() }}
{% for ingredient in form.ingredient_list %} {{ wtf.form_field(ingredient.category) }} {{ wtf.form_field(ingredient.ingredient) }} {% endfor %}
{% endblock %} {% block scripts %} {{ super() }} {% endblock %} I know it is a lot of code but I would appreciate if someone could help me understand how I could achieve what I want. Thanks for reading so far. Philippe From kingkong88 at gmail.com Wed Feb 10 00:57:28 2016 From: kingkong88 at gmail.com (King Kong) Date: Wed, 10 Feb 2016 13:57:28 +0800 Subject: [Flask] Need help deploying using mod_wsgi (Apache) Message-ID: nitori, does that mean that I must first convert my app into a package with a __init__.py file? I am now hitting a 403 Forbidden (You don't have permission to access /api on this server.) Log shows: [authz_core:error] [pid 6817:tid 3021182000] [client 220.xxx.xxx.xxx:56401] AH01630: client denied by server configuration: /Z/flask/app.wsgi. (I think my app.wsgi file hasn't got the chance to run yet.) My /Z/flask folder is pretty liberal with rights: -rwxr-xr-x 1 pi pi 302 Feb 5 18:04 app.py -rwxr-xr-x 1 pi pi 39 Feb 10 13:42 app.wsgi -rwxr-xr-x 1 pi pi 37 Feb 6 15:41 index.py drwxr-xr-x 3 pi pi 4096 Feb 5 17:56 views I am confused over the user/group in the config file. Read the documentation at https://code.google.com/archive/p/modwsgi/wikis/ConfigurationDirectives.wiki but couldn't figure out what it means regarding the user parameter. My /etc/apache2/sites-available/000-default.conf contains: WSGIDaemonProcess app user=pi group=pi threads=5 WSGIScriptAlias /api /Z/flask/app.wsgi #Alias /api /Z/flask/ WSGIProcessGroup app WSGIApplicationGroup %{GLOBAL} Options Indexes FollowSymLinks MultiViews ExecCGI AllowOverride None Order allow,deny Allow from all WSGIScriptReloading On Addhandler wsgi-script .py Am I using the correct user/group values? What is causing the access error? Thanks. > ------------------------------ > > Message: 2 > Date: Sun, 7 Feb 2016 11:33:01 +0100 > From: Lars Peter S?ndergaard > To: flask at python.org > Subject: Re: [Flask] Fwd: Need help deploying using mod_wsgi (Apache) > Message-ID: <20160207113301.5d7a89f6 at ikarus.ikarus> > Content-Type: text/plain; charset="utf-8" > > On Sat, 6 Feb 2016 23:58:30 +0800 King Kong > wrote: > > > I am trying to deploy a simple test app on a Raspberry Pi by > > following the instructions at > > http://flask.pocoo.org/docs/0.10/deploying/mod_wsgi/. > > > > I need help in what should be in the *yourapplication.wsgi* file. > > Does this file contain Python code? > > > > My project folder is /Z/flask and it runs fine in the development > > server, ie http://localhost:5000. > > > > > > */Z/flask/app.py* contains: > > > > > > #!/usr/bin/python3 > > If you use python3, you'll probably want to install > libapache2-mod-wsgi-py3 instead. Though I do not know what python3 > version it uses on your machine, if it happens to be anything below > python3.3, you'll probably have bad luck with your deployment. > > [...] > > > > > */Z/flask/views/general.py* contains: > > [...] > > > > > */Z/flask/views/__init__.py* is an empty file > > > > What should be in *yourapplication.wsgi*? Also, what does this > > paragraph in that documentation page mean: > > > > "If you don?t have a factory function for application creation but a > > singleton instance you can directly import that one as application." > > > > > > The folder /Z/flask is owned by user *pi*. I think apache2 runs > > using user *www-data*. > > > > Thanks. > > In the case of flask, you just want to import your "app" from your > app.py file, and name it "application" > > I usually just call the file "wsgi.py", because well, it's supposed to > be a python file. But that shouldn't actually matter to much. > > That file should be located in /Z/flask/ and probably contain something > like: > > from app import app as application > > That's pretty much all. > > -- > nitori > > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From lps at chireiden.net Wed Feb 10 01:24:24 2016 From: lps at chireiden.net (Lars Peter =?UTF-8?B?U8O4bmRlcmdhYXJk?=) Date: Wed, 10 Feb 2016 07:24:24 +0100 Subject: [Flask] Need help deploying using mod_wsgi (Apache) In-Reply-To: References: Message-ID: <20160210072424.06c15b2d@ikarus.ikarus> On Wed, 10 Feb 2016 13:57:28 +0800 King Kong wrote: > nitori, does that mean that I must first convert my app into a > package with a __init__.py file? No, not necessarily. > I am now hitting a 403 Forbidden (You don't have permission to > access /api on this server.) Log shows: [authz_core:error] [pid > 6817:tid 3021182000] [client 220.xxx.xxx.xxx:56401] AH01630: client > denied by server configuration: /Z/flask/app.wsgi. (I think my > app.wsgi file hasn't got the chance to run yet.) Unfortunately I don't have much experience with wsgi configuration in apache. So I can't really help there. -- nitori -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 819 bytes Desc: OpenPGP digital signature URL: From bk at breadtech.com Wed Feb 10 02:49:25 2016 From: bk at breadtech.com (Brian Kim) Date: Wed, 10 Feb 2016 02:49:25 -0500 Subject: [Flask] Need help deploying using mod_wsgi (Apache) In-Reply-To: <20160210072424.06c15b2d@ikarus.ikarus> References: <20160210072424.06c15b2d@ikarus.ikarus> Message-ID: Hi King Kong, I've run into the same issue as you have before and I feel like this should be better documented. The problem is that you've placed your app in a directory that apache doesn't acknowledge. To fix this, you want to edit your /etc/apache2/apache2.conf file and add in the follow lines: Options Indexes FollowSymLinks AllowOverride None Require all granted Let me know if this works for you. BK On Wed, Feb 10, 2016 at 1:24 AM, Lars Peter S?ndergaard wrote: > On Wed, 10 Feb 2016 13:57:28 +0800 King Kong > wrote: > > > nitori, does that mean that I must first convert my app into a > > package with a __init__.py file? > > No, not necessarily. > > > I am now hitting a 403 Forbidden (You don't have permission to > > access /api on this server.) Log shows: [authz_core:error] [pid > > 6817:tid 3021182000] [client 220.xxx.xxx.xxx:56401] AH01630: client > > denied by server configuration: /Z/flask/app.wsgi. (I think my > > app.wsgi file hasn't got the chance to run yet.) > > Unfortunately I don't have much experience with wsgi configuration in > apache. So I can't really help there. > > -- > nitori > > _______________________________________________ > Flask mailing list > Flask at python.org > https://mail.python.org/mailman/listinfo/flask > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From jerry.mccreary at mac.com Wed Feb 10 17:04:17 2016 From: jerry.mccreary at mac.com (Jerry Mccreary) Date: Wed, 10 Feb 2016 17:04:17 -0500 Subject: [Flask] flask-mongoengine custom field parameters Message-ID: Is it possible to add custom field parameters when defining a model when using flask-mongoengine? (which in turn uses WTForms) Example: class Tasks(Document): task = StringField(max_length=128, my_custom_param="hello") completed = BooleanField(default=False) The above will generate an error: flask_mongoengine/wtf/base.py", line 23, in __init__ BaseField.__init__(self, **kwargs) TypeError: __init__() got an unexpected keyword argument 'my_custom_param' Would it be a matter of defining or extending in the model __init__ method? If it's possible, could anyone provide an example? Thanks. Jerry McCreary ?????????????????? -------------- next part -------------- An HTML attachment was scrubbed... URL: From tim at akwebsoft.com Sat Feb 13 17:47:12 2016 From: tim at akwebsoft.com (Tim Johnson) Date: Sat, 13 Feb 2016 13:47:12 -0900 Subject: [Flask] Establishing foreign key back to parent class Message-ID: <20160213224712.GL2583@mail.akwebsoft.com> FYI : Python coder 12 years in CGI and MySQL new to flask and SQLAlchemy. (have always just used MysqlDB) Using SQLAlchemy Version 1.0.11 with python 2.7.6 on Ubuntu 14.04 I've followed a couple of "paint by numbers " tutorials from both th M. Grinberg book and from the following URL https://www.digitalocean.com/community/tutorials/how-to-structure-large-flask-applications The second tutorial takes little different approach to setting up data models, by implementing a base class for the date module. The code in question can be found at the URL under the heading "Step 2: Define The Module Data Model(s)" Using that code generated an error for me - "sqlalchemy.exc.NoForeignKeysError: Can't find any foreign key relationships between 'base' and 'auth_user'." None of the comments at the URL reference the problem that I had, Question 1 : could that be because of a new version of SQLAlchemy? I found my success by eliminating the Base class and moving the code from the Base class in the User Class and using db.Model as the parent class. # My working code is as follows: # Import the database object (db) from the main application module # We will define this inside /app/__init__.py in the next sections. from app import db # SQLAlchemy instance # Define a base model for other database tables to inherit # class Base(db.Model): # __abstract_ = True # id = db.Column(db.Integer, primary_key=True) # date_created = db.Column(db.DateTime, default=db.func.current_timestamp()) # date_modified = db.Column(db.DateTime, default=db.func.current_timestamp(), # onupdate=db.func.current_timestamp()) # Define a User model # class User(Base): class User(db.Model): # The following 4 assignments are taken from the Base Class __abstract_ = True id = db.Column(db.Integer, primary_key=True) date_created = db.Column(db.DateTime, default=db.func.current_timestamp()) date_modified = db.Column(db.DateTime, default=db.func.current_timestamp(), onupdate=db.func.current_timestamp()) __tablename__ = 'auth_user' # User Name name = db.Column(db.String(128), nullable=False) # Identification Data: email & password email = db.Column(db.String(128), nullable=False, unique=True) password = db.Column(db.String(192), nullable=False) # Authorisation Data: role & status role = db.Column(db.SmallInteger, nullable=False) status = db.Column(db.SmallInteger, nullable=False) # New instance instantiation procedure def __init__(self, name, email, password): self.name = name self.email = email self.password = password def __repr__(self): return '' % (self.name) Question 2: What is missing from the original code using db.Model -> Base -> User scheme? I.E. how to establish the foreign key relationship Thanks -- Tim http://www.akwebsoft.com, http://www.tj49.com From tim at akwebsoft.com Sat Feb 13 17:51:34 2016 From: tim at akwebsoft.com (Tim Johnson) Date: Sat, 13 Feb 2016 13:51:34 -0900 Subject: [Flask] Establishing foreign key back to parent class In-Reply-To: <20160213224712.GL2583@mail.akwebsoft.com> References: <20160213224712.GL2583@mail.akwebsoft.com> Message-ID: <20160213225134.GM2583@mail.akwebsoft.com> * Tim Johnson [160213 13:48]: > > The second tutorial takes little different approach to setting up > data models, by implementing a base class for the date module. Typo : Should have said "data module" not "date module" Addendum : Flask-SQLAlchemy==2.1 -- Tim http://www.akwebsoft.com, http://www.tj49.com From tim at akwebsoft.com Sun Feb 14 18:24:19 2016 From: tim at akwebsoft.com (Tim Johnson) Date: Sun, 14 Feb 2016 14:24:19 -0900 Subject: [Flask] Establishing foreign key back to parent class In-Reply-To: <20160213224712.GL2583@mail.akwebsoft.com> References: <20160213224712.GL2583@mail.akwebsoft.com> Message-ID: <20160214232419.GB3382@mail.akwebsoft.com> * Tim Johnson [160213 13:48]: <...> > # My working code is as follows: > > # class Base(db.Model): > > # __abstract_ = True > # id = db.Column(db.Integer, primary_key=True) > # date_created = db.Column(db.DateTime, default=db.func.current_timestamp()) > # date_modified = db.Column(db.DateTime, default=db.func.current_timestamp(), > # onupdate=db.func.current_timestamp()) Turns out that I was bitten by a self-inflicted ORM bug... in my original code as taken from the tutorial, I had truncated __abstract__ to __abstract_ ## one trailing underscore! Because __abstract__ was not defined as True sqlalchemy attempted to map out a "base" table and subsequently create a relationship - which failed and generated the exception. The use of "special class directives" in sqlalchemy is discussed here : http://docs.sqlalchemy.org/en/rel_0_8/orm/extensions/declarative.html live and learn ... -- Tim http://www.akwebsoft.com, http://www.tj49.com From arsh840 at gmail.com Mon Feb 15 02:19:54 2016 From: arsh840 at gmail.com (Arshpreet Singh) Date: Mon, 15 Feb 2016 12:49:54 +0530 Subject: [Flask] Flask MVC and Big applications Message-ID: I am using Flask for Gmail Analyser, Using Impalib I fetch data and using pygal return the views in form of some Graphs. Now I have read article on DigitaloCean: https://www.digitalocean.com/community/tutorials/how-to-structure-large-flask-applications What will be the real difference if one just run all project from app.py file or the structure above is described is always best approach? -- Thanks Arshpreet Singh I am Sikh boy, Learning by doing and Learning by teaching is my religion. ------------------------------------------------------------------------------ Slashdot TV. Video for Nerds. Stuff that matters. http://tv.slashdot.org/ From tariquesani at gmail.com Mon Feb 15 02:24:31 2016 From: tariquesani at gmail.com (Dr. Tarique Sani) Date: Mon, 15 Feb 2016 12:54:31 +0530 Subject: [Flask] Flask MVC and Big applications In-Reply-To: References: Message-ID: if your app is really large then the real difference would be maintainability of code. Hope that helps On Mon, Feb 15, 2016 at 12:49 PM, Arshpreet Singh wrote: > I am using Flask for Gmail Analyser, Using Impalib I fetch data and > using pygal return the views in form of some Graphs. > > Now I have read article on DigitaloCean: > > > https://www.digitalocean.com/community/tutorials/how-to-structure-large-flask-applications > > > What will be the real difference if one just run all project from > app.py file or the structure above is described is always best > approach? > -- > > Thanks > Arshpreet Singh > > I am Sikh boy, Learning by doing and Learning by teaching is my religion. > > ------------------------------------------------------------------------------ > Slashdot TV. > Video for Nerds. Stuff that matters. > http://tv.slashdot.org/ > _______________________________________________ > Flask mailing list > Flask at python.org > https://mail.python.org/mailman/listinfo/flask > -- ============================================================= Hire a CakePHP dev team : http://sanisoft.com ============================================================= -------------- next part -------------- An HTML attachment was scrubbed... URL: From miserlou at gmail.com Mon Feb 15 07:10:52 2016 From: miserlou at gmail.com (Rich Jones) Date: Mon, 15 Feb 2016 13:10:52 +0100 Subject: [Flask] When will Flask 1.0 be released? Message-ID: We are currently having a discussion around the architecture of flask-zappa[1], and a sticking point is which version of Flask to target. For our purposes, the management commands introduced in 1.0 seem ideal, but you can see why it seems strange for us to target a version of a platform which hasn't been released yet, and has no public target release date. The last public communique seemed to suggest Christmas, but that has obviously come and gone. So, is there any chance that we could get an update on the 1.0 Roadmap, and ideally a way to target a stable -dev version from pip? Thanks! R -------------- next part -------------- An HTML attachment was scrubbed... URL: From davidism at gmail.com Mon Feb 15 10:41:01 2016 From: davidism at gmail.com (David Lord) Date: Mon, 15 Feb 2016 07:41:01 -0800 Subject: [Flask] When will Flask 1.0 be released? In-Reply-To: References: Message-ID: <56C1F18D.2010801@gmail.com> This has already been discussed extensively [on GitHub][1]. In summary: The last update from mitsuhiko on that issue is from the middle of January stating that he is working on creating an org to better manage development and releases. I can confirm this is in progress. Target 0.10.1 if you need to target a released version, it is stable. Most significant changes are in Werkzeug and Jinja, which saw releases relatively recently. Write tests, and run them against 0.10.1 and 1.0-dev. I don't recall there being breaking changes, although I'm not sure. If you have failures, please report them so we can either fix or document them. Click integration can be added to 0.10 with Flask-Cli. Flask-Script is also fine for most use cases. Finally, if Flask is a major part of your product and you can't consider 0.10 stable, *you* can help make Flask 1.0 a reality. Contributions, whether bug reports, pull requests, reviews, or discussion, are always welcome and helpful. [1]: https://github.com/mitsuhiko/flask/issues/1575 On 02/15/2016 04:10 AM, Rich Jones wrote: > We are currently having a discussion around the architecture of > flask-zappa[1], and a sticking point is which version of Flask to target. > > For our purposes, the management commands introduced in 1.0 seem ideal, > but you can see why it seems strange for us to target a version of a > platform which hasn't been released yet, and has no public target > release date. > > The last public communique seemed to suggest Christmas, but that has > obviously come and gone. > > So, is there any chance that we could get an update on the 1.0 Roadmap, > and ideally a way to target a stable -dev version from pip? > > Thanks! > R > > > _______________________________________________ > Flask mailing list > Flask at python.org > https://mail.python.org/mailman/listinfo/flask > From dgleba at gmail.com Mon Feb 15 22:32:38 2016 From: dgleba at gmail.com (d gleba) Date: Mon, 15 Feb 2016 22:32:38 -0500 Subject: [Flask] Flask-Admin - Cannot login, Cannot Logout Message-ID: I have an app that used to works on some computers but I cannot login or logout on a windows machine I am doing development on. Screen shots are located here... https://github.com/dgleba/flaskplayground/tree/master/1flask/error/loginlogoutproblem The photos are named starting with a number. -- 01 shows the problem. -- 14 and 15 show the app as it should work. I have deleted cookies, and deleted all browser history. It's just running in the dev server. I don't know what to do next to troubleshoot it. Any ideas? -- dgleba at gmail.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From dgleba at gmail.com Mon Feb 15 22:53:20 2016 From: dgleba at gmail.com (d gleba) Date: Mon, 15 Feb 2016 22:53:20 -0500 Subject: [Flask] Flask-Admin - Cannot login, Cannot Logout Message-ID: I want to correct my first sentence. It should read: I have an app that works on some computers but I cannot login or logout on a windows machine I am doing development on. On Mon, Feb 15, 2016 at 10:32 PM, d gleba wrote: > > I have an app that used to works on some computers but I cannot login or > logout on a windows machine I am doing development on. > > Screen shots are located here... > > https://github.com/dgleba/flaskplayground/tree/master/1flask/error/loginlogoutproblem > > The photos are named starting with a number. > -- 01 shows the problem. > -- 14 and 15 show the app as it should work. > > > I have deleted cookies, and deleted all browser history. > It's just running in the dev server. > > I don't know what to do next to troubleshoot it. > > Any ideas? > > > > > -- > dgleba at gmail.com > -- dgleba at gmail.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From dgleba at gmail.com Wed Feb 17 06:35:08 2016 From: dgleba at gmail.com (d gleba) Date: Wed, 17 Feb 2016 06:35:08 -0500 Subject: [Flask] Flask-Admin - Cannot login, Cannot Logout In-Reply-To: References: Message-ID: I solved this. I re-ran pip install -r requirements.txt. It uninstalled flask-login and installed a newer version of it. Now it works. On Mon, Feb 15, 2016 at 10:53 PM, d gleba wrote: > > I want to correct my first sentence. It should read: > > I have an app that works on some computers but I cannot login or logout on a windows machine I am doing development on. > > > On Mon, Feb 15, 2016 at 10:32 PM, d gleba wrote: > >> >> I have an app that used to works on some computers but I cannot login or >> logout on a windows machine I am doing development on. >> >> Screen shots are located here... >> >> https://github.com/dgleba/flaskplayground/tree/master/1flask/error/loginlogoutproblem >> >> The photos are named starting with a number. >> -- 01 shows the problem. >> -- 14 and 15 show the app as it should work. >> >> >> I have deleted cookies, and deleted all browser history. >> It's just running in the dev server. >> >> I don't know what to do next to troubleshoot it. >> >> Any ideas? >> >> >> >> >> -- >> dgleba at gmail.com >> > > > > -- > dgleba at gmail.com > -- dgleba at gmail.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From maheshkumargarg07 at gmail.com Thu Feb 25 13:37:28 2016 From: maheshkumargarg07 at gmail.com (Mahesh Kumar) Date: Fri, 26 Feb 2016 00:07:28 +0530 Subject: [Flask] Multiple returns in single @app.route() Message-ID: Is it possible to return values (or send value to another api call) and continue the flow of @app.route() -------------- next part -------------- An HTML attachment was scrubbed... URL: From bk at breadtech.com Fri Feb 26 16:07:07 2016 From: bk at breadtech.com (Brian Kim) Date: Fri, 26 Feb 2016 16:07:07 -0500 Subject: [Flask] Multiple returns in single @app.route() In-Reply-To: References: Message-ID: <357C3AE6-14F3-48A0-BACD-D835BDFC7DD8@breadtech.com> Hey Mahesh, It's not clear what exactly youre asking. Could you provide an example of what you're trying to do. If you're talking about making a request to another server, I dont think that it would be a good idea to make a request as a part of a response. BK > On Feb 25, 2016, at 1:37 PM, Mahesh Kumar wrote: > > Is it possible to return values (or send value to another api call) and continue the flow of @app.route() > > > _______________________________________________ > Flask mailing list > Flask at python.org > https://mail.python.org/mailman/listinfo/flask -------------- next part -------------- An HTML attachment was scrubbed... URL: From jerry.mccreary at mac.com Fri Feb 26 22:20:32 2016 From: jerry.mccreary at mac.com (Jerry Mccreary) Date: Fri, 26 Feb 2016 22:20:32 -0500 Subject: [Flask] Multiple returns in single @app.route() In-Reply-To: <357C3AE6-14F3-48A0-BACD-D835BDFC7DD8@breadtech.com> References: <357C3AE6-14F3-48A0-BACD-D835BDFC7DD8@breadtech.com> Message-ID: Mahesh, As Brian mention, it's not clear what you want to accomplish. I have used flask-sijax in scenarios where one ajax request triggered multiple responses. Also, this snippet may be helpful: http://flask.pocoo.org/snippets/131/ ("Handling multiple sub-requests in a sing Flask request") JM ?????????????????? On Feb 26, 2016, at 4:07 PM, Brian Kim wrote: > Hey Mahesh, > > It's not clear what exactly youre asking. Could you provide an example of what you're trying to do. > > If you're talking about making a request to another server, I dont think that it would be a good idea to make a request as a part of a response. > > BK > > On Feb 25, 2016, at 1:37 PM, Mahesh Kumar wrote: > >> Is it possible to return values (or send value to another api call) and continue the flow of @app.route() >> >> >> _______________________________________________ >> Flask mailing list >> Flask at python.org >> https://mail.python.org/mailman/listinfo/flask > _______________________________________________ > Flask mailing list > Flask at python.org > https://mail.python.org/mailman/listinfo/flask -------------- next part -------------- An HTML attachment was scrubbed... URL: From plozano94 at gmail.com Sun Feb 28 14:53:56 2016 From: plozano94 at gmail.com (Pablo Lozano) Date: Sun, 28 Feb 2016 20:53:56 +0100 Subject: [Flask] How to Stream and not paralize the server Message-ID: Hi everybody, I'm making a little server where I have a loging, a page where we stream video, and another page for sending some commands. Steaming video is running this way: http://www.chioka.in/python-live-video-streaming-example/ But when it starts streaming, I cant acceed to the page of commands, because server is bloqued in a while true loop for streaming. I probe launching some threading but then I cant see the camera. What should I do? Thanks everyone. -------------- next part -------------- An HTML attachment was scrubbed... URL: From plozano94 at gmail.com Sun Feb 28 15:04:16 2016 From: plozano94 at gmail.com (Pablo Lozano) Date: Sun, 28 Feb 2016 21:04:16 +0100 Subject: [Flask] How to Stream and not paralize the server In-Reply-To: References: Message-ID: *# all the imports* *import threading* *import sqlite3* *from flask import Flask, request, session, g, redirect, url_for, \* * abort, render_template, flash, Response* *from contextlib import closing* *import serial* *from camera import VideoCamera* *# configuration* *DATABASE = '/tmp/flaskr.db'* *DEBUG = True* *SECRET_KEY = 'development key'* *USERNAME = 'admin'* *PASSWORD = 'default'* *# create our little application :)* *app = Flask(__name__)* *app.config.from_envvar('FLASKR_SETTINGS', silent=True)* *app.config['DEBUG'] = True* *app.config['SECRET_KEY'] = 'some_really_long_random_string_here'* *ser = serial.Serial('/dev/ttyACM0', 9600)* *logged= None* *@app.route('/command', methods=['GET','POST'])* *def command():* * error=None* * global logged* * if not logged:* * abort(401)* * if request.method == 'POST':* * message=request.form['command']* * message = '&'+str(message)+ '#'* * print message* * print 'Enviado'* * ser.write(message)* * #return redirect(url_for('command'))* *return render_template('command.html', error=error)* *@app.route('/camera', methods=['GET','POST'])* *def camera():* * return render_template('camera.html')* *def gen(camara):* * while True:* * frame = camara.get_frame()* * yield (b'--frame\r\n'b'Content-Type: image/jpeg\r\n\r\n' + frame + b'\r\n\r\n')* *@app.route('/login', methods=['GET', 'POST'])* *def login():* * error = None* * if request.method == 'POST':* * if request.form['username'] != USERNAME:* * str(request.form['username'])* * error = 'Invalid username'* * elif request.form['password'] != PASSWORD:* * error = 'Invalid password'* * else:* * global logged* * logged = True* * #session['logged_in'] = True* * flash('You were logged in')* * return redirect(url_for('command'))* * return render_template('login.html', error=error)* *@app.route('/logout')* *def logout():* * global logged* * logged = None* * #session.pop('logged_in', None)* * flash('You were logged out')* * return redirect(url_for('show_entries'))* *@app.route('/video_feed')* *def video_feed():* * return Response(gen(VideoCamera()), mimetype='multipart/x-mixed-replace; boundary=frame')* *if __name__ == '__main__':* * app.run(host='0.0.0.0',port=4000)* Okey, this is the code, streaming works, but when I acceed to /camera, it start streaming and I cant get out of there, because it is blocked o that while that streams. I want that the server streams, and also that I could acceed to the /command page while camera continues streaming. Sorry if im not clear, and thanks for your patience. 2016-02-28 20:55 GMT+01:00 Christophe Bal : > Hello. > > You should give a minimal example showing the probblem. > > > *Christophe BAL* > *Enseignant de math?matiques en Lyc?e **et d?veloppeur Python amateur* > *---* > *French teacher of **math** in a high school **and **amateur **Python * > *developer* > > 2016-02-28 20:53 GMT+01:00 Pablo Lozano : > >> Hi everybody, >> >> I'm making a little server where I have a loging, a page where we stream >> video, and another page for sending some commands. Steaming video is >> running this way: >> http://www.chioka.in/python-live-video-streaming-example/ But when it >> starts streaming, I cant acceed to the page of commands, because server is >> bloqued in a while true loop for streaming. >> >> I probe launching some threading but then I cant see the camera. What >> should I do? >> >> Thanks everyone. >> >> _______________________________________________ >> Flask mailing list >> Flask at python.org >> https://mail.python.org/mailman/listinfo/flask >> >> > -------------- next part -------------- An HTML attachment was scrubbed... URL: