Re: DRF and self join

2015-08-20 Thread James Schneider
Have a look at this SO post that the DRF author responded to for a similar
situation.

http://stackoverflow.com/questions/13376894/django-rest-framework-nested-self-referential-objects

As far as the view, you'll need to be more specific about what you want the
view to do. The serializer is probably the hard part though.

-James
On Aug 20, 2015 9:12 PM, "Shekar Tippur"  wrote:

> Hello,
>
> I am looking for a model/serializer/view for a self join. I can have
> nested paernt child relationship.
>
> The one I am trying:
>
> model:
>
> class ParentChild(models.Model):
>  parent=models.CharField(max_length=100, blank=False, default='',
> unique=True)
>  child=models.ForeignKey('self', blank=True, null=True )
>
> Serializer
>
> class ParentChileSerializer(serializers.ModelSerializer):
> class Meta:
> model = ParentChild
> fields = ('id', 'parent','child_id')
>
>
> View
>
>
> ??
>
>
> Not sure how to proceed. Appreciate any help.
>
>
> - Shekar
>
> --
> 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/b4bd6e40-b9ac-4b55-8631-f06417634b3f%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%2BciXW%2BATd4Zxgmj_eAuqtuueOx8YMDDtHTWZSYae5%3DhTe%3Dg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


DRF and self join

2015-08-20 Thread Shekar Tippur
Hello,

I am looking for a model/serializer/view for a self join. I can have nested 
paernt child relationship.

The one I am trying:

model:

class ParentChild(models.Model):
 parent=models.CharField(max_length=100, blank=False, default='', unique
=True)
 child=models.ForeignKey('self', blank=True, null=True )

Serializer

class ParentChileSerializer(serializers.ModelSerializer):
class Meta:
model = ParentChild
fields = ('id', 'parent','child_id')


View


??


Not sure how to proceed. Appreciate any help.


- Shekar

-- 
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/b4bd6e40-b9ac-4b55-8631-f06417634b3f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Feature Suggestion: New Setting called LOGOUT_REDIRECT_URL

2015-08-20 Thread Tim Graham
In fact, there is an accepted ticket which suggests the same: 
https://code.djangoproject.com/ticket/12405

Feel free to try your hand at a patch if you like!

On Thursday, August 20, 2015 at 4:41:05 PM UTC-4, Robert Roskam wrote:
>
> Basically, the same feature set as here: 
> https://docs.djangoproject.com/en/1.8/ref/settings/#login-redirect-url
>
> Modified it below:
>
> Default: '/accounts/logout'
>
> The URL where requests are redirected after login when the 
> contrib.auth.logout view gets no next parameter.
>
> This setting also accepts view function names and named URL patterns 
>  
> which 
> can be used to reduce configuration duplication since you don’t have to 
> define the URL in two places (settings and URLconf).
>

-- 
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/5f6ab8cf-33ad-4400-91b4-fc678386e3d3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Using ModelForms

2015-08-20 Thread Hugo Kitano
Could you elaborate on my form has some error?

On Thursday, August 20, 2015 at 1:43:32 PM UTC-7, Edgar Gabaldi wrote:
>
> The code seems right. Probably your form has some error. Try print 
> {{form.errors}} in your template to check.
>
> On Thu, Aug 20, 2015 at 4:45 PM, Hugo Kitano  > wrote:
>
>> Hi, I'm a beginner using Django, and I'm having trouble using model forms 
>> to create instances of my model.
>> When a user submits a form, the database saves nothing.  Here's my code 
>> for the view
>>
>> def submit(request): 
>>
>> SubmissionForm = modelform_factory(Submission, fields=('sub_name', 
>> 'sub_file'))
>>
>> if request.method == "POST": 
>>
>> form = SubmissionForm(request.POST)
>>
>> if form.is_valid():
>>
>> model_instance = form.save(commit=False)
>>
>> model_instance.sub_date = timezone.now()
>>
>> model_instance.save()
>>
>> return HttpResponseRedirect('http://localhost:8000/stats/') 
>>
>> else:
>>
>> form = SubmissionForm()
>>
>> return render(request, 'stats/submit.html', {'form': form})
>>
>>
>> And here's my template:
>>
>>
>>  Submit form: 
>> 
>> {% csrf_token %}
>> {{ form.as_p }}
>> 
>> 
>>
>>
>> I'd appreciate any help. Thansk!
>>
>>
>> Hugo
>>
>> -- 
>> 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/af4016f0-65e5-4a5c-99e9-7f544e7ced7c%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/48cbf996-39ae-4b92-b7cf-4391916c3fce%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Time Zone Problem when following on tutorial

