Re: Problemas con Formato numerico en django

2014-04-04 Thread Hector Armando Vela Santos
Saludos Norma.

Yo hice un paquete con las funciones que uso normalmente en el día a día. 
Puedes encontrarla aquí: https://github.com/vellonce/python_recipes

De allí la función que te puede servir, es "moneyfmt" que es una función 
que le pasas un valor numérico y te regresa un string con el formato que tu 
le especifiques, por ejemplo.

>>> d = decimal.Decimal('-1234567.8901')
>>> moneyfmt(d, curr='$')
'-$1,234,567.89'
>>> moneyfmt(d, places=0, sep='.', dp='', neg='', trailneg='-')
'1.234.568-'
>>> moneyfmt(d, curr='$', neg='(', trailneg=')')
'($1,234,567.89)'
>>> moneyfmt(decimal.Decimal(123456789), sep=' ')
'123 456 789.00'
>>> moneyfmt(decimal.Decimal('-0.02'), neg='<', trailneg='>')
'<0.02>'


Espero que te sirva. Happy coding!

On Wednesday, April 2, 2014 8:51:03 PM UTC-6, Norma Bizzozzero wrote:
>
> Me gustaría si pudieran ayudarme, quiero que al cargar en el dato 
> identifique los valores y agregue el punto de miles. 
> habia leido que en el settings agregue 
> USE_L10N = True
> USE_THOUSAND_SEPARATOR = True
> THOUSAND_SEPARATOR = '.'
> DECIMAL_SEPARATOR = ','
>  y en el template, pero el problema es que no funciona, soy nueva 
> utilizando python y django, agradecería cualquier ayuda. 
>
> {% load l10n %}
>
> {{ value|localize }}
>
>
>

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


Re: Creating multiple objects at once

2013-09-30 Thread Hector Armando Vela Santos
well, you can always write the raw SQL querie...
https://docs.djangoproject.com/en/1.4/topics/db/sql/

On Sunday, September 29, 2013 10:16:47 PM UTC-5, Lachlan Musicman wrote:
>
> Hola, 
>
> I have a inventory system with Parts and Part types. Part Types are 
> Archetypes, parts are instances of Part Types with details (unit cost, 
> serial number, date of purchase, etc). 
>
> A big issue is that not all Parts have serial numbers (box of 1000 
> screws for instance). But when we get a large quantity of parts that I 
> would like to apply serial numbers to, data entry staff don't want to 
> enter the otherwise identical data again and again. 
>
> Since most serialised products we are storing come with numbers that 
> are "in serial", I want to replace the creation process with a form 
> that also asks for "first serial number" and "number of parts" - 
> giving a nice list of easily incremented serial numbers. Then we can 
> create the requisite objects at the same time, and save them with just 
> the diff serial. 
>
> What is the best way to do this? 
>
> I've seen three solutions so far: 
>
> 1. bulk_create 
> https://docs.djangoproject.com/en/1.4/ref/models/querysets/#bulk-create 
> problem: doesn't call model save method (in my case, where the slug is 
> populated from the id). 
>
> 2. transaction.commit_manually 
>
> https://docs.djangoproject.com/en/dev/topics/db/transactions/#django.db.transaction.commit_manually
>  
>
> 3. Signals 
> https://docs.djangoproject.com/en/dev/ref/signals/#django.db.models.signals.post_save
>  
> (and now that I think about it, probably transaction.commit_manually 
> coupled with it). 
>
> What does the list recommend as a method? 
>
> Also, as I discovered in the IRC the other day, there really is a time 
> when CBVs aren't appropriate. Should this process be a CBV - it seems 
> a lot more suited to a FBV. 
>
> Cheers 
> L. 
>
>
> -- 
> Maya Otos (@maya_otos) tweeted at 9:27 PM on Tue, Jul 30, 2013: 
> When you used to be punk, and now you are still punk but not as punk, 
> are you post-punk or decaying punk or ex-punk or just not punk anymore 
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/f166ff7b-f449-47b1-add8-05d07759f9b5%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: hi [django-users] How to do something after "return HttpResponse(html)"?

2013-06-25 Thread Hector Armando Vela Santos
You can use Celery for that, I've done something similar, just with a CSV 
instead of a XML, check 
this http://docs.celeryproject.org/en/latest/django/first-steps-with-django.html

once installed and configured, its as simple as:

from celery import task

