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

2014-10-10 Thread Javier Guerra Giraldez
On Fri, Oct 10, 2014 at 6:21 PM, dk  wrote:
> I been fighting to the get the email and passing it


if you want to keep a value from one request to another, check the
Session feature.  In short, it works (almost) like a persistent
dictionary private for each web user.

-- 
Javier

-- 
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/CAFkDaoRqLOfmOvxagPFT0msRRR85MNiMis2KaWT_LgfR_i4OsA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Best approach to adding user notification and message alerts

2014-10-10 Thread Russell Keith-Magee
Hi Chris,

As with all interesting questions, the answer is "it depends" :-)

At the core, all you need to render badges like the ones you've highlighted
is a way to count the "things" that are being displayed (messages,
notifications, chickens crossing the road - it doesn't matter). Pass that
number to a template, and it's just a HTML rendering issue.

However, the complications comes with when you want those numbers to update.

If you just want the number to update every time you load a new page,
that's easy. Put the calculation in a template context manager, put the
rendering code in the header for your base page template, and every time a
page is rendered, the badges will be drawn with the count that is accurate
at the time the page was loaded.

However, if you want someone who is sitting on a page and *not* reloading
to get a "ping" when a new message/notification arrives - that's harder.
There are a number of approaches you could use here, at varying levels of
technical complexity - ranging from polling to web sockets.

Being frank - if you're in a position where you need to ask this question,
you probably want to keep it simple, and stick to the 'only update on
reload' approach. Over time, as you get more confident, you can transition
to a more complex "live" update strategy.

You also may want to give some thought to the volume of traffic you're
intending to serve, and the frequency with which notifications and messages
will be sent. If you're going to be serving a lot of traffic, evaluating
the count will become a performance consideration. A simple database
Messages.objects.filter(user=current_user).count() will obviously work, but
if you're dealing with a high traffic situation, you might want to consider
looking at memcache to reduce database traffic, or something like Redis to
move the counting logic out of your database entirely.

I hope that helps.

Yours,
Russ Magee %-)




On Sat, Oct 11, 2014 at 1:32 AM, Chris BB  wrote:

> I am working on a project that requires the system to show notifications
> and new message alerts to users when logged in (please see attached image).
> Whats the best approach to getting this done, what would the code look like
> -  all suggestions are welcomed.
>
> Thanks in Advance.
>
> --
> 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/718949ce-65be-47c0-935a-8ac16dd284d1%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/CAJxq848rio1vZxZTganrpqP7_j0MVHeyiE%2BJp5oXGeMSLS0Nwg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Writing tests for a custom auth

2014-10-10 Thread Russell Keith-Magee
Hi Valery,

We don't currently ship an integration test to validate your custom User
model, for two reasons:

 1) The requirements for a User model depends on what features you're using
- the core requirements are listed in the docs, but depending on exactly
what you're doing with the User model, there might be other integration
requirements.

 2) We haven't got a good way to distribute a test suite for a model that
we haven't defined.

That said, the baked in test suite in django.contrib.auth does test a
number of tests to ensure that custom User models work; if you're looking
for a starting point, that suite might be a good starting point. Any test
that isn't marked @skipIfCustomUser needs to pass regardless of the user
model. Tests labelled
@override_settings(AUTH_USER_MODEL='auth.ExtensionUser') are tests for
specific user models, which will give you an idea of the sort of tests you
might need to add for your own model.

I hope that helps. If, as a result of doing this, you end up with a
template for a good set of integration tests for a custom model, this would
be a good contribution back to the community - a "template" project for a
custom User model app that others can fork and modify as required would be
one way for Django to distribute an integration test suite.

Yours,
Russ Magee %-)

On Fri, Oct 10, 2014 at 4:24 PM, Valery Melou  wrote:

> Hi everybody.
> I'm creating a custom auth user model to remove 'first_name' and
> 'last_name' attributes from the default one and to make the 'email' field
> required and unique. I would like to know which tests I'm supposed to write
> to make sure that my model support each feature of the default one.
>
> --
> 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/91e947b3-b3d4-4cdc-b7d0-b3426eeea668%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/CAJxq849dDLq%3DitC7HujBqCT_8O-3VgmA_z7orpH-snZyguAxRg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


django language tag

2014-10-10 Thread 6233114 6233114
I have some javascript that displays the timespan between two dates 
according to a language code. For example in en / English: (3 years, 2 
months) , in ru / Russian (3 лет, 2 месяцев) in de / German: (3 Jahre, 2 
Monate) , etc.

The code is working ok but will be difficult to maintain, so I have tried 
to pass in a dynamic variable to change the language display but it does 
not work, and I am not sure why and I am unsure how to get it working, 
despite trying for several days now.

Here is the relevant section of the working code, that will be difficult to 
maintain if more language codes are added to the site:

function dateCalculation(date1, date2, dynamic_language_code) {

//this function will accept two dates (format: mm/) and calculate 
the difference between the 2 dates
//and display the difference as x months or x years, x months.

//arabic
if (dynamic_language_code == 'ar'){

var_month = "{% language 'ar' %}{% trans 'month' %}{% endlanguage 
%}";
var_months = "{% language 'ar' %}{% trans 'months' %}{% endlanguage 
%}";
var_year = "{% language 'ar' %}{% trans 'year' %}{% endlanguage %}";
var_years = "{% language 'ar' %}{% trans 'years' %}{% endlanguage 
%}";

} else if (dynamic_language_code == 'bg'){ //bulgaian

var_month = "{% language 'bg' %}{% trans 'month' %}{% endlanguage 
%}";
var_months = "{% language 'bg' %}{% trans 'months' %}{% endlanguage 
%}";
var_year = "{% language 'bg' %}{% trans 'year' %}{% endlanguage %}";
var_years = "{% language 'bg' %}{% trans 'years' %}{% endlanguage 
%}";

} else if (dynamic_language_code == 'zh-CN'){ //chinese (simplified)

var_month = "{% language 'zh' %}{% trans 'month' %}{% endlanguage 
%}";
var_months = "{% language 'zh' %}{% trans 'months' %}{% endlanguage 
%}";
var_year = "{% language 'zh' %}{% trans 'year' %}{% endlanguage %}";
var_years = "{% language 'zh' %}{% trans 'years' %}{% endlanguage 
%}";

}
..
more conditions & remainder of code not important for this question.
..


The above variables take the form of:

*date1: 01/2009*
*date2: 03/2012*
*dynamic_language_code: tr (a two letter language code)*

Here is the code with the passed in variables that I cannot get to work:

var_month = "{% language dynamic_language_code %}{% trans 'month' 
%}{% endlanguage %}";
var_months = "{% language dynamic_language_code %}{% trans 'months' 
%}{% endlanguage %}";
var_year = "{% language dynamic_language_code %}{% trans 'year' 
%}{% endlanguage %}";
var_years = "{% language dynamic_language_code %}{% trans 'years' 
%}{% endlanguage %}";

*How would I get the django language tag to work if I am passing in the 
dynamic_language_code variable as show immediately above?* 

I think the error is to do with the django language tag not recognising the 
dynamic_langauge_code when it is not in quotes (''), but I could be wrong.

-- 
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/2bf13bdc-6934-4b5c-80b9-a16a40dc82d1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


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

2014-10-10 Thread dk
WOW SUPER EASY
I been fighting to the get the email and passing it

thanks for the tips, and how to use it.


my url
url(r'^vote/thank/$', views.thank),


my views

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 **= "thank/?email="+your_email+"/" # here I make the 
URL*
return HttpResponseRedirect(adress)
else:
form = polls.forms_DK.NameForm()
django.setup()
all_restaurants = Restaurant.objects.all()
return render(request, "vote_form.html", {"all_restaurants": 
all_restaurants, "form": form})