2015-08-20 Thread Palmillo
Many thanks too all!! You've been really helpful

On Monday, June 23, 2014 at 7:34:03 PM UTC-3, Jerry Wu wrote:
>
> Dear every one,
>
> I am following the tutorial 
>  and meet with 
> some problem with Time Zone part. Since I am in Shanghai, China (UTC+8) , I 
> think it is necessary to reset the time part.
>
> Below is what I tried but failed with valuerror incorrect timezone setting:
>
> TIME_ZONE="UTC+8"
> TIME_ZONE="UTC+8:00"
>
> I have tried "Asia/Shanghai", it works, but I think it is kind of 
> out-of-date style due to the description 
>  
> in the tutorial.
>
> Could some one give me a hint?
>
> Thans 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/40f3c975-9755-4ecc-99d7-ad13bf1284c5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Using ModelForms

2015-08-20 Thread Edgar Gabaldi
The code seems right. Probably your form has some error. Try print
{{form.errors}} in your template to check.

On Thu, Aug 20, 2015 at 4:45 PM, Hugo Kitano  wrote:

> Hi, I'm a beginner using Django, and I'm having trouble using model forms
> to create instances of my model.
> When a user submits a form, the database saves nothing.  Here's my code
> for the view
>
> def submit(request):
>
> SubmissionForm = modelform_factory(Submission, fields=('sub_name',
> 'sub_file'))
>
> if request.method == "POST":
>
> form = SubmissionForm(request.POST)
>
> if form.is_valid():
>
> model_instance = form.save(commit=False)
>
> model_instance.sub_date = timezone.now()
>
> model_instance.save()
>
> return HttpResponseRedirect('http://localhost:8000/stats/')
>
> else:
>
> form = SubmissionForm()
>
> return render(request, 'stats/submit.html', {'form': form})
>
>
> And here's my template:
>
>
>  Submit form: 
> 
> {% csrf_token %}
> {{ form.as_p }}
> 
> 
>
>
> I'd appreciate any help. Thansk!
>
>
> Hugo
>
> --
> 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/af4016f0-65e5-4a5c-99e9-7f544e7ced7c%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/CAGjPPHn0f-rdRKDd4J9sA%3DVbH4R7zTvyPmMYv-dCb80%3DiLq%2Bsg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Feature Suggestion: New Setting called LOGOUT_REDIRECT_URL

2015-08-20 Thread Robert Roskam
Basically, the same feature set as 
here: https://docs.djangoproject.com/en/1.8/ref/settings/#login-redirect-url

Modified it below:

Default: '/accounts/logout'

The URL where requests are redirected after login when the 
contrib.auth.logout view gets no next parameter.

This setting also accepts view function names and named URL patterns 
 
which 
can be used to reduce configuration duplication since you don’t have to 
define the URL in two places (settings and URLconf).

-- 
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/5b66e82e-ca51-45d0-9a9b-80faf4d3a20d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Using ModelForms

2015-08-20 Thread Hugo Kitano
Hi, I'm a beginner using Django, and I'm having trouble using model forms 
to create instances of my model.
When a user submits a form, the database saves nothing.  Here's my code for 
the view

def submit(request): 

SubmissionForm = modelform_factory(Submission, fields=('sub_name', 
'sub_file'))

if request.method == "POST": 

form = SubmissionForm(request.POST)

if form.is_valid():

model_instance = form.save(commit=False)

model_instance.sub_date = timezone.now()

model_instance.save()

return HttpResponseRedirect('http://localhost:8000/stats/') 

else:

form = SubmissionForm()

return render(request, 'stats/submit.html', {'form': form})


And here's my template:


 Submit form: 

{% csrf_token %}
{{ form.as_p }}




I'd appreciate any help. Thansk!


Hugo

-- 
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/af4016f0-65e5-4a5c-99e9-7f544e7ced7c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: How do you access the HTTP data in a view derived from the generic View class?

2015-08-20 Thread Luis Zárate
with request.POST.get("foo", "") or request.POST.getlist("foo", [] )


