static media serve weird behavior

2010-01-27 Thread Vladimir Shulyak
Hello everyone!

Really strange problem with serving static files with
django.views.static.serve():

So I've got media/css dir with show_indexes=True for serve() method.
It gives me list like this:
Index of css/
# ../
# default.css
# general.css
...

It means that the script is able to locate both files and they both
exist. I want to retrieve this files, but... For "default.css" I get
404 and for "general.css" I got 200 response code.
Fortunately, DEBUG=True mode explains that for request which ends with
404 I got wrong media dir set incorrectly:
"/home/vladimir/.../source/mediaa/css/default.css".
But it is set explicitly in settings as:
"/home/vladimir/.../source/media/css/default.css".

And all this for exactly same directory! So seems like files in the
same dir served differently for some reason (it is true for other
files too, not only for those two).

So here is the question: where does the wrong path comes from? Is it
cached somewhere?

Thanks





-- 
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: Is IP address caching built into the Django Framework?

2009-06-29 Thread Vladimir Shulyak

> You can't rely on just the IP. If you do then you will have problems
> where large numbers of people sit behind a single IP, as will be case
> where corporate firewall is used, or where proxies or other gateway or
> NAT solution are used by ISPs.

That's right, try to use cookie check instead of IP check.

On Jun 29, 5:12 am, Graham Dumpleton <graham.dumple...@gmail.com>
wrote:
> On Jun 29, 10:33 am, Aneesh <aneeshvkulka...@gmail.com> wrote:
>
> > I believe the request object should contain the IP address regardless
> > of whether the user has an account.  You can store that IP with the
> > vote like Vladimir mentioned.
>
> You can't rely on just the IP. If you do then you will have problems
> where large numbers of people sit behind a single IP, as will be case
> where corporate firewall is used, or where proxies or other gateway or
> NAT solution are used by ISPs.
>
> Graham
>
> > Here are the docs for HttpRequest 
> > objects:http://docs.djangoproject.com/en/dev/ref/request-response/#attributes
>
> > On Jun 28, 4:38 pm, links_awakening <brianb...@gmail.com> wrote:
>
> > > Actually, I was hoping specifically for an IP-based solution - one
> > > which would not require users to create accounts on my site.  I
> > > appreciate your feedback though.
>
> > > On Jun 28, 4:58 am, Vladimir Shulyak <nc0...@gmail.com> wrote:
>
> > > > Try django-votinghttp://code.google.com/p/django-votingifyouwant
> > > > digg-like voting.
> > > > This app stores all votes in database, so it prevents user to "vote
> > > > up" multiple times.
>
> > > > Alternatively, you can develop it yourself. It's pretty
> > > > straightforward to implement imo. IP address comes with request object
> > > > (don't forget to tweak your production server) so you can store it
> > > > against voting id with datetime field.
>
> > > > On Jun 28, 1:23 am, links_awakening <brianb...@gmail.com> wrote:
>
> > > > > If users can click "vote up" on my site, I want to prevent them from
> > > > > clicking "vote up" multiple times.  To do this, I would check whether
> > > > > their IP has clicked "vote up" in the past 24 hours.
>
> > > > > Thus, I am curious whether Django helps with this sort of problem, or
> > > > > if anyone has solved this using Django already.
--~--~-~--~~~---~--~~
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: models.ManyToManyField subclass, problem with getting values by form.

2009-06-28 Thread Vladimir Shulyak

Well... Problem closed. I was trying to override things that I
shouldn't. Now I got the idea of returning manager by __get__ and
everything is just fine :)

