Tuesday, July 31, 2018

Re: django-modeltranslation latest stable release not supporting Django 2.0

Hi,

This is not an issue for the django-users group, but rather, as you already have done, open an issue on the repository itself. What you also can do is go through the code and issue a PR to fix the changes required for supporting django 2.0 - the developer will probably happily accept the changes.

The django users mailgroup is for helping you in using django - and the problems that you get with django usage. Not for asking other people to fix software in the django environment.

Good luck!

Andréas

2018-07-31 18:37 GMT+02:00 Uri Even-Chen <uri@speedy.net>:
Hi,

We are using django-modeltranslation for Speedy Net and Speedy Match (https://github.com/urievenchen/speedy-net). We are using django-modeltranslation as well as other packages. I noticed that django-modeltranslation latest stable release (0.12.2, from Jan. 26, 2018, see https://pypi.org/project/django-modeltranslation/#history) still doesn't support Django 2.0. There is a beta release which supports Django 2.0 but we don't want to use beta releases in our project. I opened an issue on GitHub (https://github.com/deschler/django-modeltranslation/issues/472) and I'm waiting for a stable release of django-modeltranslation which supports Django 2.0. This is the only package we use which still doesn't support Django 2.0 with a stable release. Can you help / join the project and release a stable release which supports Django 2.0? We want to upgrade our project to Django 2.0 and we can't do it due to this issue.

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+unsubscribe@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/CAMQ2MsH%2B95Vai_hLDBMOXx8Eb5KEUGL7HyPC0c9C5K_s8SEVBA%40mail.gmail.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+unsubscribe@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/CAK4qSCepZH0NfYE%2Bw4Pm%2BTGHFvbuchMG6i5GNrxmwE-Qaif0rg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Re: Problem with sending django channels event from models

Yes, you can't just call "group_send" without awaiting it, or you'll get those warnings. You need async_to_sync, I'm afraid. Otherwise, you're not actually waiting for the group_send function to finish and you'll start getting some unreliable test results.

Andrew

On Tue, Jul 31, 2018 at 6:14 AM luan fonceca <luanfonceca@gmail.com> wrote:
Hello Andrew, sorry for the lack of traceback on the gist. I have changed my code a bit, i was using the `async_to_sync` but now i'm using this way inside my User save method:

channel_layer = get_channel_layer()
channel_layer.group_send(
    'users_{}'.format(self.pk), {
        'type': 'users.post_save',
        'user_pk': self.pk
    }
)

And everything works fine, but my tests are raising warnings on each test, like this, if you want to see the full traceback of my test, click here:

users/tests/test_consumers.py::test_user_consumer
  /Users/luan/Sources/channels-test/users/models.py:56: RuntimeWarning: coroutine 'RedisChannelLayer.group_send' was never awaited
    'user_pk': self.pk

I have update my gist, if you want to see something else, but in general i'm using py.test, as you can see in here.



Thanks for everything, Andrew.

Em sex, 27 de jul de 2018 às 19:30, Andrew Godwin <andrew@aeracode.org> escreveu:
You need to post the full traceback, not just the last section. I suspect what you are doing is calling model methods directly in an async function, but I can't confirm that without a full traceback.

Andrew

On Thu, Jul 26, 2018 at 1:10 PM luan fonceca <luanfonceca@gmail.com> wrote:
Hello, i'm trying to implement a "post_save" signal wherever some user are update. I setup everything by following the documentation and some tutorials for Channels 2. I wrote a test using "py.test" to assert that everything is working as expected but i'm getting a exception.


Thanks in advance.

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

--
You received this message because you are subscribed to a topic in the Google Groups "Django users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/django-users/3hZUiOvhSfE/unsubscribe.
To unsubscribe from this group and all its topics, send an email to django-users+unsubscribe@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/CAFwN1uomro%2B1-qkGC8ThJw6ehz%3DHTenXwUqx-xM%3DkzzTqNgQdg%40mail.gmail.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+unsubscribe@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/CAPqSnxuydxQaBGb0FkS%3DWvyxN5TwuuPmnJ5Yx3msBDNR36%3Dx0A%40mail.gmail.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+unsubscribe@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/CAFwN1ur1zrAcVvF1r6kMJGgbWBr1m5wo9E1%3DZYze5Nmf8fuXqw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

RE: Validating count + property of a Many2Many with a through table

Hi Sanjay,
You may want to try signals.
https://docs.djangoproject.com/en/2.0/topics/signals/


-----Original Message-----
From: django-users@googlegroups.com [mailto:django-users@googlegroups.com] On Behalf Of Sanjay Bhangar
Sent: Tuesday, July 31, 2018 1:09 PM
To: django-users@googlegroups.com
Subject: Validating count + property of a Many2Many with a through table

Hello!

This is more of a code organization question than a "something is not working" question - it might get slightly rambling, so if this kind of question is not your cup of tea, you have been warned :-)