def thank(request, your_email=None): # I don't need your_email=None
c = {"thanks_body": "thanks_body view"} # I can rearenge the dictonary
*remail **= request.GET["email"] #here I pick up the email*
c["thanks_body"] = remail
return render(request, "thanks.html", c)


-- 
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/32aa270f-fd9e-44b6-b8fc-cea6ff7706ad%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Filter queryset later on in a celery task

2014-10-10 Thread Rakan Alhneiti
Hello all,

I am currently working on a push notifications library for Django 
(https://github.com/rakanalh/django-pushy). The current implementation 
provides the ability to send a push notification to all registered device 
keys (Android and iOS). 

The current use-case for the library is doing the following:

from pushy.utils import send_push_notification
send_push_notification('YOUR TITLE', 'YOUR BODY')

This would basically insert the push notification into the database and 
trigger celery to distribute *ALL device keys* into subtasks where each 
subtask sends to a certain group (0-5000, 5000-10,000 .. etc) of keys. One 
of the features i am aiming to implement for the library is the ability to 
filter the list of devices the designated push notification is to be sent 
to. So instead of having this line of code 
,
 
which basically fetches all device keys... i would like to be able to let 
the user filter these devices.

The only option that comes to mind is to add **kwargs to 
send_push_notification so that the user can supply the device query filter 
params, which then get stored in the database to be restored in the celery 
task to filter the list of devices. I currently have no idea if this would 
work because i am thinking about the possibility of the user passing 
user=user_object or some_foreign_key=instance. That would lead me to lots 
of unnecessary query handling code. The question here is: can i turn a 
queryset into a string and restore it back into a queryset object?

Otherwise, what are my options? thoughts on this design issue are 
appreciated.

Thanks,
Rakan

-- 
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/067de0f3-f282-4234-a20e-d2886fa5b7bf%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: How to get user ID and ID of newly created record in a CreateView?

2014-10-10 Thread Daniel Roseman
On Friday, 10 October 2014 19:03:49 UTC+1, Daniel Grace wrote:
>
> Hi, I am using a CreateView.  I want to create some related data on a 
> table ("Log" model), so I need the ID of the record being created for the 
> related field (see "flow" below).  Also I need the ID of the user creating 
> the record.  Something like the following:
>
> from django.utils import timezone
> from django.views.generic.edit import CreateView
> from django.contrib.auth.decorators import login_required
> from flow.models import Flow, Log
>
> class CreateFlow(CreateView):
> model = Flow
> fields = ['state']
> template_name = 'create_flow.html'
> # there is a problem with this:
> @login_required
> def form_valid(self, form):
> form.instance.created_by = self.request.user
> # ... and this:
> log = Log(user=self.request.user.id, flow=id, state=1, 
> created=timezone.now)
> log.save()
> return super(CreateFlow, self).form_valid(form)
>
>
"Something" like that? What, exactly, is wrong with that?
--
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/7826cdcf-00e0-43a0-b241-8cd38601387e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: permissions and inlines issues

2014-10-10 Thread Emanuel
Thanks, it worked.

The final code
:
models.py
class BFlow(models.Model):
...
class Meta:
permissions = (("see_BFlow", "User can see BFlow in admin index page"),)

admin.py
class BFlowAdmin(admin.ModelAdmin):
def get_model_perms(self, request):
if request.user.has_perm('see_BFlow'):
return super(BFlowAdmin, self).get_model_perms(request)
return {}

And finally it worked :) Thanks




Sexta-feira, 10 de Outubro de 2014 18:53:29 UTC+1, Emanuel escreveu:
>
> Ok 
> Thanks, I will try and post here the result later
>
>
> Sexta-feira, 10 de Outubro de 2014 18:45:46 UTC+1, Collin Anderson 
> escreveu:
>>
>> Ohh, but it might still be possible to circumvent that hiding, so I'm not 
>> sure.
>>
>

-- 
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/b0084b40-3ea4-438a-bf0d-7dfc85d6f3fe%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


How to get user ID and ID of newly created record in a CreateView?

