Re: best way to generate PDFs in django - handling concurrency

2018-12-27 Thread mazz ahmed
Use wkhtmltopdf package for that bro.

On Fri, Dec 28, 2018 at 12:02 PM Danny Blaker  wrote:

> 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/e8ef92bf-19c7-4881-9465-a04749cfad00%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/CABuXbh-tTjGtCakgT4ocrtBsgocZC%2BKimpO3SQVPfFE42cFxeQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: best way to generate PDFs in django - handling concurrency

2018-12-27 Thread Carsten Fuchs
Hello,

in my project, using ReportLab exactly as documented works very well.

Best regards,
Carsten


Am 28.12.18 um 00:05 schrieb Danny Blaker:
> we're building an app for the council where users fill in a form, then we 
> generate a PDF (containing a page of text), and users get a download link on 
> the homepage. 
> we expect many users to submit forms concurrently.
> 
> I see 2 approaches:
> 
> 1. Generate in the view as per documentation : 
> https://docs.djangoproject.com/en/2.1/howto/outputting-pdf/
> 2. Use a seperate script to generate PDF and use django api 
> https://www.django-rest-framework.org/api-guide/parsers/#fileuploadparser
> 
> However, to handle concurrency we'll also need a broker - like rabbitMQ + 
> Celery
> 
> Is there a "best practice" way to approach this, or has anyone had experience 
> with generating PDFs in django and can recommend an approach?
> 
> Thanks!!
> 
> resources:
> 
> https://realpython.com/asynchronous-tasks-with-django-and-celery/
> https://simpleisbetterthancomplex.com/tutorial/2017/08/20/how-to-use-celery-with-django.html#why-should-i-use-celery
> 
> 
> -- 
> 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/9f06d9aa-7d89-4700-8cd0-9ae3343b3128%40googlegroups.com
>  
> .
> For more options, visit https://groups.google.com/d/optout.

-- 
Dipl.-Inf. Carsten Fuchs
Industriegebiet 3 ℅ Rofu
55768 Hoppstädten-Weiersbach
https://www.cafu.de

-- 
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/33e14819-293d-8f54-9395-c5699aa29f7c%40cafu.de.
For more options, visit https://groups.google.com/d/optout.


Re: Error while running local server

2018-12-27 Thread Shekhar Nunia
Thank you guys, I got the error, I installed the package and installed it in my 
settings but after uninstall forgot to remove it.

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/2b2bdaba-3e54-47d5-8a1e-1d7a12a87612%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: best way to generate PDFs in django - handling concurrency

2018-12-27 Thread Danny Blaker
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/e8ef92bf-19c7-4881-9465-a04749cfad00%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


How we can use just like Django admin panel in tornado but i am not want to use django-admin-panel in tornado app?

2018-12-27 Thread mazz ahmed
Hello,
hope everyone doing well. I am working on tornado framework. I want to use
admin panel for that app but I am getting a single solution using
Django alongside of tornado for admin panel. I want to use some package in
the tornado which gives me admin panel.
If anyone knows let me know Please.
Thanks Mazz Ahmed

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


Re: How can I read child model class' DecimalField attribute 'decimal_places' from inside a parent Meta class

2018-12-27 Thread Mikkel Kromann
Ah! It turns out that there is a _meta method for that.

class Vehicles(models.Model):

def get_speed_decimal_places(self):
return self._meta.get_field('speed').decimal_places


Though I'm still wondering why my first shot at the problem worked from 
within the child class, but not from the parent class.


Mikkel