2015-08-20 13:58 GMT-06:00 Daniel Grace :

> Suppose I have a view as follows:
>
> from django.views.generic import View
> from django.http import HttpResponse
> from braces.views import CsrfExemptMixin
>
> class TestView(CsrfExemptMixin, View):
> def post(self, request, *args, **kwargs):
> # how to access the HTTP data here?
> return HttpResponse(content='some response', status=200)
>
> ... and I want to access the data "12345" and "abcde" as in the command:
> curl -X POST http://localhost:8000/test/ -d "foo=12345=abcde"
>
> --
> 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/2ee2e83b-c240-492a-96f8-e3781e269710%40googlegroups.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>



-- 
"La utopía sirve para caminar" Fernando Birri

-- 
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/CAG%2B5VyMnzU_%2Bo045T-vgs-uvSDK%3D-MiEJ-Wm-j50oAbgvcBYig%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: How do you access the HTTP data in a view derived from the generic View class?

2015-08-20 Thread Daniel Grace
I found the answer to this is to look at request.POST.

-- 
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/78bafb95-e266-4c00-8436-6d2254037629%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


How do you access the HTTP data in a view derived from the generic View class?

2015-08-20 Thread Daniel Grace
Suppose I have a view as follows:

from django.views.generic import View
from django.http import HttpResponse
from braces.views import CsrfExemptMixin

class TestView(CsrfExemptMixin, View):
def post(self, request, *args, **kwargs):
# how to access the HTTP data here?
return HttpResponse(content='some response', status=200)

... and I want to access the data "12345" and "abcde" as in the command:
curl -X POST http://localhost:8000/test/ -d "foo=12345=abcde"

-- 
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/2ee2e83b-c240-492a-96f8-e3781e269710%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: MIGRATION_MODULES possible bug.

2015-08-20 Thread b . wade
Thanks Tim, that looks to be the exact situation I am facing. 

On Thursday, August 20, 2015 at 9:53:03 AM UTC-7, Tim Graham wrote:
>
> I guess 
> https://github.com/django/django/commit/b9c619abc101688fbbfa981525175f831d359483
>  
> might help.
>
> On Thursday, August 20, 2015 at 10:02:04 AM UTC-4, b.w...@thelinguist.com 
> wrote:
>>
>> I believe the cause of this is line 248 in django/db/migrations/writer.py 
>>
>> create_path = os.path.join(upath(sys.path[0]), *package_dirs)
>>
>>
>> Which is automatically using the first path location in the system path 
>> list. Unfortunately with the way our buildout handles paths this is causing 
>> a problem:
>>
>>
>> In manage.py:
>>
>> import sys
>>
>> sys.path[0:0] = [
>>
>>   '/vagrant/eggs/ipython-3.0.0-py2.7.egg',  # This is where the 
>> MIGRATION_MODULES is creating the app specific migration package.
>>
>>   '/vagrant/eggs/httplib2-0.9.1-py2.7.egg',
>>
>>   '/vagrant/eggs/oauth2-1.5.211-py2.7.egg',
>>
>>   ...
>>
>> ]
>>
>>
>> This looks to be a bug to me because there is no guarantee the first path 
>> location is the one you want this package to be created in.
>>
>>
>> --
>>
>> Bruce
>>
>> On Wednesday, August 19, 2015 at 1:00:50 PM UTC-7, b.w...@thelinguist.com 
>> wrote:
>>>
>>> Hi we have a farily large Django 1.8 project and there are a few 3rd 
>>> party apps we are using that don't have Django migrations so I am trying to 
>>> create ones for the apps in question.
>>>
>>> In my settings file I have:
>>>
>>> MIGRATION_MODULES = {
>>>
>>> 'oauth_access': 'thirdparty_migrations.oauth_access_migrations',
>>>
>>> }
>>>
>>>
>>> Some background we are using buildout to handle dependancies. Now what 
>>> stumps me is for some reason when running make migrations oath_access the 
>>> module is being created under the ipython egg. This happens regardless of 
>>> where I put my own module of thirdparty_migrations it just ignores it.
>>>
>>>
>>> Is there some other setting that I am missing to specify the location 
>>> for a 3rd party migration?
>>>
>>>
>>> --
>>>
>>> Bruce
>>>
>>

-- 
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/695408e5-e852-45cd-9a2b-c056faa0ccbd%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


