Re: Django authorisation within PostgreSQL

2016-11-23 Thread Danny Remmerswaal
I indeed want to authenticate against my PostgreSQL users instead of the 
"default" table-based login, so I don't have to re-write my user-bound 
procedures and triggers. But I also want the admin interface implemented in 
my web application. Ideally, the "user" and "password" in my database 
connection string in settings.py would change based on the user credentials 
supplied when logging in, but I'm not sure if that's possible. Another 
option I thought of was having two database definitions, one of which I use 
when I login as an admin and the other when I login as an "analyst". If 
this is not possible within the timeframe I have, I'd have to go with the 
second option, but it wouldn't be my preferred choice.

Hopefully this explains it a bit more! If there's anything else you need to 
know, please ask.

With kind regards,

Danny

Op dinsdag 22 november 2016 16:14:50 UTC+1 schreef Antonis Christofides:
>
> What you want is not entirely clear. Do you want to authenticate against 
> your PostgreSQL users instead of the django.contrib.auth users? If yes, you 
> need to customize your authentication [1]. One solution would be to write a 
> custom authentication backend, but you might also be able to use 
> RemoteUserBackend [2] together with Apache and mod_auth_pgsql.
>
> Or do you want to import PostgreSQL users and groups into the 
> django.contrib.auth tables and use those from now on? This should be 
> possible with some SQL (INSERT INTO auth_user (id, first_name, last_name, 
> email, ...) SELECT ... FROM [wherever PostgreSQL keeps its users]), but the 
> "password" field might be tricky to transfer.
>
> I know these don't answer all your questions, but you need to explain a 
> bit more.
>
> Regards,
>
> Antonis
>
> [1] https://docs.djangoproject.com/en/1.10/topics/auth/customizing/
> [2] 
> https://docs.djangoproject.com/en/1.10/ref/contrib/auth/#django.contrib.auth.backends.RemoteUserBackend
>
> Antonis Christofideshttp://djangodeployment.com
>
> On 2016-11-22 14:52, Danny Remmerswaal wrote:
>
> Hey guys, 
>
> I'm working on a Django project which has a native PostgreSQL database, 
> filled with schemes that contain both read-only and normal tables and with 
> it's own user- and group roles.
>
> After manually changing the search_path variable, I have managed to import 
> my current models by running the migrate.inspectdb command and improved the 
> generated models by sorting, changing primary keys etc.
> Django's automatic admin interface added new tables which can contain 
> users, but ideally that's not what I want for my project. I'd rather have 
> my current login- and group roles defined in PostgreSQL implemented in 
> Django, because there are some already defined restrictions and triggers 
> implemented in my PostgreSQL database that use these user- and group roles. 
>
>
> Is there any convenient way to import the already defined user- and group 
> roles in PostgreSQL so they work with Django? 
> As a start I'd like a login page that based on supplied credentials grants 
> access to my database with defined users that are part of the group 
> "analyse" (I.E cevoo).
> I've included an image that shows my database schemes and user/groups. 
> Hopefully you guys can help me out!
>
> With kind regards,
>
> Danny
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to django-users...@googlegroups.com .
> To post to this group, send email to django...@googlegroups.com 
> .
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/django-users/ddbd5a11-91fa-4411-b084-306b59b39e95%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/3681775d-f0d1-43d3-bd2d-f480f323be5a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: New-style middleware

2016-11-23 Thread Torsten Bronger
Hallöchen!

Carl Meyer writes:

> [...]
>
> Yes, I agree with you that for middleware which don't implement
> request or response processing (only process_exception,
> process_view, or process_template_response), the new style is less
> concise, because it requires implementing a boilerplate __init__
> and __call__. To be honest, the primary consideration in the new
> middleware was request and response processing, and your case did
> not receive as much attention as it perhaps should have.

Thanks for the explanation!  The boilerplate is ineed not too bad.
I just wanted to make sure to not have overlooked something.

Regards,
Torste.

-- 
Torsten Bronger

-- 
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/87inreqxer.fsf%40physik.rwth-aachen.de.
For more options, visit https://groups.google.com/d/optout.