torsdag den 27. december 2018 kl. 20.59.43 UTC+1 skrev Mikkel Kromann:
>
>
> Hello.
>
> I have a parent Meta class and some child classes.
> I would like to read the decimal_places attribute from DecimalField of my 
> child instances using a function in my parent class.
> I am able to read the attribute from inside my child classes, but I cant 
> crack how to read from a function in the parent class.
> Using @classmethod I get one error, not using it, I get another (see 
> comments in the condensed example code below).
>
> I'm presently learning Python and Django, so please feel free to educate 
> me a bit here :)
>
> thanks, Mikkel
>
>
> from django.db import models
> from django.shortcuts import render
>
> class Vehicles(models.Model):
> 
> speed = models.DecimalField(max_digits=5, decimal_places=2)
> 
> @classmethod
> def get_speed_decimal_places(self):
> # @classmethod: Will raise 'DeferredAttribute' object has no attribute 
> 'decimal_places'
> # no classmethod:   Will raise 'NoneType' object has no attribute 
> 'decimal_places'
> return self.speed.decimal_places
> 
> class Meta:
> abstract = True
>
> class Train(Vehicles):
> speed = models.DecimalField(max_digits=5, decimal_places=2)
> train_speed_decimals = speed.decimal_places
> 
> class Aeroplane(Vehicles):
> speed = models.DecimalField(max_digits=5, decimal_places=1)
> aeroplane_speed_decimals = speed.decimal_places
> 
> def SpeedView(request):
> t = Train()
> context = {}
> # This works just fine
> context['decimals_own'] = t.train_speed_decimals
> # This raises error in get_speed_decimal_places()
> context['decimals_cls'] = t.get_speed_decimal_places()
> 
> return render(request,'speed_index.html',context)
>
>
>

-- 
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/6123eb77-5c35-49e9-961d-860e06b9d7cb%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


template {% url %} tag is giving server's absolute path

2018-12-27 Thread Paul Lanza
I have recently changed my django project (using A2 hosting) from fcgi to 
wsgi.  I have successfully gotten the project to work, but I am 
experiencing a minor caveat I am trying to solve.  Now, when I use the {% 
url %} tag in the templates to form a link, I get the absolute path of the 
server (the results still works but the link now looks more ugly).

For example, I might have this in my urls.py

url("^about_us/$", views.about_us, name="about_us")


Then in my template, I would have this

{% url "about_us" %}


In my development, the template will render the link "/about_us" so that 
when you click the link, it takes you to www.mysite.com/about_us.html

Now, in production, the template will render the link 
"/home/myproject/myproject/about_us" so that when you click the link, it 
takes you to www.mysite.com/home/myproject/myproject/about_us.html

How can I get my production template rendering of the url tag to replicate 
the development rendering of the url tag.

Thanks for any help!

-- 
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/cbdad29b-7048-48ac-82e8-f807bcd3bf22%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: best way to generate PDFs in django - handling concurrency

2018-12-27 Thread Peter van der Does
On 12/27/18 6:05 PM, Danny Blaker wrote:
> we're building an app for the council where users fill in a form, then
> we generate a PDF (containing a page of text), and users get a
> download link on the homepage. 
> we expect many users to submit forms concurrently.
>
> I see 2 approaches:
>
> 1. Generate in the view as per documentation
> : https://docs.djangoproject.com/en/2.1/howto/outputting-pdf/
> 2. Use a seperate script to generate PDF and use django
> api https://www.django-rest-framework.org/api-guide/parsers/#fileuploadparser
>
> However, to handle concurrency we'll also need a broker - like
> rabbitMQ + Celery
>
> Is there a "best practice" way to approach this, or has anyone had
> experience with generating PDFs in django and can recommend an approach?
>
> Thanks!!
>
> resources:
>
> https://realpython.com/asynchronous-tasks-with-django-and-celery/
> https://simpleisbetterthancomplex.com/tutorial/2017/08/20/how-to-use-celery-with-django.html#why-should-i-use-celery
>
>
>
Best way is relative.

Simplified we do the following:

  * Use Django Templates to create a HTML page.
  * Save the HTML output as a file.
  * Use subprocess to call wkhtmltopdf to convert the HTML file to PDF file.
  * Return a PDF response using the saved PDF file

It works, not sure if it is the fastest way, we see about a 4-5 sec
response time. As some of the generated PDF files can be reused we
actually keep the PDF file on disk and reuse them for other recurring
requests. This bypasses the generation of PDF file bring the response
time back to 1 sec.