WHEN EXISTS Query in SQL to Django Queryset

2015-08-20 Thread Dheerendra Rathor
Hello,

I've a complex SQL Query 
SELECT DISTINCT "event_event"."id", "event_event"."title", "event_event".
"description", "event_event"."category", "event_event"."event_time", 
"event_event"."event_place", "event_event"."time", "event_event"."cancelled"
, "event_event"."posted_by_id", 
CASE WHEN EXISTS (SELECT * FROM "event_eventviews" WHERE "event_eventviews".
"user_id" = 5 AND "event_eventviews"."event_id"=("event_event"."id")) THEN 
True ELSE False 
END AS "liked", 
CASE WHEN EXISTS (SELECT * FROM "event_eventviews" WHERE "event_eventviews".
"user_id" = 5 AND "event_eventviews"."event_id"=("event_event"."id")) THEN 
True ELSE False
 END AS "viewed" FROM "event_event" 
ORDER BY "event_event"."id" DESC

I want to convert it to Django Queryset, but I'm unable to do so. I tried 
annotation but that adds an outerjoin which results into extra result in 
queryset. 

Here is what I tried in Django: 

queryset = Event.objects.all().order_by('-id').annotate(
viewed = Case(
When(Q(views__user=request.user) & Q(views__event=F('id')), 
then=True),
output_field=models.BooleanField(),
default=False
),
liked= Case(
When(Q(likes__user=request.user) & Q(likes__event=F('id')), 
then=True),
output_field=models.BooleanField(),
default=False

)
)


-- 
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/74a0a64f-9ea6-469a-9acb-bd7fa22ccc7e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: ATOMIC_REQUESTS Middleware inside Transaction

2015-08-20 Thread Tim Graham
I'm not sure what type of reply or answer you are looking for.

Overhauling Django middleware as discussed on the developers mailing list 
might be best in the long run.
https://groups.google.com/d/topic/django-developers/uW5Ogio8QBc/discussion

On Thursday, August 20, 2015 at 3:54:20 AM UTC-4, guettli wrote:
>
> Sad, not reply since nine days ... 
> Is there something you don't understand? Please ask :-)
>
> Am Dienstag, 11. August 2015 09:24:37 UTC+2 schrieb guettli:
>>
>> I am not happy that settings.ATOMIC_REQUESTS=True isolates only the view, 
>> but not the middlewares
>> in one transaction.
>>
>> For applications like reversion (app which records the changes of a 
>> model) it is very important,
>> that the middleware runs inside the same transaction. If storing the 
>> changes
>> runs in a second transaction, inconsistencies will happen: Model got 
>> updated,
>> but storing the changes in the second transaction might fail.
>>
>> We are in the process of updating our apps to Django 1.8.
>>
>> At the moment our preferred solution:
>>
>>  - set settings.ATOMIC_REQUESTS=False
>>  - Run an own middleware which starts and ends the transaction.
>>
>> Nearly two years ago this kind of Middleware suggested in this list:
>>
>>
>> https://groups.google.com/forum/#!msg/django-users/njeVp4zT5HA/9g0wsFYZKAwJ
>>
>> Related issue for app reversion: 
>> https://github.com/etianen/django-reversion/issues/268
>>
>> What do you think?
>>
>>
>>

-- 
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/f4d70ee0-217e-4f35-9256-ada86df1d8a8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: MIGRATION_MODULES possible bug.

2015-08-20 Thread Tim Graham
I guess 
https://github.com/django/django/commit/b9c619abc101688fbbfa981525175f831d359483
 
might help.

