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
Django Form Widget Errors

The error I get is: `'MultipleChoiceField' object has no attribute 'is_hidden'`

The following is my form:

class SlackUserForm(forms.Form):
def __init__(self, *args, **kwargs):
self.request = kwargs.pop('request')
super(SlackUserForm, self).__init__(*args, **kwargs)
self.slack_access_token = get_access_token(self.request.user, 'slack')
self.channels = get_slack_channels(self.slack_access_token)
self.fields['channels'].widget = forms.MultipleChoiceField(choices=tuple(self.channels,))

family_name = forms.CharField()
given_name = forms.CharField()
primary_email = forms.EmailField()
channels = forms.MultipleChoiceField()

class Meta:
fields = ['family_name', 'given_name', 'pimary_email', 'channels']

If anyone has any idea how to fix this please let me know as I've been on it for a day now :(

/r/django
https://redd.it/6lc19b
Has anyone successfully managed to get "Download as PDF" working on Jupyter Notebook?

I've installed pandoc and texlive-xetex on my vps but still it comes up with 500 server errors when I try to download an ipython notebook as PDF

/r/IPython
https://redd.it/6lcmew
Can I simulate events with Python?

(Solved)

Is there a way to simulate events like a keypress or a mouse click using Python, by example to write text on another app, or to play a game?

/r/Python
https://redd.it/6lcwnr
Could someone help with python networkprograming?

i will change to learnpython category sorry wrong category to write

/r/Python
https://redd.it/6ldcyp
Flask newbie. Why can't Flask find my module?

from database_manager import DatabaseManager
from flask import Flask
app = Flask(__name__)


@app.route("/")
def hello():
db = DatabaseManager()

users = db.get_users()

text = ""
for user in users:
text += user["first_name"] + "<br>"

return text

The above returns a "no module named database_manager" error. database_manager.py is in the same directory.

/r/flask
https://redd.it/6lbpts
Jupyter notebook closing immediately on startup

When I try to open jupyer notebook, a window opens and then immediately closes. I installed via the anaconda package.

/r/IPython
https://redd.it/6ldusm
Top 250 Subreddits that /r/Python users are active in (ranked by deviation from the average redditor)

/r/Python
https://redd.it/6leaqy
What tips and tricks do you guys use for your Django admin panel?

I was reviewing awesome django's admin panel section while re-thinking my admin panel features and workflow and was curious to see if I couldn't pick up some new ideas.