By using Celery you don't have an exact time of when a PDF will be
generated.

There are several commercial applications available to generate PDF's
which might be much faster but for us the open source application works
fine.

wkhtmltopdf: https://wkhtmltopdf.org/

-- 
*Peter van der Does
o: ***410-584-2500
m: 732-425-3102
*ONeil Interactive, Inc *
oneilinteractive.com 
**

-- 
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/6c65e73e-2b68-3e10-0efe-51ba99042d15%40oneilinteractive.com.
For more options, visit https://groups.google.com/d/optout.


Re: how can I work with multi model forms

2018-12-27 Thread Danny Blaker
https://docs.djangoproject.com/en/2.1/topics/forms/modelforms/#inline-formsets

https://github.com/elo80ka/django-dynamic-formset/blob/master/docs/usage.rst
https://github.com/elo80ka/django-dynamic-formset/blob/master/INSTALL.rst

clone the above, then check the examples




On Wednesday, 26 December 2018 23:29:11 UTC+11, Tessnim Zrayga wrote:
>
> Hello everyone,
> I have this design: there's a firm, a firm can have multiple nodes. Each 
> node can have many scheduled actions. What I'm trying to do is to create a 
> template containing all informations about a firm and be able to create 
> multiple scheduled actions at a time, so this is what the template will 
> look like in the end:
>
> [image: jhg.png]
>
> Here is what I coded: in models.py:
>
>
> class Node(models.Model):
> ID = models.DecimalField(max_digits=19, decimal_places=10)
> name = models.CharField(default='node', max_length=32)
> nb_solenoid = models.DecimalField(max_digits=19, decimal_places=10, 
> null=True, blank=True)
> connexion = models.CharField(max_length=255)
> status = models.BooleanField(default=False)
>
>
> class Firm(models.Model):
>
> name = models.CharField(max_length=32)
> address = models.CharField(max_length=32)
>
>
> class ScheduledAction(models.Model):
> date = models.DateTimeField(default=datetime.now, blank=True)
> firm = models.ForeignKey('Firm', on_delete=models.CASCADE, null=True, 
> blank=True)
> node = models.ForeignKey('Node', on_delete=models.CASCADE, null=True, 
> blank=True)
>
>
> views.py:
>
> def planification_view(request, id):
> obj = Firm.objects.get(id=id)
> form = ScheduledActionForm(request.POST or None)
> form1 = ScheduledActionForm(request.POST or None)
> form2 = FirmForm(request.POST or None)
> if form1.is_valid() and form2.is_valid():
> #form.save()
> print(type(form))
> print(form)
> context = {
> 'object': obj,
> 'form': form
> }
> return render(request, "node/planification.html", context)
>
>
> planification.html:
>
> 
> function submitForms(){
> document.forms["form1"].submit();
> document.forms["form2"].submit();
> }
> 
> 
> {{ object }}
> Firm: {{ object.name }}
> 
> 
> {% csrf_token %}
> {% for instance in object.node_set.all %}
>  {{ instance.name }}
> {% endfor %}
> 
> 
> 
> Planification
> {% csrf_token %}
> {{ form.as_p }}
> 
> 
> 
> 
> Scheduled Actions
> {% for instance in object.scheduledaction_set.all %}
> {{instance.date}} - {{ instance.node }}
> {% endfor %}
> 
>
>
> But I can't go further and this code doesn't seem to work. I can check 
> nodes and click submit but nothing is stored in the database.
>
>
>
>

-- 
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/dc7287a1-0dfc-4bed-be96-0f2503e028e6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Error while running local server

2018-12-27 Thread Danny Blaker
run pip freeze in terminal and make sure its installed in your virtual env

On Friday, 28 December 2018 01:25:15 UTC+11, Shekhar Nunia wrote:
>
> Two days ago my project was working properly but now when I start my 
> project I get this error and I'm not able to figure out what the problem 
> is, if anyone able to understand this kindly suggests any solution.
>