On Thursday, August 20, 2015 at 10:02:04 AM UTC-4, b.w...@thelinguist.com 
wrote:
>
> I believe the cause of this is line 248 in django/db/migrations/writer.py 
>
> create_path = os.path.join(upath(sys.path[0]), *package_dirs)
>
>
> Which is automatically using the first path location in the system path 
> list. Unfortunately with the way our buildout handles paths this is causing 
> a problem:
>
>
> In manage.py:
>
> import sys
>
> sys.path[0:0] = [
>
>   '/vagrant/eggs/ipython-3.0.0-py2.7.egg',  # This is where the 
> MIGRATION_MODULES is creating the app specific migration package.
>
>   '/vagrant/eggs/httplib2-0.9.1-py2.7.egg',
>
>   '/vagrant/eggs/oauth2-1.5.211-py2.7.egg',
>
>   ...
>
> ]
>
>
> This looks to be a bug to me because there is no guarantee the first path 
> location is the one you want this package to be created in.
>
>
> --
>
> Bruce
>
> On Wednesday, August 19, 2015 at 1:00:50 PM UTC-7, b.w...@thelinguist.com 
> wrote:
>>
>> Hi we have a farily large Django 1.8 project and there are a few 3rd 
>> party apps we are using that don't have Django migrations so I am trying to 
>> create ones for the apps in question.
>>
>> In my settings file I have:
>>
>> MIGRATION_MODULES = {
>>
>> 'oauth_access': 'thirdparty_migrations.oauth_access_migrations',
>>
>> }
>>
>>
>> Some background we are using buildout to handle dependancies. Now what 
>> stumps me is for some reason when running make migrations oath_access the 
>> module is being created under the ipython egg. This happens regardless of 
>> where I put my own module of thirdparty_migrations it just ignores it.
>>
>>
>> Is there some other setting that I am missing to specify the location for 
>> a 3rd party migration?
>>
>>
>> --
>>
>> Bruce
>>
>

-- 
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/1fa4f199-8080-4321-9938-a6c87f0a72de%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Time Zone Problem when following on tutorial

2015-08-20 Thread 'Tom Evans' via Django users
On Fri, Jul 4, 2014 at 12:01 AM, Mike Dewhirst  wrote:
> On 3/07/2014 11:57 PM, Jerry Wu wrote:
>>
>> Mike,
>>
>> Sorry for the late reply.
>>
>> Your explanation about "time is constant" makes sense to me. But I still
>> didn't know what to do with time setting following the tutorial.
>
>
> One day I'll do some experiments and *really* understand how it works.
>
> My variables are:
>
> TIME_ZONE = 'Australia/Melbourne'
>
> - time stored in the database eg., "2014-06-30 22:46:29.037+10" which in
> June is AEST - Australian Eastern Standard Time or in March "2014-03-05
> 13:48:15.164+11" is daylight saving time.
>
> - USE_TZ = True

With USE_TZ=True, TIME_ZONE only controls the display of datetimes.
Django should be storing all the database values as UTC, and
converting them to TZ-aware when extracting from the database.

>
> When I find the courage I will try setting TIME_ZONE = 'UTC' and see how
> times are displayed. New ones and existing ones! Maybe I'll do it around the
> next changeover to daylight saving in Melbourne.
>

You probably don't want that, most users don't understand UTC. Always
store in UTC, but display in a human timezone.

Another thing you can do is to allow users to select their timezone
and persist it on their user/profile. You can then use a bit of
middleware to activate that timezone, or if not specified, revert back
to the one specified in settings. In code:

  from django.utils import timezone
  from django.conf import settings

  class TimeZoneMiddleware(object):
  """
  This middleware activates a user's timezone, so that all dates
we give them
  are localised correctly.
  """
  def process_request(self, request):
  if request.user.is_authenticated():
  if user.timezone:
  try:
  timezone.activate(profile.timezone)
  return
  except:
  pass
  timezone.activate(settings.TIME_ZONE)

Dates in the database would all be stored in UTC, and converted in to
whatever timezone the end user wishes to use.

Unfortunately, you can't easily determine timezone from HTTP headers,
but for bonus points, you can *request* it from the browser with
javascript and append that data to a form to allow you to provide a
"best guess".

I say "request", because you don't get back a useful timezone like
"Europe/Valencia", you will get "+0200", which is almost impossible to
map to a specific timezone. There are many timezones that have offset
"+0200" at certain points in the year...

Cheers

Tom

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


Re: Time Zone Problem when following on tutorial

2015-08-20 Thread Luis Zárate
install pytz

$ pip install pytz

In settings USE_TZ = True

https://docs.djangoproject.com/en/1.8/topics/i18n/timezones/

And the time_zone is

TIME_ZONE = "America/Argentina/Buenos_Aires"

More details in
https://en.wikipedia.org/wiki/List_of_tz_database_time_zones





2015-08-20 9:08 GMT-06:00 Palmillo :