On Jun 27, 11:13 pm, Vladimir Shulyak <nc0...@gmail.com> wrote:
> Hello,
>
> I am trying to develop sublcass of models.ManyToManyField. This class
> should return text representations of objects to forms.TextField (like
> TagField from django-tagging). The reason to make my own
> representation is because:
> - I don't need content types
> - I need "front face" to ManyToManyField, but TagField uses CharField
> and stores duplicate data.
>
> So I come to implementing my own descriptor and field like this
> (minimal code just to show exception, dpaste of same code for syntax
> highlightinghttp://dpaste.com/60470/):
>
> #descriptor of field
> class MultiModelSubclassDescriptor
> (ReverseManyRelatedObjectsDescriptor):
>
>     def __init__(self, m2m_field):
>         super(MultiModelSubclassDescriptor, self).__init__(m2m_field)
>
>     def __get__(self, instance, instance_type=None):
>         from products.models import Ingridient
>         return ", ".join(["%s" % ing.name for ing in
> Ingridient.objects.all()])
>         #super(MultiModelSubclassDescriptor, self).__get__(instance,
> instance_type)
>
>     def __set__(self, instance, value):
>         pass
>         #super(MultiModelSubclassDescriptor, self).__set__(instance,
> value)
>
> #field
> class MultiModelSubclassField(ManyToManyField):
>
>     def __init__(self, to, **kwargs):
>         super(MultiModelSubclassField, self).__init__(to, **kwargs)
>
>     def contribute_to_class(self, cls, name):
>         super(MultiModelSubclassField, self).contribute_to_class(cls,
> name)
>
>         # Make this object the descriptor for field access.
>         setattr(cls, self.name, MultiModelSubclassDescriptor(self))
>
>     def value_from_object(self, obj):
>         "Returns the value of this field in the given model instance."
>         return getattr(obj, self.attname) #original getattr(obj,
> self.attname).all() for queryset
>
>     def formfield(self, **kwargs):
>         f = FormCharField(widget = TextInput())
>         return f
>
> But as my field is a subclass of ManyToManyField, django tries to get
> PKs of my object, not value.
> Piece of django code which is responsible for it:
>
>     for f in opts.fields + opts.many_to_many:
>         if not f.editable:
>             continue
>         if fields and not f.name in fields:
>             continue
>         if exclude and f.name in exclude:
>             continue
>         if isinstance(f, ManyToManyField):
>             # If the object doesn't have a primry key yet, just use an
> empty
>             # list for its m2m fields. Calling f.value_from_object
> will raise
>             # an exception.
>             if instance.pk is None:
>                 data[f.name] = []
>             else:
>                 # MultipleChoiceWidget needs a list of pks, not object
> instances.
>                 data[f.name] = [obj.pk for obj in f.value_from_object
> (instance)] """ HERE I get exception """
>
>         else:
>             data[f.name] = f.value_from_object(instance)
>
> There is a hack I to overcome this I beleive...
>
> Any help much appreciated, I am fighting with it for 4 days...
> Thanks.
--~--~-~--~~~---~--~~
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: Is IP address caching built into the Django Framework?

2009-06-28 Thread Vladimir Shulyak

Try django-voting http://code.google.com/p/django-voting if you want
digg-like voting.
This app stores all votes in database, so it prevents user to "vote
up" multiple times.

Alternatively, you can develop it yourself. It's pretty
straightforward to implement imo. IP address comes with request object
(don't forget to tweak your production server) so you can store it
against voting id with datetime field.

On Jun 28, 1:23 am, links_awakening  wrote:
> If users can click "vote up" on my site, I want to prevent them from
> clicking "vote up" multiple times.  To do this, I would check whether
> their IP has clicked "vote up" in the past 24 hours.
>
> Thus, I am curious whether Django helps with this sort of problem, or
> if anyone has solved this using Django already.
--~--~-~--~~~---~--~~
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: Tagging, parse_lookup what is the Right current method to implement "tagging"

2009-06-28 Thread Vladimir Shulyak

> It still surprises me that the tagging module does not live with the
> rest of Django as opposed to within Python.

Nothing unusual. Your django app lives in PYTHONPATH and other modules/
apps may live in libs directory as it is also in PYTHONPATH. You could
create any directory you like (with your module), add it to your
PYTHONPATH and use it like before.

Say you've got 2 projects on django and you need tagging app in both.
You won't copy tagging app in both of your projects, right?

On Jun 28, 2:25 am, dartdog  wrote:
> Thanks I had seen the note but had not yet gone down that path,,, I'll
> report back.
> It still surprises me that the tagging module does not live with the
> rest of Django as opposed to within Python.
>
> Thanks for the quick reply!
>
> On Jun 27, 5:14 pm, Karen Tracey  wrote:
>
> > On Sat, Jun 27, 2009 at 5:46 PM, dartdog  wrote:
>
> > > Old topic but don't really get the solution...
> > > I'm using SVN 1.1 Django
> > > and Python 2.6 On win Vista
> > > I downloaded tagging and it now sits in my Site-Packages directory for
> > > Python I used Tagging 0.2.1 win 32exe from Google code
>
> > There's a note in bold on the tagging project page:
>
> >http://code.google.com/p/django-tagging/
>
> > that says "Version 0.3 is targetting Django 1.0 - please use the trunk
> > version for now".  I take that to mean if you are using Django 1.0 or
> > higher, you should use the SVN trunk version of django-tagging.  The release
> > date noted for 0.2.1 is January 2008, many months before Django 1.0.  Given
> > all the backwards-incompatible changes that went into Django in the last
> > run-up to Django 1.0, it's highly unlikely tagging 0.2.1 is going to work
> > well with Django from current SVN.
>
> > > It seems very strange to me that this Django package chooses to live
> > > in the Python Directory structure?
>
> > That's a standard Python practice.  Add-on packages can be installed under
> > Python's site-packages and then be automatically found without having to
> > list them explicitly somewhere in PYTHONPATH.  This practice is independent
> > of Django.
>
> > > Since the current Django 1.1 django.db.models.query has no parse
> > > look_up, I get errors on import
>
> > I've never used tagging, but I suspect that is because you are using a
> > version of tagging that is far too old for the version of Django you are
> > using.
>
> > > What is the right way to implement tagging (solve this problem) for
> > > future compatibility?
>
> > You could try the SVN version of tagging.
>
> > > I see a bunch of fairly old discussion on this but nothing recent.
> > > Frankly I'm not sure I understand the prior solutions?
>
> > Since you don't mention any specifics here I'm not sure what it is you don't
> > understand.
>
> > > I see that tickets referring to this are closed... but as I said I
> > > don't see a simple cogent explanation of what to do using the current
>
> > Again, you left out any specifics of what tickets you don't understand the
> > resolution of.   I do not even know if you are talking about tickets in
> > Django's tracker or tagging's issue tracker.  All I can recommend is that
> > you upgrade to the latest SVN revision of tagging and try that.
>
> > Karen
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



models.ManyToManyField subclass, problem with getting values by form.

2009-06-27 Thread Vladimir Shulyak

Hello,

I am trying to develop sublcass of models.ManyToManyField. This class
should return text representations of objects to forms.TextField (like
TagField from django-tagging). The reason to make my own
representation is because:
- I don't need content types
- I need "front face" to ManyToManyField, but TagField uses CharField
and stores duplicate data.

So I come to implementing my own descriptor and field like this
(minimal code just to show exception, dpaste of same code for syntax
highlighting http://dpaste.com/60470/):

#descriptor of field
class MultiModelSubclassDescriptor
(ReverseManyRelatedObjectsDescriptor):

def __init__(self, m2m_field):
super(MultiModelSubclassDescriptor, self).__init__(m2m_field)

def __get__(self, instance, instance_type=None):
from products.models import Ingridient
return ", ".join(["%s" % ing.name for ing in
Ingridient.objects.all()])
#super(MultiModelSubclassDescriptor, self).__get__(instance,
instance_type)

def __set__(self, instance, value):
pass
#super(MultiModelSubclassDescriptor, self).__set__(instance,
value)

