Weird form validation question

2014-10-09 Thread termopro
Hi,

I am building a user registration page. Page has a form where user can 
select his current state and city.

The problem with that is that i cannot load list of cities into the form 
when the page is being generated.
That's because i show the user only cities from his state, not all of them.

So i generate a form with a list of states and an empty 'cities'. When user 
selects one of the states, i populate 'cities' with ajax.

Everything works fine, except i don't know how to validate 'cities' 
correctly and show form errors.
What is the correct way of doing this ?

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/25d67c01-df04-424c-9171-88def729d3a6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Weird form validation question

2014-10-09 Thread Sergiy Khohlov
Are you using form_valid method in view ?

Many thanks,

Serge


+380 636150445
skype: skhohlov

On Thu, Oct 9, 2014 at 10:10 AM, termopro  wrote:

> Hi,
>
> I am building a user registration page. Page has a form where user can
> select his current state and city.
>
> The problem with that is that i cannot load list of cities into the form
> when the page is being generated.
> That's because i show the user only cities from his state, not all of them.
>
> So i generate a form with a list of states and an empty 'cities'. When
> user selects one of the states, i populate 'cities' with ajax.
>
> Everything works fine, except i don't know how to validate 'cities'
> correctly and show form errors.
> What is the correct way of doing this ?
>
> --
> 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 http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/25d67c01-df04-424c-9171-88def729d3a6%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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CADTRxJNqQ1FhOKxEVF%3DXBa2mcUsFVTyY%3DTQpMTXfg1__ZyRYFA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Weird form validation question

2014-10-09 Thread termopro
I am using form.is_valid()

On Thursday, October 9, 2014 10:54:56 AM UTC+3, Sergiy Khohlov wrote:
>
> Are you using form_valid method in view ? 
>
> Many thanks,
>
> Serge
>
>
> +380 636150445
> skype: skhohlov
>
> On Thu, Oct 9, 2014 at 10:10 AM, termopro 
> > wrote:
>
>> Hi,
>>
>> I am building a user registration page. Page has a form where user can 
>> select his current state and city.
>>
>> The problem with that is that i cannot load list of cities into the form 
>> when the page is being generated.
>> That's because i show the user only cities from his state, not all of 
>> them.
>>
>> So i generate a form with a list of states and an empty 'cities'. When 
>> user selects one of the states, i populate 'cities' with ajax.
>>
>> Everything works fine, except i don't know how to validate 'cities' 
>> correctly and show form errors.
>> What is the correct way of doing this ?
>>
>> -- 
>> 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 http://groups.google.com/group/django-users.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/django-users/25d67c01-df04-424c-9171-88def729d3a6%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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/035094d3-4359-4823-a991-e2ac2b08c96e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Weird form validation question

2014-10-09 Thread Sergiy Khohlov
could you please paste  code in form valid block ?

Many thanks,

Serge


+380 636150445
skype: skhohlov

On Thu, Oct 9, 2014 at 11:23 AM, termopro  wrote:

> I am using form.is_valid()
>
> On Thursday, October 9, 2014 10:54:56 AM UTC+3, Sergiy Khohlov wrote:
>>
>> Are you using form_valid method in view ?
>>
>> Many thanks,
>>
>> Serge
>>
>>
>> +380 636150445
>> skype: skhohlov
>>
>> On Thu, Oct 9, 2014 at 10:10 AM, termopro  wrote:
>>
>>> Hi,
>>>
>>> I am building a user registration page. Page has a form where user can
>>> select his current state and city.
>>>
>>> The problem with that is that i cannot load list of cities into the form
>>> when the page is being generated.
>>> That's because i show the user only cities from his state, not all of
>>> them.
>>>
>>> So i generate a form with a list of states and an empty 'cities'. When
>>> user selects one of the states, i populate 'cities' with ajax.
>>>
>>> Everything works fine, except i don't know how to validate 'cities'
>>> correctly and show form errors.
>>> What is the correct way of doing this ?
>>>
>>> --
>>> 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 http://groups.google.com/group/django-users.
>>> To view this discussion on the web visit https://groups.google.com/d/
>>> msgid/django-users/25d67c01-df04-424c-9171-88def729d3a6%
>>> 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 http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/035094d3-4359-4823-a991-e2ac2b08c96e%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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CADTRxJO0eMXVdjbLa9S6Q_8krUBEmxiGYwmwSfO6-58QmQkfew%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: positiveintegerfield - display value in add template & remove value in edit template