> Hi, sorry to bring this up again, but I am currently facing same issue
> here: following the tutorial (first time with both Django and Python).
> I live in Buenos Aires, Argentina (UTC-3).  Therefore, I would like to set
> the time zone for this region.
> I apologize, but although I serfed the web trying to find the answer,
> since I am not familiar with UTC codings, I still do not understand which
> code should I use at the TIME_ZONE parameter.
> Can you please help me with it? Which of the following values should I use
> in the parameter?:
> 1) TIME_ZONE = 'UTC-3'
> 2) TIME_ZONE = 'UTC-03:00'
> 3) TIME_ZONE = 'America/Argentina'
> 4) TIME_ZONE = 'AR'
>
> Many thanks in advance!!
>
> On Thursday, July 3, 2014 at 8:02:13 PM UTC-3, Mike Dewhirst wrote:
>>
>> On 3/07/2014 11:57 PM, Jerry Wu wrote:
>> > Mike,
>> >
>> > Sorry for the late reply.
>> >
>> > Your explanation about "time is constant" makes sense to me. But I
>> still
>> > didn't know what to do with time setting following the tutorial.
>>
>> One day I'll do some experiments and *really* understand how it works.
>>
>> My variables are:
>>
>> TIME_ZONE = 'Australia/Melbourne'
>>
>> - time stored in the database eg., "2014-06-30 22:46:29.037+10" which in
>> June is AEST - Australian Eastern Standard Time or in March "2014-03-05
>> 13:48:15.164+11" is daylight saving time.
>>
>> - USE_TZ = True
>>
>> When I find the courage I will try setting TIME_ZONE = 'UTC' and see how
>> times are displayed. New ones and existing ones! Maybe I'll do it around
>> the next changeover to daylight saving in Melbourne.
>>
>> Cheers
>>
>> Mike
>>
>> >
>> > Anyway, I chose to use Asia/Shanghai instead of fashion code.
>> >
>> > So far so good.
>> >
>> > Thank you very much.
>> >
>> > On Thursday, June 26, 2014 4:48:44 AM UTC+8, Mike Dewhirst wrote:
>> >
>> > Jerry
>> >
>> > I just figured it out and it is simple. Time is constant and all
>> you
>> > need to do is decide how* you want to display it. The TIME_ZONE
>> > setting tells the server.
>> >
>> > An event happens at the same time everywhere in the universe (there
>> > may be Einsteinian exceptions to this) and you can store that time
>> > in the database relative to UTC. If you choose Shanghai time in
>> > settings then all recorded times are stored/displayed as Shanghai
>> > time. That is totally fair. People elsewhere just need to know the
>> > system is runing on "Shanghai time"
>> >
>> > I don't know why it was necessary to switch the Django default to
>> > UTC except that lots of people use and can think in UTC as well as
>> > local time. The entire aviation industry for example. There may be
>> a
>> > tiny performance gain avoiding calculating a local time.
>> >
>> > The backwards compatibility thing is vital because if you have
>> > history in your database you can't just switch the base from UTC+8
>> > to UTC without making all the stored times invalid by 8 hours.
>> >
>> > What do you think?
>> >
>> > Mike
>> >
>> > On Tuesday, June 24, 2014 10:34:03 AM UTC+12, Jerry Wu wrote:
>> >
>> > Dear every one,
>> >
>> > I am following the tutorial
>> >  and
>> > meet with some problem with Time Zone part. Since I am in
>> > Shanghai, China (UTC+8) , I think it is necessary to reset the
>> > time part.
>> >
>> > Below is what I tried but failed with valuerror incorrect
>> > timezone setting:
>> >
>> > TIME_ZONE="UTC+8"
>> > TIME_ZONE="UTC+8:00"
>> >
>> > I have tried "Asia/Shanghai", it works, but I think it is kind
>> > of out-of-date style due to the description
>> > <
>> https://docs.djangoproject.com/en/1.6/ref/settings/#std:setting-TIME_ZONE>
>>
>> > in the tutorial.
>> >
>> > Could some one give me a hint?
>> >
>> > Thans 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...@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
>> >
>> 

How can I use extra data in Javascript for custom rendering

2015-08-20 Thread Ram Ganesh
Just posted a question about this on stackoverflow 


-- 
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/94513e89-3860-4095-91ad-67d34483124e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Custom page design by users

2015-08-20 Thread Aamu Padi
I am planning on building a blogging site. In that, I would like to allow
the users to customize there page using html tags and bootstrap.

1. How do I save the contents?

   - Save all the contents in the db?
   - Or create different html files and serve them?
   - Performance?