-- 
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/ec6b9cb4-a80e-48e0-aef4-c1c8940ff791%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: DJANGO FOR FINANCE !

2018-12-27 Thread Danny Blaker
depending on processing time for formulars, you might want to consider a 
broker setup 
: https://realpython.com/asynchronous-tasks-with-django-and-celery/
if processing time is negligible then no need

On Saturday, 22 December 2018 07:29:20 UTC+11, Mohamed Hashi wrote:
>
> i have a problem with models 
> i write the code
> but still dont wanna makemigrartions 
> any help 
> thanks . 
>
> ‫في الجمعة، 14 ديسمبر 2018 في 3:33 ص تمت كتابة ما يلي بواسطة ‪codesign web 
> za‬‏ <‪sh...@codesign.web.za ‬‏>:‬
>
>> I eventually chose django-chartjs and django-datatable for this
>>
>> On 13/12/2018 19:55, carlos wrote:
>>
>> yes, is posible in Django make forms for input user and output make grahp 
>> and table 
>>
>> Cheers
>>
>> On Thu, Dec 13, 2018 at 9:35 AM Mamoudou Diallo > > wrote:
>>
>>> Hey EVERYONE ! 
>>>
>>> I am working on a project where I am would like to use django to build a 
>>> site that computes certain financial formulas based on user inputs or even 
>>> better (based on Time series data set) and spits out the results in a form 
>>> of a graph or predisgned table. I have the formulas written out in python 
>>> already, but I am new to django, but I have watched a few tutorial videos 
>>> and how powerful it is. Most of the tutorials and content that I have come 
>>> accross with is primarily not related to finance but mouch more towads 
>>> building blog posts etc
>>>
>>>
>>> Please checkout the attachement for a picture view of what I want to do. 
>>> -- 
>>> 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/bddac915-325e-4a1c-af18-4c4b8ef39993%40googlegroups.com
>>>  
>>> 
>>> .
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>
>>
>> -- 
>> att. 
>> Carlos Rocha
>> -- 
>> 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/CAM-7rO2Csx2bMZBO%3DfHzSxdEwbxfkdmZFsfh4mmOnQFu1JzWGw%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...@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/4000facf-e1cb-3aef-91cf-c33290f1bf9a%40codesign.web.za
>>  
>> 
>> .
>> 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/1c2f61a7-49b0-4135-8977-ec833a41dc3d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


best way to generate PDFs in django - handling concurrency

2018-12-27 Thread Danny Blaker
we're building an app for the council where users fill in a form, then we 
generate a PDF (containing a page of text), and users get a download link 
on the homepage. 
we expect many users to submit forms concurrently.

I see 2 approaches:

1. Generate in the view as per documentation 
: https://docs.djangoproject.com/en/2.1/howto/outputting-pdf/
2. Use a seperate script to generate PDF and use django 
api https://www.django-rest-framework.org/api-guide/parsers/#fileuploadparser

However, to handle concurrency we'll also need a broker - like rabbitMQ + 
Celery

Is there a "best practice" way to approach this, or has anyone had 
experience with generating PDFs in django and can recommend an approach?

Thanks!!

resources:

https://realpython.com/asynchronous-tasks-with-django-and-celery/
https://simpleisbetterthancomplex.com/tutorial/2017/08/20/how-to-use-celery-with-django.html#why-should-i-use-celery


-- 
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/9f06d9aa-7d89-4700-8cd0-9ae3343b3128%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


How can I read child model class' DecimalField attribute 'decimal_places' from inside a parent Meta class

2018-12-27 Thread Mikkel Kromann

Hello.

I have a parent Meta class and some child classes.
I would like to read the decimal_places attribute from DecimalField of my 
child instances using a function in my parent class.
I am able to read the attribute from inside my child classes, but I cant 
crack how to read from a function in the parent class.
Using @classmethod I get one error, not using it, I get another (see 
comments in the condensed example code below).