2014-10-09 Thread Collin Anderson
hmm... you may need to override the form field on your form. I'm going to 
go out on a limb and use some soon-to-be documented syntax.

new_choices = [(id, v) for id, v in AchievementDetails.ACHIEVEMENT_TYPES if 
id != 0]
class AchievementDetailsForm(forms.ModelForm):
achievement_type = 
AchievementDetails._meta.get_field('achievement_type').formfield(choices=choices)

Actually, better yet, are you using django 1.7? You can do this:
 - change SELECT_ACHIEVEMENT_TYPE = 0 to SELECT_ACHIEVEMENT_TYPE = None
- define your field like this:
achievement_type = models.PositiveIntegerField(choices=ACHIEVEMENT_TYPES
)



-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/89579b27-934a-4488-852c-778c6f8d83b1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Multiple django inlineformset_factory problem

2014-10-09 Thread Farhan Khan
Hi all,

I am writing a tool that implements NIST security controls and having 
trouble implementing inlineformset_factory, which I think is the solution 
to this problem.

Background: I have two models, one is called 'Controls' and the other is 
'Implementation'. When the user goes to a page, the views.py should query 
several relevant controls as text (not as a Form) and then an 
Implementation form immediately afterwards. This will be repeated depending 
on the number of Controls are found.

So, lets suppose there are 20 controls, you should see a table with the 
following:

{% for control in controlset %}

Control Name: "This is the control name 1" -- Presumably this comes from: {{ 
control.name.value }}
Control Description: "This is the control description 1" -- Presumably this 
comes from: {{ control.description.value }}
Implementation Statement: [Input type=text name=1_implementation] -- Not 
sure how to display this
Implementation Status: [Input type=text name=1_status] -- Not sure how to 
display this

{% endfor %}

(This is pseudo-code, removed the HTML for visibility)

This frame should be repeated depending on the number of controls, it could 
be 5, 20 or 100, then a submit button. When the user submits the data, I 
want to capture this data into several 'Implementation' objects and save 
them in the database.

My failing code currently does this:

ControlImplementationSet = inlineformset_factory(Controls, Implementation)
allControls = Controls.objects.get(pk=1)
controlset = ControlImplementationSet(instance=allControls)

Even though I want multiple forms, I used the Controls.objects.get(pk=1) to 
specify a single control. When I send the variable controlset as a context 
to be displayed as:

{{ controlset }}

I oddly get 3 forms that look like autogenerations of the Implementation 
form with an extra "Delete" option. That makes no sense to me. I don't know 
understand why this is displayed. I want to display the queried controls, 
followed by an implementation form.

My questions are:

   1. Why do I get 3 "Implementation" forms, instead of just 1, when I did 
   Controls.objects.get(pk=1), which should specify a single Control?
   2. How do I display multiple Implementation Forms for each Control that 
   is returned?
   3. How do I only display certain elements of the Implementation form, 
   not every field in the model as an HTML  field?
   4. How do I have my views.py interpret the submitted Implementation form 
   data from the user?

And last but not least...is there a sample of this? Surely I am not the 
first one who has done this, and the he documentation is not making sense 
to me.
https://docs.djangoproject.com/en/1.7/topics/forms/modelforms/#inline-formsets

Please advise, this is day two, quite frustrated.

Thanks,
Farhan

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/89495462-3f99-4b9d-86bd-61db11126b94%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


permissions and inlines issues

2014-10-09 Thread Emanuel
Hi all!

I have this situation:

class A(models.Model):
   ...

class B(models.Model):
   ---

class C(models.Model):
   

Then I have User 1, User 2 and User 3

B and C are inlines for A

I register A, B and C in admin

I want User 1 and add and edit B and can't add or edit A

and I want User 2 can add and edit on A but not on A

But in both situations they can only do it (and see it) as they are Inlines

And I need A, B and C registered in admin because User 3 can add and edit B 
and C while they are not Inlines

I googled it and I can't find any solution

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/b02e9a8e-b27c-4280-898d-dc8f74df0542%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Multiple django inlineformset_factory problem

