Re: Handle changing users (e.g. a logout) in a scope/WebSockets

2018-02-18 Thread Andrew Godwin
Correct, it's fixed at connection time, much like a Django request object.
If you want to vary what user it is, I suggest you just reconnect the
websocket when the user logs in or out to make sure you don't have stale
data - you should be building for reconnection anyway as network
environments will cause them.

Andrew

On Sun, Feb 18, 2018 at 10:59 PM, Daniel Gilge  wrote:

> Packages: Channels 2.0, Django 2.0
>
> Hi,
>
> When I understand it correctly a scope’s user object isn’t updated when a
> user changes (e.g. logs in or out in another window) for the whole lifetime
> of the scope. (Please correct me if I am wrong.) Now this can be a serious
> issue as you can imagine.
>
> What are best practices to deal with that?
>
> My ideas so far:
>
> Logout
>
> I think that’s quite easy:
> I insert the channel name during connection to a list which is linked to
> the current user. (I’ll probably store that with redis.) I listen to the
> user_logged_out signal and close all channels of the user after a logout
> (using the list).
>
> Login
>
> I think I’ll do the same here because the JavaScript library should try to
> reconnect anyway. Then I had a new consumer instance with a new user
> object. But I’m not sure if this is a good practice.
>
> Alternatively I could update the user object of the scope/every consumer
> instance concerned. Maybe I could maintain a per user list containing types
> which perform the user object update. (But I don’t know if it’s read only
> or messes things up.)
>
> Other cases
>
> Procedere for is_active, is_anonymous and has_usable_password will be
> similar to login/logout.
>
> Suggestions are welcome!
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/django-users/60789998-0b64-40a4-9531-6c6f2a168b7c%40googlegroups.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAFwN1uqNRaDrQ_NdydzKKiKULNbUzRuAonhp4rAmGSF7X-s37w%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Do I need a special widget for multi-choice fields

2018-02-18 Thread Mike Dewhirst
The use case is on-line training software for a trainer entering a bunch 
of statements as possible answers to a single question. The student user 
needs to see this as a bunch of corresponding radio-buttons or select 
drop-down for a single answer selection.


I've looked at the docs:
https://docs.djangoproject.com/en/1.11/ref/forms/widgets/#widgets-inheriting-from-the-select-widget 


and
https://docs.djangoproject.com/en/1.11/ref/forms/widgets/#select

I'm using a ModelForm but the model's answer field does not use choices. 
The possible answers are all in (up to) six separate fields on the same 
model. I know this is premature denormalisation but it seemd like a good 
idea at the time.


Do I need to build a special widget which harvests the possibilities 
from those separate fields?


Maybe I have to construct the choices in a callable?

Is there a better way?

Thanks for any light

Cheers

Mike


--
You received this message because you are subscribed to the Google Groups "Django 
users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/f257d5f9-83fe-bde1-c277-c96a67d8184e%40dewhirst.com.au.
For more options, visit https://groups.google.com/d/optout.


Handle changing users (e.g. a logout) in a scope/WebSockets

2018-02-18 Thread Daniel Gilge
Packages: Channels 2.0, Django 2.0

Hi,

When I understand it correctly a scope’s user object isn’t updated when a 
user changes (e.g. logs in or out in another window) for the whole lifetime 
of the scope. (Please correct me if I am wrong.) Now this can be a serious 
issue as you can imagine.

What are best practices to deal with that?

My ideas so far:

Logout

I think that’s quite easy:
I insert the channel name during connection to a list which is linked to 
the current user. (I’ll probably store that with redis.) I listen to the 
user_logged_out signal and close all channels of the user after a logout 
(using the list).

Login

I think I’ll do the same here because the JavaScript library should try to 
reconnect anyway. Then I had a new consumer instance with a new user 
object. But I’m not sure if this is a good practice.

Alternatively I could update the user object of the scope/every consumer 
instance concerned. Maybe I could maintain a per user list containing types 
which perform the user object update. (But I don’t know if it’s read only 
or messes things up.)

Other cases

Procedere for is_active, is_anonymous and has_usable_password will be 
similar to login/logout.

Suggestions are welcome!

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/60789998-0b64-40a4-9531-6c6f2a168b7c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: When to use get_user_model()

2018-02-18 Thread Xavier Paniello
Hi tangoward15,

