Django and timezones ... how to initialize a field to now() in the in clients time zone?

2017-01-21 Thread Bernd Wechner
I have a model with this field:

date_time = models.DateTimeField(default=timezone.now)

if I look at the generic create form, it inializes the date_time field with 
now in UTC, not in local time. 

Now I appreciate there are two things at play here:

   1. the desired UX is to see now in my time zone.
   2. Django, running on the server has no idea what my time zone is.

Now I can think my way through this and find some solutions, not short of 
imagination here. But as I work on nutting one out, I am struck, as ever, 
with the notion that 1. is surely a ubiquitous use case ... namely I cannot 
seriously be the first person to have this desire or tackle this problem 
and is there not a stock standard approach in Django to doing this?

As I read it I can find the time zone in Javascript at the client side:

This works fine for example:

var tz_name = jstz.determine().name();
var tz_offset = new Date().getTimezoneOffset()/60;

giving me pleasing results (though I appreciate, before anyone points it 
out, that pleasing results are by no means guaranteed as it as it is 
premised on the correct TZ configuration of the client computer among other 
things, but the application in mind does not REQUIRE time accuracy (am just 
logging events that happened at a given time and timezone errors are of no 
practical data integrity or security concerns for a few good reasons) .

And I can submit these in hidden fields too.

But the obvious solution, which I find a tad kludgy alas is at the client 
side in JS to find the date_time input field, and adjust it's value from 
UTC to local time. Right now it's presenting as UTC.

Even if I could find a way to ask Django to use a different timezone 
(tmiezone.activate) it won't kow what Timezone until it's heard from the 
client. And it's not in HTTP headers alas, though someone thinks it should 
be:

http://blogs.windwardreports.com/davidt/2010/04/can-we-please-get-a-time-zone-in-the-http-request-header.html

On submission of course as I can submit the TZ info in hidden fields it 
should be easy to convert the submission back to UTC for saving into the 
database.

Still, I wonder openly, is this not long solved, more elegantly?

Regards,

Bernd.

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


[help] Django allauth - registration using facebook/google , otp varification

2017-01-21 Thread bharatgodam
Hello everyone,
I am new to django.
i want to use social authentication in my app. i am using 
python - 3.6.0
django - 1.10.5
django allauth - latest

i want custom registration using providers facebook and google.
the scenario is
user visits registration page.
provided the links - register using facebook , register using google.
depending on choice get user data.
provide extra layer i.e get user mobile and send otp.
match otp then register successfully.

Yet i have done.
installed and configured django allauth.
able to login through providers facebook and google.

So i need help with how can i customize the flow so i can send otp and 
varify.

Thanks 

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


audit trail functionality in database model

2017-01-21 Thread enrico baranski
Hi all Django users,

I'm quite new to Django and currently experimenting with the database 
model. Defining fields appears to be quite intuitive and is well described 
in the documentation. However, I am looking into audit trail 
functionalities. What that means to me. I have two tables, one is my master 
data table (rooms) and one is my audit trail table for the rooms table. 

So I aim on two major things, first I would like to increment a field 
"version" in my room-table to track any change on the table record. 
Inserting the record means version=1 and as soon as the record is changed 
the field version should increment to 2 and so on. 

Second thing would be to automatically track the changes from one version 
to another in my audit trail table. So I am looking for a way to 
automatically make table entries when I update the main table ... 

My final goal is to define the audit trail functionalities in the database 
models so it is forced on any record manipulation. 

I hope I could describe my issues comprehensible and would be very happy to 
get some feedback from you guys. 


Thanks a lot and best regards,
enrico 

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


dear django users & fans.. i really need ur help ok

2017-01-21 Thread Joshua Harmony Chinonso
My name is Joshua. I am a developer. I do most of my programming using vb.net 
(visual studio). Until my new roommate introduced me to an entire new language 
- python and it's web framework - django. I love the framework frankly speaking 
OK. 

Friends,am so new to django..I decided to write my final year project using 
django.. I have been wondering if I could ever use django (or python) to 
develop a computer based assessment. someone said I could but I don't know 
where to kick-off from.. I'll appreciate any help from anywhere. If you have 
any topic or article on django that u think might help me startup something, 
I'll also appreciate that.. Thanks all! 

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


Re: dear django users & fans.. i really need ur help ok

2017-01-21 Thread José Florencio de Queiroz Neto
Dear friend,
First of all, welcome to the Django community. 
I recommend you to complete the Django tutorial 
(https://docs.djangoproject.com/en/1.10/intro/tutorial01/).
If you have time, buy and complete the book Django Unleashed 
(https://django-unleashed.com/).
Good luck,
Florencio

Em sábado, 21 de janeiro de 2017 17:20:34 UTC-3, Joshua Harmony Chinonso 
escreveu:
>
> My name is Joshua. I am a developer. I do most of my programming using 
> vb.net (visual studio). Until my new roommate introduced me to an entire 
> new language - python and it's web framework - django. I love the framework 
> frankly speaking OK. 
>
> Friends,am so new to django..I decided to write my final year project 
> using django.. I have been wondering if I could ever use django (or python) 
> to develop a computer based assessment. someone said I could but I don't 
> know where to kick-off from.. I'll appreciate any help from anywhere. If 
> you have any topic or article on django that u think might help me startup 
> something, I'll also appreciate that.. Thanks all! 
>
>

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


Unclear Debug Message (Bug?) When Invalid Url in Extended Template

2017-01-21 Thread Connor Boyle
I've noticed that when I extend a template that references an invalid url 
name, in debug mode, the error message doesn't highlight the erroneous line 
in the parent template, but rather shows a section of the child template.

For example if "base.html" is just:

{% block content %}{% endblock %}
Page Three

And "page_one.html" is:

{% extends 'base.html' %}
{% block content %}This is page one{% endblock %}

when there is no url named "page_three", debug mode will show an error 
message entitled:

*NoReverseMatch at /page_one/*
Reverse for 'page_three' with arguments '()' and keyword arguments '{}' not 
found. 0 pattern(s) tried: []

and show a few lines of page_one.html (instead of base.html, where the 
error originated). See attached screenshot for example.

Debug mode seems to do a fine job of highlighting the invalid line in the 
parent template for other errors, such as an {% if %} without an {% endif %} 
or an unrecognized tag (e.g. {% asdf %} ).

Is this a bug? Or at least a sorely missing feature? Am I crazy for 
thinking that this is not how this error should be displayed?

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


Re: audit trail functionality in database model

2017-01-21 Thread Mike Dewhirst
You could have a look at Marty Alchin's Pro Django (not really for 
beginners but ...) on page 263 where he shows how to do almost exactly 
what you describe. If you got that book it would accelerate your 
progress in Django anyway. The only downside is it was published in 2008 
and Django has moved on since then - but in a good way. Largely backward 
compatible. It is probably still all relevant and very valuable.


Mike

On 21/01/2017 11:15 PM, enrico baranski wrote:

Hi all Django users,

I'm quite new to Django and currently experimenting with the database 
model. Defining fields appears to be quite intuitive and is well 
described in the documentation. However, I am looking into audit trail 
functionalities. What that means to me. I have two tables, one is my 
master data table (rooms) and one is my audit trail table for the 
rooms table.


So I aim on two major things, first I would like to increment a field 
"version" in my room-table to track any change on the table record. 
Inserting the record means version=1 and as soon as the record is 
changed the field version should increment to 2 and so on.


Second thing would be to automatically track the changes from one 
version to another in my audit trail table. So I am looking for a way 
to automatically make table entries when I update the main table ...


My final goal is to define the audit trail functionalities in the 
database models so it is forced on any record manipulation.


I hope I could describe my issues comprehensible and would be very 
happy to get some feedback from you guys.



Thanks a lot and best regards,
enrico
--
You received this message because you are subscribed to the Google 
Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send 
an email to django-users+unsubscr...@googlegroups.com 
.
To post to this group, send email to django-users@googlegroups.com 
.

Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/8f9d2c8e-3fd9-4e75-b628-4e6ff99ee83c%40googlegroups.com 
.

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


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


Re: audit trail functionality in database model

2017-01-21 Thread Fred Stluka

  
  
Enrico,

I've done this in the past.  I didn't use Django directly for the
audit
tables.  Instead I defined DB triggers on each primary table that 
inserted a row of audit values into the audit table.  I can send you
sample trigger code that works in Oracle and MySQL.

The nice things about this approach are that Django can entirely 
ignore the audit tables, manipulating only the primary tables, and
that audit table entries are ALWAYS created, even of you bypass 
Django and do a direct INSERT, UPDATE, or DELETE to a primary
table.

You should still be able to define the audit tables as Django
models,
to get the benefit of schema migrations, etc., and to make it easier
to write an audit trail viewer.

In my case, I didn't have an explicit "version" field in the primary

tables, but you could have the triggers handle that also.  Or you 
could do it in the Django save() method of each model, or in a 
custom manager.

If you go the custom save() or custom manager route, you could
do all of the work there, and avoid the need for triggers, but then
it would be easy to bypass the audit table by doing a direct INSERT,

UPDATE, or DELETE to a primary table.

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

On 1/21/17 7:15 AM, enrico baranski
  wrote:


  Hi all Django users,

I'm quite new to Django and currently experimenting with the
database model. Defining fields appears to be quite intuitive
and is well described in the documentation. However, I am
looking into audit trail functionalities. What that means to me.
I have two tables, one is my master data table (rooms) and one
is my audit trail table for the rooms table. 

So I aim on two major things, first I would like to increment a
field "version" in my room-table to track any change on the
table record. Inserting the record means version=1 and as soon
as the record is changed the field version should increment to 2
and so on. 

Second thing would be to automatically track the changes from
one version to another in my audit trail table. So I am looking
for a way to automatically make table entries when I update the
main table ... 

My final goal is to define the audit trail functionalities in
the database models so it is forced on any record manipulation.


I hope I could describe my issues comprehensible and would be
very happy to get some feedback from you guys. 


Thanks a lot and best regards,
enrico 
  
  -- 
  You received this message because you are subscribed to the Google
  Groups "Django users" group.
  To unsubscribe from this group and stop receiving emails from it,
  send an email to django-users+unsubscr...@googlegroups.com.
  To post to this group, send email to django-users@googlegroups.com.
  Visit this group at https://groups.google.com/group/django-users.
  To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/8f9d2c8e-3fd9-4e75-b628-4e6ff99ee83c%40googlegroups.com.
  For more options, visit https://groups.google.com/d/optout.


  




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