Re: Django authorisation within PostgreSQL

2016-11-23 Thread Antonis Christofides
Ah, OK, so you want: (1) To authenticate as a PostgreSQL user; (2) To connect to
the database as that user.

As I said, (1) is probably possible with Apache+mod_auth_pgsql plus
RemoteUserBackend. For (2), you need to create a custom database backend.

Antonis Christofides
http://djangodeployment.com

On 2016-11-23 12:28, Danny Remmerswaal wrote:
> I indeed want to authenticate against my PostgreSQL users instead of the
> "default" table-based login, so I don't have to re-write my user-bound
> procedures and triggers. But I also want the admin interface implemented in my
> web application. Ideally, the "user" and "password" in my database connection
> string in settings.py would change based on the user credentials supplied when
> logging in, but I'm not sure if that's possible. Another option I thought of
> was having two database definitions, one of which I use when I login as an
> admin and the other when I login as an "analyst". If this is not possible
> within the timeframe I have, I'd have to go with the second option, but it
> wouldn't be my preferred choice.
>
> Hopefully this explains it a bit more! If there's anything else you need to
> know, please ask.
>
> With kind regards,
>
> Danny
>
> Op dinsdag 22 november 2016 16:14:50 UTC+1 schreef Antonis Christofides:
>
> What you want is not entirely clear. Do you want to authenticate against
> your PostgreSQL users instead of the django.contrib.auth users? If yes,
> you need to customize your authentication [1]. One solution would be to
> write a custom authentication backend, but you might also be able to use
> RemoteUserBackend [2] together with Apache and mod_auth_pgsql.
>
> Or do you want to import PostgreSQL users and groups into the
> django.contrib.auth tables and use those from now on? This should be
> possible with some SQL (INSERT INTO auth_user (id, first_name, last_name,
> email, ...) SELECT ... FROM [wherever PostgreSQL keeps its users]), but
> the "password" field might be tricky to transfer.
>
> I know these don't answer all your questions, but you need to explain a
> bit more.
>
> Regards,
>
> Antonis
>
> [1] https://docs.djangoproject.com/en/1.10/topics/auth/customizing/
> 
> [2]
> 
> https://docs.djangoproject.com/en/1.10/ref/contrib/auth/#django.contrib.auth.backends.RemoteUserBackend
> 
> 
>
> Antonis Christofides
> http://djangodeployment.com
>
> On 2016-11-22 14:52, Danny Remmerswaal wrote:
>> Hey guys,
>>
>> I'm working on a Django project which has a native PostgreSQL database,
>> filled with schemes that contain both read-only and normal tables and
>> with it's own user- and group roles.
>>
>> After manually changing the search_path variable, I have managed to
>> import my current models by running the migrate.inspectdb command and
>> improved the generated models by sorting, changing primary keys etc.
>> Django's automatic admin interface added new tables which can contain
>> users, but ideally that's not what I want for my project. I'd rather have
>> my current login- and group roles defined in PostgreSQL implemented in
>> Django, because there are some already defined restrictions and triggers
>> implemented in my PostgreSQL database that use these user- and group 
>> roles. 
>>
>>
>> Is there any convenient way to import the already defined user- and group
>> roles in PostgreSQL so they work with Django? 
>> As a start I'd like a login page that based on supplied credentials
>> grants access to my database with defined users that are part of the
>> group "analyse" (I.E cevoo).
>> I've included an image that shows my database schemes and user/groups.
>> Hopefully you guys can help me out!
>>
>> With kind regards,
>>
>> Danny
>> -- 
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to django-users...@googlegroups.com .
>> To post to this group, send email to django...@googlegroups.com
>> .
>> Visit this group at https://groups.google.com/group/django-users
>> .
>> To view this discussion on the web visit
>> 
>> https://groups.google.com/d/msgid/django-users/ddbd5a11-91fa-4411-b084-306b59b39e95%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 use

Help!! After a while Django no longer send information to client

2016-11-23 Thread 谭力彬
Here is My Django code