2014-10-09 Thread Collin Anderson
Ahh, yes, those docs assume you've also read the non-model formset docs:
https://docs.djangoproject.com/en/1.7/topics/forms/formsets/

Why do I get 3 "Implementation" forms, instead of just 1, when I did 
> Controls.objects.get(pk=1), which should specify a single Control? 

It will show one form for each implementation already in the database, 
plus, by default, one "extra" blank form for adding an additional 
implementation for that control.

How do I display multiple Implementation Forms for each Control that is 
> returned?

Formsets are for handling an arbitrary number of forms, and it sounds like 
you want _multiple_ _formsets_.

How do I only display certain elements of the Implementation form, not 
> every field in the model as an HTML  field?

Pass in "fields" to your factory call.
https://docs.djangoproject.com/en/1.7/topics/forms/modelforms/#modelform-factory-function

How do I have my views.py interpret the submitted Implementation form data 
> from the user?

I think your case is pretty complicated. Does this seem right?

ControlImplementationSet = inlineformset_factory(Controls, Implementation, 
fields=['implementation', 'status'])

def the_view(request):
controls = Controls.objects.all()
controlsets = []
if request.method == 'POST':  # handling submitted data
all_valid = True
for control in controls:
formset = ControlImplementationSet(request.POST, instance=
control, prefix='control_%s' % control.pk)
if not formset.is_valid():
all_valid = False
controlsets.append(formset)
if all_valid:
for formset in controlsets:
formset.save()
return redirect('/success!/')
else:  # displaying the forms the first time
for control in controls:
formset = ControlImplementationSet(instance=control, prefix=
'control_%s' % control.pk)
controlsets.append(formset)
return render(request, 'the_template.html', {'controlsets': controlsets
})

Then, in your template:
{% for formset in controlsets %}

Control Name: {{ formset.instance.name }}
Control Description: {{ formset.instance.description }}

{% for form in formset %}  {# multiple forms per control #}
Implementation Statement: {{ form.implementation }}
Implementation Status: {{ form.status }}
{% endform %}

{% endfor %}

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/7db396d5-3302-4500-a37d-709e5e923475%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: permissions and inlines issues

2014-10-09 Thread Collin Anderson
Why can't the first two users edit the data the same way as user 3?

I'd recommend overriding get_readonly_fields() on the ModelAdmin for A so 
that all fields are readonly for the users who aren't allowed to edit model 
A. They'll still need the "can edit" permission for model A.
https://docs.djangoproject.com/en/1.7/ref/contrib/admin/#django.contrib.admin.ModelAdmin.get_readonly_fields

I _think_ the inlines will automatically figure out if the user has 
permission to edit them. Otherwise, you can override get_inline_instances() 
to remove the inlines if they can't edit them.
https://docs.djangoproject.com/en/1.7/ref/contrib/admin/#django.contrib.admin.ModelAdmin.get_inline_instances

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/8e764a78-bd95-41cd-8de0-d3781d1979b7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: cant pass the "CSRF verification failed. Request aborted." error

2014-10-09 Thread dk
Ah   nice trick, store the variables into the url and then pass the url 
with some regular expression.
=)



def vote(request):
if request.method == "POST":
form = polls.forms_DK.NameForm(request.POST)
if form.is_valid():
*your_email **= form.cleaned_data["your_email"]*
*ratio **= str(form.cleaned_data["ratio"])*
*adress **= "thanks/"+your_email+"/"*
return HttpResponseRedirect(adress)
else:
form = polls.forms_DK.NameForm()
django.setup()
all_restaurants = Restaurant.objects.all()
#return render_to_response("vote_form.html", {"all_restaurants": 
all_restaurants, "form": form})
return render(request, "vote_form.html", {"all_restaurants": 
all_restaurants, "form": form})


ok now to learn how to catch that url
will something like this would work?
url(r'^thanks/(?Pw+)/$', views.thanks),


-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/f906713c-6b72-4353-8d12-c0c45982c9b5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Upgrading Django (to 1.7)

2014-10-09 Thread Fred Stluka

On 10/8/14 11:30 PM, Andrew Pinkham wrote:

Hi,
Upgrading Django (to 1.7) Part III: Django 1.7's New Features is now available!

