Re: SOLUTION FounD : How to restore Models original Properties - Problem in Models column Exclude

2019-05-31 Thread Alexis Roda
Hi Balaji,

Sorry but I don't understand what do you mean with "*If we put this code
with necessary care*".

All I can say is that your code is not thread safe and it *may* break. How
likely is this to happen depends on the usage patterns of your app. How
serious it will be depends on the leaked data. Depending on
context/constraints it might be a perfectly *good enough* solution. It's up
to you deciding if it's worth fixing it.

That being said, overriding get_exclude works for me: it hides/shows some
fields in an admin form depending on some condition (and it's thread safe).
It requires django 1.11 or newer and it may be affected by fields and
readonly_fields defined in the model admin and in the model form. Please,
provide the relevant code, errors etc. if you require further assistance
with this.

Another approach would be overriding get_form as shown in the django
docs[1].

The point is that neither of those solutions makes changes to shared state
(the admin).


HTH

[1] https://docs.djangoproject.com/en/1.11/ref/contrib/admin/

Missatge de Balaji Shetty  del dia dv., 31 de maig
2019 a les 16:42:

> Dear Alexis Roda Sir
>
> Thank You very Much.
>
> definitely Race Condition may arise if we do not put code inn critical
> section. But your suggested approach did not work and i found another
> alternative which is working fine. If we put this code with necessary care
> than will it be ok?
>
>
>
> On Tue, May 28, 2019 at 8:33 PM Alexis Roda <
> alexis.roda.villalo...@gmail.com> wrote:
>
>> No, it isn't. It's not thread safe.
>>
>> Changes in shared state in multi-threaded code may lead to race
>> conditions[1].
>>
>> Depending on your usage it may be very unlikely, but under the right
>> circumstances root may end up having some missing fields in the form or dgp
>> may see fields that it is not intended to see.
>>
>> Either protect the critical section[2] with some kind of lock or, as I
>> suggested in my previous answer, create non-shared (request local) state.
>>
>>
>> [1] https://en.wikipedia.org/wiki/Race_condition
>> [2] https://en.wikipedia.org/wiki/Critical_section
>>
>> --
>> 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/CAMDYoXa16C5goSadFbSoXQg1-v2zh9vrq%2BAk%3Dkqbq1rk%3DsgSQw%40mail.gmail.com
>> <https://groups.google.com/d/msgid/django-users/CAMDYoXa16C5goSadFbSoXQg1-v2zh9vrq%2BAk%3Dkqbq1rk%3DsgSQw%40mail.gmail.com?utm_medium=email_source=footer>
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>
> --
>
>
> *Mr. Shetty Balaji S.Asst. ProfessorDepartment of Information Technology,*
> *SGGS Institute of Engineering & Technology, Vishnupuri, Nanded.MH.India*
> *Official: bsshe...@sggs.ac.in  *
> *  Mobile: +91-9270696267*
>
> --
> 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/CAECSbOvKUK0H2mrt_S%2BhmbVmmeneQXXc%2BR9a%3DFGHE7XOVmOK-Q%40mail.gmail.com
> <https://groups.google.com/d/msgid/django-users/CAECSbOvKUK0H2mrt_S%2BhmbVmmeneQXXc%2BR9a%3DFGHE7XOVmOK-Q%40mail.gmail.com?utm_medium=email_source=footer>
> .
> 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/CAMDYoXb%3D7D99YNQrAos%2BVWaxqxq%2B4z9m_kw3nLPZ28bfrZ-Ujw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Model Forms Dynamic

2019-05-28 Thread Alexis Roda
Something like that?

def model_form_factory(model_class):
class MyModelForm(forms.ModelForm):
class Meta:
model = model_class
return MyModelForm

AuthorForm = model_form_factory(Author)
BookForm = model_form_factory(Book)


Missatge de Yoo  del dia dt., 28 de maig 2019 a les
18:01:

> https://docs.djangoproject.com/en/2.2/topics/forms/modelforms/
>
> In the example of model form, they say
> model = Author
> Is it possible to set a variable to set the model? Like could I make a
> variable and set it to whatever model I’d like, then say model = var?
>
> --
> 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/918196f4-0ab8-45e8-803d-d62a38a1e396%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/CAMDYoXbELKWgyRTWN1WYS5q8-50a-9UQg7brZ3PCvAPvoTq1MA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: SOLUTION FounD : How to restore Models original Properties - Problem in Models column Exclude

2019-05-28 Thread Alexis Roda
No, it isn't. It's not thread safe.

Changes in shared state in multi-threaded code may lead to race
conditions[1].

Depending on your usage it may be very unlikely, but under the right
circumstances root may end up having some missing fields in the form or dgp
may see fields that it is not intended to see.

Either protect the critical section[2] with some kind of lock or, as I
suggested in my previous answer, create non-shared (request local) state.


[1] https://en.wikipedia.org/wiki/Race_condition
[2] https://en.wikipedia.org/wiki/Critical_section

-- 
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/CAMDYoXa16C5goSadFbSoXQg1-v2zh9vrq%2BAk%3Dkqbq1rk%3DsgSQw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Single place for validation

2019-05-27 Thread Alexis Roda
Hi,
an approach that comes to mind would be defining validation in the model
and using model forms[1] for the user site.


HTH

[1] https://docs.djangoproject.com/en/2.2/topics/forms/modelforms/

Missatge de Harsh Gundecha  del dia dl., 27 de
maig 2019 a les 16:20:

> hello,
> i am currently learning django and i have query as following
> is it that we have  to put validators in both the model definition and
> form validation to apply validation to both admin and user site ?
> i tired on reusing a form class assuming that the validator there would
> apply on both user and admin site but it didnt happen.
>
>
> in short,
> i would like to define validation at one place and get them applied on
> both user and admin site
>
> Thank you
> Regards, Harsh
>
> --
> 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/8a5280cf-d52b-4a7d-8e21-0d18a741f02a%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/CAMDYoXY3ae8SYD8PBfxNEnPLsAuPB90V%2BFA434p1iAR8Rx0r1Q%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: How to restore Models original Properties - Problem in Models column Exclude

2019-05-27 Thread Alexis Roda
Not an admin expert here.

You are modifying the modeladmin instance and, by the behavior you're
describing, it looks like it is a global (shared) object. I'm guessing, you
can confirm this by printing id(self) in add_view(). I'll bet you get the
same value in each request, so the instance is shared, so the change is
visible (persisted) across request boundaries.

You may think about adding self.exclude = () in the else branch in order to
not exclude anything. Don't do that, you may end up leaking private
information to dgp if both root and dgp are logged in at the same time.

Instead override the get_exclude method.

See
https://docs.djangoproject.com/en/2.2/ref/contrib/admin/#django.contrib.admin.ModelAdmin.get_exclude

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


Re: Trouble upgrading ModelField class for django 1.10

2017-06-03 Thread Alexis Roda

El 03/06/17 a les 16:27, Simon Charette ha escrit:

Hello Alexis,

As you've noticed Django 1.8 changed values()/values_list() to 
converts values returned

from the database just like any other ORM method[0].

If you want to use the json module to serialize your horari.Horari 
instances you'll have

to define your own JSONEncoder (or DjangoJSONEncoder) subclass.

class ToStrJSONEncoder(DjangoJSONEncoder):
def default(o):
if hasattr(o, 'to_str'):
return o.to_str()
return super().default(o)

Cheers,
Simon

[0] https://docs.djangoproject.com/en/1.8/releases/1.8/#subfieldbase


Thank you Simon!

I've missed this change. I should spend some time rereading the changelogs.


Regards

--
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/c71bfdd0-2c78-9f7c-0f72-a6f0608af31f%40gmail.com.
For more options, visit https://groups.google.com/d/optout.


Trouble upgrading ModelField class for django 1.10

2017-06-03 Thread Alexis Roda

Hi,

I have a custom ModelField (HorariField, a simple weekly timetable) 
written for django 1.7 and I'm trying to upgrade it to work with django 
1.10, so I have removed the SubfieldBase metaclass and added the 
from_db_value method. The field inherits from CharField and stores 
Horari instances that are serialized to/from strings like 
"mo,tu,we:08:00-14:00", it works like the HandField in the django docs.


After the changes I'm getting errors when serializing to json the models 
that have that kind of field:


   TypeError: 
   is not JSON serializable

I'm not using the django serializers. The json serialization look like:

   json.dumps(list(result), cls=DjangoJSONEncoder)

where result is a ValuesQuerySet.

After some debugging it seems that with the old HorariField class the 
json serializer already receives a serialized value, so it worked until 
now, but upgrading the field class the serializer receives an Horari 
instance.


I'm wondering if I'm missing something, some magic provided by 
SubfieldBase that I've no replicated in the new class, or this is how 
it's supposed to work and I need to take care of this in the serializer.



Here's the code for the field:

   class HorariField(models.CharField):
description = _(u"Horari")

def __init__(self, *args, **kwargs):
if "max_length" not in kwargs:
kwargs["max_length"] = 188
if "default" not in kwargs:
kwargs["default"] = None
super(HorariField, self).__init__(*args, **kwargs)

def get_internal_type(self):
return "CharField"

def from_db_value(self, value, expression, connection, context):
if value is None:
return None
return horari.Horari(value)

def to_python(self, value):
if isinstance(value, horari.Horari):
return value
return horari.Horari(value)

def get_prep_value(self, value):
if value is None:
return None
return value.to_str()

def formfield(self, form_class=fields.HorariField, **kwargs):
return super(HorariField,
   self).formfield(form_class=form_class, **kwargs)

I've tried defining the value_to_string method but I get the same error. 
The method it's never called. I assume that it's meant for django 
serializers' consumption.



TIA

--
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/a54deb48-8d5e-169d-00d7-86c93add02f5%40gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Problems receiving data from DB (sqlite3)

2013-04-07 Thread Alexis Roda

Al 07/04/13 22:50, En/na Johannes ha escrit:

yea, my knowledge from python is like larry and you told, the pyc-files
get rebuild if the timestamp of the py and pyc files differs.
But, because in my case it seems to be handled different, I wondered if
django handles this in another way.


I'm not a django/python guru, but I don't think so. The settings module 
is imported by the 'django.utils.importlib.import_module' function which 
ultimately calls the '__import__' builtin.


After a quick grep in the django 1.5 source it seems that neither the 
'__import__' builtin is rebound nor import hooks are registered. So I'd 
expect the default behaviour.




Regards

--
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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Problems receiving data from DB (sqlite3)

2013-04-07 Thread Alexis Roda

Al 07/04/13 21:35, En/na Johannes ha escrit:

I get again to different results.
the shell accesses the settings.py while  from the testserver the
settings.pyc is accessed.  After I deleted the pyc-file. the testserver
uses the settings.py too.
When and in which cases the pyc-file gets (re)-build?


Johannes,
AFAIK python rebuilds them automatically if they are older than the 
corresponding '.py' file. Probably the first time they are imported, but 
not sure about that.


You can trigger a manual compilation with the 'compileall' module 
included in the stdlib:


  python -m compileall 

To be in the safe side I'd recommend deleting all '.pyc' files before 
rebuilding them.



Regards

--
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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Problems receiving data from DB (sqlite3)

2013-04-07 Thread Alexis Roda

Al 07/04/13 20:35, En/na Johannes ha escrit:

In order to diagnose what the problem really is I'd suggest to add a
print to some of your views:


databases {'default': {'ENGINE': 'django.db.backends.sqlite3',
'TEST_MIRROR': None, 'NAME': ':memory:', 'TEST_CHARSET': None,
'TIME_ZONE': 'UTC', 'TEST_COLLATION': None, 'OPTIONS': {}, 'HOST': '',
'USER': '', 'TEST_NAME': None, 'PASSWORD': '', 'PORT': ''}


and in the shell just:


the shell output:
databases {'default': {'ENGINE': 'django.db.backends.sqlite3',
'TEST_MIRROR': None, 'NAME': 'nacc.db', 'TEST_CHARSET': None,
'TIME_ZONE': 'UTC', 'TEST_COLLATION': None, 'OPTIONS': {}, 'HOST': '',
'USER': '', 'TEST_NAME': None, 'PASSWORD': '', 'PORT': ''}}


so the name does not match. Do I miss something to import?


So it looks like django is using two different settings.py (or the same 
settings.py which has some kind of conditional configuration).


Again, in any view and in the django shell, compare the output:

import os
settings = os.environ["DJANGO_SETTINGS_MODULE"]
module = __import__(settings)
print settings, module.settings.__file__

Hopefully this will give you some clue.



HTH

--
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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Problems receiving data from DB (sqlite3)

2013-04-04 Thread Alexis Roda

Al 03/04/13 19:38, En/na Johannes ha escrit:

Hi list,
I have a confusing behaviour when I try to access some data in the DB.
I created a model and build the database with syncdb.
I can create and save data via python manage.py shell and it's still
available after I a restart of the shell.
But this data is not visible from the testserver. Even more, If I create
and save data from the testserver, it's only available until I restart
the server.


Sounds like you're using two DBs ... does not make much sense since I'd 
expect you're using the same settings.py in both cases, so the same 
database. In the testserver it looks like an in memory database which is 
destroyed upon restart.


Out of curiosity, what happens to the data created through the shell 
after starting/stoping the testserver, it's still there?


In order to diagnose what the problem really is I'd suggest to add a 
print to some of your views:


def your_view(request, ...):
from django.conf import settings
print "databases", settings.DATABASES
...
rest of your code

and in the shell just:

from django.conf import settings
print "databases", settings.DATABASES

Compare both outputs to make sure you're using the same database.


HTH

--
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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: djano user registration form and login(full example)

2013-04-01 Thread Alexis Roda

Al 01/04/13 21:11, En/na sachin ha escrit:

Hello,

I'm just starting with Django. I want to create a user registration form
which will take input like username, password, first and last name,
email, address etc.
using the same information I want to send a conformation mail to user
and authenticate her/him.


Hi sachin,
I'd suggest you to take a look at django-registration. It does what 
you're asking for.


https://bitbucket.org/ubernostrum/django-registration
http://docs.b-list.org/django-registration/0.8/


HTH

--
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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Using Django docs to find widget readonly specification

2013-03-31 Thread Alexis Roda

Al 31/03/13 23:42, En/na AJP ha escrit:

I'm new to learning Django.  I want to find the documentation regarding
the readonly attribute you can set for admin widgets.


Do you mean?

https://docs.djangoproject.com/en/1.5/ref/contrib/admin/#django.contrib.admin.ModelAdmin.readonly_fields

It's linked in the front page (https://docs.djangoproject.com/en/1.5/), 
in the "The admin" section, "Admin site".


Also, googling for "django admin readonly field" returns the page in the 
first place.



Regards

--
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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: how do I specify optional params in url?

2013-03-31 Thread Alexis Roda

Al 31/03/13 22:43, En/na frocco ha escrit:

Thank you for taking the time to help me.


You're welcome.

One last thing. I'm not a native english speaker, so if I sound rude 
it's not my intention. That said ...


When you ask for help in the list try to include more information: the 
error message, explain what you're doing, what input do you provide, 
what result do you expect and what result do you get, provide some 
sample code etc.


Try to be clear and concise .. but not as concise as "this does not work" ;)

Also, when replying to a message keep some of the relevant context. That 
will help the reader in knowing what has been done so far.



In short: help us to help you.



Regards

--
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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: how do I specify optional params in url?

2013-03-31 Thread Alexis Roda

Al 31/03/13 21:55, En/na frocco ha escrit:

I am kinda lost with url encoding being a newbie in django.

I do not see my error.

  Can you give me an example?


Here it is:

views.py:

  def my_view(request, foo, bar="spam"):
  pass

urls.py

  # choose descriptive names for the views
  ...
  url(r"^narrow/(\d+)/$", views.my_view, name="narrow1"),
  url(r"^narrow/(\d+)/(\w+)/$", views.my_view, name="narrow2"),
  ...

in python code (views etc.):

  reverse("narrow1", args=(23, )) -> ".../narrow/23/"
  reverse("narrow2", args=(23, "foo")) -> ".../narrow/23/foo"

in templates:

  {% url "narrow1" 23 %}  -> ".../narrow/23/"
  {% url "narrow2" 23 "foo" %} -> ".../narrow/23/foo/"

Important: if you're using django < 1.5 you should remove the quotes 
around the view name in the url tag.





HTH

--
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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: how do I specify optional params in url?

2013-03-31 Thread Alexis Roda


El diumenge 31 de març de 2013 21:01:55 UTC+2, frocco va escriure:
>
>  url(r'^narrow_category/(\d+)/$', 'catalog.views.narrow_category', 
> name="narrow_category"),
> url(r'^narrow_category/(\d+)/(\w+)/$', 
> 'catalog.views.narrow_category', name="narrow_category"),
> url(r'^narrow_category/(\d+)/(\w+)/(\d+)/$', 
> 'catalog.views.narrow_category', name="narrow_category"),
> url(r'^narrow_category/(\d+)/(\w+)/(\d+)/(\d+)/$', 
> 'catalog.views.narrow_category', name="narrow_category"),
> url(r'^narrow_category/(\d+)/(\w+)/(\d+)/(\d+)/(\d+)/$', 
> 'catalog.views.narrow_category', name="narrow_category"),
>
> def narrow_category(request, pk, search='', size1='', size2='', size3=''):
>  
> Page not found (404)Request Method:GETRequest URL:
> http://127.0.0.1:8000/narrow_category/8/2657018///
>

I missed this in my first read: you should give each rule a different name.


Regards

-- 
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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: how do I specify optional params in url?

2013-03-31 Thread Alexis Roda

Al 31/03/13 21:01, En/na frocco ha escrit:

  url(r'^narrow_category/(\d+)/$', 'catalog.views.narrow_category',
name="narrow_category"),
 url(r'^narrow_category/(\d+)/(\w+)/$',
'catalog.views.narrow_category', name="narrow_category"),
 url(r'^narrow_category/(\d+)/(\w+)/(\d+)/$',
'catalog.views.narrow_category', name="narrow_category"),
 url(r'^narrow_category/(\d+)/(\w+)/(\d+)/(\d+)/$',
'catalog.views.narrow_category', name="narrow_category"),
 url(r'^narrow_category/(\d+)/(\w+)/(\d+)/(\d+)/(\d+)/$',
'catalog.views.narrow_category', name="narrow_category"),

def narrow_category(request, pk, search='', size1='', size2='', size3=''):


  Page not found (404)

Request Method: GET
Request URL:http://127.0.0.1:8000/narrow_category/8/2657018///



Take a look carefully at the URL that's causing the error:

  http://127.0.0.1:8000/narrow_category/8/2657018///

does it matches any of your rules?



HTH

--
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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: how do I specify optional params in url?

2013-03-31 Thread Alexis Roda

Al 31/03/13 19:00, En/na frocco ha escrit:

Hello,

Here is my current url.

url(r'^narrow_category/(\d+)/(\w*)/(\d*)/(\d*)/(\d*)/$',
'catalog.views.narrow_category', name="narrow_category"),

d+ is required
w* can be optional
last three d* can be optional

This setting is not working.


You should be a bit more explicit about what "is not working" means.

I presume that you expect that an URL like "narrow_category/23" should 
be matched against your url definition. No, it won't, since the slashes 
are not optional. All those will match against your regular expression:


  narrow_category/23/
  narrow_category/23/foo
  narrow_category/23/45
  narrow_category/23///23//

I think that the cleanest solution is defining a set of urls and, 
somehow, provide default values for the missing parts:


  def my_view(request, foo, bar="spam", baz=1234):
  pass

  url(r"^narrow/(\d+)/$", views.my_view, ...)
  url(r"^narrow/(\d+)/(\w+)/$", views.my_view, ...)
  url(r"^narrow/(\d+)/(\w+)/(\d+)/$", views.my_view, ...)

Note that the parts are no longer optional (+ instead of *).

It works like this:

  /narrow/23/
matches the 1st rule
django calls: my_view(request, "23")
the view gets the arguments: foo="23", bar="spam", baz=1234

  /narrow/23/baz/
2nd rule
my_view(request, "23", "baz")
foo="23", bar="baz", baz=1234

  /narrow/23/baz/45/
3rd rule
my_view(request, "23", "baz", "45")
foo="23", bar="baz", baz="45"

  /narrow/23/45/
2nd rule
my_view(request, "23", "45")
foo="23", bar="45", baz=1234


HTH

--
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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: How do I get these field values in my template?

2013-03-31 Thread Alexis Roda

Al 31/03/13 15:18, En/na frocco ha escrit:

cat = Product.objects.values_list('category__image_path','category__id')

outputs;
(u'category/goodyear logo.jpg', 13)

I tried for c in cat:
c.image_path
c.id


As its name may suggest values_lists() returns (kind) a list of lists, 
so you must index by position, not by field name:


for c in cat:
print c[0], c[1]

{% for c in cat %}
   {{ c.0 }} {{c.1}}
{% endfor %}

If you want to index by field name you should use values(), which 
returns a list of dictionaries mapping "field name" to "value".




HTH

--
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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Doubt regarding JSON/SQL in Django

2013-03-30 Thread Alexis Roda

Al 30/03/13 19:25, En/na Parin Porecha ha escrit:

Yes, I meant the former ( managing presentation on the client ).

Also, considering that a user might have as many as 100 - 200 tasks in
one JSON file ( their description, dates, tags and all ),
is it better performance wise ?


The responsiveness of the application will be better. By the way, you're 
not required to load all the tasks at a time, you can paginate the query 
result and request chunks of data from the server as the user scrolls 
down the list.




Regards

--
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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Doubt regarding JSON/SQL in Django

2013-03-30 Thread Alexis Roda

Al 30/03/13 16:41, En/na Parin Porecha ha escrit:

Thanks !

Okay, so i am dropping the idea of using JSON for storage.

So, if I use JSON only as a format to send data
to client ( All the parsing will be done client side ), is it better
than using {{ task.name }}, {{ task.start_date }} ? ( Sorry to ask
this again, but i haven't got it )


Sorry, but I still don't get the point on your question. Do you mean "is 
better to manage presentation on the client (json response + javascript) 
or in the server (django templates)"?




Regards

--
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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Doubt regarding JSON/SQL in Django

2013-03-30 Thread Alexis Roda

Al 30/03/13 14:37, En/na Parin Porecha ha escrit:

Also, would it be beneficial performance wise ?


It depends on how you implement it:

* on a "traditional" client/server application I think that 
loading/parsing/processing/encoding/saving the json file on each request 
will be very expensive compared to database access.


* if all the processing logic is in the client side and django acts as 
an storage service it may be ok.



One more doubt -
is it better to convert query results ( obtained from sql tables ) to
JSON, and send it as an http response to the client and use it to show
data, or to simply send the query result to the client and show it via
task.name, task.start_date etc. ?


IIUC you can't return the query (as a python object) to the client. You 
must convert the data on it to some format (json, xml, ...) that the 
client understands. That will depend on the libraries that you use in 
the client side.




Regards

--
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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Doubt regarding JSON/SQL in Django

2013-03-30 Thread Alexis Roda

Al 30/03/13 14:14, En/na Parin Porecha ha escrit:

Hi,

I have just started using Django. I want to create a to-do task
manager application. Users would register, login and can work with
their tasks. So, instead of creating a table in the database for each
user, I want to create a JSON file for each user which will store all
his tasks.

Is there any way I can do this in Django ?
I mean, use the database only for authentication, and use JSON to
store data instead of storing it in the database.


Yes, just import json and work with it, but be aware that you'll loose 
most of the functionality that makes django so productive: no 
ModelForms, no ORM/Querysets, no admin for tasks, ...




Regards

--
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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




management commands in namespaced apps

2013-03-28 Thread Alexis Roda

Hi all,
I'm having a hard time making management commands defined in a 
namespaced app available to "manage.py".


I have a namespace python package "dja.skel.core" that provides some 
functionality and a namespace app "dja.skel.django_skel" which defines 
functionality specific to django, a management command named "skel".


"dja.skel.django_skel" is in INSTALLED_APPS but when I run "python 
manage.py help" the "skel" management command is not listed.


Tracking down the problem it seems to be caused by the 
"imp.find_module()" function in 
"django.core.management.find_management_module()".


When calling imp.find_module("dja", None) it returns 
'/home/alex/prog/dja_skel/dja.skel.core/dja' for the path, so locating 
"dja.skel.django_skel.management" will fail as it is being searched for 
in "dja.skel.core".


So my question is if is this a bug or namespace apps are no supported by 
django in the way I'm trying to use them?




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+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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: 发生了什么,

2012-09-27 Thread Alexis Roda

Al 27/09/12 10:10, En/na Huahui Zhou ha escrit:




http://stackoverflow.com/questions/6778638/manage-py-runserver-error-errno-10013

--
You received this message because you are subscribed to the Google Groups "Django 
users" group.
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: httplib exception in Django model

2012-09-19 Thread Alexis Roda

Al 19/09/12 10:42, En/na airween ha escrit:


   File "/usr/lib/python2.6/socket.py", line 547, in create_connection
 for res in getaddrinfo(host, port, 0, SOCK_STREAM):
error: Int or String expected
 >>>


What should I do, what is the problem?


According to the last line it seems that 'host' or 'port' have the wrong 
type. Since 'host' must be an string or None the problem seems to be 
related with 'port'.


Printing httphost and httpport's type and value before creating the 
connection may give you some clue.




HTH

--
You received this message because you are subscribed to the Google Groups "Django 
users" group.
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: Hard time debugging an strange problem

2012-08-31 Thread Alexis Roda

Al 31/08/12 18:26, En/na Tomas Neme ha escrit:

I'd like to see some of your management commands' code.

It smells somewhat like you're running a shell subprocess and not
waiting for it to be done before going on to the next thing



Thanks for taking the time to answer.

I've thought on this. On a prior version the "python setup.py develop" 
was executed from the management command, but I've commented it out and 
I've added it as a separated command in the script (just in case).


I think that I've found what the problem is. It's explained in other e-mail.

If you're still interested on taking a look at the code drop me a 
private mail.





Regards,
Alexis

--
You received this message because you are subscribed to the Google Groups "Django 
users" group.
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: Hard time debugging an strange problem

2012-08-31 Thread Alexis Roda

Hi again,
doing some more testing I've realized that the problem happens because 
the .py and .pyc files are out of sync. My guess is that the .py files 
are modified so quickly that the timestamp does not change and a 
recompilation is not triggered. After some research I've found that the 
timestamp resolution depends on the filesystem (I'm doing the tests on 
ext3 which has a resolution of 1 second).




Regards
Alexis

--
You received this message because you are subscribed to the Google Groups "Django 
users" group.
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.



Hard time debugging an strange problem

2012-08-30 Thread Alexis Roda

Hi all,
sorry for the ambiguous subject, but I can't summarize it in a few words.

This is my first message to the list asking for help so I think that is 
polite to give a big thanks to those of you that are making developing 
with django such a great pleasure. This is a great community.


Said that, I'm working on a management command that adds 'paster create' 
like functionality to 'manage.py'. In order to do tests I have created a 
simple bash script that:


* cleans the environment (uninstall the app from the virtualenv, removes 
the project, app, sqlite database etc.)

* creates a new project (with my command)
* creates a new app (with my command)
* installs the app in develop mode
* creates an empty model (with my command)
* overwrites the model definition with one that has a couple of fields
* runs syncdb
* loads a fixture
* creates a set of views (with my command)

When I run the script, more often than not, I get exceptions in the 
'manage.py' command. If I run the individual commands "by hand" I get no 
errors. What is driving me mad is that adding a 'sleep 1' between the 
commands in the script the exceptions go away (tested running the script 
in a while [ $? != 0 ] loop for more than an hour).


The management command does no black magic: it takes context variables 
from the command line, adds some variables (like the app object returned 
by cache.get_app(), the model we are operating on etc.) and expands a 
set of cheetah templates.


The exceptions are of different types:

http://pastebin.com/sW0AAmHn in this run cache.get_app() is unable to 
find the 'foobar' app. Of course it is in INSTALLED_APPS.


http://pastebin.com/mRSdkgCb in this run syncdb does not create the 
table for the FirstModel model and 'manage.py loaddata' complains. 
FirstModel exists, has an applabel="foobar" attribute and is imported 
from 'models/__init__.py'.


Here's the script:
http://pastebin.com/08veXtJ6

site-packages:
Cheetah-2.4.4-py2.7-linux-i686.egg/
Django-1.3.3-py2.7.egg/
Django-1.4.1-py2.7.egg/
django_crispy_forms-1.1.4-py2.7.egg/
django_tables2-0.11.0-py2.7.egg/
dja-skel.egg-link
easy-install.pth
foobar.egg-link
ipython-0.13-py2.7.egg/
Markdown-2.2.0-py2.7.egg
pep8-1.3.3-py2.7.egg/
pip-1.0.2-py2.7.egg/
Pymacs/
setuptools-0.6c11-py2.7.egg
setuptools.pth

python version:
Python 2.7 (r27:82500, Jul 17 2010, 02:48:50)
[GCC 4.4.3] on linux2

Django 1.4.1


I don't care for having to wait a few seconds in order to get a clean 
environment but I'm very curious about what the problem may be. Any idea?




Regards,
Alexis

--
You received this message because you are subscribed to the Google Groups "Django 
users" group.
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: SyntaxError Creating New Project

2012-08-22 Thread Alexis Roda

Al 22/08/12 23:00, En/na Bestrafung ha escrit:

I'm new to Django and though I've dabbled with Linux off and on for a
decade I'm still learning so please go easy on me. I'm following this
guide

to setup a Django 1.4.1 test project. So far I've setup Python 2.5 with
MySQL-python-1.2.3 and setuptools, setup mod_wsgi, and edited
.bash_profile. I've downloaded Django 1.4.1 (not trunk) and so far
everything looks good. As soon as I run "django-admin.py startproject
testproject" I receive an error and am having trouble resolving it. I
apologize if this has come up before bet a quick search wasn't helpful.
Thanks in advance for any assistance, the error is below:

[-bash-3.2 root@server1: /home/username/sites/domain.com] #
/home/username/sites/domain.com/django/bin/django-admin.py
startproject testproject
Traceback (most recent call last):
File "/home/username/sites/domain.com/django/bin/django-admin.py",
line 2, in ?
from django.core import management
File "/home/username/sites/domain.com/django/__init__.py", line 15
parts = 2 if version[2] == 0 else 3
^
SyntaxError: invalid syntax
[-bash-3.2 root@server1: /home/username/sites/domain.com] #


The "var = value if predicate else value" syntax was introduce in python 
2.5, so it seems like the python interpreter that's being used to run 
django-admin.py is older.


Try executing python and look at the version number. Check the shebang 
in the 'django-admin.py' too.


As a workaround execute:

/path/to/python2.5 /path/to/django-admin.py startproject testproject



HTH

--
You received this message because you are subscribed to the Google Groups "Django 
users" group.
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: HttpResponseNotModified returning 200 code

2012-08-22 Thread Alexis Roda

Al 22/08/12 21:36, En/na Kevin Anthony ha escrit:

Here is my code:

id = get_id(request)
  if id is not None:
  host = request.GET['host']
  if host!=None:
  command =
command_queue.objects.all().filter(destination_hostname=host,user__id=id)
  if not command.count():
  HttpResponseNotModified()
  retval =
JSONResponse(command.values('command','command_text'),Extra={"success":True})
  command.delete()
  return retval
 return HttpResponseForbidden()

I know it's getting to the HttpResponseNotModified, but I'm still
getting a HTTP status code of 200.

Can someone point me in the correct direction?


return HttpResponseNotModified()



HTH

--
You received this message because you are subscribed to the Google Groups "Django 
users" group.
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: Updating a model instance with extra checks.

2012-08-20 Thread Alexis Roda

Al 20/08/12 18:53, En/na Sebastien Flory ha escrit:

Hi everyone,

I'm looking for the proper django way to do an update of an attribute on
my model instance, but only if the attribute current value is checked
agains't a condition, in an atomic way, something like this:

def use_money(self, value):
begin_transaction()
real_money = F('money')
if real_money >= value:
self.money = F('money') - value
self.save()
end_transaction()

I want to make sure that I avoid race condition so money never goes below 0.


Take a look at:

https://docs.djangoproject.com/en/1.4/topics/db/transactions/

Tying transactions to HTTP requests
===

The recommended way to handle transactions in Web requests is to tie 
them to the request and response phases via Django’s TransactionMiddleware.


It works like this: When a request starts, Django starts a transaction. 
If the response is produced without problems, Django commits any pending 
transactions. If the view function produces an exception, Django rolls 
back any pending transactions.


...

However, if you need more fine-grained control over how transactions are 
managed, you can use a set of functions in django.db.transaction to 
control transactions on a per-function or per-code-block basis.





HTH

--
You received this message because you are subscribed to the Google Groups "Django 
users" group.
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: Problem with the urls.py "unexpected end of pattern"

2012-08-17 Thread Alexis Roda

I think that this is not the problem because I can access to volunters
without problems. I have problems only with admin, organizers and events
paths.


So you have problems with all the urls past the first with a wrong pattern.

~$ python
Python 2.6.5 (r265:79063, Apr 16 2010, 13:09:56)
[GCC 4.4.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import re
>>> re.compile(r'^volunters/(?V\d+)/$')
Traceback (most recent call last):
  File "", line 1, in 
  File "/usr/lib/python2.6/re.py", line 190, in compile
return _compile(pattern, flags)
  File "/usr/lib/python2.6/re.py", line 245, in _compile
raise error, v # invalid expression
sre_constants.error: unexpected end of pattern
>>> re.compile(r'^volunters/(?P\d+)/$')
<_sre.SRE_Pattern object at 0xb76ec590>


Regards

--
You received this message because you are subscribed to the Google Groups "Django 
users" group.
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: Problem with the urls.py "unexpected end of pattern"

2012-08-17 Thread Alexis Roda

Al 17/08/12 17:42, En/na Rafael Romero Carmona ha escrit:

Hi, I'm learning Django and I have problems with the urls.py. I show you
how that's writed:

from django.conf.urls import patterns, include, url

from django.contrib import admin
admin.autodiscover()

urlpatterns = patterns('users.views',

 url(r'^volunters/$', 'voluntersindex'),
 url(r'^volunters/(?V\d+)/$', 'volunterdetails'),
 url(r'^organizers/$', 'organizersindex'),
 url(r'^organizers/(?O\d+)/$', 'organizerdetails'),
 url(r'^events/$', 'eventsindex'),
 url(r'^events/(?E\d+)/$', 'eventdetails'),

)

urlpatterns += patterns('',
 url(r'^admin/', include(admin.site.urls)),
)

When I try to show admin/, organizers/ and events/ I receive a menssage
like:"unexpected end of pattern; Exception Location:
/usr/lib/python2.6/re.py in _compile, line 245"

How can I fix it? Thanks and sorry if I have errors in my sentences.


The regular expressions are wrong, Try with (?P\d+) etc.



HTH

--
You received this message because you are subscribed to the Google Groups "Django 
users" group.
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: Adding Button in admin form

2012-08-17 Thread Alexis Roda

Al 17/08/12 13:05, En/na Madhu ha escrit:

Yes, That's right. I tried to change the admin form, but the button is
not added.
the fuctionality Jani Tiainen said i want the same fuctionality, but the
now first problem is adding button in change form.


As Jani has pointed I think that a custom widget (text field + button) 
plus a custom form that associates that widget to the 'url' field could 
do the trick.



HTH

--
You received this message because you are subscribed to the Google Groups "Django 
users" group.
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: installing django extensions

2012-08-16 Thread Alexis Roda

Al 16/08/12 19:16, En/na Sells, Fred ha escrit:

Thanks, that last post was the clue I needed. I have 2 independent, active 
django projects and was erroneously editing the settings.py in the wrong 
project.  Just plain old stupid error, but I may have not seen it for days 
without all your help.  Thanks and apologies for taking up your time.



This mistake sounds familiar :)


Regards

--
You received this message because you are subscribed to the Google Groups "Django 
users" group.
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: installing django extensions

2012-08-16 Thread Alexis Roda

Al 16/08/12 17:20, En/na Sells, Fred ha escrit:

It seems to import OK, see below:

more manage.bat

\alltools\python26\python manage.py %1 %2 %3 %4 %5

C:\all\projects\AccTherapySchedulerServer\AccTherapySite>manage shell

C:\all\projects\AccTherapySchedulerServer\AccTherapySite>\alltools\python26\python
 manage.py shell
Python 2.6.6 (r266:84297, Aug 24 2010, 18:46:32) [MSC v.1500 32 bit (Intel)] on 
win32
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)


import django_extensions
dir(django_extensions)

['VERSION', '__builtins__', '__doc__', '__file__', '__name__', '__package__', 
'__path__', '__version__', 'str_version']

django_extensions.VERSION

(0, 9)



however if I run manage help I see the following which does not 
seem like it has extensions--
Available subcommand
   cleanup
   compilemessages

...

   test
   testserver
   validate


right, django-extensions' commands are missing.


Now this is a W7 system I use for development FWIW.


I have no experience developing on w7. I have tested it on linux with a 
clean virtualenv (python 2.6.2, django 1.3 and django-extensions 0.9) 
and it works fine.


If I run 'python' by itself I can get the django commands but not the 
d-e ones:


$ python
Python 2.6.2 (r262:71600, May 21 2009, 18:30:52)
[GCC 4.1.2 20061115 (prerelease) (Debian 4.1.1-21)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from django.core.management import get_commands
>>> get_commands().keys()
['compilemessages', 'dumpdata', 'startproject', 'sqlcustom',
...
'loaddata', 'cleanup', 'sqlindexes']


If I run 'python manage.py shell' I get both django and d-e commands:

$ python manage.py shell
Python 2.6.2 (r262:71600, May 21 2009, 18:30:52)
[GCC 4.1.2 20061115 (prerelease) (Debian 4.1.1-21)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> from django.core.management import get_commands
>>> get_commands().keys()
['show_urls', 'generate_secret_key', 'set_fake_passwords',
...
'describe_form', 'cleanup', 'sqlindexes']


That makes me believe that the problem is somewhat related with the 
settings not being (properly) loaded. Could you try:


$ python manage.py shell
Python 2.6.2 (r262:71600, May 21 2009, 18:30:52)
[GCC 4.1.2 20061115 (prerelease) (Debian 4.1.1-21)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> from django.conf import settings
>>> settings.INSTALLED_APPS
['django.contrib.auth', 'django.contrib.contenttypes', 
'django.contrib.sessions', 'django.contrib.sites', 
'django.contrib.messages', 'django.contrib.staticfiles', 
'django_extensions']

>>> import os
>>> os.environ["DJANGO_SETTINGS_MODULE"]
'foo.settings'


I expect that you'll get an ImportError exception (your environment is 
not properly configured) or that 'django_extensions' is missing (the 
wrong settings.py is being loaded).




Regards

--
You received this message because you are subscribed to the Google Groups "Django 
users" group.
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: installing django extensions

2012-08-16 Thread Alexis Roda

Al 16/08/12 15:23, En/na Sells, Fred ha escrit:


C:\alltools\python26>python

Python 2.6.6 (r266:84297, Aug 24 2010, 18:46:32) [MSC v.1500 32 bit
(Intel)] on win32

Type "help", "copyright", "credits" or "license" for more information.


>> import django_extensions



>> dir(django_extensions)


['VERSION', '__builtins__', '__doc__', '__file__', '__name__',
'__package__', '__path__', '__version__', 'str_version']


Your INSTALLED_APPS snippet looks right to me.

What happens if you import 'django_extensions' from 'manage.py shell' ?

...>\alltools\python26\python manage.py shell
...
>> import django_extensions
>> dir(django_extensions)


Regards

--
You received this message because you are subscribed to the Google Groups "Django 
users" group.
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: 'bool' object has no attribute 'render'

2012-08-15 Thread Alexis Roda

Al 15/08/12 02:59, En/na yao ge ha escrit:

class NewsAdmin(admin.ModelAdmin):
 list_display = ('title','newstype','newsdate',)
 search_fields=('title',)
 list_filter =('newstype',)
 delete_selected_confirmation_template = True
 raw_id_fields = ('rateperson','ratetvplay',)
admin.site.register(News,NewsAdmin)


Why??



https://docs.djangoproject.com/en/1.4/ref/contrib/admin/#custom-template-options

 ModelAdmin.delete_selected_confirmation_template
New in Django 1.2: Please see the release notes

Path to a custom template, ...


HTH

--
You received this message because you are subscribed to the Google Groups "Django 
users" group.
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: Not reading from TEMPLATE_DIRS in settings.py

2012-08-14 Thread Alexis Roda

Al 14/08/12 12:50, En/na madala ha escrit:


So I carried on and started tutorial 3 till I got halfway down and had
to do same thing but no matter what I try can't get Django to recognize
my directories.

Can anyone see where I am going wrong please? thanks in anticipation.


What error are you getting? template not found? please pastebin the 
traceback.




Regards

--
You received this message because you are subscribed to the Google Groups "Django 
users" group.
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: Added wiring for basic authentication?

2012-08-11 Thread Alexis Roda

Al 11/08/12 19:48, En/na Jonathan Hayward ha escrit:

I have a Django project with the root view @login_required, and I'm not
sure how to populate /accounts so that that heirarchy will hangle
login-related information. The Django Book at
https://docs.djangoproject.com/en/dev/topics/auth/ seems to say that it
will happen automagically with my default settings.py:


...


When I decorate my root view with @login_required, I get redirected to
http://localhost:8000/accounts/login/?next=/, which presents the Django
debug mode 404 page.


Probably you have forgot adding:

urlpatterns = patterns(
  ...
  url(r"^accounts/", include("django.contrib.auth.urls"))
  ...
)

to your root urlconf. That's required in order to "activate" the auth 
related views.


If you get a TemplateDoesNotExist error the next step is to create a 
"registration/login.html" template in order to display the login form.



HTH

--
You received this message because you are subscribed to the Google Groups "Django 
users" group.
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: how to organize models

2012-08-11 Thread Alexis Roda

Al 11/08/12 15:57, En/na Jojo ha escrit:

Hi, I'm developing my first web application with Django. The model is
growing up quite fast and I started to split the code in different files
I putted under models directory with its __init__.py file. Everything
works fine, but syncdb doesn't recognize new models, and consequently
doesn't create new tables.


You should import the models from __init__.py and add to every model

class Meta :
app_label = "your_app_label"


https://docs.djangoproject.com/en/1.4/ref/models/options/#app-label
https://docs.djangoproject.com/en/1.4/topics/db/models/#meta-options


HTH

--
You received this message because you are subscribed to the Google Groups "Django 
users" group.
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: edit a submitted form-load it on template

2012-08-07 Thread Alexis Roda

Al 07/08/12 14:04, En/na mapapage ha escrit:



$(document).ready(function () {
$("a").on("click", function(event) {
event.preventDefault();
var id = $(this).attr("id");
$.get("edit_wreqs"+"/"+id+"/", function(data) {
});
});
});



Disclaimer: I don't use jquery myself. My response is based on my 
experience with other js toolkits. The same ideas probably apply but the 
details may be different.


Well, you actually don't do anything with the value returned from the 
server (the function passed to 'get' is empty).


Once the 'get' call completes you'll get a chunk of HTML, corresponding 
to the rendering of the template 'main_Webrequests.html', that you 
should process in some way: the callback should locate the relevant HTML 
"code" within 'data' and insert-into/replace-part-of the current page 
with that "code". A quick googling shows that 'replaceWith' may be useful.


Depending on what you're trying to do it may be simpler (and faster) 
just fetching the object attributes from the server (instead of the 
whole page) and use those values to populate an edit form.




HTH

--
You received this message because you are subscribed to the Google Groups "Django 
users" group.
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: named url patterns - invalid syntax

2012-08-05 Thread Alexis Roda

Al 05/08/12 13:43, En/na Blaxton ha escrit:


Hi

Why following line cause an invalid syntax :
(r'^myform/$', 'mysite.views.myform', name="myform"),


Because it's syntax is invalid: the 'name=value' is allowed in function 
calls but not in tuples.


Try with:

urlpatterns = patterns('',
url(r'^myform/$', 'mysite.views.myform', name="myform"),
...
)


it seems named url pattern has changed from name="myform" to just 'myform'
because when I change it to:
(r'^myform/$', 'mysite.views.myform', 'myform'),

it pass the syntax error and throw another error :

dictionary update sequence element #0 has length 1; 2 is required


When you use a tuple the syntax is:

(regular expression, Python callback function [, optional dictionary [, 
optional name]])


the third element, if present, is expected to be a dictionary. Try with:

(r'^myform/$', 'mysite.views.myform', {}, 'myform')




HTH

--
You received this message because you are subscribed to the Google Groups "Django 
users" group.
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: Strange query string/doubled value?

2010-09-19 Thread Alexis Roda

En/na Benjamin Buch ha escrit:

1: Pass the ValueError like this:

if 'picture' in request.GET:
try:
pictures.insert(0, pictures.pop(int(request.GET['picture']) -1))
except IndexError:
pass
except ValueError:
pass


As a rule of thumb you must always validate values coming from the user 
before using them.


With the first approach you perform some kind of (implicit) validation, 
so I think that it is preferable over the second.


I case that it fits in your app, a third approach would be to change the 
URL schema and let django deal with tampered URLs:


  http://dorthegoeden.de/.../horch-was-waechst/4/

With the appropriate urlpattern/urlconf your view will be called only 
with valid input (an string of digits). In case of URLs like:


  http://dorthegoeden.de/.../horch-was-waechst/4/5/
  http://dorthegoeden.de/.../horch-was-waechst/notanumber/

django will return a Not Found response.





HTH

--
You received this message because you are subscribed to the Google Groups "Django 
users" group.
To post to this group, send email to django-us...@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: enumerating view functions

2010-06-16 Thread Alexis Roda

En/na Dmitry Beransky ha escrit:

Hi,

Is there a way to enumerate view functions that are currently
associated with a url patern?  In the end, I'd like to get a list of
triples: pattern name, pattern, callback function.


If you want to get a dump of the (regex, view, name) triples on the 
screen take a look at django-command-extensions[1], command 'show_urls'.


If you want to get the list from your app in order to do some processing 
on it [2] provides a simple example on how to "introspect" the URLs.


[1] http://code.google.com/p/django-command-extensions/
[2] http://djangosnippets.org/snippets/2059/


HTH

--
You received this message because you are subscribed to the Google Groups "Django 
users" group.
To post to this group, send email to django-us...@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.