2014-10-10 Thread Daniel Grace
Hi, I am using a CreateView.  I want to create some related data on a table 
("Log" model), so I need the ID of the record being created for the related 
field (see "flow" below).  Also I need the ID of the user creating the 
record.  Something like the following:

from django.utils import timezone
from django.views.generic.edit import CreateView
from django.contrib.auth.decorators import login_required
from flow.models import Flow, Log

class CreateFlow(CreateView):
model = Flow
fields = ['state']
template_name = 'create_flow.html'
# there is a problem with this:
@login_required
def form_valid(self, form):
form.instance.created_by = self.request.user
# ... and this:
log = Log(user=self.request.user.id, flow=id, state=1, 
created=timezone.now)
log.save()
return super(CreateFlow, self).form_valid(form)

-- 
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/9922a44a-b4ce-4fdd-9b4b-044507c3d1ca%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Best approach to adding user notification and message alerts

2014-10-10 Thread Chris BB
I am working on a project that requires the system to show notifications 
and new message alerts to users when logged in (please see attached image). 
Whats the best approach to getting this done, what would the code look like 
-  all suggestions are welcomed.

Thanks in Advance.

-- 
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/718949ce-65be-47c0-935a-8ac16dd284d1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: permissions and inlines issues

2014-10-10 Thread Emanuel
Ok 
Thanks, I will try and post here the result later


Sexta-feira, 10 de Outubro de 2014 18:45:46 UTC+1, Collin Anderson escreveu:
>
> Ohh, but it might still be possible to circumvent that hiding, so I'm not 
> sure.
>

-- 
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/6d067e5b-55e4-468f-ade5-408288a7d738%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: permissions and inlines issues

2014-10-10 Thread Collin Anderson
Ohh, but it might still be possible to circumvent that hiding, so I'm not 
sure.

-- 
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/0251e587-4880-4dfd-baeb-00c13c5313f3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: permissions and inlines issues

2014-10-10 Thread Collin Anderson
Ohh. Yes. I get it now. At my work we've used the undocumented, unsupported 
ModelAdmin.get_model_perms() to hide models from the index page.
http://stackoverflow.com/questions/2431727/django-admin-hide-a-model

-- 
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/0259d491-cc48-4249-90f7-da1d1a109c3e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: permissions and inlines issues

2014-10-10 Thread Emanuel
Yes. But they have permission to them. But I want some people only have 
permission to see when the models are inlines from another model. And other 
people have permission to see always...

Thanks

Sexta-feira, 10 de Outubro de 2014 13:22:35 UTC+1, Collin Anderson escreveu:
>
> So the remaining problem is that models are showing up in the admin index 
> page when people don't have permission to them?
>

-- 
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/2883eaf5-cad1-4fd8-aff1-16e5fd412f45%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Question on url routing

2014-10-10 Thread robert brook
It would seem that this should be a common issue for any web site.

based on the DRY principle, how has this been resolved by other developers

On Friday, October 10, 2014 8:09:12 AM UTC-4, robert brook wrote:
>
> If I have 2 urls coded in the file for example
>
> url(r'^abc/$', views.abc),
> url( r'^abc/def/$', views.def),
>
> And the first url should be accessible by typing it into the browser.
>
> The 2nd url should only be accessible from the application, not by virtue 
> of a user typing it into the browser.
>
> How do I accomplish that?
> How do I capture that and reroute it to a valid page?
>
> Thanks is advance
>

-- 
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/c90c55a0-c657-4e49-b4e2-77903f37e082%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Question on url routing

2014-10-10 Thread Vijay Khemlani
I think in those cases you would need to add some custom logic to your view
to check whether the URL is valid for the "step" the user is in the
workflow.

On Fri, Oct 10, 2014 at 10:47 AM, robert brook  wrote:

> I know how to detect an ajax request.
>
> I am interested int the general issue of the user typing in a valid url
> for the application, but not appropriate for the particular workflow.
>
> I utilize the @login_required decorater.
>
>  I am looking for an analgous function to pass the user back to an
> appropriate page.
>
>
>
> On Friday, October 10, 2014 8:35:47 AM UTC-4, Collin Anderson wrote:
>>
>> Do you mean ajax-only?
>>
>> def my_view(request):
>> if not request.is_ajax():
>> return redirect('/a-valid-page/')
>>
>> https://docs.djangoproject.com/en/1.7/ref/request-response/#django.http.
>> HttpRequest.is_ajax
>>
>  --
> 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/00884451-604a-4ac1-99d1-860f6080c366%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/CALn3ei2hSCD99_PK03StdO2%2BnxEZQqnoZ49ZpPGO%3DwAq6BFLwA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Question on url routing

2014-10-10 Thread robert brook
I know how to detect an ajax request.

I am interested int the general issue of the user typing in a valid url for 
the application, but not appropriate for the particular workflow.

I utilize the @login_required decorater.

 I am looking for an analgous function to pass the user back to an 
appropriate page.



On Friday, October 10, 2014 8:35:47 AM UTC-4, Collin Anderson wrote:
>
> Do you mean ajax-only?
>
> def my_view(request):
> if not request.is_ajax():
> return redirect('/a-valid-page/')
>
>
> https://docs.djangoproject.com/en/1.7/ref/request-response/#django.http.HttpRequest.is_ajax
>

-- 
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/00884451-604a-4ac1-99d1-860f6080c366%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Custom Exception Handler not being called

2014-10-10 Thread Daniel Roseman
On Friday, 10 October 2014 03:14:32 UTC+1, Néstor Boscán wrote:
>
> 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 should ask this on the Django Rest Framework mailing list.
--
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/887b67c8-b558-4079-84fa-513cdf7b641d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Question on url routing

2014-10-10 Thread Collin Anderson
Do you mean ajax-only?

def my_view(request):
if not request.is_ajax():
return redirect('/a-valid-page/')

https://docs.djangoproject.com/en/1.7/ref/request-response/#django.http.HttpRequest.is_ajax

-- 
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/9857af3c-adee-4469-b981-8e3461519a8d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


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

2014-10-10 Thread Daniel Roseman
On Friday, 10 October 2014 01:00:29 UTC+1, dk wrote:
>
> 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   )
>
>

I think you're trying too hard here. Regexes for email are usually 
concerned with *validation*, ie checking in a form that the thing typed 
into the "email" field looks like an actual email. But that is not, or 
should not be, a consideration in a URL: at this point the email has 
already been validated, and all you want to do is to send it to the next 
page. So you probably just want to grab everything after the `thank` part:

'^vote/thank/(?.*)$'

To be honest though, this is something I wouldn't even try to catch in the 
URL at all. Instead, pass it as a querystring parameter, so the URL would 
be in the format "/vote/thank/?email=f...@bar.com" and you get it in the 
view as `request.GET['email']`.
--
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/9ad145a3-08f2-4144-bbc6-75fb949b1184%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: permissions and inlines issues

2014-10-10 Thread Collin Anderson
So the remaining problem is that models are showing up in the admin index 
page when people don't have permission to them?

-- 
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/ba993c0b-db14-4d6f-b16e-556928aa7c59%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Question on url routing

2014-10-10 Thread François Schiettecatte
Hi

You could check request.META['HTTP_REFERER'], it should be set if the user 
clicks on a link and unset if the user entered the url in the address bar. 
Obviously this is browser dependent. If you really want to be sure I would use 
a one time url with a uuid which you generate and store to validate against 
when you get the request.

François

On Oct 10, 2014, at 8:09 AM, robert brook  wrote:

> If I have 2 urls coded in the file for example
> 
> url(r'^abc/$', views.abc),
> url( r'^abc/def/$', views.def),
> 
> And the first url should be accessible by typing it into the browser.
> 
> The 2nd url should only be accessible from the application, not by virtue of 
> a user typing it into the browser.
> 
> How do I accomplish that?
> How do I capture that and reroute it to a valid page?
> 
> Thanks is advance
> 
> -- 
> 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/b8423a99-7798-4458-b817-5f5179373603%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/6D7DADBF-5562-4E61-9941-7FC140458BB5%40gmail.com.
For more options, visit https://groups.google.com/d/optout.