For the article:
   afrg.co/updj17/a3/

For all of the material:
   afrg.co/updj17/

Any feedback appreciated. I hope you find the material helpful.

Andrew


Andrew,

Excellent 3rd article.  Thanks again!

I've recommended it to my team, summarizing it as:
- South vs Django 1.7 Native Migrations
- Upgrading from South to Django 1.7 Native Migrations
- New "App Registry"
- New "System Check Framework"
  -- Invoke via: % python manage.py check
  -- Also runs implicitly as part of most manage.py commands.
  -- Has hooks to add your own checks to enforce project standards, like:
 --- All Models must have a __str__ method.
- New "Custom Querysets"
  -- Often better than writing a custom manager
- Improved prefetch_related()
- New "Custom Lookups"
- Improved form error handling


The App Registry section is not entirely clear to me, probably
because I'm coming from 1.4, not from 1.6.

It might help if you explained how the App Registry relates to
1.4 concepts.  Like, I assume it replaces INSTALLED_APPS, plus
a whole lot more, right?

Otherwise, can you suggest where I can find an article similar to
yours that gets me from 1.4 to 1.5 and on to 1.6 before I use
yours to get me from 1.6 to 1.7?

Thanks!
--Fred

Fred Stluka -- mailto:f...@bristle.com -- http://bristle.com/~fred/
Bristle Software, Inc -- http://bristle.com -- Glad to be of service!
Open Source: Without walls and fences, we need no Windows or Gates.


--
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/543703BF.3040706%40bristle.com.
For more options, visit https://groups.google.com/d/optout.


Re: cant pass the "CSRF verification failed. Request aborted." error

2014-10-09 Thread Collin Anderson

>
> ok now to learn how to catch that url
> will something like this would work?
> url(r'^thanks/(?Pw+)/$', views.thanks),
>

That should work in theory, although the "w" in the regular expression 
won't match the @ sign or the periods.

If you use the /thanks/?email=y...@email.etc you can use this syntax in the 
urls:
url(r'^thanks/$', views.thanks),
And this in the view:
def thanks(request):
render(request, 'thanks.html', {'email': request.GET.get('email')})

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/7c6b89fa-7089-4215-a7a0-be06e68a327b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: django admin interface - how to enable adding new entries to foreign key-linked dropdown menu?

2014-10-09 Thread Russell Keith-Magee
Hi Eliezer,

The trick is to add a ModelAdmin for Exercise.

The obvious consequence of this is that you'll get a "top level" menu
option to add exercises. However, a side effect is that everywhere that you
have a model with a foreign key to exercise (like in your Segment inline),
you'll get a little green "plus" sign next to the foreign key selector. If
you click on that plus, you'll get a popup that will let you create a new
Exercise. The popup will have the same layout as the "Add Exercise" page
you get if you go through the top level menu, but without the navigation
elements.

When you hit "save" on the new Exercise, the foreign key you clicked on
will be updated to point at the newly added exercise instance.

Yours,
Russ Magee %-)


On Wed, Oct 8, 2014 at 10:02 AM, Eliezer Kanal  wrote:

> I'm writing a rudimentary exercise app in django, with the following table
> structure:
>
> Routine Exercise Segment
> = = =
> routine_name exercise_name routine_id (fk)
> routine_id exercise_id exercise_id (fk)
> order
> duration
>
> * (fk) = foreign key
>
> In practice, this looks as follows:
>
>
> 
> A Routine contains numerous Segments, and each segment contains one
> Exercise, the order number (where the segment appears in the routine –
> first, second, third, etc), and the duration of that segment.
>
> My question is, is there an way to allow someone to add a new exercise
> type from the "Add routine" view? I.e., if I'm making a new routine, I
> don't necessarily want to have to drop out and go to the Exercise table
> view to add a new exercise to the list. Thanks in advance!
>
> Elli
>
>
> *Note: This was cross-posted to StackOverflow
> ,
> with very few views there. I thought I'd try here as well.*
>
> --
> 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 http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/4955d625-d898-4fdf-b186-a8db536363b9%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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAJxq849nvs8Bu3NSv3gwXRfx6tjTiXX%3DOkMsiQP_uRX59nQtBg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


best aproach to pass an email from the url to a view?