Django will use auth.User as the user model in the system, unless you 
change AUTH_USER_MODEL = RegUser in settings.py

Be carefull, to change the user model has some particularities you can read 
in docs (warning section):
https://docs.djangoproject.com/en/2.0/ref/settings/#auth-user-model

Other option to extend auth.User is a model with a one2one field related to 
auth.User, or a proxy model:
https://simpleisbetterthancomplex.com/tutorial/2016/07/22/how-to-extend-django-user-model.html

Salut!


El diumenge, 18 febrer de 2018 15:23:53 UTC+1, tangoward15 va escriure:
>
> @Mukul Agrawal,
>
> thanks, i'll read this.
>
>
> @Xavier,
>
> the model in forms.py, does it mean it will use the RegUser class from the 
> models.py? Sorry, I am confuse.
>
> On Sun, Feb 18, 2018 at 9:41 PM, Mukul Agrawal  > wrote:
>
>> The answer on this link can also help you in why and when to use 
>> get_user_model(). 
>>
>> https://stackoverflow.com/questions/24629705/django-using-get-user-model-vs-settings-auth-user-model
>>
>>
>> On Feb 18, 2018 4:11 AM, "tango ward" > 
>> wrote:
>>
>>
>> Hi, 
>>
>> I am playing around with user registration. I came across a code where 
>> the get_user_model() was assigned to a model in Meta class inside a form. I 
>> was just wondering, what is the benefit of using the get_user_model() as 
>> Model in a form instead of importing a class from models.py then use that 
>> class as model of the form and when should I use it?
>>
>> models.py
>> class RegUser(User):
>>
>> def __str__(self):
>> return self.username
>>
>> forms.py
>>
>> class UserCreateForm(UserCreationForm):
>>
>> class Meta:
>> fields = ('username', 'password1', 'password2')
>> model = get_user_model()
>>
>>
>> Thanks,
>> Jarvis
>>
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to django-users...@googlegroups.com .
>> To post to this group, send email to django...@googlegroups.com 
>> .
>> Visit this group at https://groups.google.com/group/django-users.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/django-users/CAA6wQL%2Bq1kQ7ukjtE3gV64iu9y2SXdgojZXBF3R46BCuTN0xoA%40mail.gmail.com
>>  
>> 
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>>
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to django-users...@googlegroups.com .
>> To post to this group, send email to django...@googlegroups.com 
>> .
>> Visit this group at https://groups.google.com/group/django-users.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/django-users/CACRd7haky8%2BY7%2BNDHNFV3EbiSxBU4B65CJUSF7v3mXb3%3DP8D%2BA%40mail.gmail.com
>>  
>> 
>> .
>>
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/226fceca-eb59-49c8-9606-b869f0c25feb%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Basic note/trello app - how to link model object IDs

2018-02-18 Thread Lylio
Hi everyone,

I've unfortunately hit another brick wall with my Django app. I have my 
list of card objects, and when one of them is clicked, I'd like a new page 
to open that contains the details for the card that was clicked. I found 
out how to create a URL using {{ card.id }}:

{% for card in cards.all %}
{{ card.title 
}} 
{% endfor %}


and in views the card def is simply:

def card(request):
return render(request, 'scrumbuddy/card.html')


So, for example if I click on the third card object in the list, the URL 
returned is http://127.0.0.1:8000/scrumbuddy/card/3

But I'm unsure of how to populate 
the http://127.0.0.1:8000/scrumbuddy/card/3 page with the database info for 
card 3. Hopefully this screenshot can demonstrate:























On Monday, 12 February 2018 21:00:53 UTC, Lylio wrote:
>
> Hi everyone,
>
> I'm new to Django and currently working on a very simple app. It's 
> basically a note app, a bit like a Trello board but aimed at creating 
> user-story cards for software development teams (code at 
> https://github.com/Lylio/scrumbuddy_project).
>
> I made a mock-up in Photoshop of how it's supposed to look:
>
>   
>
>
> I've got some basic functionality up and running - users can register and 
> create a user-story card. When a new card is created, a title, description, 
> time estimation are inputted. Cards are just displayed as list items in 
> columns. I'm trying to add a button to the cards so that when it's clicked, 
> the details of the card open up in a new and a user can edit the card info 
> or delete it. 
>
> A couple of noob questions:
>
> 1. To click on a card so it opens up and displays the details, am I right 
> to say I should create a card.html file in the templates folder for this? 
>
> 2. I'm confused about how Django keeps track of the cards in my app - I 
> presume each card object has an ID in the database and I'd need this ID in 
> order to retrieve the card's details when it's clicked - but I'm unsure of 
> how to link the two. In the two pictures above, say someone clicked on the 
> 'class progression' card on the left... I'd like a new page to open up that 
> display the details for that card and allows the user to edit the info or 
> completely delete the card.
>
> I'm maybe asking a bit much here - but I'm unsure of how complex these 
> requirements are. It feels like it should be *fairly *straightforward. 
> Any thoughts or advice would be greatly appreciated.
>
> Thanks for your time
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/5e39f472-d372-42b8-a5fe-ac1c3a0d75ea%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [1.11] Django loads sub-string url

2018-02-18 Thread Henrik Baran
Hi Daniel,

thanks a lot, that solved it for me!


On 18.02.2018 19:25, Daniel Roseman wrote:
> On Sunday, 18 February 2018 16:19:31 UTC, Henrik Baran wrote:
>
> Hi,
>
> I face a very weird phenomenon. I have following two urls
> established:
>
> url(r'types/$', views.types, name='types'),
> url(r'box_types/$', views.box_types, name='box types')
>
>
> If I load "/types/" the view "types" is shown, all ok. In case I
> load "/box_types" unexpectedly also "types" is shown. However, I
> expect "box_types" to load. How is this possible? I tested with
> some other urls and it seem like in case a url string is a
> sub-string of another url, it always loads the sub-string url.
>
> Is this a feature I am not aware of or are we looking on a bug?
>
> Thanks for reply and best regards,
> Henrik
>
>
>
> There is a bug, but it is in your regexes. You need to anchor the
> pattern to the start of the string: 
>
> url(r'^types/$', views.types, name='types'),
> url(r'^box_types/$', views.box_types, name='box types')
>
> --
> DR.
> -- 
> You received this message because you are subscribed to the Google
> Groups "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to django-users+unsubscr...@googlegroups.com
> .
> To post to this group, send email to django-users@googlegroups.com
> .
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/e31b2082-9b80-49a2-a8d4-c3007b155f48%40googlegroups.com
> .
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/857697f5-30b6-4cde-7422-63dd02fb2cae%40posteo.de.
For more options, visit https://groups.google.com/d/optout.


signature.asc
Description: OpenPGP digital signature


Re: [1.11] Django loads sub-string url

2018-02-18 Thread Daniel Roseman
On Sunday, 18 February 2018 16:19:31 UTC, Henrik Baran wrote:
>
> Hi,
>
> I face a very weird phenomenon. I have following two urls established: 
>
> url(r'types/$', views.types, name='types'),
> url(r'box_types/$', views.box_types, name='box types')
>
>
> If I load "/types/" the view "types" is shown, all ok. In case I load 
> "/box_types" unexpectedly also "types" is shown. However, I expect 
> "box_types" to load. How is this possible? I tested with some other urls 
> and it seem like in case a url string is a sub-string of another url, it 
> always loads the sub-string url. 
>
> Is this a feature I am not aware of or are we looking on a bug?
>
> Thanks for reply and best regards,
> Henrik
>


There is a bug, but it is in your regexes. You need to anchor the pattern 
to the start of the string: 

url(r'^types/$', views.types, name='types'),
url(r'^box_types/$', views.box_types, name='box types')

--
DR.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/e31b2082-9b80-49a2-a8d4-c3007b155f48%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Stripe problem: InvalidRequestError: This customer has no attached payment source

2018-02-18 Thread Etienne Robillard
I'd suggest you look into the api_requestor.py source code to actually 
trace this problem.


HTH,

Etienne


Le 2018-02-18 à 10:30, Tom Tanner a écrit :

I've been following the Quickstart guides from Stripe.

https://stripe.com/docs/quickstart

https://stripe.com/docs/subscriptions/quickstart


This is what my form looks like:

|

        {% csrf_token %}
        {% for field in registration_form %}
{{ field }}
            {% if field.errors %}
{{ field.errors.as_text|cut:"* "|escape }}
            {% endif %}
        {% endfor %}
        {% if registration_form.non_field_errors %}
{{ 
registration_form.non_field_errors.as_text|cut:"* "|escape }}

        {% endif %}




btn-primary"type="submit">Register



vardisplayError=  document.getElementById('card-errors');
varstripe=Stripe("pk_test_BjhejGz5DZNcSHUVaqoipMtF");
varelements=      stripe.elements();

varstyle={
                base:{
                    fontSize:"1.1875rem",
                    fontSmoothing:"always",
                    fontWeight:"600"
}
};

varcard=elements.create("card",{style:style});
            card.mount("#card-element");
            card.addEventListener('change',function(event){

if(event.error){
                    displayError.textContent =event.error.message;
}else{
                    displayError.textContent ='';
}
});

varformID="register-form";
varform=document.getElementById(formID);
            form.addEventListener("submit",function(event){
                event.preventDefault();

                stripe.createToken(card).then(function(result){
if(result.error){
                        displayError.textContent=result.error.message;
}else{
                        stripeTokenHandler(result.token,formID);
}
})
});
// tut https://stripe.com/docs/stripe-js/elements/quickstart#create-form
functionstripeTokenHandler(token,formID){
// Insert the token ID into the form so it gets submitted to the server
varform =document.getElementById(formID);
varhiddenInput =document.createElement('input');
                hiddenInput.setAttribute('type','hidden');
                hiddenInput.setAttribute('name','stripeToken');
                hiddenInput.setAttribute('value',token.id);
                form.appendChild(hiddenInput);
// Submit the form
                form.submit();
}


|



Then my `views.py` has this:

|
ifregistration_form.is_valid():
  stripe.api_key="sk_test_8rdFokhVsbsJJysHeKgyrMTc"
  stripeCustomer=stripe.Customer.create(
   email=request.POST["username"],
)
  subscription=stripe.Subscription.create(
   customer=stripeCustomer["id"],
   items=[{"plan":"plan_CLFfBrRAKl7TRt"}],
)
|



This gives me an error:
|


InternalServerError:/login-register/
Traceback(most recent call last):
File"/home/myUserName/myDjangoProjectWithStripe/local/lib/python2.7/site-packages/django/core/handlers/exception.py",line 
42,ininner

        response =get_response(request)
File"/home/myUserName/myDjangoProjectWithStripe/local/lib/python2.7/site-packages/django/core/handlers/base.py",line 
249,in_legacy_get_response

        response =self._get_response(request)
File"/home/myUserName/myDjangoProjectWithStripe/local/lib/python2.7/site-packages/django/core/handlers/base.py",line 
178,in_get_response
        response 
=middleware_method(request,callback,callback_args,callback_kwargs)
File"/home/myUserName/myDjangoProjectWithStripe/local/lib/python2.7/site-packages/mezzanine/pages/middleware.py",line 
98,inprocess_view

returnview_func(request,*view_args,**view_kwargs)
File"/home/myUserName/myDjangoProjectWithStripe/product_blog/theme/views.py",line 
154,inlogin_register

        items=[{"plan":"plan_CLFfBrRAKl7TRt"}],
File"/home/myUserName/myDjangoProjectWithStripe/local/lib/python2.7/site-packages/stripe/api_resources/subscription.py",line 
33,increate

returnsuper(Subscription,cls).create(**params)
File"/home/myUserName/myDjangoProjectWithStripe/local/lib/python2.7/site-packages/stripe/api_resources/abstract/createable_api_resource.py",line 
17,increate

        response,api_key =requestor.request('post',url,params,headers)
File"/home/myUserName/myDjangoProjectWithStripe/local/lib/python2.7/site-packages/stripe/api_requestor.py",line 
153,inrequest

        resp =self.interpret_response(rbody,rcode,rheaders)
File"/home/myUserName/myDjangoProjectWithStripe/local/lib/python2.7/site-packages/stripe/api_requestor.py",line 
365,ininterpret_response

self.handle_error_response(rbody,rcode,resp.data,rheaders)
File"/home/myUserName/myDjangoProjectWithStripe/local/lib/python2.7/site-packages/stripe/api_requestor.py",line 
178,inhandle_error_response

raiseerr
InvalidRequestError:Requestreq_o39ceLlhtpJmmr:Thiscustomer has 
noattached payment source

|


How do I attach a payment source to the customer? Since I'm testing, I 
use the testing credit card, which has the number `4242 4242 4242 4242`.

--
You received this message because you are subscribed to the Google 
Groups "Django users" group.
To unsubscribe from this group and stop receiving emai

[1.11] Django loads sub-string url

2018-02-18 Thread Henrik Baran
Hi,

I face a very weird phenomenon. I have following two urls established:

url(r'types/$', views.types, name='types'),
url(r'box_types/$', views.box_types, name='box types')


If I load "/types/" the view "types" is shown, all ok. In case I load
"/box_types" unexpectedly also "types" is shown. However, I expect
"box_types" to load. How is this possible? I tested with some other urls
and it seem like in case a url string is a sub-string of another url, it
always loads the sub-string url.

Is this a feature I am not aware of or are we looking on a bug?

Thanks for reply and best regards,
Henrik

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/e5d1b683-c6e3-8bc8-01f3-853ff4cb97ca%40posteo.de.
For more options, visit https://groups.google.com/d/optout.


signature.asc
Description: OpenPGP digital signature


Re: Django 1.9 Apps aren't loaded yet

2018-02-18 Thread Kaleemullah Rao

>
> I am getting this error while i create a newapp and integrate in the 
>>> setting and urls file in sample project 
>>
>> C:\Users\RaoKaleemullah\Desktop\django-tutorial\sample>python manage.py 
>>> runserve
>>
>> r
>>
>> Traceback (most recent call last):
>>
>>   File "manage.py", line 10, in 
>>
>> execute_from_command_line(sys.argv)
>>
>>   File 
>>> "C:\Users\RaoKaleemullah\Anaconda2\lib\site-packages\django-1.9-py2.7.egg
>>
>> \django\core\management\__init__.py", line 350, in 
>>> execute_from_command_line
>>
>> utility.execute()
>>
>>   File 
>>> "C:\Users\RaoKaleemullah\Anaconda2\lib\site-packages\django-1.9-py2.7.egg
>>
>> \django\core\management\__init__.py", line 342, in execute
>>
>> self.fetch_command(subcommand).run_from_argv(self.argv)
>>
>>   File 
>>> "C:\Users\RaoKaleemullah\Anaconda2\lib\site-packages\django-1.9-py2.7.egg
>>
>> \django\core\management\__init__.py", line 176, in fetch_command
>>
>> commands = get_commands()
>>
>>   File 
>>> "C:\Users\RaoKaleemullah\Anaconda2\lib\site-packages\django-1.9-py2.7.egg
>>
>> \django\utils\lru_cache.py", line 100, in wrapper
>>
>> result = user_function(*args, **kwds)
>>
>>   File 
>>> "C:\Users\RaoKaleemullah\Anaconda2\lib\site-packages\django-1.9-py2.7.egg
>>
>> \django\core\management\__init__.py", line 71, in get_commands
>>
>> for app_config in reversed(list(apps.get_app_configs())):
>>
>>   File 
>>> "C:\Users\RaoKaleemullah\Anaconda2\lib\site-packages\django-1.9-py2.7.egg
>>
>> \django\apps\registry.py", line 137, in get_app_configs
>>
>> self.check_apps_ready()
>>
>>   File 
>>> "C:\Users\RaoKaleemullah\Anaconda2\lib\site-packages\django-1.9-py2.7.egg
>>
>> \django\apps\registry.py", line 124, in check_apps_ready
>>
>> raise AppRegistryNotReady("Apps aren't loaded yet.")
>>
>> django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet.
>>
>>
>>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/416c267f-4660-42a8-b3e6-4b909542511a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Stripe problem: InvalidRequestError: This customer has no attached payment source

2018-02-18 Thread Tom Tanner
I've been following the Quickstart guides from Stripe.

https://stripe.com/docs/quickstart

https://stripe.com/docs/subscriptions/quickstart


This is what my form looks like:


{% csrf_token %}
{% for field in registration_form %}
{{ field }}
{% if field.errors %}
{{ field.errors.as_text|cut:"* 
"|escape }}
{% endif %} 
{% endfor %}
{% if registration_form.non_field_errors %}
{{ 
registration_form.non_field_errors.as_text|cut:"* "|escape }}
{% endif %}


  


Register


var displayError=   document.getElementById('card-errors');
var stripe= Stripe("pk_test_BjhejGz5DZNcSHUVaqoipMtF");
var elements=   stripe.elements();

var style=  {
base: {
fontSize: "1.1875rem",
fontSmoothing: "always",
fontWeight: "600"
}
};

var card=   elements.create("card",{style:style});
card.mount("#card-element");
card.addEventListener('change', function(event) {

if (event.error) {
displayError.textContent = event.error.message;
} else {
displayError.textContent = '';
}
});

var formID= "register-form";
var form=   document.getElementById(formID);
form.addEventListener("submit",function(event){
event.preventDefault();

stripe.createToken(card).then(function(result){
if(result.error) {
displayError.textContent=   result.error.message;
} else {
stripeTokenHandler(result.token, formID);
}   
})
});
// tut 
https://stripe.com/docs/stripe-js/elements/quickstart#create-form
function stripeTokenHandler(token, formID) {
// Insert the token ID into the form so it gets submitted 
to the server
var form = document.getElementById(formID);
var hiddenInput = document.createElement('input');
hiddenInput.setAttribute('type', 'hidden');
hiddenInput.setAttribute('name', 'stripeToken');
hiddenInput.setAttribute('value', token.id);
form.appendChild(hiddenInput);
// Submit the form
form.submit();
}





Then my `views.py` has this:

 if registration_form.is_valid():
  stripe.api_key= "sk_test_8rdFokhVsbsJJysHeKgyrMTc"
  stripeCustomer= stripe.Customer.create(
   email=request.POST["username"],
  )
  subscription= stripe.Subscription.create(
   customer=stripeCustomer["id"],
   items=[{"plan":"plan_CLFfBrRAKl7TRt"}],
  )



This gives me an error:


Internal Server Error: /login-register/
Traceback (most recent call last):
  File 
"/home/myUserName/myDjangoProjectWithStripe/local/lib/python2.7/site-packages/django/core/handlers/exception.py"
, line 42, in inner
response = get_response(request)
  File 
"/home/myUserName/myDjangoProjectWithStripe/local/lib/python2.7/site-packages/django/core/handlers/base.py"
, line 249, in _legacy_get_response
response = self._get_response(request)
  File 
"/home/myUserName/myDjangoProjectWithStripe/local/lib/python2.7/site-packages/django/core/handlers/base.py"
, line 178, in _get_response
response = middleware_method(request, callback, callback_args, 
callback_kwargs)
  File 
"/home/myUserName/myDjangoProjectWithStripe/local/lib/python2.7/site-packages/mezzanine/pages/middleware.py"
, line 98, in process_view
return view_func(request, *view_args, **view_kwargs)
  File 
"/home/myUserName/myDjangoProjectWithStripe/product_blog/theme/views.py", 
line 154, in login_register
items=[{"plan":"plan_CLFfBrRAKl7TRt"}],
  File 
"/home/myUserName/myDjangoProjectWithStripe/local/lib/python2.7/site-packages/stripe/api_resources/subscription.py"
, line 33, in create
return super(Subscription, cls).create(**params)
  File 
"/home/myUserName/myDjangoProjectWithStripe/local/lib/python2.7/site-packages/stripe/api_resources/abstract/createable_api_resource.py"
, line 17, in create
response, api_key = requestor.request('post', url, params, headers)
  File 
"/home/myUserName/myDjangoProjectWithStripe/local/lib/python2.7/site-packages/stripe/api_requestor.py"
, line 153, in request
resp = self.interpret_response(rbody, rcode, rheaders)
  File 
"/home/myUserName/myDjangoProjectW

Re: When to use get_user_model()

2018-02-18 Thread tango ward
@Mukul Agrawal,

thanks, i'll read this.


@Xavier,

the model in forms.py, does it mean it will use the RegUser class from the
models.py? Sorry, I am confuse.

On Sun, Feb 18, 2018 at 9:41 PM, Mukul Agrawal  wrote:

> The answer on this link can also help you in why and when to use
> get_user_model().
> https://stackoverflow.com/questions/24629705/django-
> using-get-user-model-vs-settings-auth-user-model
>
>
> On Feb 18, 2018 4:11 AM, "tango ward"  wrote:
>
>
> Hi,
>
> I am playing around with user registration. I came across a code where the
> get_user_model() was assigned to a model in Meta class inside a form. I was
> just wondering, what is the benefit of using the get_user_model() as Model
> in a form instead of importing a class from models.py then use that class
> as model of the form and when should I use it?
>
> models.py
> class RegUser(User):
>
> def __str__(self):
> return self.username
>
> forms.py
>
> class UserCreateForm(UserCreationForm):
>
> class Meta:
> fields = ('username', 'password1', 'password2')
> model = get_user_model()
>
>
> Thanks,
> Jarvis
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit https://groups.google.com/d/ms
> gid/django-users/CAA6wQL%2Bq1kQ7ukjtE3gV64iu9y2SXdgojZXBF3R4
> 6BCuTN0xoA%40mail.gmail.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/django-users/CACRd7haky8%2BY7%2BNDHNFV3EbiSxBU4B65CJUSF7v3mX
> b3%3DP8D%2BA%40mail.gmail.com
> 
> .
>
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAA6wQLJDaCw30Rm05pEGOhpUJJt9yGSJ9R7FdnnNopANobY%2B7A%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: When to use get_user_model()

2018-02-18 Thread Mukul Agrawal
The answer on this link can also help you in why and when to use
get_user_model().
https://stackoverflow.com/questions/24629705/django-using-get-user-model-vs-settings-auth-user-model


On Feb 18, 2018 4:11 AM, "tango ward"  wrote:


Hi,

I am playing around with user registration. I came across a code where the
get_user_model() was assigned to a model in Meta class inside a form. I was
just wondering, what is the benefit of using the get_user_model() as Model
in a form instead of importing a class from models.py then use that class
as model of the form and when should I use it?

models.py
class RegUser(User):

def __str__(self):
return self.username

forms.py

class UserCreateForm(UserCreationForm):

class Meta:
fields = ('username', 'password1', 'password2')
model = get_user_model()


Thanks,
Jarvis

-- 
You received this message because you are subscribed to the Google Groups
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/
msgid/django-users/CAA6wQL%2Bq1kQ7ukjtE3gV64iu9y2SXdgojZX
BF3R46BCuTN0xoA%40mail.gmail.com

.
For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CACRd7haky8%2BY7%2BNDHNFV3EbiSxBU4B65CJUSF7v3mXb3%3DP8D%2BA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: When to use get_user_model()

2018-02-18 Thread Xavier Paniello
Hi tangoward15,

The User model by default is auth.User, but you can define a custom one and 
reference it at settings: 
https://docs.djangoproject.com/en/2.0/ref/settings/#auth-user-model

So, get_user_model() will return the model defined at AUTH_USER_MODEL 
setting.

Salut!

El dissabte, 17 febrer de 2018 23:44:34 UTC+1, tangoward15 va escriure:
>
> I also checked the documentation of it but I am confuse. It says "Instead 
> of referring to User 
> 
>  
> directly, you should reference the user model using 
> django.contrib.auth.get_user_model(). This method will return the 
> currently active user model – the custom user model if one is specified, or 
> User 
> 
>  
> otherwise." When it says "currently active user mode" is it the model that 
> I created in models.py or the one that is currently logged in to the 
> website? what does "or User otherwise" mean? 
>
> My apologies for asking too many questions.
>
> On Sun, Feb 18, 2018 at 6:39 AM, tango ward  > wrote:
>
>>
>> Hi, 
>>
>> I am playing around with user registration. I came across a code where 
>> the get_user_model() was assigned to a model in Meta class inside a form. I 
>> was just wondering, what is the benefit of using the get_user_model() as 
>> Model in a form instead of importing a class from models.py then use that 
>> class as model of the form and when should I use it?
>>
>> models.py
>> class RegUser(User):
>>
>> def __str__(self):
>> return self.username
>>
>> forms.py
>>
>> class UserCreateForm(UserCreationForm):
>>
>> class Meta:
>> fields = ('username', 'password1', 'password2')
>> model = get_user_model()
>>
>>
>> Thanks,
>> Jarvis
>>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/00ed285c-9adf-4814-8626-6b856baee8a0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Strange problem with Django

2018-02-18 Thread Andy
How did you try to run the command? It sounds that you told you computer to 
open the file instead.
You have to run that in the command shell of your OS. (Terminal on OSX or 
Powershell in Windows)

Am Samstag, 17. Februar 2018 18:48:58 UTC+1 schrieb Tet Yeap:
>
> Hi,
>
> I was trying to learn Django. I have installed Python 3.6 and Django. 
> The installation was successful. When I ran "django-admin startproject 
> mysite" to create a new project, the attached file showed up and the 
> program stop. What is wrong?
>
> Thank you.
>
> Tet Yeap
>  
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/b30fad7c-cdba-4699-be5f-81eff4799a3d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.