2. I was planning on using lxml  for stripping
dangerous codes( scripts/iframe).

   - Or should I use some other tool (bleach
   /BeautifulSoup
   ) or way of stripping the
   content?


3. What other security measures I should be taking?

Your opinions and suggestions are very important. Could you please help me
with making it possible. Thank you.

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


Re: Time Zone Problem when following on tutorial

2015-08-20 Thread Palmillo
Hi, sorry to bring this up again, but I am currently facing same issue 
here: following the tutorial (first time with both Django and Python).
I live in Buenos Aires, Argentina (UTC-3).  Therefore, I would like to set 
the time zone for this region.
I apologize, but although I serfed the web trying to find the answer, since 
I am not familiar with UTC codings, I still do not understand which code 
should I use at the TIME_ZONE parameter.
Can you please help me with it? Which of the following values should I use 
in the parameter?:
1) TIME_ZONE = 'UTC-3'
2) TIME_ZONE = 'UTC-03:00'
3) TIME_ZONE = 'America/Argentina'
4) TIME_ZONE = 'AR'

Many thanks in advance!!

On Thursday, July 3, 2014 at 8:02:13 PM UTC-3, Mike Dewhirst wrote:
>
> On 3/07/2014 11:57 PM, Jerry Wu wrote: 
> > Mike, 
> > 
> > Sorry for the late reply. 
> > 
> > Your explanation about "time is constant" makes sense to me. But I still 
> > didn't know what to do with time setting following the tutorial. 
>
> One day I'll do some experiments and *really* understand how it works. 
>
> My variables are: 
>
> TIME_ZONE = 'Australia/Melbourne' 
>
> - time stored in the database eg., "2014-06-30 22:46:29.037+10" which in 
> June is AEST - Australian Eastern Standard Time or in March "2014-03-05 
> 13:48:15.164+11" is daylight saving time. 
>
> - USE_TZ = True 
>
> When I find the courage I will try setting TIME_ZONE = 'UTC' and see how 
> times are displayed. New ones and existing ones! Maybe I'll do it around 
> the next changeover to daylight saving in Melbourne. 
>
> Cheers 
>
> Mike 
>
> > 
> > Anyway, I chose to use Asia/Shanghai instead of fashion code. 
> > 
> > So far so good. 
> > 
> > Thank you very much. 
> > 
> > On Thursday, June 26, 2014 4:48:44 AM UTC+8, Mike Dewhirst wrote: 
> > 
> > Jerry 
> > 
> > I just figured it out and it is simple. Time is constant and all you 
> > need to do is decide how* you want to display it. The TIME_ZONE 
> > setting tells the server. 
> > 
> > An event happens at the same time everywhere in the universe (there 
> > may be Einsteinian exceptions to this) and you can store that time 
> > in the database relative to UTC. If you choose Shanghai time in 
> > settings then all recorded times are stored/displayed as Shanghai 
> > time. That is totally fair. People elsewhere just need to know the 
> > system is runing on "Shanghai time" 
> > 
> > I don't know why it was necessary to switch the Django default to 
> > UTC except that lots of people use and can think in UTC as well as 
> > local time. The entire aviation industry for example. There may be a 
> > tiny performance gain avoiding calculating a local time. 
> > 
> > The backwards compatibility thing is vital because if you have 
> > history in your database you can't just switch the base from UTC+8 
> > to UTC without making all the stored times invalid by 8 hours. 
> > 
> > What do you think? 
> > 
> > Mike 
> > 
> > On Tuesday, June 24, 2014 10:34:03 AM UTC+12, Jerry Wu wrote: 
> > 
> > Dear every one, 
> > 
> > I am following the tutorial 
> >  and 
> > meet with some problem with Time Zone part. Since I am in 
> > Shanghai, China (UTC+8) , I think it is necessary to reset the 
> > time part. 
> > 
> > Below is what I tried but failed with valuerror incorrect 
> > timezone setting: 
> > 
> > TIME_ZONE="UTC+8" 
> > TIME_ZONE="UTC+8:00" 
> > 
> > I have tried "Asia/Shanghai", it works, but I think it is kind 
> > of out-of-date style due to the description 
> > <
> https://docs.djangoproject.com/en/1.6/ref/settings/#std:setting-TIME_ZONE> 
>
> > in the tutorial. 
> > 
> > Could some one give me a hint? 
> > 
> > Thans 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...@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/96dec3fb-1cb1-449b-99e1-8668c62105a4%40googlegroups.com
>  
> > <
> https://groups.google.com/d/msgid/django-users/96dec3fb-1cb1-449b-99e1-8668c62105a4%40googlegroups.com?utm_medium=email_source=footer>.
>  
>
> > 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 Live Site to Localhost (Testing)