2014-10-09 Thread dk
I put the Email that I got from a form into the url (I am using the url as 
a variable to store the email)

and look like this
http://127.0.0.1:8000/polls/vote/thank/a...@b.com/


url:
url(r'^vote/thank/(?   #here should be RE catching the email   
 )$', views.thank),
view:
def thank(request, your_email=None):
c = {"thanks_body": "thanks_body view"}
c["his_email"] = your_email
return render(request, "thanks.html", c)

I am having issues to try to come up with a RE to grab the email
I try 
http://stackoverflow.com/questions/201323/using-a-regular-expression-to-validate-an-email-address
using it on my url
such 
url(r'^vote/thank/(?
*^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$* ', 
views.thank),
 and I still don't catch it, I think because I am just copy pasting but in 
the url string should be arrenge diferntly?
I was reading about a  get function that can make a quary on the url like a 
dictionary?  any example on how to use it?

thanks,  (I order a book for RE  =)  just to be able to udertand a little 
bit more   )



-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/b84874c3-32ad-47fb-82db-5e48b87a975d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Upgrading Django (to 1.7)

2014-10-09 Thread Andrew Pinkham
Hi Fred,
Thanks again for the positive feedback!

I'm sorry I lost you at the App Registry section. I'm afraid I can't recommend 
an article to help with the topic, either. Given your questions, I can see I 
missed the mark. Let me give it another go (warning: this is neither 
technically reviewed nor copy edited).

Django uses the `INSTALLED_APPS` setting to find all of the apps in a project, 
and to build a list of apps to run and use, called an app registry. The way 
Django builds the app registry has changed radically from Django 1.6 to Django 
1.7.