Question on url routing

2014-10-10 Thread robert brook
If I have 2 urls coded in the file for example

url(r'^abc/$', views.abc),
url( r'^abc/def/$', views.def),

And the first url should be accessible by typing it into the browser.

The 2nd url should only be accessible from the application, not by virtue 
of a user typing it into the browser.

How do I accomplish that?
How do I capture that and reroute it to a valid page?

Thanks is advance

-- 
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/b8423a99-7798-4458-b817-5f5179373603%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Writing tests for a custom auth

2014-10-10 Thread Valery Melou
Hi everybody.
I'm creating a custom auth user model to remove 'first_name' and 
'last_name' attributes from the default one and to make the 'email' field 
required and unique. I would like to know which tests I'm supposed to write 
to make sure that my model support each feature of the default one.

-- 
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/91e947b3-b3d4-4cdc-b7d0-b3426eeea668%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: permissions and inlines issues

2014-10-10 Thread Emanuel
Hi

Thanks for the answer. The current solution I had it's the one that you 
sugest.

But I still have the problem that on the index admin page shows the 
application.
The scenario is this:
A factory have a diary production (A)
And every day people produce Articles and to do that they use some Feedstock
I have two different models to control Articles and Feedstock flow, FlowB 
(B) and FlowC(C)

Some users can add a diary production, and in there add some articles and 
some feedstock
And for those users, the only way that Articles go in and feedstock go out 
is in the diary production (Diary)

But sometimes other people take some feedstock for other pruposes, and that 
not belong to the Diary. Also only the Administrator can allow that 
situation, and therefore he have to add an entrance directly on C. This is 
why I need to have C registered in Admin.

But to the other users can add C elements in the diary (A), they see C in 
index and I want them not to see, only the Administrator

Thanks

Quinta-feira, 9 de Outubro de 2014 21:02:28 UTC+1, Collin Anderson escreveu:
>
> 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/8274079a-0f59-424d-81de-2dd5d5c3e90d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: How to trace a page not showing up?

2014-10-10 Thread Helgi Örn Helgason
Thank's Tom,

solr is most probably not running.
sudo netstat -lpn | grep java
gave nothing at all

/Helgi