So, I went over to [awesome django](https://github.com/rosarior/awesome-django#admin-interface) and looked at their list. It seems admin panels have come a long way since I last checked out admin add-ons.

I'm thinking of trying out a plugin or two (maybe jet or grappelli), though I know django people are usually pretty creative with their own solutions and keen on making a solid workflow. All that said, what have you guys done to make your admin panels work well for you? Do any of the plugins do the job, or did you modify them to?

/r/django
https://redd.it/6ld29e
I thought It was going to be simple...

I'm currently starting the website and I am having issues best deploying user models.

I know that django has a built in user model but I still reading over the docs and trying to understand. There are very few examples so I find it difficult to relate to my project.

I don't want any of my users to have the django admin access. I just want for three user groups, (SuperUser:me, Coach:can view and change athelete profiles, and athletes:can change some profile attributes.

This is how I am thinking about modeling it:

from django.db import models
from django.contrib.auth.models import User

class Coach(models.Model):
user_rec = models.ForeignKey(User)
first_name
last_name
email_address
phone_number
not_active

class Athlete(models.Model):
user_rec
first_name
last_name
email_address
phone_number
reg_date
week_one_start_date
not_active

class AthleteBio(models.Model):
user_rec
age
height
weight
body_fat

The next app would be a 6 week template where the user or coach clicks on the week and enters Weight, and Body fat each week. The reason I need a coach group vs Athlete group is because the coach is the only one that can enter data for week 1 and 6 (athlete can see it) and Athlete can enter data for weeks 2 through 5.

So I'm trying to create a user model that ensures that coaches has all viewing and data entry rights and athletes can only view their own data and enter only on weeks 2-5.

I thought this was going to be super easy looking at tutorials since they always explain and everything makes sense.... but now that I'm at the wheel... I'm not sure how to connect the dots.

Would anyone be interested in helping me out?

Edit: I have looked at the docs for the class models.Permission but still not sure how to integrate it.

/r/djangolearning
https://redd.it/6li2n2
Does anybody know how to get a plotly widget to run in offline mode?

This is the example from their website:

import pandas as pd
import plotly.plotly as py

from ipywidgets import widgets
from IPython.display import display, clear_output, Image
from plotly.graph_objs import *
from plotly.widgets import GraphWidget

# define our widgets
g = GraphWidget('https://plot.ly/~kevintest/1149/')
w = widgets.Dropdown(
options=['red', 'blue', 'green'],
value='blue',
description='Colour:',
)

# generate a function to handle changes in the widget
def update_on_change(change):
g.restyle({'marker.color': change['new']})

# set a listener for changes to the dropdown widget
w.observe(update_on_change, names="selected_label")

display(w)
display(g)

This doesn't run for me at all, only the drop down appears, but no graph.
How would one go about creating a dropdown widget in offline mode? There don't seem to be any real examples with the plotly package.

/r/IPython
https://redd.it/6lf01l
[HELP] My details page isn't shown, why?

Hi, people. I'm a beginner Django developer so sorry if it's a basic question.

I have a webpage that shows a list of movies and each movie has a details view, but for some reason, the details view is never rendered.

#views.py

def index(request):
latest_movies = Movie.objects.order_by('-movie_id')[:5]

template = loader.get_template('ytsmirror/index.html')
context = {
'latest_movies' : latest_movies,
}

return HttpResponse(template.render(context, request))

def detail(request, movie_id):

movie = Movie.objects.get(movie_id=movie_id)
template = loader.get_template('ytsmirror/details.html')

context = {
'movie' : movie,
'plot': 'Lorem impsum',
}

return HttpResponse(template.render(context, request))

And my urls.py

#urls.py

from django.conf.urls import url

from . import views

app_name = 'ytsmirror'
urlpatterns = [
url(r'$', views.index, name='index'),
url(r'^(?P<movie_id>\d{4})$', views.detail, name='detail'),
]

When I try to reach /ytsmirror/4200/ for example, I don't get any error and Django apparently reaches the correct URL pattern but doesn't render the details view, it stays on the index view, without any change.

What am I doing wrong?

/r/djangolearning
https://redd.it/6lhjxy
Do you mix Vue.js templates with Django templates?

So there was this [Vue.js intro video](https://www.youtube.com/watch?v=C7oiYr4_NdU&feature=youtu.be&t=5m56s), and it showed a template with the usual Django tags (e.g. `{% %}`) with Vue.js mixed right in, so the Vue.js delimiters were set to `[[ ]]` to avoid conflicts. Is this a widely-used practice?



/r/django
https://redd.it/6lk02b
[D] Is training a NN to mimic a closed-source library legal ?

Let's imagine the following situation.
John has access to the binaries of a closed source library that computes some nice image filtering, which means that he can apply it to any input image.
Now he would like to get rid of the dependency on this library and have his own filter but does not have time to do all the research, so he trains a regression CNN (that produces filtered images) on a dataset which he creates by considering a lot of images, and - as a ground truth - the output of the library on such images.

Do you have any insight on where this stands from a legal point a view ? Is it considered as IP infringement, or maybe reverse-engineering ? Does it only depend on the license agreement of the closed-source library ?

/r/MachineLearning
https://redd.it/6lk6cu
[R] Main recommendation system algorithms and how they work
https://blog.statsbot.co/recommendation-system-algorithms-ba67f39ac9a3

/r/MachineLearning
https://redd.it/6lm529
Is Django a Good Framework for Live Data

I'm trying to decide a framework backend to learn so I can begin to learn web development. The tossup for me is to a) either Javascript and then follow with nodeJS, or continue with my knowledge and learning of Python and choose django.

Esentially the type of apps I want to make are of three categories.
Possibily a payment application like Paypal. Where individuals send and recieve each other money or any type of currency.

A Live stock ticker update application like the one shown here... http://www.marketwatch.com/investing/stock/live
where the ticker and price per stock changes WITHOUT refreshing the page. As well as other charting that I would like to do.

And possibly even to build a music streaming website. Familiar to soundcloud (I think they use rails at soundcloud).

So for me is Django a good choice? And more importantly when is Django not a good choice. Thank You.

/r/django
https://redd.it/6lmpc9
Help with making SEO friendly Form URLs

Hi All,

I have created first Django/coding project - a jobs aggregator, I'm hoping to change the default search URL query to a more google friendly URL.

The app uses Haystack/elasticsearch, it has 3 optional search forms. No input (defaults to all), 1, 2 or all 3 inputs can be used:

* q, label = ('Job Title')
* company, label = ('Company')
* location, label = ('Location')

Pressing submit on a search generates a URL of

example.com/**?q=geologist&company=BHP%20Billiton&location=Houston**

I wish for that to become a bit more friendly for SEO purposes

example.com/optional/**geologist-jobs-at-BHP-Billiton-in-Houston**

The search page has similar logic displayed at the front end to handle the 3-option search form.

{% if form.q.value %} {{ form.q.value|title }}{% endif %}
Oil & Gas Jobs
{% if form.location.value %} in {{ form.location.value|capfirst }}{% endif %}
{% if form.company.value %} at {{ form.company.value|capfirst }}{% endif %}

Result for example query is "Geologist Oil & Gas Jobs in Houston at BHP Billiton"

but I don't know where to start for URLs from queries. My googling/StackOverflow searches lead me to think its something related to [QueryDict](https://docs.djangoproject.com/en/1.11/ref/request-response/#django.http.QueryDict) but I'm not making much progress

Some modules used in this app that may be relevant

* Django==1.10.7
* django-crispy-forms==1.6.1
* elasticsearch==2.4.1
* django-haystack==2.6.1

Anyone know where I should look, or if I should be doing this at all?

/r/django
https://redd.it/6ljul6