Django 1.6 (and before, but I admit I don't know how far back) used the 
`AppCache` class to maintain a list of these apps. The system was problematic 
because each `AppCache` instance shared state - any change to one `AppCache` 
object lead to a change in all `AppCache` objects. Because of migrations (and 
the need for historical/frozen models), the `AppCache` had to change in Django 
1.7.

Django 1.7 now provides an `Apps` class to be the app registry. Each instance 
is separate from others, allowing the migration system to build historical apps 
and models. You can fetch the `Apps` object (not class!) for your own project 
with:

from django.apps import apps as django_apps

Referred to as the master registry (the app registry for your project as it 
runs), `django_apps` is an instance of `Apps`, which contains a list of 
`AppConfig` objects.

Starting in Django 1.7 all apps now have an `AppConfig` object attached to 
them. These are built automatically by Django, meaning many developers will be 
able to get away without ever creating an `/app_name/apps.py` file for their 
projects. The ability to override `AppConfig`, however, is quite useful. It 
allows for the implementation of a `ready()` method (seen in the admin 
`AppConfig` subclass) as well as the ability to explicitly set the app label, 
allowing developers to easily rectify namespace conflicts.

Note that we avoid a namespace error thanks to `as django_apps` with 
`AppConfig`. I recommend you do this even if there is no namespace error.

from django.apps import apps as django_apps
from . import apps

To deal with this list of `AppConfig` objects (and the models within), all 
`Apps` instances sport a brand new API. We saw it throughout Part II and Part 
III of the article, using it to help us with data migrations and to build our 
checks. 

The only trick with `Apps` is that it must be fully built and configured before 
Django can take certain actions, including loading the custom user model, or 
using parts of the translation system. I touched a little bit on it in Part 
III, but plan to expand on it in Part IV.

The bottom line is that the app registry works mostly in the background by 
building a master registry and performing many of its key functions without 
developers ever knowing (just as many developers never knew about Django 1.6's 
`AppCache`). However, understanding the system even a little allows for the 
developer to better edit migrations and create checks, and I suspect that 
interacting with apps via this API will become commonplace.

Fred: Is the above helpful? Feel free to ask more questions.

On Oct 9, 2014, at 4:53 PM, Fred Stluka  wrote:
> Otherwise, can you suggest where I can find an article similar to 
> yours that gets me from 1.4 to 1.5 and on to 1.6 before I use 
> yours to get me from 1.6 to 1.7?


No, but I hope the process I lay out in Part IV will help you indirectly.

Andrew

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/46921726-891C-4AD3-8B12-88459761D52D%40andrewsforge.com.
For more options, visit https://groups.google.com/d/optout.


Custom Exception Handler not being called

2014-10-09 Thread Néstor Boscán
Hi

I've created a rest service using the APIView and created my own custom 
exception handler. I configured my custom exception handler in my 
settings.py file using:

REST_FRAMEWORK = {
'EXCEPTION_HANDLER': 'module.custom_exception_handler'
}

But when an exception is raised my custom exception handler is not invocked.

Regards,

Néstor

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/105ca293-2e02-450b-acce-a93eeb04923d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Upgrading Django (to 1.7)

2014-10-09 Thread Fred Stluka

Andrew,

Yes, that explains a lot.  I'd recommend including this explanation
in one of the articles of your current series.

BTW, one other thing to keep in mind is that we 1.4 users don't
know what an apps.py file is, so we don't appreciate not having
to create one, since we never did before.

Thanks again!
--Fred

Fred Stluka -- mailto:f...@bristle.com -- http://bristle.com/~fred/
Bristle Software, Inc -- http://bristle.com -- Glad to be of service!
Open Source: Without walls and fences, we need no Windows or Gates.

On 10/9/14 10:09 PM, Andrew Pinkham wrote:

Hi Fred,
Thanks again for the positive feedback!

I'm sorry I lost you at the App Registry section. I'm afraid I can't recommend 
an article to help with the topic, either. Given your questions, I can see I 
missed the mark. Let me give it another go (warning: this is neither 
technically reviewed nor copy edited).

Django uses the `INSTALLED_APPS` setting to find all of the apps in a project, 
and to build a list of apps to run and use, called an app registry. The way 
Django builds the app registry has changed radically from Django 1.6 to Django 
1.7.

Django 1.6 (and before, but I admit I don't know how far back) used the 
`AppCache` class to maintain a list of these apps. The system was problematic 
because each `AppCache` instance shared state - any change to one `AppCache` 
object lead to a change in all `AppCache` objects. Because of migrations (and 
the need for historical/frozen models), the `AppCache` had to change in Django 
1.7.

Django 1.7 now provides an `Apps` class to be the app registry. Each instance 
is separate from others, allowing the migration system to build historical apps 
and models. You can fetch the `Apps` object (not class!) for your own project 
with:

 from django.apps import apps as django_apps

Referred to as the master registry (the app registry for your project as it 
runs), `django_apps` is an instance of `Apps`, which contains a list of 
`AppConfig` objects.

Starting in Django 1.7 all apps now have an `AppConfig` object attached to 
them. These are built automatically by Django, meaning many developers will be 
able to get away without ever creating an `/app_name/apps.py` file for their 
projects. The ability to override `AppConfig`, however, is quite useful. It 
allows for the implementation of a `ready()` method (seen in the admin 
`AppConfig` subclass) as well as the ability to explicitly set the app label, 
allowing developers to easily rectify namespace conflicts.

Note that we avoid a namespace error thanks to `as django_apps` with 
`AppConfig`. I recommend you do this even if there is no namespace error.

 from django.apps import apps as django_apps
 from . import apps

To deal with this list of `AppConfig` objects (and the models within), all 
`Apps` instances sport a brand new API. We saw it throughout Part II and Part 
III of the article, using it to help us with data migrations and to build our 
checks.

The only trick with `Apps` is that it must be fully built and configured before 
Django can take certain actions, including loading the custom user model, or 
using parts of the translation system. I touched a little bit on it in Part 
III, but plan to expand on it in Part IV.

The bottom line is that the app registry works mostly in the background by 
building a master registry and performing many of its key functions without 
developers ever knowing (just as many developers never knew about Django 1.6's 
`AppCache`). However, understanding the system even a little allows for the 
developer to better edit migrations and create checks, and I suspect that 
interacting with apps via this API will become commonplace.

Fred: Is the above helpful? Feel free to ask more questions.

On Oct 9, 2014, at 4:53 PM, Fred Stluka  wrote:

Otherwise, can you suggest where I can find an article similar to
yours that gets me from 1.4 to 1.5 and on to 1.6 before I use
yours to get me from 1.6 to 1.7?


No, but I hope the process I lay out in Part IV will help you indirectly.

Andrew



--
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/5437445F.6000500%40bristle.com.
For more options, visit https://groups.google.com/d/optout.