decorators and generic views

2011-03-24 Thread Ian Stokes-Rees
I think with the move to class-based Generic Views it is necessary to update 
this documentation:

Limiting access to generic views 

To limit access to a *generic 
view*, 
write a thin wrapper around the view, and point your URLconf to your wrapper 
instead of the generic view itself. For example:

from django.views.generic.date_based import object_detail
@login_requireddef limited_object_detail(*args, **kwargs):
return object_detail(*args, **kwargs)

I am trying to put an @login_required decorator around ListView.as_view(...) 
but not having any luck.  Advice on how properly map from urls.py to a 
function in the wrapped view would be appreciated.  My current best attempt 
is below

Cheers,

Ian

urls.py BEFORE:

from gridportal.wsmr.models import WSMRTask
from gridportal.wsmr.views  import list, create, view, edit, 
copy, delete, reset

urlpatterns = patterns('',
(r'tasks/?$' , ListView.as_view(model=WSMRTask)), # 
working, but no access control

urls.py AFTER:

from gridportal.wsmr.models import WSMRTask
from gridportal.wsmr.views  import list, create, view, edit, 
copy, delete, reset

urlpatterns = patterns('',
(r'tasks/?$' , list()), # not working

views.py AFTER:

@login_required()
def list(*args, **kwargs):
return ListView.as_view(model=WSMRTask)

I get the exception:

_wrapped_view() takes at least 1 argument (0 given)


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



Configuring common site URL paths for use in templates

2011-03-23 Thread Ian Stokes-Rees
I have a bunch of regular site paths that I'd like to be able to refer to 
both in my Python code and in my  templates, e.g.

settings.py:
site_root = "/portal"
contact_url = site_root + "/contact"
sitemap_url = site_root + "/sitemap"
login_url = site_root + "/account/login"
logout_url = site_root + "/account/logout"
newspost_url = site_root + "/news/post"

and then make these accessible in some random template using somthing like 
the following:

404.html:
{% extends "base.html" %}
{% block content %}
Sorry, we couldn't find that page.

Maybe it has moved -- why not look in the 
Site Directory?

If it seems like an error, please contact 
us.
{% endblock %}

Can anyone suggest a good way of doing this?

TIA,

Ian

-- 
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: FormPreview with file upload problems

2011-02-10 Thread Ian Stokes-Rees
This problem is more subtle than I had originally appreciated.  Textual data 
is just re-submitted via an embedded hidden form, and the security hash is 
used to ensure that it hasn't been modified.  File data is harder to cope 
with.  There are a few options:

1. The originally uploaded file is held in some temporary location during 
the preview stage and then moved to the final location on "submit".  This 
allows uploaded files to be part of the validation/preview processing 
chain.  The problem is that they must be removed if the final "submit" never 
happens.  It is also tricky figuring out how to put these files in some 
"temporary" location.

2. The original preview form does not include files.  These are only 
uploaded with the final "submit".  This should "just work", but the down 
side is that there is no easy way to validate things like file not uploaded 
(mandatory upload files) or that the file format/content is as expected.

3. The originally uploaded file is processed like all is well and assumes a 
"submit" will happen.  The final "submit" process then has to re-link the 
pre-uploaded file to the form object before saving it.

If there are other alternatives, I'd love to know what they are.  1. and 3. 
seem like the best plans.  I feel like I should move forward with 1.

Comments welcome.

Ian

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



FormPreview with file upload problems

2011-02-10 Thread Ian Stokes-Rees
I've followed the instructions here:

http://docs.djangoproject.com/en/dev/ref/contrib/formtools/form-preview/

to setup a form preview system.  The problem is that my form includes a 
mandatory file upload.  I modified the form template to include:



however I still have problems processing the uploaded form, with the 
"preview" step returning an error stating:

   - This field is required.

Even when the file has been supplied.  Can someone advise how I can 
modify/manage FormPreview to handle uploaded files?

Thanks,

Ian

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



upload_to chicken and egg problem

2011-02-10 Thread Ian Stokes-Rees
I would like to do the following:

class WSMRTask(GridTask):
tasktype= "wsmr"
mtz_fp  = FileField("MTZ file", upload_to=WSMRTask.path_gen)

class GridTask(Model):
tasktype= "unspec"
def path_gen(instance, filename):
return "%s/%s" % (WSMR_RELPATH, self.tasktype, self.taskname, 
self.filename)

since the properties to generate the upload_to pathname+filename come from 
the model instance itself.  I can't do this since the WSMRTask isn't defined 
at the point when I reference it (inside the class def).  Any good 
suggestions about how I can do this *other* than the obvious option of 
creating a separate module of functions that support the specific class?  
That is *so* not OO, but I'll do it if it is the only option.

Ian

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



FormPreview and ModelForms

2011-02-10 Thread Ian Stokes-Rees
I'm using FormPreview with a ModelForm.  My done() method gets the request 
and the cleaned_data once form.is_valid() evaluates to True.  I'm wondering 
if I need to do anything special to use the cleaned_data or handle the 
form-uploaded files.  My current class definition is:

class WSMRTaskFormPreview(FormPreview):
def done(self, request, cleaned_data):
WSMRTaskForm(request.POST, request.FILES).save() 
return HttpResponseRedirect(reverse('success'))

but I'm wondering if it should be:

class WSMRTaskFormPreview(FormPreview):
def done(self, request, cleaned_data):
WSMRTaskForm(cleaned_data, request.FILES).save()  # cleaned_data 
instead of request.POST
return HttpResponseRedirect(reverse('success'))

or even:

class WSMRTaskFormPreview(FormPreview):
def done(self, request, cleaned_data):
if request.FILES.has_key('mtz_fp'):
WSMRTaskForm(request.POST, request.FILES).save() 
return HttpResponseRedirect(reverse('success'))
else:
return HttpResponseRedirect(reverse('missing_files'))

TIA, Ian

-- 
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: Including apps for inherited models in INSTALLED_APPS

2011-02-08 Thread Ian Stokes-Rees
I'm (reasonably) happy to include base models in INSTALLED_APPS, but
this argument:

On 2/8/11 4:32 AM, Tom Evans wrote:
> Explicit is better than implicit. If you want models from app 'base'
> installed on your system, you add the 'base' app to INSTALLED_APPS.
> Otherwise, its a series of $MAGIC working out what apps/DB tables are
> required, and $MAGIC is never good - might as well be using rails.

feels fairly arbitrary -- the whole point of a web framework like Django
is that "magic happens", and stuff "just works".

Ian

-- 
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: read-only Form.as_* views

2011-02-07 Thread Ian Stokes-Rees


On 2/7/11 5:29 PM, Ian Stokes-Rees wrote:
> This sounds good.  Form Preview could be useful, but right now I just
> want to be able to use Generic Views (DetailView.as_view()) to render
> the default context object using "as_table()", but I'm failing to do that.
>
> {{ object.as_table }} returns nothing, whereas, {{ object.name }} etc.
> works just fine.  I don't understand why object.as_table wouldn't
> work.  Below are some code fragments.

I think I can answer my own question: as_table() is a method of
ModelForm objects, not Model objects.  So I tried pointing DetailView at
WSMRTaskForm, but now I get the exception:

type object 'WSMRTaskForm' has no attribute '_default_manager'


Frustrating!  Any suggestions?  It doesn't seem unreasonable to want the
DetailView to be able to render the "default" tabular view of the Model
created by:

class WSMRTaskForm(ModelForm):
class Meta:
model = WSMRTask

Thanks,

Ian

-- 
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: read-only Form.as_* views

2011-02-07 Thread Ian Stokes-Rees
This sounds good.  Form Preview could be useful, but right now I just want 
to be able to use Generic Views (DetailView.as_view()) to render the default 
context object using "as_table()", but I'm failing to do that.

{{ object.as_table }} returns nothing, whereas, {{ object.name }} etc. works 
just fine.  I don't understand why object.as_table wouldn't work.  Below are 
some code fragments.

Cheers,

Ian

urls.py:
(r'task/(?P\d+)/?$'  , DetailView.as_view(model=WSMRTask)),

to

templates/wsmr/wsmrtask_detail.html:


{{ object.as_table }}



-- 
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: Including apps for inherited models in INSTALLED_APPS

2011-02-07 Thread Ian Stokes-Rees


On 2/7/11 3:50 PM, Shawn Milochik wrote:
> Because when the model isn't abstract, the fields
> in the base model aren't created for the subclass -- the subclass has
> a foreign key to an instance of the base model.
> That last bit should explain why you need to have the base app in
> installed apps.

Not really -- it explains why adding it makes things work, but it
doesn't explain why I *have* to include it.  "syncdb" is smart enough to
figure out that DerivedModel(BaseModel) has django.db.models.Model
*somewhere* in its super-class ancestry, so I don't see why it can't
also be smart enough to then figure out that "BaseModel" needs to be
included for ORM automatically.

Ian

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



read-only Form.as_* views

2011-02-07 Thread Ian Stokes-Rees
I love the fact that I can quickly and easily get a "view" of my objects in 
Django, but is there any current way to get "read-only" views of objects 
where fields are not editable?  I want to be able to display the "forms" 
once they are completed but with the fields displayed just as table entries 
or textareas which can't be edited.  In other words, no  or  
tags.

TIA.  Ian Stokes-Rees

-- 
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: Including apps for inherited models in INSTALLED_APPS

2011-02-07 Thread Ian Stokes-Rees
On 2/7/11 3:38 PM, Shawn Milochik wrote:
> Is your base model abstract? If it is not, then the ORM will want to
> create it in the database.

No, it isn't abstract.  It has a particular content model and methods
associated with it.  When you say the ORM will "want" to create it in
the DB, do you mean:

1. It should figure this out on its own and create the base model table; or
2. The ORM needs this so it must be listed in INSTALLED_APPS to have the
relevant table created in the DB.

Right now it looks like the situation is 2., but I'm wondering if there
is a good reason why it can't be 1.

Thanks,

Ian

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



Including apps for inherited models in INSTALLED_APPS

2011-02-07 Thread Ian Stokes-Rees
Does it make sense that inherited models also need their apps included in 
INSTALLED_APPS?  Right now if I have:

base/models.py:

class MyBaseModel(django.db.models.Model):
   stuff

and then elsewhere:

derived/models.py:

class MyDerivedModel(base.MyBaseModel):
   stuff

I need to include both "derived" and "base" in my INSTALLED_APPS list in 
settings.py, otherwise the table for the MyBaseModel content is never 
created.  It seems to me that "syncdb" should be able to "see" that 
MyDerivedModel has MyBaseModel as a super class in the chain to 
django.db.models.Model and consequently create the necessary tables for 
MyBaseModel.

Or have I just misunderstood why it was necessary for me to include "base" 
in order to get the tables created properly by "manage.py syncdb"?

TIA, Ian Stokes-Rees

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



upload file to specific directory/id?

2008-06-25 Thread stoKes

within django is it possible to customize upload_to in order to save
the file into a /folder/id/category type situation?

so far it just dumps everything into one directory.

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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: offline application for searching entire disks of images

2008-02-22 Thread stoKes



On Feb 22, 12:03 pm, stoKes <[EMAIL PROTECTED]> wrote:
> offline application searches an entire disk for images, this is going
> to be out of the scope and control of media_url. i thought about using
> static serve, however, i think that will conflict with the other
> existing views.
>
> anyone know of a way to make this work?
>
> thanks
> adam

one option i was considering was just symlinking all results into a
media path but not sure of the overhead of that..

other options appreciated.
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



offline application for searching entire disks of images

2008-02-22 Thread stoKes

offline application searches an entire disk for images, this is going
to be out of the scope and control of media_url. i thought about using
static serve, however, i think that will conflict with the other
existing views.

anyone know of a way to make this work?

thanks
adam
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Problem setting up a separate media server

2007-01-05 Thread stoKes




On Dec 13 2006, 7:46 pm, "Joseph Heck" <[EMAIL PROTECTED]> wrote:

Good point - done.

http://code.djangoproject.com/wiki/CookBookUsingExternalMedia

-joehttp://www.rhonabwy.com/wp/

On 12/13/06, Jeremy Dunck <[EMAIL PROTECTED]> wrote:



> On 12/13/06, Joseph Heck <[EMAIL PROTECTED]> wrote:
> > We're using

> > blah blah  blah
> ...
> > And then in the settings.py under TEMPLATE_CONTEXT_PROCESSORS, we added:
> >"myproject.context_processors.common",

> > There may well be a much better way to accomplish this all, but that
> worked
> > out nicely for us.

> We're doing exactly the same thing.  This isn't a provided dj context
> processor due to the slippery slope of including all settings in
> context.  It's been raised many times.  Adding media_url should
> probably be a cookbook entry...


what about defining images in your stylesheets?


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



python syntax highlighter style change issue

2007-01-05 Thread stoKes


hi all,

using a little bit of code snippets from pygments demo app views and of
course using pygments with django for syntax highlighting. im running
into an issue where no matter what style ive selected i can't get it to
highlight properly.. to get around this ive manually copied a
stylesheet from pygments.pocoo.org and using one style at the moment.

if anyone has any experience with this i'd appreciate the help, here is
my templates/views

{% extends "base.html" %}
{% block title %}
{{ code.id }}
{% endblock %}
{% block content %}
{% load sitevars %}
Entry {{ code.id }}

Paste some code!

Style
   
   {% for style in styles %}
   {{ style }}
   {% endfor %}
   
   


   
   {{ code.hlcode }}
   

{% endblock %}


and my view
# Create your views here.
from django.http import HttpResponse, HttpResponseRedirect
from django.shortcuts import render_to_response
from django.contrib import auth
from django.contrib.auth.models import User
from djangoprojects.cpaste.models import CPaste

from pygments import highlight
from pygments.lexers import get_lexer_by_name,LEXERS
from pygments.formatters import HtmlFormatter
from pygments.styles import STYLE_MAP

from datetime import datetime

#
# globals
HTML_STYLE='trac'
fmter =
HtmlFormatter(style=HTML_STYLE,cssclass='syntax',encoding='utf-8')

lexers = [(x[1], x[2]) for x in LEXERS.values()]
lexers.sort()

lx_name = dict((lx[1][0],lx[0]) for lx in lexers)
lx_name[''] = ''

def detail(request,code_id):
   if not request.user.is_authenticated():
   user = ''
   else:
   user = request.user
   uid = User.objects.get(username=request.user)
   try:
   code = CPaste.objects.get(pk=code_id)
   _do_hl(code)
   code.save()
   except CPaste.DoesNotExist:
   return HttpResponseRedirect("/toolbox/cpaste/")
   style = request.GET.get('style')
   if style and style in STYLE_MAP:
   request.session['style'] = style
   else:
   style = request.session.get('style', 'friendly')

   return render_to_response('cpaste/detail.html',
dict(code=code,styles=STYLE_MAP.keys(),curstyle=style,user=user))

def _do_hl(code):
   lexer=get_lexer_by_name(code.sourcelang)
   code.hlcode =
highlight(code.sourcecode,lexer,fmter).decode('utf-8')

so as far as saving the content based on style that seems to work, but
i can't figure out how to push the selected style back into the
template? from what i noticed on pygments.pocoo.org is that it writes
to a /media/pygments_style.css each time a different style is
requested.

thx
adam


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: problem with inclusion_tag

2007-01-04 Thread stoKes




On Jan 4, 6:42 pm, "Jorge Gajon" <[EMAIL PROTECTED]> wrote:

On 1/4/07, stoKes <[EMAIL PROTECTED]> wrote:



> On Jan 4, 12:10 pm, "Jorge Gajon" <[EMAIL PROTECTED]> wrote:
> > Hi Adam,

> > On 1/3/07, stoKes <[EMAIL PROTECTED]> wrote:

> > > base.html
> > > {% showmenu %}
> > > {% for service in services %}
> > > {{
> > > service.name }}
> > > {% endfor %}

> > > but receiving this error:

> > > Exception Type: TemplateSyntaxError
> > > Exception Value:Invalid block tag: 'showmenu'Try putting {% load 
showmenu %} before the call to the tag, for example:

> > {% load showmenu %}
> > {% showmenu %}
> > {% for service in services %}
> > {{service.name 
}}
> > {% endfor %}

> > The {% load %} tag loads a .py file that contains your custom tags. In
> > this case it will try to load the file
> > /project/templatetags/showmenu.py

> > If the .py file with your custom tags had a different name, for
> > example "mytags.py" then you would need to type a {% load mytags %} in
> > your template before using your custom tags.

> Hey Jorge,

> I had tried that, however, this is the error I got :

> Exception Type: TemplateSyntaxError
> Exception Value:'showmenu' is not a valid tag library: Could not load
> template library from django.templatetags.showmenu, No module named
> showmenu

> i've created other templatetags before that loaded perfectly if i did
> it for a certain app, for example,

> /project/myapp/templatetags/tag.py

> but this is more of a global template tag so im not sure if my
> procedure in doing this is correct or notOh I didn't noticed that little 
detail. But no, you can't have a
"global" templatetag, your custom tags must be inside the
'templatetags' folder inside your app. This is what the documentation
says about it:

  """The {% load %} tag looks at your INSTALLED_APPS setting and only
allows the loading of template libraries within installed Django apps.
This is a security feature: It allows you to host Python code for many
template libraries on a single computer without enabling access to all
of them for every Django installation.

If you write a template library that isn't tied to any particular
models/views, it's perfectly OK to have a Django app package that only
contains a templatetags package."""

Hope it helps

Regards,
Jorge


It does, thanks for clearing that up. What I think ill do is create a
seperate layout APP and only views for things I need displayed
"globally" and just have each other app extend its template off that.

Thanks
adam


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: problem with inclusion_tag

2007-01-04 Thread stoKes




On Jan 4, 12:10 pm, "Jorge Gajon" <[EMAIL PROTECTED]> wrote:

Hi Adam,

On 1/3/07, stoKes <[EMAIL PROTECTED]> wrote:

> base.html
> {% showmenu %}
> {% for service in services %}
> {{
> service.name }}
> {% endfor %}

> but receiving this error:

> Exception Type: TemplateSyntaxError
> Exception Value:Invalid block tag: 'showmenu'Try putting {% load 
showmenu %} before the call to the tag, for example:

{% load showmenu %}
{% showmenu %}
{% for service in services %}
{{service.name }}
{% endfor %}

The {% load %} tag loads a .py file that contains your custom tags. In
this case it will try to load the file
/project/templatetags/showmenu.py

If the .py file with your custom tags had a different name, for
example "mytags.py" then you would need to type a {% load mytags %} in
your template before using your custom tags.

Regards,
Jorge


Hey Jorge,

I had tried that, however, this is the error I got :

Exception Type: TemplateSyntaxError
Exception Value:'showmenu' is not a valid tag library: Could not load
template library from django.templatetags.showmenu, No module named
showmenu

i've created other templatetags before that loaded perfectly if i did
it for a certain app, for example,

/project/myapp/templatetags/tag.py

but this is more of a global template tag so im not sure if my
procedure in doing this is correct or not
Thanks,
adam


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



problem with inclusion_tag

2007-01-03 Thread stoKes


Running into a bit of an issue trying to load a custom tag in my
base.html file.

ive got
/project/templates/base.html
/project/templatetags/showmenu.py

showmenu.py
from django.template import Library, Node
from django.contrib.auth.models import User
from django.conf import settings

register = Library()

def showmenu(user):
   services = TBService.objects.filter(user=user.id)
   return {'services': services}

register.inclusion_tag('base.html', takes_context=True)(showmenu)

base.html
{% showmenu %}
   {% for service in services %}
   {{
service.name }}
   {% endfor %}

but receiving this error:

Exception Type: TemplateSyntaxError
Exception Value:Invalid block tag: 'showmenu'

im still a bit confused on inclusion_tags, and ive searched the mailing
lists for possible explanations on implementing user specific
information in a base template file for use in template inheritance.

any guidance is appreciated
thx


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



template inheritance problem

2006-12-28 Thread stoKes


I'm having a bit of an issue with template inheritance and using the
linebreaks filter. When displaying text the linebreaks successfully get
interpreted to paragraph and br tags and the source displays them as
so. However, paragraph tags are not creating and extra line space,
everything is being interpreted as single line breaks no matter what.

has anyone run into this obscure problem before?

Note that not using template inheritance allows the text to be
displayed properly with para and br tags.

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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: manytomany not being properly generated in db

2006-12-20 Thread stoKes




On Dec 20, 2:50 am, "Russell Keith-Magee" <[EMAIL PROTECTED]>
wrote:

On 12/20/06, stoKes <[EMAIL PROTECTED]> wrote:



> However, running `python manage.py syncdb` doesn't create table
> `blogs_tag_blog` for the many to many relation. Am I missing a
> particular column to finish the relation or is it a possible bug?My initial 
guess would be that there is an old version of the Tag
table in your database - one that was created when you didn't have the
m2m relation. When syncdb looks at your model, it sees that the Tag
table already exists, so it ignores that table (thereby ignoring the
the m2m table).

'sqlall' doesn't pay any attention to the existing tables - it just
tells you what would be created if you were starting from scratch.
Hence, it correctly identifies the need for the m2m table.

If you start with a completely clean database does the problem still occur?

Yours,
Russ Magee %-)


Ah there it is :) Thanks for the explanation that will come in handy
during development :)