@channel_session
def ws_connect(message):
# Extract the room from the message. This expects message.path to be of 
the
# form /chat/{label}/, and finds a Room if the message path is 
applicable,
# and if the Room exists. Otherwise, bails (meaning this is a some 
othersort
# of websocket). So, this is effectively a version of 
_get_object_or_404.
try:
# prefix, label = 
message['path'].decode('ascii').strip('/').split('/')
prefix, label = message['path'].strip('/').split('/')
if prefix != 'chat':
log.debug('invalid ws path=%s', message['path'])
return
room, created = Room.objects.get_or_create(label=label)
except ValueError:
log.debug('invalid ws path=%s', message['path'])
return
except Room.DoesNotExist:
log.debug('ws room does not exist label=%s', label)
return

log.debug('chat connect room=%s client=%s:%s',
  room.label, message['client'][0], message['client'][1])

# Need to be explicit about the channel layer so that testability works
# This may be a FIXME?
Group('chat-' + label, 
channel_layer=message.channel_layer).add(message.reply_channel)

message.channel_session['room'] = room.label


@channel_session
def ws_receive(message):
# Look up the room from the channel session, bailing if it doesn't exist
try:
label = message.channel_session['room']
room = Room.objects.get(label=label)
except KeyError:
log.debug('no room in channel_session')
return
except Room.DoesNotExist:
log.debug('recieved message, buy room does not exist label=%s', 
label)
return

# Parse out a chat message from the content text, bailing if it doesn't
# conform to the expected message format.
try:
# data = json.loads(message['bytes'].decode(errors='replace'))
tcl_json_info = message['bytes'].decode('utf-8', 
errors="replace").strip()
tcl_json_info = tcl_json_info.replace("\n", "\\n")
tcl_json_info = tcl_json_info.replace("\r", "\\r")
tcl_json_info = tcl_json_info.replace("\t", "\\t")
# data = json.loads(tcl_json_info)
data = ast.literal_eval(tcl_json_info)
except ValueError:
log.debug("ws message isn't json binary=%s", data)
return

if set(data.keys()) != set(('newline', 'mf', 'message', 'level', 
'timestamp', 'color', 'type')):
log.debug("ws message unexpected format data=%s", data)
return

if data:
log.debug('chat message room=%s timestamp=%s newline=%s mf=%s 
level=%s color=%s type=%s message=%s',
  room.label, data['timestamp'], data['newline'], 
data['mf'], data['level'], data['color'], data['type'], data['message'])
# with transaction.atomic():
# m = room.messages.create(**data)
# m = room.messages.create(**data)

# See above for the note about Group
# Group('chat-' + label, 
channel_layer=message.channel_layer).send({'text': json.dumps(m.as_dict())})
Group('chat-' + label, 
channel_layer=message.channel_layer).send({'text': json.dumps(data)})




Here is my javascript code:

ws.onopen = function (evt) {

  var keepAliveMsg = {newline: '1', mf: '0',message: '',level: 
'info',timestamp: '0',color: 'black',type: 'buffer'};

  // var byteArray = new Uint8Array(keepAliveMsg);
  var blob = new Blob([JSON.stringify(keepAliveMsg)]);

  ws.interval_event = $interval(function () {
ws.send(blob);
  }, 5000)
};


-- 
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/a0264ee9-1201-4fb7-aaca-35218cca41ae%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


'CSRF Verification Failed' in Django Translation

2016-11-23 Thread Veni Kunche
Hi everyone,

I've set up translation for a Django app using this tutorial 
. I am using Python 
3.4.5 and Django 1.9.10.  I used set_language to switch between the 
languages. Everything was working great locally. However, I get a "CSRF 
Verification Failed" error on our test server sometimes. I've tried the 
common suggestions that I've found online:

   - I verified that {% csrf_token %} is inside the form
   - I checked that 'django.middleware.locale.LocaleMiddleware' has been 
   added
   - I do have url(r'^i18n/', include('django.conf.urls.i18n')), in urls.p 
   y

These are the settings that are different in the test environment:

CSRF_COOKIE_SECURE = True
SESSION_COOKIE_SECURE = True
SESSION_COOKIE_HTTPONLY = True
SECURE_CONTENT_TYPE_NOSNIFF = True
CSRF_COOKIE_HTTPONLY = True
SECURE_BROWSER_XSS_FILTER = True
X_FRAME_OPTIONS = 'DENY'
CORS_ORIGIN_ALLOW_ALL = True


The test environment is running on https. 
*The application has other forms which do posts and those are working fine. 
It's only the set_language form that's causing the error. *
My questions:

   1. Is there anything else that I should look into?
   2. Is there another way to switch the language besides set_language in a 
   form like this?
   
   
   {% csrf_token %}
   
   
   {% get_current_language as LANGUAGE_CODE %}
   {% get_available_languages as LANGUAGES %}
   {% for lang in LANGUAGES %}
   
   {{ lang.1 }} ({{ lang.0 }})
   
   {% endfor %}
   
   
   
   
Thank you for your help! Let me know if I can clarify further.

-Veni

-- 
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/1f077982-d7d4-4598-ab3c-cf0799eb7049%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Pre-populate formset with a user saved data on revisit

2016-11-23 Thread Said Akhmedbayev
I need to pre-populate a formset field with a user's saved data

Here is my form.py

EssayQuestionFormSetBase = modelformset_factory(models.EssayQuestion,
extra=0,
fields=('prompt',),
 widgets={
 'prompt': forms.
TextInput(
 attrs={'readonly': 
True, 'class': 'borderless'}),
 },
)


class EssayQuestionFormSet(EssayQuestionFormSetBase):
def add_fields(self, form, index):
super(EssayQuestionFormSet, self).add_fields(form, index)
form.fields['answer'] = forms.CharField(widget=forms.Textarea, 
label='')


As you can see, I added a field to accept answers in the 
EssayQuestionFormSet

My views.py looks like following:

class QuizDetail(View):


def get(self, request, **kwargs):


step = models.Quiz.objects.get(pk=self.kwargs['step_pk'])


eqs = models.EssayQuestion.objects.filter(quiz_id=self.kwargs[
'step_pk'])
eqs_formset = forms.EssayQuestionFormSet(queryset=eqs, prefix=
'essay')
   
def post(self, request, *args, **kwargs):
step = models.Quiz.objects.get(pk=self.kwargs['step_pk'])   


eqs = models.EssayQuestion.objects.filter(quiz_id=self.kwargs[
'step_pk'])
eqs_formset = forms.EssayQuestionFormSet(request.POST, queryset=
eqs, prefix='essay')


  
if eqs_formset.is_valid():
for form in eqs_formset:
# create a NEW Answer for this form's associated 
question
new_answer = models.Answer.objects.create(question=form.
instance,
  eq_answer_text
=form.cleaned_data.get('answer'),
  student=models
.Student.objects.get(user=request.user.pk))

   

Currently, the view properly renders empty Textarea field for the answer 
field on the get and properly saves answers on the post. My question, 
however, **how can I pre-populate the answer field with user's saved 
answer?**

Here is the Answer model

class Answer(models.Model):
date_answered = models.DateTimeField(default=timezone.now)
student = models.ForeignKey(Student, blank=True, null=True, 
related_name='answers')
question = models.ForeignKey(Question)
eq_answer_text = models.TextField(blank=False, null=True)

-- 
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/5c18b614-5fe8-4230-a340-05c3144a68dc%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [ANNOUNCE] Django security advisory: Vulnerability in password reset (master branch only)

2016-11-23 Thread William Hakizimana
While we are at it, could we implement these NIST new password guidelines 

 
into django? Just

On Monday, November 21, 2016 at 3:13:21 PM UTC-6, Tim Graham wrote:
>
> We don't normally give security advisories for issues that affect only
> the master branch, but in this case we've made an exception as the issue
> could be high impact.
>
> Please see the blog post for details:
>
> https://www.djangoproject.com/weblog/2016/nov/21/passwordresetconfirmview-security-advisory/
>

-- 
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/71b646e9-9a39-4e47-9aa9-c6cfacd82b6e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: help for creating relationship between User model an another model !!