On Friday, 10 October 2014 10:34:35 UTC, Tom Evans wrote:
>
> On Fri, Oct 10, 2014 at 10:45 AM, Helgi Örn Helgason 
> > wrote: 
> > 
> > Thank you Erik and Collin for your replies, of which I yet haven't tried 
> > out, perhaps because I don't fully understand them. Like a said; I am a 
> noob 
> > in Django/Python. :-/ 
> > 
> > But I have stumbled upon something that could maybe be of help, a thing 
> > called solr seems to be causing some problems. 
> > 
> > supervisor error log says: 
> > Failed to query Solr using 'django_ct:projects.project': [Errno 110] 
> > Connection timed out 
> > 
> > and manage.py rebuild_index gives me this: 
> > Removing all documents from your index because you said so. 
> > Failed to clear Solr index: [Errno 110] Connection timed out 
> > All documents removed. 
> > Indexing 3933 People. 
> > Failed to add documents to Solr: [Errno 110] Connection timed out 
> > 
> > Can this solr thing block pages from showing? 
> > 
> > There are now three branches of our site tree that are not showing up. 
> :( 
> > 
> > The system is Django 1.3, Python 2.7.3, PostgreSQL, Nginx. 
> > 
>
> Yes, SOLR is a search index/database/analysis engine. Depending how 
> much your site uses it, it could be essential to displaying web pages. 
>
> The errors messages you get from SOLR are "Connection timed out" 
> (errno=110). This means you tried to connect to SOLR, it waited a 
> bunch of time (probably 30 seconds) and then gave up. The problem is 
> that your webserver will wait a bunch of time (probably also 30 
> seconds) and then give up and deliver an empty/blank/error page to the 
> client (depends on the server). 
>
> Is SOLR running? It is usually run inside tomcat, and has a web ui 
> interface for controlling it. It usually runs on port 8983, "sudo 
> netstat -lpn | grep java" if it is not. 
>
> Tom 
>
> PS Django 1.3 has known security flaws, please do upgrade to Django 
> 1.4, which has long term support and should not require major changes 
> to your own code. 
>

-- 
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/bc9e6ca8-3a01-44c5-a060-45468c2dc44b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: How to trace a page not showing up?

2014-10-10 Thread Tom Evans
On Fri, Oct 10, 2014 at 10:45 AM, Helgi Örn Helgason
 wrote:
>
> Thank you Erik and Collin for your replies, of which I yet haven't tried
> out, perhaps because I don't fully understand them. Like a said; I am a noob
> in Django/Python. :-/
>
> But I have stumbled upon something that could maybe be of help, a thing
> called solr seems to be causing some problems.
>
> supervisor error log says:
> Failed to query Solr using 'django_ct:projects.project': [Errno 110]
> Connection timed out
>
> and manage.py rebuild_index gives me this:
> Removing all documents from your index because you said so.
> Failed to clear Solr index: [Errno 110] Connection timed out
> All documents removed.
> Indexing 3933 People.
> Failed to add documents to Solr: [Errno 110] Connection timed out
>
> Can this solr thing block pages from showing?
>
> There are now three branches of our site tree that are not showing up. :(
>
> The system is Django 1.3, Python 2.7.3, PostgreSQL, Nginx.
>

Yes, SOLR is a search index/database/analysis engine. Depending how
much your site uses it, it could be essential to displaying web pages.

The errors messages you get from SOLR are "Connection timed out"
(errno=110). This means you tried to connect to SOLR, it waited a
bunch of time (probably 30 seconds) and then gave up. The problem is
that your webserver will wait a bunch of time (probably also 30
seconds) and then give up and deliver an empty/blank/error page to the
client (depends on the server).

Is SOLR running? It is usually run inside tomcat, and has a web ui
interface for controlling it. It usually runs on port 8983, "sudo
netstat -lpn | grep java" if it is not.

Tom

PS Django 1.3 has known security flaws, please do upgrade to Django
1.4, which has long term support and should not require major changes
to your own code.

-- 
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/CAFHbX1KxKqB6YsbVwUrMx68Uvdg1o4%3DX7uZtZR-adxGN-WTJ3g%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: How to trace a page not showing up?

2014-10-10 Thread Helgi Örn Helgason

Thank you Erik and Collin for your replies, of which I yet haven't tried 
out, perhaps because I don't fully understand them. Like a said; I am a 
noob in Django/Python. :-/

But I have stumbled upon something that could maybe be of help, a thing 
called solr seems to be causing some problems.

supervisor error log says:
Failed to query Solr using 'django_ct:projects.project': [Errno 110] 
Connection timed out

and manage.py rebuild_index gives me this:
Removing all documents from your index because you said so.
Failed to clear Solr index: [Errno 110] Connection timed out
All documents removed.
Indexing 3933 People.
Failed to add documents to Solr: [Errno 110] Connection timed out

Can this solr thing block pages from showing?

There are now three branches of our site tree that are not showing up. :(

The system is Django 1.3, Python 2.7.3, PostgreSQL, Nginx.

-- 
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/f437437b-62e5-4452-84b1-e2552a31370a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


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

2014-10-10 Thread James Schneider
Try adding a capital P after the ? in your named capture group.

Otherwise your capture group does not place its value in the your_email
variable as you are expecting:

(?P...


Check out the Python re module syntax for an explanation:

https://docs.python.org/2/library/re.html

-James

On Thursday, October 9, 2014, dk  wrote:

> 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.
>

-- 
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/CA%2Be%2BciUX_d%2BEay9%3DrjqcmpyHvm32eqBNH-eO%2B4WmX5by9oDX4Q%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.