I'm presently learning Python and Django, so please feel free to educate me 
a bit here :)

thanks, Mikkel


from django.db import models
from django.shortcuts import render

class Vehicles(models.Model):

speed = models.DecimalField(max_digits=5, decimal_places=2)

@classmethod
def get_speed_decimal_places(self):
# @classmethod: Will raise 'DeferredAttribute' object has no attribute 
'decimal_places'
# no classmethod:   Will raise 'NoneType' object has no attribute 
'decimal_places'
return self.speed.decimal_places

class Meta:
abstract = True

class Train(Vehicles):
speed = models.DecimalField(max_digits=5, decimal_places=2)
train_speed_decimals = speed.decimal_places

class Aeroplane(Vehicles):
speed = models.DecimalField(max_digits=5, decimal_places=1)
aeroplane_speed_decimals = speed.decimal_places

def SpeedView(request):
t = Train()
context = {}
# This works just fine
context['decimals_own'] = t.train_speed_decimals
# This raises error in get_speed_decimal_places()
context['decimals_cls'] = t.get_speed_decimal_places()

return render(request,'speed_index.html',context)


-- 
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/27f4b78d-86f8-4c73-b4bd-707ee677e530%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Error while running local server

2018-12-27 Thread Shashank hegde
Somewhere 'flag' has been imported improperly or there is no module called
flag.

On Thu, 27 Dec 2018 at 19:54, Shekhar Nunia  wrote:

> Two days ago my project was working properly but now when I start my
> project I get this error and I'm not able to figure out what the problem
> is, if anyone able to understand this kindly suggests any solution.
>
> --
> 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/b3a250f2-a40b-4f76-a007-693b857a271b%40googlegroups.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>


-- 
Thanks & Regards,
Shashank Hegde

-- 
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/CAN86-grKk0GG2SvMGvbDHQ3QanVtNECEypkHxiqhL0BM%3DnFe%2BA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Can I define classes in Django settings, and how can I override such settings in tests?

2018-12-27 Thread Derek
You don't need to create a class; you can just define new settings in the 
settings file.

For example, I have added a setting called CUSTOMER.  I could have logic 
which defines other behavior based on that:

from django.conf import settings
if setttings.CUSTOMER == 'ABC Corp':
logo = 'ABC'
else:
logo = 'generic'

Your classes can use also directly use these settings in a similar way 