2016-11-23 Thread adonis simo
Thanks for looking
This is the whole stack trace :
Operations to perform:
  Apply all migrations: admin, auth, blog, contenttypes, polls, sessions
Running migrations:
  Applying blog.0007_article_user...Traceback (most recent call last):
  File "manage.py", line 22, in 
execute_from_command_line(sys.argv)
  File 
"/home/adonis97/Documents/codages/mysite/lib/python3.5/site-packages/django/core/management/__init__.py"
, line 367, in execute_from_command_line
utility.execute()
  File 
"/home/adonis97/Documents/codages/mysite/lib/python3.5/site-packages/django/core/management/__init__.py"
, line 359, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
  File 
"/home/adonis97/Documents/codages/mysite/lib/python3.5/site-packages/django/core/management/base.py"
, line 294, in run_from_argv
self.execute(*args, **cmd_options)
  File 
"/home/adonis97/Documents/codages/mysite/lib/python3.5/site-packages/django/core/management/base.py"
, line 345, in execute
output = self.handle(*args, **options)
  File 
"/home/adonis97/Documents/codages/mysite/lib/python3.5/site-packages/django/core/management/commands/migrate.py"
, line 204, in handle
fake_initial=fake_initial,
  File 
"/home/adonis97/Documents/codages/mysite/lib/python3.5/site-packages/django/db/migrations/executor.py"
, line 115, in migrate
state = self._migrate_all_forwards(state, plan, full_plan, fake=fake, 
fake_initial=fake_initial)
  File 
"/home/adonis97/Documents/codages/mysite/lib/python3.5/site-packages/django/db/migrations/executor.py"
, line 145, in _migrate_all_forwards
state = self.apply_migration(state, migration, fake=fake, fake_initial=
fake_initial)
  File 
"/home/adonis97/Documents/codages/mysite/lib/python3.5/site-packages/django/db/migrations/executor.py"
, line 244, in apply_migration
state = migration.apply(state, schema_editor)
  File 
"/home/adonis97/Documents/codages/mysite/lib/python3.5/site-packages/django/db/migrations/migration.py"
, line 129, in apply
operation.database_forwards(self.app_label, schema_editor, old_state, 
project_state)
  File 
"/home/adonis97/Documents/codages/mysite/lib/python3.5/site-packages/django/db/migrations/operations/fields.py"
, line 84, in database_forwards
field,
  File 
"/home/adonis97/Documents/codages/mysite/lib/python3.5/site-packages/django/db/backends/sqlite3/schema.py"
, line 231, in add_field
self._remake_table(model, create_fields=[field])
  File 
"/home/adonis97/Documents/codages/mysite/lib/python3.5/site-packages/django/db/backends/sqlite3/schema.py"
, line 113, in _remake_table
self.effective_default(field)
  File 
"/home/adonis97/Documents/codages/mysite/lib/python3.5/site-packages/django/db/backends/base/schema.py"
, line 221, in effective_default
default = field.get_db_prep_save(default, self.connection)
  File 
"/home/adonis97/Documents/codages/mysite/lib/python3.5/site-packages/django/db/models/fields/related.py"
, line 909, in get_db_prep_save
return self.target_field.get_db_prep_save(value, connection=connection)
  File 
"/home/adonis97/Documents/codages/mysite/lib/python3.5/site-packages/django/db/models/fields/__init__.py"
, line 755, in get_db_prep_save
prepared=False)
  File 
"/home/adonis97/Documents/codages/mysite/lib/python3.5/site-packages/django/db/models/fields/__init__.py"
, line 938, in get_db_prep_value
value = self.get_prep_value(value)
  File 
"/home/adonis97/Documents/codages/mysite/lib/python3.5/site-packages/django/db/models/fields/__init__.py"
, line 946, in get_prep_value
return int(value)
TypeError: int() argument must be a string, a bytes-like object or a number, 
not 'datetime.datetime'