if (the xml format is ERROR) == True:
return HttpResponse(ERROR FORMAT")
else:
do_something.delay(the_xml_file)
return HttpResponse(RIGHT FORMAT")
#I must give a response first, And do other thing. Because the spend 
time of do_something() may be long.

@task(ignore_result=True)
def do_something(xml):
#do something time consuming


and the do_something function will be called in second plane, and the user 
will get an instant response, even if the parsing file process takes half 
an hour

On Tuesday, June 25, 2013 8:32:59 AM UTC-5, lx wrote:
>
> Thank you.
>
> The real demand is:
>
> 1.
> receive the xml file from client.
>
> 2.
> if (the xml format is ERROR) == True:
> return HttpResponse(ERROR FORMAT")
> else:
> return HttpResponse(RIGHT FORMAT")
> #I must give a response first, And do other thing. Because the spend 
> time of do_something() may be long.
> do_something(the xml file)
>
>
>
>
>
>
> 2013/6/25 Sandro Dutra >
>
>> The question is: What you're trying to do?
>>
>> 1. You can do any other process before the return line, the return will 
>> be the same... for example:
>>
>> from django.http import HttpResponse
>> from datetime import datetime
>> def current_datetime(request):
>>   now = datetime.now()
>>   html = "It is now %s." % now
>>   year = now.year()
>>   return HttpResponse(html)
>>
>>
>> 2. You can use a conditional to have multiple returns:
>> from django.http import HttpResponse
>> from datetime import datetime
>> def current_datetime(request):
>>   now = datetime.now()
>>   html = "It is now %s." % now
>>   year = now.year()
>>   if year == 2013:
>>   return HttpResponse(html)
>>  else:
>>   return HttpResponse(Sorry it's not 
>> 2013.")
>>
>>
>> 2013/6/25 Timster >
>>
>>> You cannot do something after the "return" line. This is Python 
>>> functionality. When you return, the function exits and does not process 
>>> anything else.
>>>
>>> What exactly are you trying to do? There is probably another way to 
>>> accomplish it.
>>>
>>>  -- 
>>> You received this message because you are subscribed to the Google 
>>> Groups "Django users" group.
>>> To unsubscribe from this group and stop receiving emails from it, send 
>>> an email to django-users...@googlegroups.com .
>>> To post to this group, send email to django...@googlegroups.com
>>> .
>>> Visit this group at http://groups.google.com/group/django-users.
>>> For more options, visit https://groups.google.com/groups/opt_out.
>>>  
>>>  
>>>
>>
>>  -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to django-users...@googlegroups.com .
>> To post to this group, send email to django...@googlegroups.com
>> .
>> Visit this group at http://groups.google.com/group/django-users.
>> For more options, visit https://groups.google.com/groups/opt_out.
>>  
>>  
>>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.




Re: quantize result has too many digits for current context

2013-01-18 Thread Hector Armando Vela Santos
Are you sure that that's the only thing you are doing? have you done 
something before with the prices(preco_unit, valor_total)?? I had once this 
error but was because I was trying to save a decimal field wich exceeded 
the length of the integer part of my decimal field.

On Thursday, January 17, 2013 2:02:14 PM UTC-6, Fellipe Henrique wrote:
>
> Hello,
>
> I have this model:
>
> class ItensPedido(models.Model):
> idvenda_pedido_itens = models.IntegerField(u'Código', 
> primary_key=True, null=False)
> idvenda_pedido = models.ForeignKey('Pedido', 
> db_column='idvenda_pedido', null=False, blank=False)
> idproduto = models.ForeignKey('Produto', db_column='idproduto', 
> verbose_name=u'Produto', null=False, blank=False)
> qnt = models.IntegerField(verbose_name=u'Quantidade', null=False, 
> blank=False, default=1)
> preco_unit = models.DecimalField(u'Preço Unit.', max_digits=12, 
> decimal_places=4, null=False, default=0)
> valor_total = models.DecimalField(u'Vlr. Total', max_digits=12, 
> decimal_places=4, null=False, default=0)
>
> class Meta:
> managed = False
> db_table = 'venda_pedido_itens'
>
>
> and in my template I try to use: {{ form.idpedido }}
>
> but when I`m use this, django show me this error:
>
> quantize result has too many digits for current context
>
> I have lookup the internet and I see some error like this, but always 
> about Decimals fields.. but in my case this error appears in Foreign Key 
> field.
>
> My question is: Why this error appears? How can I fix this?
>
> Thanks for all,
>
> Regards,
> T.·.F.·.A.·. S+F
> *Fellipe Henrique P. Soares*
>
> *"Quemadmodum gladius neminem occidit, occidentis telum est."* (Epistulae 
> morales ad 
> Lucilium, 
> Lucius Annaeus Seneca)
>
> *"Any intelligent fool can make things bigger, more complex, and more 
> violent. It takes a touch of genius -- and a lot of courage -- to move in 
> the opposite direction."* 
> Albert Einstein (March 14th 1879 – April 18th 1955)
>  

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/AT5qAS-uS3oJ.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: django/celery - celery status: Error: No nodes replied within time constraint

2012-11-29 Thread Hector Armando Vela Santos
Hi I solved my problem, it was a very simple solution, but it was also a 
weird one:
What I did was:

  $ /etc/init.d/celerybeat restart
  $ /etc/init.d/celeryd restart
  $ service celeryd restart


I had to do this in that order, other way I'd get an ugly Error: No nodes 
replied within time constraint



On Tuesday, November 27, 2012 5:57:38 AM UTC-6, Hector Armando Vela Santos 
wrote:
>
> I'm trying to deploy a simple example of celery in my production server, 
> I've followed the tutorial in the celery website about running celery as 
> daemon
> http://docs.celeryproject.org/en/latest/tutorials/daemonizing.html#daemonizing,
>  
> and I got the config file in*/etc/default/celeryd*
> *
> *
>
>  1 # Name of nodes to start
>   2 # here we have a single node
>   3 CELERYD_NODES="w1"
>   4 # or we could have three nodes:
>   5 #CELERYD_NODES="w1 w2 w3"
>   6 
>   7 # Where to chdir at start.
>   8 CELERYD_CHDIR="/home/audiwime/cidec_sw"
>   9 
>  10 # Python interpreter from environment.
>  11 ENV_PYTHON="/usr/bin/python26"
>  12 
>  13 # How to call "manage.py celeryd_multi"
>  14 CELERYD_MULTI="$ENV_PYTHON $CELERYD_CHDIR/manage.py celeryd_multi"
>  15 
>  16 # # How to call "manage.py celeryctl"
>  17 CELERYCTL="$ENV_PYTHON $CELERYD_CHDIR/manage.py celeryctl"
>  18 
>  19 # Extra arguments to celeryd
>  20 CELERYD_OPTS="--time-limit=300 --concurrency=8"
>  21 
>  22 # Name of the celery config module.
>  23 CELERY_CONFIG_MODULE="celeryconfig"
>  24 
>  25 # %n will be replaced with the nodename.
>  26 CELERYD_LOG_FILE="/var/log/celery/%n.log"
>  27 CELERYD_PID_FILE="/var/run/celery/%n.pid"
>  28 
>  29 # Workers should run as an unprivileged user.
>  30 CELERYD_USER="audiwime"
>  31 CELERYD_GROUP="audiwime"
>  32 
>  33 export DJANGO_SETTINGS_MODULE="cidec_sw.settings"
>
> but if I run
>
> celery status
>
> in the terminal, i got this response:
>
> Error: No nodes replied within time constraint
>
> I can restart celery via the celeryd script provided in
> https://github.com/celery/celery/tree/3.0/extra/generic-init.d/
>
> /etc/init.d/celeryd restart
> celeryd-multi v3.0.12 (Chiastic Slide)
> > w1.one.cloudwime.com: DOWN
> > Restarting node w1.one.cloudwime.com: OK
>
> I can run
>
> python26 manage.py celeryd -l info
>
> and my tasks in django run fine, but if I let the daemon do its work i 
> dont get any results, don't even errors in */var/log/celery/w1.log*
>
> I know that my task has been registered because I did this from celery 
> import current_app def call_celery_delay(request): print current_app.tasks 
> run.delay(request.GET['age']) return HttpResponse(content="celery task 
> set",content_type="text/html") and I get a dictionary in wich my task appear
>
> {'celery.chain': <@task: celery.chain>, 'celery.chunks': <@task: 
> celery.chunks>, 'celery.chord': <@task: celery.chord>, 'tasks.add2': 
> <@task: tasks.add2>, 'celery.chord_unlock': <@task: 
> celery.chord_unlock>,*'tareas.tasks.run': 
> <@task: tareas.tasks.run>*, 'tareas.tasks.add': <@task: 
> tareas.tasks.add>, 'tareas.tasks.test_two_minute': <@task: 
> tareas.tasks.test_two_minute>, 'celery.backend_cleanup': <@task: 
> celery.backend_cleanup>, 'celery.map': <@task: celery.map>, 'celery.group': 
> <@task: celery.group>, 'tareas.tasks.test_one_minute': <@task: 
> tareas.tasks.test_one_minute>, 'celery.starmap': <@task: celery.starmap>}
>
> but besides that I get nothing else, no result from my task, no error in 
> the logs, nothing. Can anyone tell me what can be wrong? You are my only 
> hope...
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/NUciKmM0z-4J.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



django/celery - celery status: Error: No nodes replied within time constraint

2012-11-27 Thread Hector Armando Vela Santos
I'm trying to deploy a simple example of celery in my production server, 
I've followed the tutorial in the celery website about running celery as 
daemon
http://docs.celeryproject.org/en/latest/tutorials/daemonizing.html#daemonizing, 
and I got the config file in*/etc/default/celeryd*
*
*

 1 # Name of nodes to start
  2 # here we have a single node
  3 CELERYD_NODES="w1"
  4 # or we could have three nodes:
  5 #CELERYD_NODES="w1 w2 w3"
  6 
  7 # Where to chdir at start.
  8 CELERYD_CHDIR="/home/audiwime/cidec_sw"
  9 
 10 # Python interpreter from environment.
 11 ENV_PYTHON="/usr/bin/python26"
 12 
 13 # How to call "manage.py celeryd_multi"
 14 CELERYD_MULTI="$ENV_PYTHON $CELERYD_CHDIR/manage.py celeryd_multi"
 15 
 16 # # How to call "manage.py celeryctl"
 17 CELERYCTL="$ENV_PYTHON $CELERYD_CHDIR/manage.py celeryctl"
 18 
 19 # Extra arguments to celeryd
 20 CELERYD_OPTS="--time-limit=300 --concurrency=8"
 21 
 22 # Name of the celery config module.
 23 CELERY_CONFIG_MODULE="celeryconfig"
 24 
 25 # %n will be replaced with the nodename.
 26 CELERYD_LOG_FILE="/var/log/celery/%n.log"
 27 CELERYD_PID_FILE="/var/run/celery/%n.pid"
 28 
 29 # Workers should run as an unprivileged user.
 30 CELERYD_USER="audiwime"
 31 CELERYD_GROUP="audiwime"
 32 
 33 export DJANGO_SETTINGS_MODULE="cidec_sw.settings"

but if I run

celery status

in the terminal, i got this response:

Error: No nodes replied within time constraint

I can restart celery via the celeryd script provided in
https://github.com/celery/celery/tree/3.0/extra/generic-init.d/

/etc/init.d/celeryd restart
celeryd-multi v3.0.12 (Chiastic Slide)
> w1.one.cloudwime.com: DOWN
> Restarting node w1.one.cloudwime.com: OK

I can run

python26 manage.py celeryd -l info

and my tasks in django run fine, but if I let the daemon do its work i dont 
get any results, don't even errors in */var/log/celery/w1.log*

I know that my task has been registered because I did this from celery 
import current_app def call_celery_delay(request): print current_app.tasks 
run.delay(request.GET['age']) return HttpResponse(content="celery task 
set",content_type="text/html") and I get a dictionary in wich my task appear

{'celery.chain': <@task: celery.chain>, 'celery.chunks': <@task: 
celery.chunks>, 'celery.chord': <@task: celery.chord>, 'tasks.add2': 
<@task: tasks.add2>, 'celery.chord_unlock': <@task: 
celery.chord_unlock>,*'tareas.tasks.run': 
<@task: tareas.tasks.run>*, 'tareas.tasks.add': <@task: tareas.tasks.add>, 
'tareas.tasks.test_two_minute': <@task: tareas.tasks.test_two_minute>, 
'celery.backend_cleanup': <@task: celery.backend_cleanup>, 'celery.map': 
<@task: celery.map>, 'celery.group': <@task: celery.group>, 
'tareas.tasks.test_one_minute': <@task: tareas.tasks.test_one_minute>, 
'celery.starmap': <@task: celery.starmap>}

but besides that I get nothing else, no result from my task, no error in 
the logs, nothing. Can anyone tell me what can be wrong? You are my only 
hope...

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/mO6feEMUlrgJ.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.