So - I have a set of models like this (highly simplified):

class Item(models.Model):
title = models.CharField(...)
price = models.IntegerField(...)
tags = models.ManyToManyField(Tag, through=ItemTag)

class Tag(models.Model):
name = models.CharField(...)

class ItemTag(models.Model):
item = models.ForeignKey(Item)
tag = models.ForeignKey(Tag)
is_primary = models.BooleanField()


So, I have an Item model that has some properties - it has a ManyToMany relationship with Tag, and one or more tags can be selected as "is_primary" tags for the model.

Now, to validate properties on the Item model, I call validation methods inside a "clean" method on the Item model, something like:

def clean(self):
if self.price > 10000:
raise ValidationError('Price cannot be so high!")

This is simplified, but you get the idea - this works great, errors are propagated in the Admin, as well as raised when I import data via a CSV file for example. I know there's a few different places one can define validations - I personally like to have them in the model, but I would love to hear alternate view-points if this is not the best place to put them.

So, coming to the problem: there is now a requirement to validate that a model cannot have more than 3 primary tags associated with it - i.e.
cannot be associated with more than 3 tags with the through table specifying is_primary=True.

This, of course, cannot really go in the `clean` method of the Item model. The ItemTag relationships don't exist yet, and I don't have the data I need to be able to validate a maximum of 3 tags.

The problem is, I cannot seem to be able to do this kind of validation in the ItemTag model either, since it depends on knowing how many existing ItemTag relationships to Item there are - and before the entire transaction is committed to the database, a single ItemTag doesn't know whether the total exceeds the allowed 3.

The only place to put it that worked (and made sense) was in the Formset definition for the inline form in the admin.

So, we landed up over-riding the formset used for the ItemTag inline in the admin, adding our validations to the `clean` method - roughly
like:

class ItemImageInlineFormset(forms.models.BaseInlineFormSet):
def clean(self):
image_count = 0
for form in self.forms:
if form.cleaned_data.get('primary') == True:
image_count += 1
if image_count > 3:
raise ValidationError('Cannot have more than 3 primary tags')


This works. However, it seems a bit strange to have validations split between a model method, and a subclass of a formset of an admin form.
It seems confusing in terms of maintainability - also, writing tests for the validations in the model seemed a lot more straightforward when validations were just in the model's `clean` method.

I can see why this is so. Am just wondering if I'm getting something wrong in terms of patterns here / if there is a way other folks solve this, to, ideally, be able to have all the validation that pertains to a particular model in one place, and be able to test all model validations in a consistent manner.

Thank you to whoever read this far :-)

-Sanjay

--
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+unsubscribe@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/CAG3W7ZFZnemOSOwDRjDN--JLKdF94QEJNrbuTw2MCPoK1QxP7Q%40mail.gmail.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+unsubscribe@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/8888981a20654ff4b41e32c600464ddd%40ISS1.ISS.LOCAL.
For more options, visit https://groups.google.com/d/optout.

Validating count + property of a Many2Many with a through table

Hello!

This is more of a code organization question than a "something is not
working" question - it might get slightly rambling, so if this kind of
question is not your cup of tea, you have been warned :-)

So - I have a set of models like this (highly simplified):

class Item(models.Model):
title = models.CharField(...)
price = models.IntegerField(...)
tags = models.ManyToManyField(Tag, through=ItemTag)

class Tag(models.Model):
name = models.CharField(...)