Le mardi 22 novembre 2016 02:16:51 UTC+1, adonis simo a écrit :
>
> Hi django users,
> I am new to django and i am using django 1.10, i follow up all the 
> tutorial in the documentation and now i have build an blog application with 
> models like :
> Article , Commentaire(comment in english) and Tag. It's working but now i 
> want to add an relation between User (the one who is connected and creating 
> the article)
> and the Article but i dont know how to do this . I find on google and try 
> what i see but nothing ran ,
> this is my code 
> Saisissez le code ici.
>
> from django.contrib.auth.models import User
>
>
> class Article(models.Model):
> titre = models.CharField(max_length=254)
> description = models.TextField()
> contenu = models.TextField()
> date_publication = models.DateField()
> image = models.ImageField(upload_to='blog/static/blog/images/')
> publie = models.BooleanField(default=False) # par defaut un article n'est 
> pas publier
> tag = models.ManyToManyField(Tag)
> auteur = models.ForeignKey('auth.User', verbose_name='auteur', 
> default=1)# here is the relationshp creation
>
>
> ..
> And when i run 
> python manager.py migrate 
>
> it give me a long error message with at the end of it :
> TypeError: int() argument must be a string, a bytes-li

Re: help for creating relationship between User model an another model !!

2016-11-23 Thread pradam programming
Hi,
Please refer this link.
http://stackoverflow.com/questions/34473323/typeerror-int-argument-must-be-a-string-a-bytes-like-object-or-a-number-not

On 23 Nov 2016 9:55 pm, "adonis simo"  wrote:

> Thanks for looking
> This is the whole stack trace :
> Operations to perform:
>   Apply all migrations: admin, auth, blog, contenttypes, polls, sessions
> Running migrations:
>   Applying blog.0007_article_user...Traceback (most recent call last):
>   File "manage.py", line 22, in 
> execute_from_command_line(sys.argv)
>   File "/home/adonis97/Documents/codages/mysite/lib/python3.5/
> site-packages/django/core/management/__init__.py", line 367, in
> execute_from_command_line
> utility.execute()
>   File "/home/adonis97/Documents/codages/mysite/lib/python3.5/
> site-packages/django/core/management/__init__.py", line 359, in execute
> self.fetch_command(subcommand).run_from_argv(self.argv)
>   File "/home/adonis97/Documents/codages/mysite/lib/python3.5/
> site-packages/django/core/management/base.py", line 294, in run_from_argv
> self.execute(*args, **cmd_options)
>   File "/home/adonis97/Documents/codages/mysite/lib/python3.5/
> site-packages/django/core/management/base.py", line 345, in execute
> output = self.handle(*args, **options)
>   File "/home/adonis97/Documents/codages/mysite/lib/python3.5/
> site-packages/django/core/management/commands/migrate.py", line 204, in
> handle
> fake_initial=fake_initial,
>   File "/home/adonis97/Documents/codages/mysite/lib/python3.5/
> site-packages/django/db/migrations/executor.py", line 115, in migrate
> state = self._migrate_all_forwards(state, plan, full_plan, fake=fake,
> fake_initial=fake_initial)
>   File "/home/adonis97/Documents/codages/mysite/lib/python3.5/
> site-packages/django/db/migrations/executor.py", line 145, in
> _migrate_all_forwards
> state = self.apply_migration(state, migration, fake=fake, fake_initial
> =fake_initial)
>   File "/home/adonis97/Documents/codages/mysite/lib/python3.5/
> site-packages/django/db/migrations/executor.py", line 244, in
> apply_migration
> state = migration.apply(state, schema_editor)
>   File "/home/adonis97/Documents/codages/mysite/lib/python3.5/
> site-packages/django/db/migrations/migration.py", line 129, in apply
> operation.database_forwards(self.app_label, schema_editor, old_state,
> project_state)
>   File "/home/adonis97/Documents/codages/mysite/lib/python3.5/
> site-packages/django/db/migrations/operations/fields.py", line 84, in
> database_forwards
> field,
>   File "/home/adonis97/Documents/codages/mysite/lib/python3.5/
> site-packages/django/db/backends/sqlite3/schema.py", line 231, in
> add_field
> self._remake_table(model, create_fields=[field])
>   File "/home/adonis97/Documents/codages/mysite/lib/python3.5/
> site-packages/django/db/backends/sqlite3/schema.py", line 113, in
> _remake_table
> self.effective_default(field)
>   File "/home/adonis97/Documents/codages/mysite/lib/python3.5/
> site-packages/django/db/backends/base/schema.py", line 221, in
> effective_default
> default = field.get_db_prep_save(default, self.connection)
>   File "/home/adonis97/Documents/codages/mysite/lib/python3.5/
> site-packages/django/db/models/fields/related.py", line 909, in
> get_db_prep_save
> return self.target_field.get_db_prep_save(value, connection=connection
> )
>   File "/home/adonis97/Documents/codages/mysite/lib/python3.5/
> site-packages/django/db/models/fields/__init__.py", line 755, in
> get_db_prep_save
> prepared=False)
>   File "/home/adonis97/Documents/codages/mysite/lib/python3.5/
> site-packages/django/db/models/fields/__init__.py", line 938, in
> get_db_prep_value
> value = self.get_prep_value(value)
>   File "/home/adonis97/Documents/codages/mysite/lib/python3.5/
> site-packages/django/db/models/fields/__init__.py", line 946, in
> get_prep_value
> return int(value)
> TypeError: int() argument must be a string, a bytes-like object or a
> number, not 'datetime.datetime'
>
>
>
> Le mardi 22 novembre 2016 02:16:51 UTC+1, adonis simo a écrit :
>>
>> Hi django users,
>> I am new to django and i am using django 1.10, i follow up all the
>> tutorial in the documentation and now i have build an blog application with
>> models like :
>> Article , Commentaire(comment in english) and Tag. It's working but now i
>> want to add an relation between User (the one who is connected and creating
>> the article)
>> and the Article but i dont know how to do this . I find on google and try
>> what i see but nothing ran ,
>> this is my code
>> Saisissez le code ici.
>>
>> from django.contrib.auth.models import User
>>
>>
>> class Article(models.Model):
>> titre = models.CharField(max_length=254)
>> description = models.TextField()
>> contenu = models.TextField()
>> date_publication = models.DateField()
>> image = models.ImageField(upload_to='blog/static/blog/images/')
>> publie = models.BooleanField(default=False) # par defaut un artic