-Adam


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



manytomany not being properly generated in db

2006-12-19 Thread stoKes


Im using django .96-pre and searched the bug page but didn't find
anything relevant.

Here is my code model to create a 'tag' like datamodel for my blog
entries :

class Blog(models.Model):
   title = models.CharField(maxlength=200)
   body = models.TextField()
   pub_date = models.DateTimeField('date published')
   def __str__(self):
   return self.title
   def was_published_today(self):
   return self.pub_date.date() == datetime.date.today()
   was_published_today.short_description = 'Published today?'

   class Admin:
   pass
   list_display = ('title', 'pub_date', 'was_published_today')
   list_filter = ['pub_date']
   search_fields = ['title']
   date_hierarchy = 'pub_date'

class Tag(models.Model):
   name = models.CharField(maxlength=100)
   blog = models.ManyToManyField(Blog)
   def __str__(self):
   return self.name

   class Admin:
   pass

Now when running `python manage.py sqlall` i see :

ninjastance $ python manage.py sqlall blogs
BEGIN;
CREATE TABLE `blogs_blog` (
   `id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY,
   `title` varchar(200) NOT NULL,
   `body` longtext NOT NULL,
   `pub_date` datetime NOT NULL
);
CREATE TABLE `blogs_tag` (
   `id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY,
   `name` varchar(100) NOT NULL
);
CREATE TABLE `blogs_tag_blog` (
   `id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY,
   `tag_id` integer NOT NULL REFERENCES `blogs_tag` (`id`),
   `blog_id` integer NOT NULL REFERENCES `blogs_blog` (`id`),
   UNIQUE (`tag_id`, `blog_id`)
);
CREATE INDEX blogs_comment_blog_id ON `blogs_comment` (`blog_id`);
COMMIT;

However, running `python manage.py syncdb` doesn't create table
`blogs_tag_blog` for the many to many relation. Am I missing a
particular column to finish the relation or is it a possible bug?

Thanks
adam


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---