On Thursday, 27 December 2018 10:18:28 UTC+2, Uri Even-Chen wrote:
>
> Hi,
>
> We are using Django for Speedy Net and Speedy Match 
>  (currently Django 1.11.17, we 
> can't upgrade to a newer version of Django because of one of our 
> requirements, django-modeltranslation). I want to define some of our 
> settings as classes. For example:
>
> class UserSettings(object):
> MIN_USERNAME_LENGTH = 6
> MAX_USERNAME_LENGTH = 40
>
> MIN_SLUG_LENGTH = 6
> MAX_SLUG_LENGTH = 200
>
> # Users can register from age 0 to 180, but can't be kept on the site 
> after age 250.
> MIN_AGE_ALLOWED_IN_MODEL = 0  # In years.
> MAX_AGE_ALLOWED_IN_MODEL = 250  # In years.
>
> MIN_AGE_ALLOWED_IN_FORMS = 0  # In years.
> MAX_AGE_ALLOWED_IN_FORMS = 180  # In years.
>
> MIN_PASSWORD_LENGTH = 8
> MAX_PASSWORD_LENGTH = 120
>
> PASSWORD_VALIDATORS = [
> {
> 'NAME': 'speedy.core.accounts.validators.PasswordMinLengthValidator',
> },
> {
> 'NAME': 'speedy.core.accounts.validators.PasswordMaxLengthValidator',
> },
> ]
>
> (which is defined in 
> https://github.com/speedy-net/speedy-net/blob/uri_merge_with_master_2018-12-26_a/speedy/net/settings/global_settings.py).
>  
> And then in the models, I tried to use:
>
> from django.conf import settings as django_settings
>
> class User(ValidateUserPasswordMixin, PermissionsMixin, Entity, 
> AbstractBaseUser):
> settings = django_settings.UserSettings
>
> (and then use attributes of `settings`, such as 
> `settings.MIN_USERNAME_LENGTH`, in the class).
>
> But it throws an exception
>
> AttributeError: 'Settings' object has no attribute 'UserSettings'
>
> (but it doesn't throw an exception if I use there a constant which is not 
> a class).
>
> This is the first problem. In the meantime, I defined instead:
>
> from speedy.net.settings import global_settings as 
> speedy_net_global_settings
>
> class User(ValidateUserPasswordMixin, PermissionsMixin, Entity, 
> AbstractBaseUser):
> settings = speedy_net_global_settings.UserSettings
>
> The second problem, is how do I override such settings in tests? For 
> example, I use the following code:
>
> from speedy.core.settings import tests as tests_settings
>
>
> @override_settings(MAX_NUMBER_OF_FRIENDS_ALLOWED=tests_settings.OVERRIDE_MAX_NUMBER_OF_FRIENDS_ALLOWED)
>
> in 
> https://github.com/speedy-net/speedy-net/blob/uri_merge_with_master_2018-12-26_a/speedy/core/friends/tests/test_views.py.
>  
> But if `MAX_NUMBER_OF_FRIENDS_ALLOWED` would be defined in the class 
> `UserSettings`, how do I override it?
>
> Thanks,
> אורי (Uri)
> u...@speedy.net 
>

-- 
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/a47584ec-6fdd-40a4-b795-1d8a140ab935%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: how can I work with multi model forms

2018-12-27 Thread Ira Abbott
Hi,

Model forms have one model.  To have the form update fields in other models, 
you can overload form_valid in views so that it writes the addition form field 
to their respective models.

Ira

Sent from my iPhone

> On Dec 26, 2018, at 9:45 AM, Nur Mohsin  wrote:
> 
> Hi, in views.py form.save() is commented. Remove comment and try again. Then, 
> tell us what happens?
> 
>> On Wed, Dec 26, 2018 at 6:29 PM Tessnim Zrayga  
>> wrote:
>> Hello everyone,
>> I have this design: there's a firm, a firm can have multiple nodes. Each 
>> node can have many scheduled actions. What I'm trying to do is to create a 
>> template containing all informations about a firm and be able to create 
>> multiple scheduled actions at a time, so this is what the template will look 
>> like in the end:
>> 
>> 
>> 
>> Here is what I coded: in models.py:
>> 
>> 
>> 
>> class Node(models.Model):
>> ID = models.DecimalField(max_digits=19, decimal_places=10)
>> name = models.CharField(default='node', max_length=32)
>> nb_solenoid = models.DecimalField(max_digits=19, decimal_places=10, 
>> null=True, blank=True)
>> connexion = models.CharField(max_length=255)
>> status = models.BooleanField(default=False)
>> 
>> 
>> class Firm(models.Model):
>> 
>> name = models.CharField(max_length=32)
>> address = models.CharField(max_length=32)
>> 
>> 
>> class ScheduledAction(models.Model):
>> date = models.DateTimeField(default=datetime.now, blank=True)
>> firm = models.ForeignKey('Firm', on_delete=models.CASCADE, null=True, 
>> blank=True)
>> node = models.ForeignKey('Node', on_delete=models.CASCADE, null=True, 
>> blank=True)
>> 
>> views.py:
>> def planification_view(request, id):
>> obj = Firm.objects.get(id=id)
>> form = ScheduledActionForm(request.POST or None)
>> form1 = ScheduledActionForm(request.POST or None)
>> form2 = FirmForm(request.POST or None)
>> if form1.is_valid() and form2.is_valid():
>> #form.save()
>> print(type(form))
>> print(form)
>> context = {
>> 'object': obj,
>> 'form': form
>> }
>> return render(request, "node/planification.html", context)
>> 
>> planification.html:
>> 
>> function submitForms(){
>> document.forms["form1"].submit();
>> document.forms["form2"].submit();
>> }
>> 
>> 
>> {{ object }}
>> Firm: {{ object.name }}
>> 
>> 
>> {% csrf_token %}
>> {% for instance in object.node_set.all %}
>>  {{ instance.name }}
>> {% endfor %}
>> 
>> 
>> 
>> Planification
>> {% csrf_token %}
>> {{ form.as_p }}
>> 
>> 
>> 
>> 
>> Scheduled Actions
>> {% for instance in object.scheduledaction_set.all %}
>> {{instance.date}} - {{ instance.node }}
>> {% endfor %}
>> 
>> 
>> But I can't go further and this code doesn't seem to work. I can check nodes 
>> and click submit but nothing is stored in the database.
>> 
>> 
>> 
>> -- 
>> 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/5d2fd9de-991e-4526-8303-84287df0dfc2%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/CAM0c9RqU7VW0B-BaR_O-ahqOTZEb9AXhc_ZUSaCd%2Bckqr3M9og%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+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/43A15F92-0F2A-4077-A385-8AB912765252%40gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Can I define classes in Django settings, and how can I override such settings in tests?

2018-12-27 Thread Ira Abbott
You need an instance to evaluate member variables.   These are mutable, so can 
be different per instance.

Settings should use a dictionary.

Sent from my iPhone

> On Dec 27, 2018, at 3:15 AM, אורי  wrote:
> 
> Hi,
> 
> We are using Django for Speedy Net and Speedy Match (currently Django 
> 1.11.17, we can't upgrade to a newer version of Django because of one of our 
> requirements, django-modeltranslation). I want to define some of our settings 
> as classes. For example:
> 
>   class UserSettings(object):
>   MIN_USERNAME_LENGTH = 6
>   MAX_USERNAME_LENGTH = 40
> 
>   MIN_SLUG_LENGTH = 6
>   MAX_SLUG_LENGTH = 200
> 
>   # Users can register from age 0 to 180, but can't be kept on 
> the site after age 250.
>   MIN_AGE_ALLOWED_IN_MODEL = 0  # In years.
>   MAX_AGE_ALLOWED_IN_MODEL = 250  # In years.
> 
>   MIN_AGE_ALLOWED_IN_FORMS = 0  # In years.
>   MAX_AGE_ALLOWED_IN_FORMS = 180  # In years.
> 
>   MIN_PASSWORD_LENGTH = 8
>   MAX_PASSWORD_LENGTH = 120
> 
>   PASSWORD_VALIDATORS = [
>   {
>   'NAME': 
> 'speedy.core.accounts.validators.PasswordMinLengthValidator',
>   },
>   {
>   'NAME': 
> 'speedy.core.accounts.validators.PasswordMaxLengthValidator',
>   },
>   ]
> 
> (which is defined in 
> https://github.com/speedy-net/speedy-net/blob/uri_merge_with_master_2018-12-26_a/speedy/net/settings/global_settings.py).
>  And then in the models, I tried to use:
> 
>   from django.conf import settings as django_settings
> 
>   class User(ValidateUserPasswordMixin, PermissionsMixin, Entity, 
> AbstractBaseUser):
>   settings = django_settings.UserSettings
> 
> (and then use attributes of `settings`, such as 
> `settings.MIN_USERNAME_LENGTH`, in the class).
> 
> But it throws an exception
> 
>   AttributeError: 'Settings' object has no attribute 'UserSettings'
> 
> (but it doesn't throw an exception if I use there a constant which is not a 
> class).
> 
> This is the first problem. In the meantime, I defined instead:
> 
>   from speedy.net.settings import global_settings as 
> speedy_net_global_settings
> 
>   class User(ValidateUserPasswordMixin, PermissionsMixin, Entity, 
> AbstractBaseUser):
>   settings = speedy_net_global_settings.UserSettings
> 
> The second problem, is how do I override such settings in tests? For example, 
> I use the following code:
> 
>   from speedy.core.settings import tests as tests_settings
> 
>   
> @override_settings(MAX_NUMBER_OF_FRIENDS_ALLOWED=tests_settings.OVERRIDE_MAX_NUMBER_OF_FRIENDS_ALLOWED)
> 
> in 
> https://github.com/speedy-net/speedy-net/blob/uri_merge_with_master_2018-12-26_a/speedy/core/friends/tests/test_views.py.
>  But if `MAX_NUMBER_OF_FRIENDS_ALLOWED` would be defined in the class 
> `UserSettings`, how do I override it?
> 
> Thanks,
> אורי (Uri)
> u...@speedy.net
> -- 
> 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/CABD5YeFfW-JbXawLmxX2aUjD41qS90CF7PbzUMwn0uqSWVwt7w%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+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/A443C25D-738E-4F49-9D4F-43CCA03F3FC7%40gmail.com.
For more options, visit https://groups.google.com/d/optout.


Can I define classes in Django settings, and how can I override such settings in tests?

2018-12-27 Thread אורי
Hi,

We are using Django for Speedy Net and Speedy Match
 (currently Django 1.11.17, we
can't upgrade to a newer version of Django because of one of our
requirements, django-modeltranslation). I want to define some of our
settings as classes. For example:

class UserSettings(object):
MIN_USERNAME_LENGTH = 6
MAX_USERNAME_LENGTH = 40

MIN_SLUG_LENGTH = 6
MAX_SLUG_LENGTH = 200

# Users can register from age 0 to 180, but can't be kept on the site after
age 250.
MIN_AGE_ALLOWED_IN_MODEL = 0  # In years.
MAX_AGE_ALLOWED_IN_MODEL = 250  # In years.

MIN_AGE_ALLOWED_IN_FORMS = 0  # In years.
MAX_AGE_ALLOWED_IN_FORMS = 180  # In years.

MIN_PASSWORD_LENGTH = 8
MAX_PASSWORD_LENGTH = 120

PASSWORD_VALIDATORS = [
{
'NAME': 'speedy.core.accounts.validators.PasswordMinLengthValidator',
},
{
'NAME': 'speedy.core.accounts.validators.PasswordMaxLengthValidator',
},
]

(which is defined in
https://github.com/speedy-net/speedy-net/blob/uri_merge_with_master_2018-12-26_a/speedy/net/settings/global_settings.py).
And then in the models, I tried to use:

from django.conf import settings as django_settings

class User(ValidateUserPasswordMixin, PermissionsMixin, Entity,
AbstractBaseUser):
settings = django_settings.UserSettings

(and then use attributes of `settings`, such as
`settings.MIN_USERNAME_LENGTH`, in the class).

But it throws an exception

AttributeError: 'Settings' object has no attribute 'UserSettings'

(but it doesn't throw an exception if I use there a constant which is not a
class).

This is the first problem. In the meantime, I defined instead:

from speedy.net.settings import global_settings as
speedy_net_global_settings

class User(ValidateUserPasswordMixin, PermissionsMixin, Entity,
AbstractBaseUser):
settings = speedy_net_global_settings.UserSettings

The second problem, is how do I override such settings in tests? For
example, I use the following code:

from speedy.core.settings import tests as tests_settings

@override_settings(MAX_NUMBER_OF_FRIENDS_ALLOWED=tests_settings.OVERRIDE_MAX_NUMBER_OF_FRIENDS_ALLOWED)

in
https://github.com/speedy-net/speedy-net/blob/uri_merge_with_master_2018-12-26_a/speedy/core/friends/tests/test_views.py.
But if `MAX_NUMBER_OF_FRIENDS_ALLOWED` would be defined in the class
`UserSettings`, how do I override it?

Thanks,
אורי (Uri)
u...@speedy.net

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