#field
class MultiModelSubclassField(ManyToManyField):

def __init__(self, to, **kwargs):
super(MultiModelSubclassField, self).__init__(to, **kwargs)

def contribute_to_class(self, cls, name):
super(MultiModelSubclassField, self).contribute_to_class(cls,
name)

# Make this object the descriptor for field access.
setattr(cls, self.name, MultiModelSubclassDescriptor(self))

def value_from_object(self, obj):
"Returns the value of this field in the given model instance."
return getattr(obj, self.attname) #original getattr(obj,
self.attname).all() for queryset

def formfield(self, **kwargs):
f = FormCharField(widget = TextInput())
return f





But as my field is a subclass of ManyToManyField, django tries to get
PKs of my object, not value.
Piece of django code which is responsible for it:

for f in opts.fields + opts.many_to_many:
if not f.editable:
continue
if fields and not f.name in fields:
continue
if exclude and f.name in exclude:
continue
if isinstance(f, ManyToManyField):
# If the object doesn't have a primry key yet, just use an
empty
# list for its m2m fields. Calling f.value_from_object
will raise
# an exception.
if instance.pk is None:
data[f.name] = []
else:
# MultipleChoiceWidget needs a list of pks, not object
instances.
data[f.name] = [obj.pk for obj in f.value_from_object
(instance)] """ HERE I get exception """

else:
data[f.name] = f.value_from_object(instance)



There is a hack I to overcome this I beleive...

Any help much appreciated, I am fighting with it for 4 days...
Thanks.
--~--~-~--~~~---~--~~
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: Session variables

2009-02-03 Thread Vladimir Shulyak

Any progress on this problem?
I've got exactly the same problem with sessions on ubuntu/database-
backend sessions. But the most interesting thing that variables like
instances of large classes are deleted while simple instances like
integers are fine.

class Cart():

items = {}
totalPrice = 0
count = 0
company = 0

items variable holds a dictionary of objects (instances of
models.Model), other variables are just integer objects. items var
becomes empty after some time, other variables are ok. Seems like I am
not allowed to hold model instances in session... But why?

On Jan 9, 8:29 pm, bradders  wrote:
> No this is Linux (SUSE10), runing behind Apache and not filesystem.
>
> John
>
> On Jan 9, 1:27 am, Malcolm Tredinnick 
> wrote:
>
> > On Thu, 2009-01-08 at 05:12 -0800, bradders wrote:
> > > I will try to put something together.   I have a fairly detailed trace
> > > that I have put in thesessioncode that shows mysessionvariables
> > > are set when it calls one of my views, but the trace shows that the
> > > nextsessionsave only a newsessionvariable set in that view exists
> > > all the othersessionvariables have disappeared. I am not knowingly
> > > clearing the other variables.
>
> > By the way, are your using Windows by any chance and the
> > filesystem-basedsessionbackend? I remembered later last night that
> > there is one bug due to problems in the Windows filesystem (#9084).
>
> > Regards,
> > Malcolm

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---