class ItemTag(models.Model):
item = models.ForeignKey(Item)
tag = models.ForeignKey(Tag)
is_primary = models.BooleanField()


So, I have an Item model that has some properties - it has a
ManyToMany relationship with Tag, and one or more tags can be selected
as "is_primary" tags for the model.

Now, to validate properties on the Item model, I call validation
methods inside a "clean" method on the Item model, something like:

def clean(self):
if self.price > 10000:
raise ValidationError('Price cannot be so high!")

This is simplified, but you get the idea - this works great, errors
are propagated in the Admin, as well as raised when I import data via
a CSV file for example. I know there's a few different places one can
define validations - I personally like to have them in the model, but
I would love to hear alternate view-points if this is not the best
place to put them.

So, coming to the problem: there is now a requirement to validate that
a model cannot have more than 3 primary tags associated with it - i.e.
cannot be associated with more than 3 tags with the through table
specifying is_primary=True.

This, of course, cannot really go in the `clean` method of the Item
model. The ItemTag relationships don't exist yet, and I don't have the
data I need to be able to validate a maximum of 3 tags.

The problem is, I cannot seem to be able to do this kind of validation
in the ItemTag model either, since it depends on knowing how many
existing ItemTag relationships to Item there are - and before the
entire transaction is committed to the database, a single ItemTag
doesn't know whether the total exceeds the allowed 3.

The only place to put it that worked (and made sense) was in the
Formset definition for the inline form in the admin.

So, we landed up over-riding the formset used for the ItemTag inline
in the admin, adding our validations to the `clean` method - roughly
like:

class ItemImageInlineFormset(forms.models.BaseInlineFormSet):
def clean(self):
image_count = 0
for form in self.forms:
if form.cleaned_data.get('primary') == True:
image_count += 1
if image_count > 3:
raise ValidationError('Cannot have more than 3 primary tags')


This works. However, it seems a bit strange to have validations split
between a model method, and a subclass of a formset of an admin form.
It seems confusing in terms of maintainability - also, writing tests
for the validations in the model seemed a lot more straightforward
when validations were just in the model's `clean` method.

I can see why this is so. Am just wondering if I'm getting something
wrong in terms of patterns here / if there is a way other folks solve
this, to, ideally, be able to have all the validation that pertains to
a particular model in one place, and be able to test all model
validations in a consistent manner.

Thank you to whoever read this far :-)

-Sanjay

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

django-modeltranslation latest stable release not supporting Django 2.0

Hi,