Re: Channels: startup order of daphne and workers leads to issues

2016-11-23 Thread Andrew Godwin
Hi Alex,

It sounds like this isn't a daphne/workers ordering bug (things just queue
and run when available) but a serialisability issue - that is, you expected
`websocket.connect` to run before `websocket.receive` but in the released
version they will run in parallel if both have queued messages.

This is fixed in channels master and will come out in the next release, but
you can opt into it in the meantime by using
`@enforce_ordering(slight=True)` as a decorator on your consumers. The
Channels docs has more:
http://channels.readthedocs.io/en/stable/getting-started.html#enforcing-ordering

Andrew

On Tue, Nov 22, 2016 at 3:16 PM, Alex Peitsinis 
wrote:

> Hello,
>
> I noticed a weird thing during a deployment of a service that uses
> channels at work the other day. We use docker, so we have a container for
> daphne and a container for workers (currently 4). We start a service that
> some other machines connect to almost automatically (reconnecting etc), and
> we also patched some of the auth stuff  wrote to do authentication based on
> HTTP headers. So, in order to connect, you must have a header that is
> recognized, or else you are disconnected.
>
> So, after the service was up, the reconnecting client was reporting that
> it was connected, but he did not get the response (the response is sent
> from the 'websocket.connect' consumer). Which means that he did connect,
> but none of the auth code had ran. The reason was that daphne had started
> before the workers, so we had docker set up the workers first and then
> daphne.
>
> Is this expected behaviour or a bug? I guess it can be considered as a
> security bug, but not really sure.
>
> 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/9520d123-a2ec-46bc-b887-0906392074a3%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/CAFwN1urG6uSbq%2B2LWmGEar%2BC%3DKpQCQi0kYzQ%2BJfeCy7G-cmipQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.