2015-08-20 Thread bhanu
We have a completely developed Django Site running on live, But it never 
had a testing environment. Now, I downloaded all the files of Website and 
download a mysql dump file. 
I want to run this on my local machine windows (Just to push my changes 
here to test before going live). 
I installed all requirements (Python 2.7, Pip, Mysql, Django), and able to 
create a new project and run the server. How do I configure and run the 
downloaded site now?  

Your help is highly Appreciated.

Thanks,
Bhanu.

-- 
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/8ec6f13f-53fb-49e0-b7c2-98be447e7960%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


django rest framework with mongoengine login

2015-08-20 Thread Selva sundar raj
currently i am doing application in DRF with mongoengine ,
in that how to do login with mongoengine user
any can help me?

-- 
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/bd57d177-cb0c-4c18-a54d-191175fe5c76%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: MIGRATION_MODULES possible bug.

2015-08-20 Thread b . wade
I believe the cause of this is line 248 in django/db/migrations/writer.py 

create_path = os.path.join(upath(sys.path[0]), *package_dirs)


Which is automatically using the first path location in the system path 
list. Unfortunately with the way our buildout handles paths this is causing 
a problem:


In manage.py:

import sys

sys.path[0:0] = [

  '/vagrant/eggs/ipython-3.0.0-py2.7.egg',  # This is where the 
MIGRATION_MODULES is creating the app specific migration package.

  '/vagrant/eggs/httplib2-0.9.1-py2.7.egg',

  '/vagrant/eggs/oauth2-1.5.211-py2.7.egg',

  ...

]


This looks to be a bug to me because there is no guarantee the first path 
location is the one you want this package to be created in.


--

Bruce

On Wednesday, August 19, 2015 at 1:00:50 PM UTC-7, b.w...@thelinguist.com 
wrote:
>
> Hi we have a farily large Django 1.8 project and there are a few 3rd party 
> apps we are using that don't have Django migrations so I am trying to 
> create ones for the apps in question.
>
> In my settings file I have:
>
> MIGRATION_MODULES = {
>
> 'oauth_access': 'thirdparty_migrations.oauth_access_migrations',
>
> }
>
>
> Some background we are using buildout to handle dependancies. Now what 
> stumps me is for some reason when running make migrations oath_access the 
> module is being created under the ipython egg. This happens regardless of 
> where I put my own module of thirdparty_migrations it just ignores it.
>
>
> Is there some other setting that I am missing to specify the location for 
> a 3rd party migration?
>
>
> --
>
> Bruce
>

-- 
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/a3c3d63b-5fc1-41b9-b28f-f29d5d00ae39%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: ATOMIC_REQUESTS Middleware inside Transaction

2015-08-20 Thread guettli
Sad, not reply since nine days ... 
Is there something you don't understand? Please ask :-)

Am Dienstag, 11. August 2015 09:24:37 UTC+2 schrieb guettli:
>
> I am not happy that settings.ATOMIC_REQUESTS=True isolates only the view, 
> but not the middlewares
> in one transaction.
>
> For applications like reversion (app which records the changes of a model) 
> it is very important,
> that the middleware runs inside the same transaction. If storing the 
> changes
> runs in a second transaction, inconsistencies will happen: Model got 
> updated,
> but storing the changes in the second transaction might fail.
>
> We are in the process of updating our apps to Django 1.8.
>
> At the moment our preferred solution:
>
>  - set settings.ATOMIC_REQUESTS=False
>  - Run an own middleware which starts and ends the transaction.
>
> Nearly two years ago this kind of Middleware suggested in this list:
>
> https://groups.google.com/forum/#!msg/django-users/njeVp4zT5HA/9g0wsFYZKAwJ
>
> Related issue for app reversion: 
> https://github.com/etianen/django-reversion/issues/268
>
> What do you think?
>
>
>

-- 
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/5e293ffb-164e-4ed6-b481-cfed272415ae%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.