We are using django-modeltranslation for Speedy Net and Speedy Match (https://github.com/urievenchen/speedy-net). We are using django-modeltranslation as well as other packages. I noticed that django-modeltranslation latest stable release (0.12.2, from Jan. 26, 2018, see https://pypi.org/project/django-modeltranslation/#history) still doesn't support Django 2.0. There is a beta release which supports Django 2.0 but we don't want to use beta releases in our project. I opened an issue on GitHub (https://github.com/deschler/django-modeltranslation/issues/472) and I'm waiting for a stable release of django-modeltranslation which supports Django 2.0. This is the only package we use which still doesn't support Django 2.0 with a stable release. Can you help / join the project and release a stable release which supports Django 2.0? We want to upgrade our project to Django 2.0 and we can't do it due to this issue.

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+unsubscribe@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/CAMQ2MsH%2B95Vai_hLDBMOXx8Eb5KEUGL7HyPC0c9C5K_s8SEVBA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

concurrency to request django multi url have problems

concurrency to request two urls, django app get each url's header have problems.................please jump to https://stackoverflow.com/questions/51606850/django-concurrency-request-two-url-each-request-header-is-wrong-to-each-url

--
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+unsubscribe@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/53a07599-cbc3-4ae0-9686-2aeac9fe6207%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Live Streaming Video through WebCam

Hello Everyone, I'm using the Live Streaming Video through WebCam. It's storing in .avi format. When i'm playing the Video. I'm not getting the audio of that video. I hope that opencv does not provide the audio features. Kindly let me know if you have any idea. Thanks,


Please find the below code:---------------

import os.path
import numpy as np
import cv2, time
import random

def change_res(cap, width, height):
cap.set(3, width)
cap.set(4, height)

#Standard Video Dimensions Sizes
STD_DIMENSIONS = {
'480p': (640, 480),
'720p': (1280, 720),
'1080p': (1920, 1080),
'4k': (3840, 2160),
}

VIDEO_TYPE = {
'avi':cv2.VideoWriter_fourcc(*'XVID'),
'mp4':cv2.VideoWriter_fourcc(*'XVID'),
}

def get_video_type(filename):
ext = os.path.splitext(filename),
if ext in VIDEO_TYPE:
return VIDEO_TYPE[ext]
return VIDEO_TYPE['avi']

def get_dims(cap, res='480p'):
width, height = STD_DIMENSIONS['480p']
if res in STD_DIMENSIONS:
width, height = STD_DIMENSIONS[res]
change_res(cap, width, height)
return width, height

#--------------START LIVE VIDEO----------#
random_id = random.randint(10000,99999)
livevideo_name = str('livevideo_'+str(random_id)+'.avi')
frames_per_second = 20.0  #..Frame Per Second
my_res = '480p'  #..Frame Size

# Capture video from camera
livevideos = '/livevideos/'+livevideo_name
cap = cv2.VideoCapture(-1)
dims = get_dims(cap, res=my_res)
video_type_cv2 = get_video_type(livevideos) 

# Define the codec and create VideoWriter object
fourcc = cv2.VideoWriter_fourcc(*'XVID') # Be sure to use the lower case
out = cv2.VideoWriter(livevideos, video_type_cv2, frames_per_second, dims)
while(True):
ret, frame = cap.read()
if ret==True:
frame = cv2.flip(frame,1)
# Write the frame into the file
out.write(frame)
cv2.imshow('frame',frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
else:
break

# When everything done, release the video capture and video write objects
cap.release()
out.release()
# Closes all the frames
cv2.destroyAllWindows()

--
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+unsubscribe@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/CAEr6%3DdzZyO44sDLkd-HPoqh-LCuuvvnRiXDfEeXWZduCxBuw4g%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Re: Intregration Of on form submit user recive a sms in his phone

Build your sms function in python. When the form is submitted fire off a celery task to send the sms

On Tuesday, July 31, 2018 at 9:32:02 AM UTC-4, im...@wsegames.com wrote:
How to impement this feature Intregration Of on form submit user recive a sms in his phone.

--
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+unsubscribe@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/4ca48658-e48e-4af3-b24a-e04ecb3ca12e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Re: Intregration Of on form submit user recive a sms in his phone

I use this company:

https://www.reach-interactive.com/

On Tuesday, 31 July 2018 14:32:02 UTC+1, im...@wsegames.com wrote:
How to impement this feature Intregration Of on form submit user recive a sms in his phone.

--
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+unsubscribe@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/e818b28e-a933-4f5e-8759-4978e77e0605%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Re: Problem with sending django channels event from models

Hello Andrew, sorry for the lack of traceback on the gist. I have changed my code a bit, i was using the `async_to_sync` but now i'm using this way inside my User save method:

channel_layer = get_channel_layer()
channel_layer.group_send(
    'users_{}'.format(self.pk), {
        'type': 'users.post_save',
        'user_pk': self.pk
    }
)

And everything works fine, but my tests are raising warnings on each test, like this, if you want to see the full traceback of my test, click here:

users/tests/test_consumers.py::test_user_consumer
  /Users/luan/Sources/channels-test/users/models.py:56: RuntimeWarning: coroutine 'RedisChannelLayer.group_send' was never awaited
    'user_pk': self.pk

I have update my gist, if you want to see something else, but in general i'm using py.test, as you can see in here.



Thanks for everything, Andrew.

Em sex, 27 de jul de 2018 às 19:30, Andrew Godwin <andrew@aeracode.org> escreveu:
You need to post the full traceback, not just the last section. I suspect what you are doing is calling model methods directly in an async function, but I can't confirm that without a full traceback.

Andrew

On Thu, Jul 26, 2018 at 1:10 PM luan fonceca <luanfonceca@gmail.com> wrote:
Hello, i'm trying to implement a "post_save" signal wherever some user are update. I setup everything by following the documentation and some tutorials for Channels 2. I wrote a test using "py.test" to assert that everything is working as expected but i'm getting a exception.


Thanks in advance.

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

--
You received this message because you are subscribed to a topic in the Google Groups "Django users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/django-users/3hZUiOvhSfE/unsubscribe.
To unsubscribe from this group and all its topics, send an email to django-users+unsubscribe@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/CAFwN1uomro%2B1-qkGC8ThJw6ehz%3DHTenXwUqx-xM%3DkzzTqNgQdg%40mail.gmail.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+unsubscribe@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/CAPqSnxuydxQaBGb0FkS%3DWvyxN5TwuuPmnJ5Yx3msBDNR36%3Dx0A%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Intregration Of on form submit user recive a sms in his phone

How to impement this feature Intregration Of on form submit user recive a sms in his phone.

--
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+unsubscribe@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/aaa81e20-506b-4ac5-8767-c6e12b0b8b13%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Re: Change the default route of a view

For the view that I wrote, you won't need an id in the request or on the url at all. It uses the currently logged in user for all of the requests.

You will need to pass some kind of token in the request - so that you know which user is logged in.

But the url could be something like this:

urlpatterns = [
  path('/profile', views.UserProfileChangeAPIView.as_view(), name='profile'),
]

That way the /profile url would be used for the view.

Regards,

Andréas

2018-07-30 17:35 GMT+02:00 Jason <jjohns98684@gmail.com>:
its not a url, its a http verb.  rely on those for API requests.  

and it would be a user ID for that request.  if you're using oauth tokens, that should be handled in your view authenticator, not the view itself

--
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+unsubscribe@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/c36b4a7e-3c53-4805-9e45-35e22eb20357%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+unsubscribe@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/CAK4qSCdcHGMe3inZKtM7A%2BzNiYjG%3DdQYVF7DvxF5rx0Mqfj-Vg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Re: How to use multiple ForeignKeys

put a foreign key in invoices model that points to vendor model .

On Tue, 31 Jul 2018, 00:38 Alexander Joseph, <Alexander.V.Joseph@gmail.com> wrote:
I'm building a Purchase Order app that uses a ForeignKey for Vendors. I want to be able to use another ForeignKey for invoices once a Vendor is selected. So the choices of Invoices would get filtered based on the users selection of the Vendor. How would I do this in the model? I assume I'd need ajax to load the invoices based on the Vendor in the template? 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+unsubscribe@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/3c0e8bfb-30fb-467f-aa2f-58677e203480%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+unsubscribe@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/CAHV4E-dSB2W2dAkAK_YtvLLyBj%3D33v8VaUtEH%2B1huXmRFu5jeA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Monday, July 30, 2018

How to use multiple ForeignKeys

I'm building a Purchase Order app that uses a ForeignKey for Vendors. I want to be able to use another ForeignKey for invoices once a Vendor is selected. So the choices of Invoices would get filtered based on the users selection of the Vendor. How would I do this in the model? I assume I'd need ajax to load the invoices based on the Vendor in the template? 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+unsubscribe@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/3c0e8bfb-30fb-467f-aa2f-58677e203480%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Re: Django tests and token timeout

Hi!

On 07/30/2018 05:04 PM, Kasper Laudrup wrote:
> Hi Birger,
>
> On 2018-07-30 16:12, Birger Schacht wrote:
>> i'm using my own PasswordResetTokenGenerator which has a timeout that is
>> not given in days but hours, to make the password token timeout more
>> fine grained. Is there a way to test such a timeout in Django tests,
>> i.e. something that lets the unit test use a fake time in the future?
>>
>
> You can mock out pretty much everything using the mock module in the
> standard Python unittest library that Django already uses.
>
> Depending on your code of course, but something like:
>
> @mock.path('os.time.now')
> def test_my_token(self, mock_now):
>   mock_now.return_value = datetime(3000, 12, 31)
>   # The rest of your test code goes here
>
> Now your code should see the current time as being new years 3000.
>
> I haven't tested this and there might be better ways to do that, but
> that's how I would handle it. Hope that helps.

thanks, that did the trick!

cheers,
Birger

--
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+unsubscribe@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/ce3eeff8-2bc5-c687-1777-414e2316e0cc%40rantanplan.org.
For more options, visit https://groups.google.com/d/optout.

Re: Change the default route of a view

its not a url, its a http verb.  rely on those for API requests.  

and it would be a user ID for that request.  if you're using oauth tokens, that should be handled in your view authenticator, not the view itself

--
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+unsubscribe@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/c36b4a7e-3c53-4805-9e45-35e22eb20357%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Re: Django tests and token timeout

Hi Birger,

On 2018-07-30 16:12, Birger Schacht wrote:
> i'm using my own PasswordResetTokenGenerator which has a timeout that is
> not given in days but hours, to make the password token timeout more
> fine grained. Is there a way to test such a timeout in Django tests,
> i.e. something that lets the unit test use a fake time in the future?
>

You can mock out pretty much everything using the mock module in the
standard Python unittest library that Django already uses.

Depending on your code of course, but something like:

@mock.path('os.time.now')
def test_my_token(self, mock_now):
mock_now.return_value = datetime(3000, 12, 31)
# The rest of your test code goes here

Now your code should see the current time as being new years 3000.

I haven't tested this and there might be better ways to do that, but
that's how I would handle it. Hope that helps.

Kind regards,

Kasper Laudrup

--
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+unsubscribe@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/b35369b8-8f76-074a-ad19-02e8543d0fc8%40stacktrace.dk.
For more options, visit https://groups.google.com/d/optout.

Re: Django tests and token timeout

Whenever I need to set the date or datetime to something specific for unit tests, I use Forbidden Fruit (https://github.com/clarete/forbiddenfruit).

On Mon, 2018-07-30 at 16:12 +0200, Birger Schacht wrote:
hi,    i'm using my own PasswordResetTokenGenerator which has a timeout that is  not given in days but hours, to make the password token timeout more  fine grained. Is there a way to test such a timeout in Django tests,  i.e. something that lets the unit test use a fake time in the future?    cheers,  Birger    
-- 
Adam (adam@csh.rit.edu)

Django tests and token timeout

hi,

i'm using my own PasswordResetTokenGenerator which has a timeout that is
not given in days but hours, to make the password token timeout more
fine grained. Is there a way to test such a timeout in Django tests,
i.e. something that lets the unit test use a fake time in the future?

cheers,
Birger

--
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+unsubscribe@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/0908c2cb-6b0b-de14-765f-be1e81b33769%40rantanplan.org.
For more options, visit https://groups.google.com/d/optout.

Re: Change the default route of a view

Andréas, but in this case what is the PUT url for example, with profile / {id}? And in the id parameter you pass the userid or token of OAuth2?

Thank you


Em domingo, 29 de julho de 2018 04:50:25 UTC-3, Andréas Kühne escreveu:
If you are using DRF with normal URLs you just create a view that inherits from the delete, update and retrieve mixins. Something like this should work:

from rest_framework import generics, mixins, permissions

User = get_user_model()


class UserProfileChangeAPIView(generics.RetrieveAPIView,
mixins.DestroyModelMixin,
mixins.UpdateModelMixin):
permission_classes = (
permissions.IsAuthenticated,
)
serializer_class = UserProfileChangeSerializer

def get_object(self):
return self.request.user

def delete(self, request, *args, **kwargs):
return self.destroy(request, *args, **kwargs)

def put(self, request, *args, **kwargs):
return self.update(request, *args, **kwargs)

You need to import the get_user_model and the UserProdilfChangeSerializer (or whatever you called your serializer for the profile).

Regards,

Andréas

2018-07-27 19:49 GMT+02:00 Fernando Miranda <fndmi...@gmail.com>:
Hi Andrea,

So, I'm getting the user that way, I'm in doubt is how to mount the routes to an account view, where you have the retrieve, update and delete of the current user.


Em sexta-feira, 27 de julho de 2018 12:23:24 UTC-3, Andréas Kühne escreveu:
Hi Fernando,

In DRF even with token authentication you will be able to get the currently logged in user via the user object on the request. So request.user will be the user doing the request.

If you for example want to have an endpoint that is for the current user you could just check the request.user to see which user is doing the request. Then you don't need to use the id from the url.

Regards,

Andréas

2018-07-27 16:36 GMT+02:00 Fernando Miranda <fndmi...@gmail.com>:
I think I understood about the rest, the right one to edit for example would be to have the route of type PUT passing the token OAuth2 in the route and there I look for the user owner of the token? Or the user ID and check if the authenticated user is the same as the last ID?

Em sexta-feira, 27 de julho de 2018 08:10:19 UTC-3, Jason escreveu:
you can probably do this with overriding a few things, but for me, your use case has some major problems.  you're effectively breaking away from the basics of REST.

If you want to implement some sort of non-sequential identifiers for users/resources, use UUIDs.  Any token passed in the headers should be used for auth only, not contain explicit routing values.

On Thursday, July 26, 2018 at 4:10:55 PM UTC-4, Fernando Miranda wrote:
Hello, I'm using Django Rest Framework, I was wondering if you have how to change the default url of an endpoint in a view? In case it is a view of account where I wanted the retrieve method to be without / {id} this also for the delete and edit because I will identify the user by the token passed in the header.

--
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/875eb467-9cd2-492b-9aea-e311bb3da022%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...@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/554e0c24-29d7-474a-982b-cb40838b2b14%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+unsubscribe@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/b75dd86c-baf0-4cfc-8eca-21610849033b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Re: [Channels] How to write tests with database access?

The question is whether testing asynchronous operations and <any other stateful information> is compatible.

In my understanding, Andrew's hint points you in the only good direction.  You've got to turn the async initiate/complete cycle back into a synchronous flow.

You can poll from another thread, or use a message queue, or any of a number of approaches.  But there is no way around the need to wait until completion before your test the state after completion.

On Saturday, July 28, 2018 at 10:49:39 AM UTC-4, Neraste wrote:
Thanks for the hint, Andrew. I think it is a neat approach. But I start to wonder if asynchronous tests + database manipulation are naturally and painlessly compatible.

Le dimanche 22 juillet 2018 18:44:52 UTC+2, Andrew Godwin a écrit :
Asynchronous testing is very hard, unfortunately. I suspect what you are doing is awaiting the sending of the message, but not awaiting any response back, so your test continues once it's sent the message into the application but not waiting for that application to finish processing.

The best pattern for this is probably to send something back when you've finished processing and await receiving that, then you should guarantee that the work has been finished before your test continues.

Andrew

On Thu, Jul 19, 2018 at 8:18 AM Neraste <neraste...@gmail.com> wrote:

Hello Django users,

This sounds like a pretty newbish question, but I am struggling on how to write tests for Django-channels 2 websocket consumers that access the database. I am not familiar with pytest and asynchronous programming (the bread and butter of Channels testing), so while I caught up with pytest, I am still a bit lost between `async` and `await`.

Using Django/Django-REST, when I test a view method which modifies a database object for a given request, here is what I usually do:

  1. Assert the initial state of the object ;
  2. Use the test client to send the request ;
  3. Assert the outcome of the request ;
  4. Assert the final state of the object, which should be different.

All of this synchronously. With Channels, I thought I could do the same for a consumer method which modifies a database object on a given event:

  1. Assert the initial state of the object ;
  2. Use the test communicator to send the event ;
  3. Assert the final state of the object, which should have changed.

All of this asynchronously, as stated in the documentation, but this is a synchronous test scenario! Obviously, it does not work, as step 2. is executed with `await` and step 3. is achieved before step 2. finishes. I tried to execute step 2. synchronously using `async_to_sync` but it does not work (I can give details).

I am missing something, how can I test such a consumer method? Is this possible? The documentation does not give any hint on this…

Help would be much appreciated!

Cheers,

--   Neraste

--
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/c22c1afb-ff85-5af9-66f6-a94cdc77a545%40gmail.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+unsubscribe@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/e2824e79-cb0b-4d70-9867-884104e0508f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Re: Django App plugins

>
> one hack around is to load all the plugins once you create the project
> , but make them hidden or unaccessible untill the user want a certain
> option-plugin so you make it visible for him

This is not possible, as it should be possible to download and install a
plugin with one click, and it's running. And that's a heck of a task in
Django, OMG.
Right now, I'm overthrowing the "one django app as a plugin" system,a s
it has too many disadvantages.

--
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+unsubscribe@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/bddb356f-2466-9334-bd20-ac555fd45897%40nerdocs.at.
For more options, visit https://groups.google.com/d/optout.

Re: Django App plugins

wow , i faced the [ static and preload problem ] of settings.py once .. you cant govl around it becouse its how they designed django , you cant even pass empty containers for any future values , or will be calculated from the very next script after settings.py , you cant do that , there is no such a lazy load in settings.py so dont try this way , think of another way or you have to mess with django source code ..


one hack around is to load all the plugins once you create the project , but make them hidden or unaccessible untill the user want a certain option-plugin so you make it visible for him 

On Mon, 30 Jul 2018, 07:36 Melvyn Sopacua, <m.r.sopacua@gmail.com> wrote:
On zondag 29 juli 2018 23:14:34 CEST Christian González wrote:
> On zondag 29 juli 2018 11:02:30 CEST Christian González wrote:

> > There might also be another reason and that is that in the Python
> > community, there's a good realisation that downloadable and instantly
> > installable plugins for a web project without dev(ops) interference
> > isn't necessarily a good thing.
>
> Mh, not really. Look at Owncloud/Nextcloud. Is PHP, but a good example
> that this works.

I have a good amount of experience with Magento, which has the same principle
and dealt with all the downsides of it. But I personally don't know of any
similar project within the Python community.

Doesn't mean it doesn't exist, just not as wide spread and after having dealt
with the security holes, low quality not performing code, layout breakers and
what not - I can't say I'm surprised. Magento has invested quite a bit in ways
to check code quality on everything that hits the store.

Either way, keep in mind that you're not going to solve this *just* at the
Django layer. You'll need some way to trigger the WSGI processor to load the
new code in a safe manner and then run migrations. Good luck!

--
Melvyn Sopacua


--
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+unsubscribe@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/1637102.li6HjgoyNo%40fritzbook.
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+unsubscribe@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/CAHV4E-fzyNP7gsLtZgYSWwX%2BeUxG3QKK7eaN0Kq6Q2UK0O9tbA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Re: Authentication (Login view)

in your templates you make a check using {%  if request.user.is_authenticated % } content to show {% else %} the login url {% endif %}

On Mon, 30 Jul 2018, 13:41 SAD BOIII, <ar80pro@gmail.com> wrote:
?guys, how can i stop logged in users from accessing the log in page again


--
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+unsubscribe@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/39c8091c-1e46-4bc5-8dee-b50804390467%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+unsubscribe@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/CAHV4E-fns4BGa3Dppzt%2BNigk7ZEudr8P3gQ86mtgTfpeksKbeQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Re: Authentication (Login view)

On 2018-07-30 07:33, SAD BOIII wrote:
> ?guys, how can i stop logged in users from accessing the log in page again
>

In your view for the login page:

if user.is_authenticated():
return HttpResponseForbidden()

Or something similar?

--
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+unsubscribe@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/9f8ccb51-e08e-791a-8d45-95b5a1b9f73f%40stacktrace.dk.
For more options, visit https://groups.google.com/d/optout.

Re: Django template cheat sheet or ebook

i think docs are very good

On Mon, 30 Jul 2018, 13:41 , <benjamin.bernard-bouissieres@ipexia.com> wrote:
Hello,

I have found a lot of example on the Django's CookBook, at this url : https://code.djangoproject.com/wiki/CookBook

Le lundi 30 juillet 2018 05:44:44 UTC+2, aditya a écrit :
Can anyone tell me where I can find Django template cheat sheet or ebook.

A quelle Vitesse surfez-vous ? Testez le Débit de votre Accès internet [Test Complet]

--
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+unsubscribe@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/2e09e0e4-e59e-42d2-b702-7567b77b6897%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+unsubscribe@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/CAHV4E-dwQBGVk6GL%3Dtu0SRfuwzg-Lu_UXMNwX2LHgYCdta2d3w%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.