send_mail on MAC OS X 10.7

2012-10-01 Thread Cheng
Hi,

I am new to django.

I am following The Definitive Guide to Django SECOND EDITION by Adrian 
Holovaty and Jacob Kaplan -Moss and I cannot get the contact form to send 
mail. First the eg did not work at all until I added the @csrf-exempt 
decorator. Keeps getting Error 61 Connection Failure after that. 

Would be grateful if someone can help.

Thanks,
Cheng

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/r40DN0e3ybAJ.
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.

Title: Contact us



	Contact us 
	
	{% if errors %}
		
			{% for error in errors %}
			{{error}}
			{% endfor %}
		,/ul>
	{% endif %}
	  
		Subject: 
		Your e-mail(optional): 
		Message: 
		
	

	# Django settings for mysite project.

DEBUG = True
TEMPLATE_DEBUG = DEBUG

ADMINS = (
# ('Your Name', 'your_em...@example.com'),
)

MANAGERS = ADMINS

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
'NAME': 'mydb',  # Or path to database file if using sqlite3.
'USER': 'beh',  # Not used with sqlite3.
'PASSWORD': 'swallow',  # Not used with sqlite3.
'HOST': '',  # Set to empty string for localhost. Not used with sqlite3.
'PORT': '',  # Set to empty string for default. Not used with sqlite3.
}
}

# Local time zone for this installation. Choices can be found here:
# http://en.wikipedia.org/wiki/List_of_tz_zones_by_name
# although not all choices may be available on all operating systems.
# In a Windows environment this must be set to your system time zone.
TIME_ZONE = 'US/Pacific'

# Language code for this installation. All choices can be found here:
# http://www.i18nguy.com/unicode/language-identifiers.html
LANGUAGE_CODE = 'en-us'

SITE_ID = 1

# If you set this to False, Django will make some optimizations so as not
# to load the internationalization machinery.
USE_I18N = True

# If you set this to False, Django will not format dates, numbers and
# calendars according to the current locale.
USE_L10N = True

# If you set this to False, Django will not use timezone-aware datetimes.
USE_TZ = True

# Absolute filesystem path to the directory that will hold user-uploaded files.
# Example: "/home/media/media.lawrence.com/media/"
MEDIA_ROOT = ''

# URL that handles the media served from MEDIA_ROOT. Make sure to use a
# trailing slash.
# Examples: "http://media.lawrence.com/media/";, "http://example.com/media/";
MEDIA_URL = ''

# Absolute path to the directory static files should be collected to.
# Don't put anything in this directory yourself; store your static files
# in apps' "static/" subdirectories and in STATICFILES_DIRS.
# Example: "/home/media/media.lawrence.com/static/"
STATIC_ROOT = ''

# URL prefix for static files.
# Example: "http://media.lawrence.com/static/";
STATIC_URL = '/static/'

# Additional locations of static files
STATICFILES_DIRS = (
# Put strings here, like "/home/html/static" or "C:/www/django/static".
# Always use forward slashes, even on Windows.
# Don't forget to use absolute paths, not relative paths.
)

# List of finder classes that know how to find static files in
# various locations.
STATICFILES_FINDERS = (
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
#'django.contrib.staticfiles.finders.DefaultStorageFinder',
)

# Make this unique, and don't share it with anybody.
SECRET_KEY = '9xo!_4#txadx-gju-%=vc@mg5nzah9o=%zsmz8dzwnuf&)@44l'

# List of callables that know how to import templates from various sources.
TEMPLATE_LOADERS = (
'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader',
# 'django.template.loaders.eggs.Loader',
)

MIDDLEWARE_CLASSES = (
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware'

Re: send_mail on MAC OS X 10.7

2012-10-02 Thread Cheng
Hi Laxmikant,

Do you mean this statement (I can't find any other that refers to csrf) in 
settings

   'django.middleware.csrf.CsrfViewMiddleware',

I commented it, but it still gives me error 61 - Connection refused.

Thanks,
Cheng Hong


On Monday, October 1, 2012 10:36:43 PM UTC-7, Laxmikant Gurnalkar wrote:
>
> Comment the csrf from settings. It doesnt work when you want.I use session 
> and own credentials to do that 
> And just write a simple view to send mail. 
> This will work without csrf or any of credentials & etc.
>
> *Cheers* 
>
> Laxmikant
>
> On Tue, Oct 2, 2012 at 6:15 AM, Cheng 
> > wrote:
>
>> Hi,
>>
>> I am new to django.
>>
>> I am following The Definitive Guide to Django SECOND EDITION by Adrian 
>> Holovaty and Jacob Kaplan -Moss and I cannot get the contact form to send 
>> mail. First the eg did not work at all until I added the @csrf-exempt 
>> decorator. Keeps getting Error 61 Connection Failure after that. 
>>
>> Would be grateful if someone can help.
>>
>> Thanks,
>> Cheng
>>
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Django users" group.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msg/django-users/-/r40DN0e3ybAJ.
>> To post to this group, send email to django...@googlegroups.com
>> .
>> To unsubscribe from this group, send email to 
>> django-users...@googlegroups.com .
>> For more options, visit this group at 
>> http://groups.google.com/group/django-users?hl=en.
>>
>
>
>
> -- 
> * 
>
>  GlxGuru
>
> *
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/Jd23CoR6TtEJ.
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: send_mail on MAC OS X 10.7

2012-10-03 Thread Cheng
Hi Dennis,

I am not familiar with setting up the Mac. How do I check the STMP service 
on the Mac?

I am able to send email through the Mac's Mail application though. The 
outgoing mail server for the Mail application is smtp.googlemail.com. The 
incoming mail server for the Mail application is imap.googlemail.com.

Thanks,
Cheng 

On Tuesday, October 2, 2012 9:45:17 AM UTC-7, Dennis Lee Bieber wrote:
>
> On Tue, 2 Oct 2012 07:25:39 -0700 (PDT), Cheng 
> > 
>
> declaimed the following in gmane.comp.python.django.user: 
>
> > 
> > I commented it, but it still gives me error 61 - Connection refused. 
> > 
> How is the outgoing email SMTP configuration specified? 
>
>  
> -- 
> Wulfraed Dennis Lee Bieber AF6VN 
> wlf...@ix.netcom.com 
> HTTP://wlfraed.home.netcom.com/ 
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/V_tyVy8ZqSAJ.
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: send_mail on MAC OS X 10.7

2012-10-03 Thread Cheng
Hi Kobe,

I am not familiar with the Mac's setup.
Do you mean the Mac's Mail application?  If so, yes. If not, how do I start 
the sendmail program?

Thanks,
Cheng

On Wednesday, October 3, 2012 1:37:45 AM UTC-7, Kolbe wrote:
>
> did you start the sendmail program?
>
> On Tuesday, October 2, 2012 8:45:38 AM UTC+8, Cheng wrote:
>>
>> Hi,
>>
>> I am new to django.
>>
>> I am following The Definitive Guide to Django SECOND EDITION by Adrian 
>> Holovaty and Jacob Kaplan -Moss and I cannot get the contact form to send 
>> mail. First the eg did not work at all until I added the @csrf-exempt 
>> decorator. Keeps getting Error 61 Connection Failure after that. 
>>
>> Would be grateful if someone can help.
>>
>> Thanks,
>> Cheng
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/VIOCOKZcatsJ.
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.



varible reference in template problem

2008-10-06 Thread Stephen Cheng

Hi django friends

I got a problem with varible reference in template. the case is like
this:

I pass a map to a template, I am trying to get map[key], in the case
the key= modelA.id, then I have to use map.modelA.id, then it won't
work.

How can I conquer this? Can I assign modelA.id to another varible? I
don't know how to handle this. Please help.

Thank you.
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



form submission problem

2008-10-09 Thread Stephen Cheng

I defined a field title in model the max length is 30
title=models.CharField("Title",max_length=30)

while after I key in none - english characters, eg, Chinese and submit
the form, it [database] can only take 10 Chinese characters,otherwise
raise an exception.

I also use an validation rule in the clean_title method in the form to
raise an exception if the length exceeds 6, I meant to only allow 6
Chinese input.

def clean_title(self):
title = self.cleaned_data["title"]

if len(title)> 6:#6 chinese chars
raise forms.ValidationError("The message length is 
greater than
allowed: 6 Chinese")

return title

So now if I enter less than 6 Chinese, then it's valid,The safe range
for db is 30/10*6=18 english words.

I am wondering how I can treat all string from clean_xxx() same,no
mater if it's english or chinese.

btw, is the max_length in model for unicode or just for bytestring?
--~--~-~--~~~---~--~~
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: form submission problem

2008-10-09 Thread Stephen Cheng

Hi Malcolm

Sorry, I didn't express clearly because I am also not sure where the
problem is.

I figure out that the database encoding is a problem. I use
postgres8.2 and I checked that its encoding is SQL_ASCII, that's the
problem. I have corrected this and now there is no problem with saving
correct number of characters into db.

But this hasn't totally resolved the form validation problem. I got
Key Error in clean_XXX.

I try to achieve: 1) only allow user to input no more than 6
characters for title 2) the number of chacters for title + str(price)
is less than 10.

It worked fine in cases:

A) OK = 6 chars for title + 4 chars for
B) Validation Error for lean_price = 6 chars for title + 5 digit for
price
C) Key Error when = 7 chars for title +4 digit for price

Failed at if len(str(price))+len(self.clean_title())> 10: with
self.clean_title()

I know the problem is that I shall use a proper way to get form.field,
can you advise how I can get a specific field?


=Code =

class Card(models.Model):
title=models.CharField("Title",max_length=30)
price=models.IntegerField("Price",blank=True)#optional for special
card
msg=models.CharField("Message",max_length=240)

class CardForm(forms.ModelForm):
msg=forms.CharField(max_length=80,widget=forms.Textarea)

def clean_title(self):
title = self.cleaned_data["title"]

if len(title)> 6:
raise forms.ValidationError("The message length is 
greater than
allowed: 10 Chinese")

return title

def clean_price(self):
price = self.cleaned_data["price"]

if len(str(price))+len(self.clean_title())> 10:
raise forms.ValidationError("The length of title plus 
price should
be less than 10 characters")

return price

class Meta:
model=Card


On Oct 9, 10:26 pm, Malcolm Tredinnick <[EMAIL PROTECTED]>
wrote:
> On Thu, 2008-10-09 at 04:57 -0700, Stephen Cheng wrote:
> > I defined a field title in model the max length is 30
> > title=models.CharField("Title",max_length=30)
>
> > while after I key in none - english characters, eg, Chinese and submit
> > the form, it [database] can only take 10 Chinese characters,otherwise
> > raise an exception.
>
> It sounds like your database does not have the right encoding set. Are
> you doing something like using MySQL and the table encoding is set to
> latin1, rather than UTF-8? For MySQL have a look at the output of
>
> show create table 
>
> (I'm guessing MySQL here because that seems to be the one that's easiest
> to get the encoding wrong.)
>
> You should be able to store 30 unicode characters in the database, if
> the encoding is set correctly, regardless of the database (max_length
> specifies the unicode character length, not the bytestring length).
>
>
>
>
>
> > I also use an validation rule in the clean_title method in the form to
> > raise an exception if the length exceeds 6, I meant to only allow 6
> > Chinese input.
>
> >def clean_title(self):
> >title = self.cleaned_data["title"]
>
> >if len(title)> 6:#6 chinese chars
> >raise forms.ValidationError("The message length is 
> > greater than
> > allowed: 6 Chinese")
>
> >return title
>
> > So now if I enter less than 6 Chinese, then it's valid,The safe range
> > for db is 30/10*6=18 english words.
>
> > I am wondering how I can treat all string from clean_xxx() same,no
> > mater if it's english or chinese.
>
> I'm not quite sure what the problem is here. By the time you take the
> data out of cleaned_data, it will already be a unicode string. So
> there's no concept of Chinese or English or anything else. They're just
> unicode characters. Thus, the len() function is computing the length in
> characters, not the lengths in bytes when encoded as UTF-8.
>
> It sounds like you are trying to avoid a problem with the database
> encoding. Assuming that is the case, it would be better to fix that
> problem. Make sure your database tables are encoded as UTF-8 and things
> will just work without you having to worry about how many bytes the
> storage takes up. That's the reason that Django uses Unicode strings
> internally: everything requires a lot less work from the developer.
>
> So, if you need more help here, you'll need to tell us (a) what database
> backend you are using, (b) work out what the encoding on the table is,
> (c) explain what the problem

Re: form submission problem

2008-10-09 Thread Stephen Cheng

Sorry about the silly question. This is resolved. All are documented:
http://docs.djangoproject.com/en/dev/ref/forms/validation/#using-validation-in-practice

Thanks for your help!
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



distinct for ForeignKey field

2008-10-11 Thread Stephen Cheng

I am wondering how to get distinct values for a ForeignKey field

For example:
class ModelA(models.Model):
.
city=models.ForeignKey(City)

I understand that I can pass the list to template than probably use
regroup and get the group values, but is there a efficient way to
handle this without using SQL statement?

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



subdomains cookie problem

2009-06-28 Thread Stephen Cheng

Hi

I am facing a problem in DEV server that I really have no idea how to
resolve, which is related to cookie variable for subdomains.

I use wildcard subdomains, eg. sub1.abc.com, sub2.abc.com,
sub3.abc.com and all sub domains point to one running instance of
django app.

The problem is that I hope the cookievar will be available for all
subdomains but it seems django doesn't support(correct me if I am
wrong)

eg, I setup cookieabc="abc" in sub1.abc.com, however cookieabc=None
when accessing sub1.abc.com in the same view. I tried to enable
SESSION_COOKIE_DOMAIN, but it doesn't work.

I have no idea how to resolve this. Any idea?

Thanks,

Stephen
--~--~-~--~~~---~--~~
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: subdomains cookie problem

2009-06-29 Thread Stephen Cheng

Yes, I check the cookie value in view or in middleware class.

Just give example, eg, I want the browser to remember online user's
city, so next time when they type www.mydomain.com, it will be
diverted to cityx.mydomain.com.

Now the problem is that:
  1. When I setup a cookie varible cityname=city5 in
city1.mydomain.com (in a view), I expect in my middleware class to
redirect to city5.mydomain.com if the subdomain name is www, but the
cityname cookie var is none and the cityanme=city5 exists only in
subdomain city1.mydomain.com
  2. I tried to diagnose the problem and found that I have to setup
the same cookie var in each of separate subdomain view, which is not
acceptable.

Hope this clarify things.

Thanks,

Stephen

On Jun 29, 7:36 pm, Raja  wrote:
> Just checking, Are you submitting back to the server before checking
> for the cookie value ?  Cookies are sent only when the request reaches
> the server.
>
> -- Raja
>
> On Jun 29, 9:21 am, Stephen Cheng  wrote:
>
> > Hi
>
> > I am facing a problem in DEV server that I really have no idea how to
> > resolve, which is related to cookie variable for subdomains.
>
> > I use wildcard subdomains, eg. sub1.abc.com, sub2.abc.com,
> > sub3.abc.com and all sub domains point to one running instance of
> > django app.
>
> > The problem is that I hope the cookievar will be available for all
> > subdomains but it seems django doesn't support(correct me if I am
> > wrong)
>
> > eg, I setup cookieabc="abc" in sub1.abc.com, however cookieabc=None
> > when accessing sub1.abc.com in the same view. I tried to enable
> > SESSION_COOKIE_DOMAIN, but it doesn't work.
>
> > I have no idea how to resolve this. Any idea?
>
> > Thanks,
>
> > Stephen
--~--~-~--~~~---~--~~
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: subdomains cookie problem

2009-06-29 Thread Stephen Cheng

Hi Raja

This looks great.

Thanks for helping out.

Stepehn

On Jun 29, 9:17 pm, Raja  wrote:
> Setup thecookie.domain attribute value to '.mydomain.com' (The first
> dot is important) and all hosts in that domain will get thecookie.
>
> -- Raja
>
> On Jun 29, 4:01 pm, Stephen Cheng  wrote:
>
> > Yes, I check thecookievalue in view or in middleware class.
>
> > Just give example, eg, I want the browser to remember online user's
> > city, so next time when they typewww.mydomain.com, it will be
> > diverted to cityx.mydomain.com.
>
> > Now the problem is that:
> >   1. When I setup acookievarible cityname=city5 in
> > city1.mydomain.com (in a view), I expect in my middleware class to
> > redirect to city5.mydomain.com if thesubdomainname is www, but the
> > citynamecookievar is none and the cityanme=city5 exists only in
> >subdomaincity1.mydomain.com
> >   2. I tried to diagnose the problem and found that I have to setup
> > the samecookievar in each of separatesubdomainview, which is not
> > acceptable.
>
> > Hope this clarify things.
>
> > Thanks,
>
> > Stephen
>
> > On Jun 29, 7:36 pm, Raja  wrote:
>
> > > Just checking, Are you submitting back to the server before checking
> > > for thecookievalue ?  Cookies are sent only when the request reaches
> > > the server.
>
> > > -- Raja
>
> > > On Jun 29, 9:21 am, Stephen Cheng  wrote:
>
> > > > Hi
>
> > > > I am facing a problem in DEV server that I really have no idea how to
> > > > resolve, which is related tocookievariable for subdomains.
>
> > > > I use wildcard subdomains, eg. sub1.abc.com, sub2.abc.com,
> > > > sub3.abc.com and all sub domains point to one running instance of
> > > > django app.
>
> > > > The problem is that I hope the cookievar will be available for all
> > > > subdomains but it seems django doesn't support(correct me if I am
> > > > wrong)
>
> > > > eg, I setup cookieabc="abc" in sub1.abc.com, however cookieabc=None
> > > > when accessing sub1.abc.com in the same view. I tried to enable
> > > > SESSION_COOKIE_DOMAIN, but it doesn't work.
>
> > > > I have no idea how to resolve this. Any idea?
>
> > > > Thanks,
>
> > > > Stephen
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Pass context vars to django-registration

2009-05-07 Thread Stephen Cheng

I have got a case like this: I have a drop down list of value of 8
cities which requires a db query every time when every page loads. The
problem is when the url is diverted to django-registration module,
then I don't know how to properly pass the citylist as a context value
to django-registration.

I have got two solutions here:
1) For the view directly in registration module, I can just invoke my
post-processed response,
eg: in stead of using:
return render_to_response(template_name,
  { 'form': 
form },
  
context_instance=context)
   I will hack it to:
return mysiteresp(request,template_name,
  { 'form': form },
  
context_instance=context)

then in mysiteresp: I will add the context varible:cityList to the
dictionary.

I really don't like to intrude to third party's module, but this is a
way to do it.

However when the url is login, then it requires to use django's auth
view

   url(r'^login/$',
   auth_views.login,
   {'template_name': 'registration/
login.html'},
   name='auth_login'),

then I can't do anything at all, I can't touch the system level
functions. So how do I do? Any suggestion.

2) The other thought I got is to just hard code the city list in to
the base.html template. eg:


AAA
BBB
   
..


but I know that I am hesitated to do this.

Any suggestion is appreciated.

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



Admin page with my own themes/skins

2009-05-07 Thread Stephen Cheng

I have thought this for quite a while and no idea so far. I like the
forms/pages auto generated by Admin engine, but I also want to
incorporate some of the forms/pages into my site with following
expectations:

1. I can use my own template.
2. use my own template and also use the context variables from my apps
3. possibly use nicer url instead of auto url

Any thought? or this is silly?
--~--~-~--~~~---~--~~
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: Pass context vars to django-registration

2009-05-07 Thread Stephen Cheng

No bother, I have found the solution. Simply use the ContextProcessor.

On May 7, 10:27 pm, Stephen Cheng  wrote:
> I have got a case like this: I have a drop down list of value of 8
> cities which requires a db query every time when every page loads. The
> problem is when the url is diverted to django-registration module,
> then I don't know how to properly pass the citylist as a context value
> to django-registration.
>
> I have got two solutions here:
> 1) For the view directly in registration module, I can just invoke my
> post-processed response,
> eg: in stead of using:
> return render_to_response(template_name,
>   { 'form': 
> form },
>   
> context_instance=context)
>I will hack it to:
> return mysiteresp(request,template_name,
>   { 'form': form },
>   
> context_instance=context)
>
> then in mysiteresp: I will add the context varible:cityList to the
> dictionary.
>
> I really don't like to intrude to third party's module, but this is a
> way to do it.
>
> However when the url is login, then it requires to use django's auth
> view
>
>url(r'^login/$',
>auth_views.login,
>{'template_name': 'registration/
> login.html'},
>name='auth_login'),
>
> then I can't do anything at all, I can't touch the system level
> functions. So how do I do? Any suggestion.
>
> 2) The other thought I got is to just hard code the city list in to
> the base.html template. eg:
>
> 
> 
>  
> value="10">AAA
> 
>  
> value="11">BBB
>
> ..
> 
>
> but I know that I am hesitated to do this.
>
> Any suggestion is appreciated.
>
> Stephen
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Why file path and name disappear for Image Field when/after validation

2009-05-23 Thread Stephen Cheng

I suppose that all the fields' value in the form defined in model can
be captured and remained when/after you do form validation. My problem
is that :

1. When the form is not valid, the filename of image field is gone
once you click submit or
2. If I intend to do something else once all fields are valid, the
image filename is still gone.

So is this a common problem that django does not remmember the
filename? do you experience this?

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



Strange:Dev Web server crash with a python.core dump after Admin page being refreshed exactly 16 times

2008-05-31 Thread Stephen Cheng

Hi Guys

This is a very strange problem and I haven't resolved it. Dev Web
server just crash with a python.core dump and no exception log at all.

Problem occurs when you go around the Admin page, either refresh page,
add record, delete record. Now I can reproduce it by keeping refresh
the admin page exactly 16 times when just login to the admin home
page.

I found there seems to be a similar problem here:http://
code.djangoproject.com/ticket/2414, I follow the resolution: I
reinstall python with option :THREAD_STACK_SIZE=0x10 but it didn't
help.

The environment is:

FreeBSD 7
python 2.5.2
django latest svn
Postgres 8.3

The site is a just a sample site following the django book charpter 6:
Admin page, I tested with data and droping all data in db, I have used
none of own template, all are from django contrib admin template page.

Any one experienced this? I really have no idea now. could somebody
advise what the problem really is?

Stephen


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



How to handle asian language?

2008-06-01 Thread Stephen Cheng

I got exception in admin page when I input chinese character into one
field and try to save to db. I am not sure which lib I should install
to make it work or any configure I should enable.

Any advice?



UnicodeEncodeError at /admin/books/author/add/
'ascii' codec can't encode characters in position 0-2: ordinal not in
range(128)
Request Method: POST
Request URL:http://192.168.1.166:1920/admin/books/author/add/
Exception Type: UnicodeEncodeError
Exception Value:'ascii' codec can't encode characters in position
0-2: ordinal not in range(128)
Exception Location: /home/stephen/python-lib/lib/python2.5/site-
packages/django/utils/encoding.py in force_unicode, line 53
Python Executable:  /home/stephen/python-lib/bin/python
Python Version: 2.5.2
Python Path:[''/home/stephen/python-lib/lib/python2.5/site-packages/
setuptools-0.6c8-py2.5.egg', '/home/stephen/python-lib/lib/
python25.zip', '/home/stephen/python-lib/lib/python2.5', '/home/
stephen/python-lib/lib/python2.5/plat-freebsd7', '/home/stephen/python-
lib/lib/python2.5/lib-tk', '/home/stephen/python-lib/lib/python2.5/lib-
dynload', '/home/stephen/python-lib/lib/python2.5/site-packages', '/
home/stephen/python-lib/lib/python2.5/site-packages/Numeric', '/home/
stephen/python-lib/lib/python2.5/site-packages/PIL', '/home/stephen/
python-lib/lib/python2.5/site-packages/gtk-2.0', '/usr/local/lib/
python2.5/site-packages', '/usr/local/lib/python2.5/site-packages/
Numeric', '/usr/local/lib/python2.5/site-packages/PIL', '/usr/local/
lib/python2.5/site-packages/gtk-2.0']
Server time:Sun, 1 Jun 2008 08:07:24 -0500


Environment:

Request Method: POST
Request URL: http://192.168.1.166:1920/admin/books/author/add/
Django Version: 0.97-pre-SVN-7568
Python Version: 2.5.2
Installed Applications:
['django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.sites',
 'TestSite.books',
 'django.contrib.admin']
Installed Middleware:
('django.middleware.common.CommonMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.middleware.doc.XViewMiddleware')


Traceback:
File "/home/stephen/python-lib/lib/python2.5/site-packages/django/core/
handlers/base.py" in get_response
  82. response = callback(request, *callback_args,
**callback_kwargs)
File "/home/stephen/python-lib/lib/python2.5/site-packages/django/
contrib/admin/views/decorators.py" in _checklogin
  62. return view_func(request, *args, **kwargs)
File "/home/stephen/python-lib/lib/python2.5/site-packages/django/
views/decorators/cache.py" in _wrapped_view_func
  44. response = view_func(request, *args, **kwargs)
File "/home/stephen/python-lib/lib/python2.5/site-packages/django/
contrib/admin/views/main.py" in add_stage
  266. LogEntry.objects.log_action(request.user.id,
ContentType.objects.get_for_model(model).id, pk_value,
force_unicode(new_object), ADDITION)
File "/home/stephen/python-lib/lib/python2.5/site-packages/django/
utils/encoding.py" in force_unicode
  53. s = unicode(str(s), encoding, errors)

Exception Type: UnicodeEncodeError at /admin/books/author/add/
Exception Value: 'ascii' codec can't encode characters in position
0-2: ordinal not in range(128)

--~--~-~--~~~---~--~~
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: Strange:Dev Web server crash with a python.core dump after Admin page being refreshed exactly 16 times

2008-06-01 Thread Stephen Cheng

Hi

I resolve the problem, but this was a long way to make it and so far i
am still not sure why and how it's been resolved.

What I did was as follow:

1. I doubt python version, then I uninstall python 2.5.1 and install
2.5.2,I actually use virtual python but this has nothing to do with
the problem. it doesn't resolve the problem.

2. Then I decide to see how's going with 2.4.3. I install 2.4.3 and
use vitrual python to link to real binary file, it's even worse,I
couldn't even start up the django shell or db shell. all of them dump
the python.core immediately.

3. I tried to install 2.5 and 2.4 both and use them separately, and I
have installed them for over 10 times again and again.

4. Suddenly when i switch back to use python2.5, and I tried as usual
to refresh admin page for 16 times and it passed and doesn't happen
again.

I have no idea what I have done or switched on during the process,
it's just working fine now :)

Hope this help some others.

On Jun 2, 12:32 am, "Karen Tracey" <[EMAIL PROTECTED]> wrote:
> On Sun, Jun 1, 2008 at 2:41 AM, Stephen Cheng <[EMAIL PROTECTED]>
> wrote:
>
>
>
>
>
> > Hi Guys
>
> > This is a very strange problem and I haven't resolved it. Dev Web
> > server just crash with a python.core dump and no exception log at all.
>
> > Problem occurs when you go around the Admin page, either refresh page,
> > add record, delete record. Now I can reproduce it by keeping refresh
> > the admin page exactly 16 times when just login to the admin home
> > page.
>
> > I found there seems to be a similar problem here:http://
> > code.djangoproject.com/ticket/2414, I follow the resolution: I
> > reinstall python with option :THREAD_STACK_SIZE=0x10 but it didn't
> > help.
>
> > The environment is:
>
> > FreeBSD 7
> > python 2.5.2
> > django latest svn
> > Postgres 8.3
>
> > The site is a just a sample site following the django book charpter 6:
> > Admin page, I tested with data and droping all data in db, I have used
> > none of own template, all are from django contrib admin template page.
>
> > Any one experienced this? I really have no idea now. could somebody
> > advise what the problem really is?
>
> I don't have any idea, but I notice that you are the second person in as
> many days to report a really weird problem on the FreeBSD 7/python 2.5.2
> combination, see:
>
> http://groups.google.com/group/django-users/browse_thread/thread/535a...
>
> Particularly in your case, it makes me suspicious there is something screwy
> with the Python on this platform.  Pure Python code (as Django is) should
> not be able to cause a core dump.
>
> 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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Dojo vs Mochikit for Django dev?

2006-10-17 Thread Cheng Zhang


On Oct 18, 2006, at 2:53 AM, iain duncan wrote:

> I have not dug into either Dojo or Mochikit yet and am wondering if  
> one
> is more suited to Django dev than the other for adding AJAX type bells
> and whistles. Pros and Cons of either?

Recently we ran into JQuery [1], a very exciting Javascript library.  
We are now considering to replace our usage of Dojo with JQuery. If  
you are interested, highly recommended to check out Visual JQuery  
Magazine [2] and it's mother site Visual JQuery [3].

[1] http://jquery.com/
[2] http://visualjquery.com/magazine.html
[3] http://visualjquery.com/


-Cheng Zhang
http://www.ifaxian.com
1st Django powered site in Chinese ;-)
http://www.aiyo.cn
Our 2nd Django powered site in Chinese


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



Re: Django & Movable Python

2006-10-25 Thread Cheng Zhang


On Oct 25, 2006, at 3:44 PM, Perica Zivkovic wrote:

>
> People,
>
> movable python is cool but I think open should remain open without any
> fees. So, few days ago, just for experiment, I placed python 2.5 +
> django on a usb stick and it worked! :) now I'm able to carry my work
> setup all around... didn't tested it much but I created django test
> site and it starts and you can access it in a browser. Sqlite3 works
> also so in next few days I will be testing that. If you people are
> interested I can pack it and drop it somewhere on the web so you can
> also play with it. Hell, we can even make a small project "Django on a
> stick" and spread that nice warm feeling called Django to the rest of
> the world :)
>
> Ideas? Suggestions?

Cool idea, +1!
Please get something started soon.


-Cheng Zhang
http://www.ifaxian.com
1st Django powered site in Chinese ;-)
http://www.aiyo.cn
Our 2nd Django powered site in Chinese


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



Re: How to auto create a from Model just the Admin do?

2006-10-30 Thread Cheng Zhang


On Oct 27, 2006, at 9:57 PM, 张沈鹏 wrote:

> as title,
> if I has a class like this
>
> class Media(models.Model):
>fileByte = models.IntegerField('文件大小(单位:字节)')
>fileName = models.CharField('文件名',maxlength='255')
>class Admin: pass

zsp007:

Because English is the default language of this m-list, please try  
not to have Chinese characters within your post, that might confuse  
other non-Chinese speaking participants.

Thanks.



-Cheng Zhang
http://www.ifaxian.com
1st Django powered site in Chinese ;-)
http://www.aiyo.cn
Our 2nd Django powered site in Chinese


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



Re: looking for Django Contractors

2006-11-01 Thread Cheng Zhang


On Nov 1, 2006, at 2:33 PM, Benjamin Ward wrote:

> Hey good people,
>
> I'm wondering where i should post a Job availability? Is there a site
> that could be recommended?
>
> I'm wanting to find some talented Django developers to work on a site
> i'm building. It's a new site for the Record Label i work for - quite
> a big scope. I've managed to convince my Boss that Django is the way
> to go, but deadlines are pressing in and i'd like to get some more
> hands on deck. i don't mind tele-commuters, as long as time-zones are
> favourable etc. I'm in Sydney Australia.
>
> Is this list an appropriate forum for a Job listing?

Our company does Django based web project via an onsite/offshore  
model mainly for clients in United States. Our humble static pages  
are http://www.aragonconsultinggroup.com/.
If you are interested in working with engagement manager located in  
San Francisco, California and engineering team in Beijing, China, we  
can discuss more.

BR,
-Cheng Zhang
Gentoo/Python/Django Powered
http://www.ifaxian.com
1st Django powered site in Chinese ;-)
http://www.aiyo.cn
Our 2nd Django powered site in Chinese


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



Re: So I made a forum with Django

2006-11-03 Thread Cheng Zhang


On Nov 4, 2006, at 2:15 AM, argh44z wrote:

>
> Here: http://huzzah.cc/
>
> I'm thinking about cleaning up the code and open-sourcing it. Is  
> anyone
> interested? I ask this because 3 weeks ago when I started working on
> it, I didn't really see much forum software written with Django that
> was in much actual usage. There were things like Zyons and Myghty, but
> I didn't see many sites using them.
>
> I'm very impressed with Django btw. I hadn't heard of Django 4 weeks
> ago, picked it up, very easy to learn and use, and quite powerful.

Another happy Django story. :-)
+1! Looking forward to.


-Cheng Zhang
Gentoo/Python/Django Powered
http://www.ifaxian.com
1st Django powered site in Chinese ;-)
http://www.aiyo.cn
Our 2nd Django powered site in Chinese


--~--~-~--~~~---~--~~
 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: High Load

2006-12-08 Thread Cheng Zhang


在 2006-12-4,下午6:34,graham_king 写道:

>  What web server are you using in development ? I suspect this  
> might be
> a lighttpd / fastcgi problem. Have you tried Apache / mod_python ?
>
>  Just as a reference I'm managing 90,000+ hits a day on one Apache  
> on a
> UML virtual server, with the load rarely going above 2. With you setup
> and Django you should be able to take on the world :-)

Graham

I am interested to know about your UML virtual server's  
configuration. We use UML VPS from Linode [1]. With the plan of 150Mhz 
+ CMR, 150MB, our Django app is running on Gentoo 2006.1, Postgres  
8.1.5, Lighttpd w/ scgi. The speed to the site is visually slow.

[1] http://www.linode.com/products/linodes.cfm


-Cheng Zhang
Gentoo/PostgreSQL/Lighttpd/Python/Django/jQuery Powered
(Web) http://www.aragonconsultinggroup.com
http://www.ifaxian.com
1st Django powered site in Chinese ;-)
http://www.aiyo.cn
Our 2nd Django powered site in Chinese


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



IOError: Client read error (Timeout?)

2006-07-02 Thread Qi Cheng

Hi, guys.
This is a problem that troubled me for months, but maybe it is very
easy to you.

I guess it is an problem that has something relation with mod-python or
cookie, but I am not sure. Since many corresponding softwares I use,
between our production and develope server, are the same except
Linux/Debian version. But on production server, SOMETIMES this error
will be encountered, while on develop server, this error NEVER happens.

The behavior that cause this error is an ajax call, that will generate
some HTML elements on the pages. Simply to say, it is something like,
when I click a button in the page, there will be some TABLES added to
the current page. Then comes the problem, sometimes it works,
sometimes, it fails when I am using IE. But in firefox, it is always
okay.

The following are the error log get from django:

Traceback (most recent call last):

  File "/usr/lib/python2.3/site-packages/django/core/handlers/base.py",
line 113, in get_response
request_repr = repr(request)

  File
"/usr/lib/python2.3/site-packages/django/core/handlers/modpython.py",
line 16, in __repr__
return
''
% \

  File
"/usr/lib/python2.3/site-packages/django/core/handlers/modpython.py",
line 45, in _get_post
self._load_post_and_files()

  File
"/usr/lib/python2.3/site-packages/django/core/handlers/modpython.py",
line 28, in _load_post_and_files
self._post, self._files =
httpwrappers.QueryDict(self.raw_post_data),
datastructures.MultiValueDict()

  File
"/usr/lib/python2.3/site-packages/django/core/handlers/modpython.py",
line 95, in _get_raw_post_data
self._raw_post_data = self._req.read()

IOError: Client read error (Timeout?)


Request repr() unavailable



 software version I am using 

Apache2 : 2.0.55-4
Mod-pyton: 3.1.3-3
Django: 0.91 r2509
Linux/Debian: 2.6.12.2, error happenes at this server, which is our
production server
Linux/Debian: 2.6.8.1, this one works fine, which is our development
server
Browser: IE 6.0 sp2  

Any suggestions will be appreicated. Thanks.

BR~
ChengQi


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



Re: Compilation of 30 Django tutorials

2006-07-18 Thread Cheng Zhang

Great collection. :-)
Will it be more informational if there is one line of summary for  
each tutorial?

- Cheng

On Jul 18, 2006, at 3:34 AM, [EMAIL PROTECTED] wrote:

>
> Hi all,
>
> I put together a compilation of 30 Django tutorials. They're mostly
> from the community page but I think it's nice to have them in a  
> concise
> list. I also posted it onto digg so go digg it!
>
> Thanks to all the writers of the tuts. They've been and are really
> helpful to me.
>
> Direct link.
> http://blixtra.org/blog/2006/07/17/top-30-django-tutorials-and- 
> articles/
>
> Digg link.
> http://digg.com/programming/Top_30_Django_Tutorials_and_Articles
>
> The Rails list that spurred me to write it.
> http://digg.com/programming/TOP_30_Ruby_on_Rails_Tutorials
>
> Chris
>
>
> >


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



Re: New - monkey

2006-07-23 Thread Cheng Zhang

Of 'coz you can download everything needed on your windows box, then  
transfer over.

- Cheng

On Jul 21, 2006, at 7:59 PM, Rajeshwar Singh Jenwar wrote:

> Hi ALL,
> I m new to Django.
> My linux box does not have net connection.
> Can someone suggest me how to intsall Django with MySQL on Linux RH  
> FC4 without net connection.
> Anyway i can transfer file on Linux machine from my windows machine  
> by FTP.
>
> >


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



Re: [Changeset] r3455 - django/trunk/docs

2006-07-26 Thread Cheng Zhang

Adrian

Would you mind to point out which OSCON presentation it is? Just  
curious. Thanks.

- Cheng Zhang

On Jul 27, 2006, at 8:46 AM, [EMAIL PROTECTED] wrote:

>
> Author: adrian
> Date: 2006-07-26 19:46:32 -0500 (Wed, 26 Jul 2006)
> New Revision: 3455
>
> Modified:
>django/trunk/docs/contributing.txt
> Log:
> Added 'Please do not put your name in the code' section to docs/ 
> contributing.txt. Thanks to OSCON presentation for the inspiration
>
> Modified: django/trunk/docs/contributing.txt
> ===
> --- django/trunk/docs/contributing.txt2006-07-26 21:30:14 UTC (rev  
> 3454)
> +++ django/trunk/docs/contributing.txt2006-07-27 00:46:32 UTC (rev  
> 3455)
> @@ -168,6 +168,10 @@
>
>{{foo}}
>
> +* Please don't put your name in the code. While we appreciate all
> +  contributions to Django, our policy is not to publish  
> individual
> +  developer names in code -- for instance, at the top of  
> Python modules.
> +
>  Committing code
>  ===
>
>
>
> >


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



Re: generic ModifiedPreorderTreeTraversal app

2006-07-26 Thread Cheng Zhang

Great.
If you get time, I suggest you update the wiki page accordingly.

- Cheng Zhang

On Jul 27, 2006, at 12:05 PM, nkeric wrote:

> hi all,
>
> Base upon Julio's mptt-0.9 which handles nested contents:
>
> http://code.djangoproject.com/wiki/ModifiedPreorderTreeTraversal
>
> I made this more "generic" version mptt-0.95, from the README:
>
> [snip]
> orignal mptt readme
> [/snip]
>
> Follow up by me
>
> ===
>
>
>
> First of all, ***BIG Thanks*** to `Gijs Van Tulder's excellent
> article`_ on the MPTT subject &
>
> Julio's GREAT work on this django implementation!
>
>
>
> mptt-0.95 (following django's svn version number:) based on Julio's
> code, and make it even more
>
> "generic":
>
>
>
>  - Julio's version treats the root content (for example, an Article
> object which is going to be
>
>  commented/follow-up'd) & the tree of the root content differently),
> so the Node model is in
>
>  response for both "describing a tree" & "storing node content".
>
>
>
>  - In this modified version, I "limit" the Node model's responsibility
> to only "describing a
>
>  tree": you keep storing your model's data in a "flat" way, once
> necessary, you can organize
>
>  them into a "tree", and, ***you can organize this tree across all of
> the models of your site***,
>
>  that means, you can build your tree with User, Article, Group,
> WhatEver model's object instances
>
>  as the tree's node:)
>
>
>
> While comparing the code between Julio's original version and my
> modified version, please note:
>
>
>
> Both versions are using the GenericForeignKey_ like technique, and
> both have content_type &
>
> object_id fields, however, they are different:
>
>
>
>  - Julio's version uses these fields to refer to the ***root content
> object of the Node tree***;
>
>  - This modified version uses them to refer to ***content object that
> becomes a nodes of the tree***
>
>
>
> Please check the code for detail:)
>
>
>
> Sample code
>
> ---
>
>
>
> from path.to.your.models import Article
>
> from agv.apps.mptt.models import Node
>
>
>
> a1 = Article.objects.get(pk=1)
>
> a2 = Article.objects.get(pk=2)
>
> a3 = Article.objects.get(pk=3)
>
> a4 = Article.objects.get(pk=4)
>
> a5 = Article.objects.get(pk=5)
>
>
>
> n1 = Node(content_object=a1) # the root node
>
> n1.save()
>
>
>
> # 2nd level nodes
>
> n2 = Node(content_object=a2, parent=a1)
>
> n2.save()
>
>
>
> n3 = Node(content_object=a3, parent=a1)
>
> n3.save()
>
>
>
> # 3rd level nodes
>
> n4 = Node(content_object=a4, parent=a2)
>
> n4.save()
>
>
>
> n5 = Node(content_object=a5, parent=a3)
>
> n5.save()
>
>
>
> # you can even do this
>
> from path.to.your.other.models import Banana
>
>
>
> b = Banana.objects.get(pk=1)
>
>
>
> # add the banana to the tree of articles! :-p
>
> n6 = Node(content_object=b, parent=a1)
>
> n6.save()
>
>
>
>
>
> Thanks again to Julio's code!
>
>
>
> Please help me to test it if you're interested:)
>
>
>
> Sorry for my poor English! With any problem, find me at:
>
>
>
> Eric Hsu
>
> [EMAIL PROTECTED]
>
>
>
> .. _Gijs Van Tulder's excellent article:
> http://www.sitepoint.com/print/hierarchical-data-database
>
> .. _GenericForeignKey:
> http://feh.holsman.net/articles/2006/06/19/django-generic-relations
>
> --  
> - http://www.ifaxian.com
> - http://groups.google.com/group/nkeric-daily
> - http://nkeric.3322.org
>
>
> > 


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



Re: favicon.ico displaying in page

2006-08-18 Thread Cheng Zhang


On Aug 17, 2006, at 5:22 PM, a wrote:

>
> getting and storing favicon.ico as an image, problems
> I need to get the favicon.ico using urllib2.urlretrive or somehting
> like that
> and webpages dont uniformly handle favicons.ico they dont different
> references
> such as
> /favicon.ico
> or /media/favicon.ico
> some page link the favicon to
> /favicon.ico
>
> and some others
>  href="http://cache.valleywag.com/assets/www.valleywag.com/img/ 
> favicon.ico"/>
>
> is there an easy way to handle this, if anyone has done this, pls  
> share
>
> thanks a lot
> as i m doing an aggregator, i need to display these icons next to the
> content
> so i was asking if some1 has experience doing this
> thanks
>

I found this article (http://www.kryogenix.org/days/2005/01/31/ 
favatarsUrlparse) might be helpful to you.

-Cheng Zhang
http://www.ifaxian.com
1st Django powered site in Chinese ;-)




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



Re: Mac vs. PC for Django work.

2006-09-15 Thread Cheng Zhang


On Sep 13, 2006, at 11:21 PM, Eric Walstad wrote:

> One of the developers on my team works on a Mac, while the other  
> two of
> us are on Linux.  Our apps are deployed on Linux PC machines.  The Mac
> guy had a harder time setting up his development environment,  
> having to
> compile more packages from source, than we Linux guys did.  However,
> once set up, we had few issues with cross-platform compatibility.  One
> was that there were some differences in the capabilities of the Mac
> Python, if I recall correctly, that forced us to drop the use of
> Django's 'include' template tag.  That was wayyy back in the  
> days of
> Django 0.91, though, so that may no longer be an issue on Django  
> trunk.

I am surprised to know that. In our situation, I write code on my  
Mac, and we deploy on Gentoo Linux. No any single compatibility issue  
or setup issue at all. Setting up our dev environment on Windows is a  
bit tricker than on Mac or Gentoo Linux, but it's still pretty smooth.

If your Mac guy use the stock Python installation (2.3) comes with  
Mac OS X, then he should upgrade it from http://pythonmac.org/ 
packages/py24-fat/index.html immediately.
With the combined help from that link, easy_install and darwinports 
(now rename as macports)/fink, the Mac ride will be flawless.


-Cheng Zhang
http://www.ifaxian.com
1st Django powered site in Chinese ;-)
http://www.aiyo.cn
Our 2nd Django powered site in Chinese


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



Re: Mac vs. PC for Django work.

2006-09-15 Thread Cheng Zhang


On Sep 14, 2006, at 8:01 PM, spacedman wrote:

> I'd be tempted to say to do your development on the platform that most
> closely matches your deployment platform. We're using Apache and
> mod_python on our own Linux web server here, so that's the best thing
> for development for us.

My opinion is that doesn't matter. We are going with the most  
convenience/comfortable route.
IMHO the built-in web server is perfect for development usage,  
autoloading, easy message output on console, etc.
Apache + mod_python is only one way out of many Django deployment  
methods. In our experience, lighttpd + scgi is much better than that.  
Again, pick what is the most comfortable one is always our guideline.


-Cheng Zhang
http://www.ifaxian.com
1st Django powered site in Chinese ;-)
http://www.aiyo.cn
Our 2nd Django powered site in Chinese


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



Re: Mac vs. PC for Django work.

2006-09-15 Thread Cheng Zhang

Totally agree with Tyson. You won't regret picking a Mac for Django/ 
Python or any web design work at all.
TextMate is a great editor, at least as much powerful as Vim or  
Emacs, with a overwhelmingly damn pretty looking and enjoyable GUI.  
The only con of TextMate is it ain't free and open source. :-)
Rails guys are using Mac everywhere, since they also know the joy of  
using Mac and TextMate.

The only con of Mac might be the price if you are also looking at a  
Dell laptop, but if your eyes are on a ThinkPad, you might be  
surprised by the price of equally equipped Mac laptop.
My 867MHz/768MB PowerBook G4 still serve my work and life pretty  
well, after all these 3 years. :-)
And it's getting faster and faster with each update from Apple. It  
might be a surprise if you come from Windoze world, but that's pretty  
normal with Linux world as well. With the improvement on  
infrastructure open-source software like GCC, the same set of app  
will run faster on the same set of hardware.


-Cheng Zhang
http://www.ifaxian.com
1st Django powered site in Chinese ;-)
http://www.aiyo.cn
Our 2nd Django powered site in Chinese

On Sep 14, 2006, at 1:13 AM, Tyson Tate wrote:

>
> Heck, why not get the best of both worlds: Get a MacBook or other
> Intel Mac. You can run the delicious UNIX-y goodness of MacOS X for
> real work and then drop in to Windows when you need to do whatever it
> is that people would want to do in Windows (get headaches?).
>
> Django works wonderfully on MacOS X. It's a perfect development
> environment, really. TextMate, the Mac-only text editor, is one of
> the best programming editors out there (aside from Vim and Emacs, I
> guess). There's also a few Django bundles out there for TextMate
> which are amazingly useful in hammering out code quickly.
>
> -Tyson
>
> On Sep 13, 2006, at 8:01 AM, keukaman wrote:
>
>> I am in the market for a notebook computer that I will be doing my  
>> web
>> design work on. Could I get some comments related to which is better
>> for Django work - P.C. or Mac, as well as some pros & cons of each?
>> 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
-~--~~~~--~~--~--~---



Re: Editing inline object individually

2005-11-17 Thread Qi Cheng

> For the specific case of editing an inline_edited object seperately in
> its own admin form, (which I believe the original poster would be
> satisfied with as a stop gap measure), this should already work in
> new-admin AFAIK. The foreign key with edit_inline=whatever is rendered
> as a foreign key select field like any other, ie you can select the
> objects "parent".

We are now developping 3 level interface with new-admin branch exactly
like original poster, and found out that need modify tons of lines of
source code, not an easy work.
Would you please let us know from where/who we can get the working
admin, or how long will it be merged into [new-]admin.

Thanks.



Re: ZODB Anyone ?

2005-11-20 Thread Cheng Zhang


I am curious to learn more about why "object DBs are not good fit for  
the MVC-like separation". Previously I had very basic exposure to  
ZODB, along with the concept of object database, when I played with  
Zope a bit years ago.


Thanks.
- Cheng

On Nov 20, 2005, at 1:12 PM, Tom Tobin wrote:


ZODB is an object database, not a relational one; based on my
experience with it and other object DBs, it's not a good fit for the
MVC-like separation Django adheres to.





OODB with Django? Was Re: ZODB Anyone ?

2005-11-20 Thread Cheng Zhang


Informative pointer!
I read the introduction of Moellus. Seems to me that it offers a even  
quicker way of rapid prototyping. When we frequently change the model  
during cycles of rapid prototyping, there is no need to manually  
alter the tables in RDB to make it consistent with the model over and  
over again, since the model and the DB is one entity. Once the  
changes to the model settle down, we can map it to a relational  
implementation (at least Moellus claims it's easy to do so). This  
way, we can gain both the speed in the development phase and the  
stability and performance in the deployment phase.


- Cheng

On Nov 20, 2005, at 7:22 PM, mario ruggier wrote:

One of these is the moellus package, that is a layer on top of the  
small Durus OODB (that is a ZODB-inspired OODB, but intentionally  
simpler), that organizes items (objects) in containers (tables).  
The package allows you to define an object model, similar to an  
ORM. However, you can think of this as an ORM without the mapping  
layer, as your model *is* your database. Other advantages you get  
for free are real object references, as well as typically difficult- 
to-have features such as "mutable compound primary keys". Moellus  
is at:

<http://ruggier.org/software/moellus/>




How do I specify default value for a form field while using manipulator

2005-11-22 Thread Cheng Zhang


How do I specify default value for a form field, which maps to a  
foreign key as Poll.submitted_user shown below, with manipulator, in  
particular AddManipulator? I couldn't find relevant information from  
the django-users archive, at least searching with keywords:  
manipulator, default didn't help.


My model is:
class Poll(meta.Model):
question = meta.CharField(maxlength=200)
pub_date = meta.DateTimeField('date published')
submitted_user = meta.ForeignKey(users.User)

In the template for creating a poll, I use the form manipulator of  
'coz. Partially it is:



question: {{ form.question }}
{% if form.question.errors %}*** {{ form.question.errors|join:",  
" }}{% endif %}



pub_date: {{ form.pub_date }}
{% if form.pub_date.errors %}*** {{ form.pub_date.errors|join:",  
" }}{% endif %}



submitted_user:  
{{ form.submitted_user }}
{% if form.submitted_user.errors %}***  
{{ form.submitted_user.errors|join:", " }}{% endif %}





To add a new poll, when I login as a user, say 'test1', I want the  
'submitted_user' form field (render as a pulldown list) to be  
selected as 'test1' automatically. It would be better if this field  
is disabled or hidden from the page.
Currently, I have no idea how to do so. Any suggestions will be  
appreciated. Thanks a lot.


- Cheng



Re: How do I specify default value for a form field while using manipulator

2005-11-22 Thread Cheng Zhang


Thanks. Guess I should get the habit of searching wiki, esp. the  
cookbook.


On Nov 22, 2005, at 9:21 PM, Grigory Fateyev wrote:


http://code.djangoproject.com/wiki/CookBookManipulators there are two
ways to do this stuff.




Re: Django job in Dallas, Texas

2005-11-22 Thread Cheng Zhang


Looks like Django is starting to occupy the fields of news  
organization, beyond the stronghold of World Online. :-)
Hopefully we will see such signs all over the world in near future,  
indicating the rapid occupation/adaptation of Django, at least as a  
competent counterpart of Rails.


- Cheng

On Nov 22, 2005, at 11:54 PM, Adrian Holovaty wrote:



I spotted this on the Dallas craigslist:

"""
Pegasus News is looking for a Python programmer -- better yet for you
and us if you're versed in Django -- to help with some light
programming/tweaking on pre-existing content management system.
"""

http://dallas.craigslist.org/art/112889763.html

Adrian





Re: Standalone template language

2005-11-24 Thread Cheng Zhang


It's possible, based on my limited knowledge of Django. I think such  
usage is more like using a Python library.
In your case, you need to set the environment variable  
DJANGO_SETTINGS_MODULE as shown in tutorial 1, e.g. export  
DJANGO_SETTINGS_MODULE=myproject.settings


- Cheng

On Nov 24, 2005, at 6:20 PM, paolo wrote:



I wonder if it's possible to use Django's template engine outside of
Django.

I tried to import Template from django.core.template but Python
interpreter complains about undefined DJANGO_SETTINGS_MODULE.





Re: replaces_module

2005-11-29 Thread Cheng Zhang



On Nov 29, 2005, at 10:26 PM, Adrian Holovaty wrote:


   class META:
   db_table = 'anastas_users'
   replaces_module = 'auth.users'
   admin = meta.Admin()
   # field names to remove from parent model
   remove_fields = ['password', 'is_staff', 'is_superuser']


Would you please elaborate this new meta option 'replaces_module',  
which I couldn't find in the doc?

Thanks.

- Cheng



Re: Which user posted the blog entry.

2005-12-12 Thread Cheng Zhang



On Dec 12, 2005, at 10:11 PM, [EMAIL PROTECTED] wrote:



I was digging around the source for djangoproject.com and noticed that
in the blog model, it looks like the user has fills in the "author" as
a text field.  Is there a better way for the blog to know which user
posted that entry?  Can that info be gotten by who was logged in and
made that post?



Of 'coz, for example you can use
author = meta.ForeignKey(users.User)
for your purpose.

- Cheng



Re: [NOOB] ImportError: No module named django.core

2005-12-13 Thread Cheng Zhang



On Dec 13, 2005, at 9:43 PM, patrick kranzlmüller wrote:



i just wanted to create a new app using
django-admin.py startapp manage

and i get the error
ImportError: No module named django.core

by the way, i already created an app last week, which worked fine.

patrick


This is due to old *.pyc files as I know. Searching the group archive  
will help you with many previous replies.




Modeling a category entity which has parent-child structure

2005-12-13 Thread Cheng Zhang


I am trying to model a category entity which has parent-child  
structure. My model is:


class Category(meta.Model):
parent = meta.ForeignKey(Tag, related_name="parent_category")
child = meta.ForeignKey(Tag, related_name="child_category")
class META:
admin = meta.Admin()

def __repr__(self):
return str(self.get_child().name)

If parent is as same as child, this is considered as top-level  
category. But how may I use db api to get such top-level categories?

categorys.get_list(parent__exact=child__exact) doesn't work.

Thanks.

- Cheng



Re: Modeling a category entity which has parent-child structure

2005-12-13 Thread Cheng Zhang



On Dec 13, 2005, at 10:53 PM, Alex Bondarenko wrote:


On 12/13/05, Cheng Zhang <[EMAIL PROTECTED]> wrote:


I am trying to model a category entity which has parent-child
structure. My model is:

...

If parent is as same as child, this is considered as top-level

Maybe just use "parent == None" condition?
And child field. as  ForeignKey... Your parents have only one child?


The parent==child thing doesn't work as easily as I thought. So I  
changed to mark top-level category as parent is null.
The help comes from "Many-to-one relationships that can be  
null" (http://www.djangoproject.com/documentation/models/ 
many_to_one_null/)


The child is a ForeignKey to Tag, a parent can have more than one  
children.




Re: Additional User Data?

2006-01-03 Thread Cheng Zhang


I had the similar (or the same) error with my customer User_Profile  
model, when I specify nothing for admin, like

admin = meta.Admin(
)
If I specify something like 'list_display', the error is gone.
admin = meta.Admin(
list_display = ('user', 'location', 'website',),
)

I don't need to specifying 'ordering' parameter for admin, just FYI.

- Cheng


On Jan 3, 2006, at 11:44 PM, Adrian Holovaty wrote:



On 12/31/05, Andreas Neumeier <[EMAIL PROTECTED]> wrote:

But when I try to use the admin interface, it gives me bad errors:

--- cut ---
OperationalError at /app/admin/match/members/
(1109, "Unknown table 'auth_users' in order clause")
--- cut ---


Try specifying an "ordering" parameter in the admin options for your
custom user-info model.

http://www.djangoproject.com/documentation/model_api/#admin-options

Adrian


--
Adrian Holovaty
holovaty.com | djangoproject.com | chicagocrime.org




Re: ANN: "Snakes and Rubies" (Django/Rails meetup) video/audio available

2006-01-05 Thread Cheng Zhang


Cool, feels like have been waiting for this video forever. ;-)

Special cheers to Jacob's video editing efforts. I know how painful  
it could be.


- Cheng Zhang

On Jan 5, 2006, at 10:20 PM, Adrian Holovaty wrote:



Last month, there was a Django/Rails meetup in Chicago, at which I
spoke about Django and David H. of Rails spoke about Rails. Last night
we made available video and audio of both presentations, plus the Q&A
session.

Jacob spent a *ton* of time condensing the 13 hours of raw video into
nicely edited files for your downloading pleasure. Check them out
here: http://www.djangoproject.com/snakesandrubies/

Adrian

--
Adrian Holovaty
holovaty.com | djangoproject.com | chicagocrime.org




Re: models can't use globals

2006-01-10 Thread Cheng Zhang


I use such way to get around that. Don't know is there any better  
ways to do it though.


def is_mutual_friend(friend):
  """
  Test whether myself and friend is mutual friend, which means we both
  are in each other's friend list
  """
  # The next line can't be moved to the top of the file
  from django.models import get_module
  mod = get_module('portal', 'friends')
  try:
f = mod.get_object(myself__id__exact=friend.get_friend().id,
  friend__id__exact=friend.get_myself().id)
  except (KeyError, mod.FriendDoesNotExist):
return False
  else:
return True

- Cheng Zhang

On Jan 10, 2006, at 3:58 PM, Greg wrote:



When writing a method for one of my model classes, I find that I want
to access a function from another module. The reference documentation
(http://www.djangoproject.com/documentation/model_api/#model-methods)
is plenty clear on the fact that you can't just import a module at the
top of the model-definition file and then use it from within a method,
but what's the best workaround? I ended up passing it in as a default
argument:

  from django.core import meta
  import my_module
  ...
  class Poll(meta.Model):
  ...
  def my_method(self, my_module=my_module):
  return my_module.foo(self.question)

but that's not beautiful of course. And I could put the import inside
my method, but that's not ideal either. Any thoughts? Is this a
restriction that will be lifted by the magic removal branch? (And I
don't mean to sound whiny but when's the magic removal work planned to
be merged to the trunk? I can't wait!)





Re: best practices for translating content

2006-01-10 Thread Cheng Zhang


We discussed a bit about this topic in our project as well.
Surely that's one way to do it, or maybe the only practical way we  
could come up with. But the problem is once you support more than 2  
languages, keeping schema in sync will become a headache and  
definitely not DRY.


- Cheng Zhang

On Jan 10, 2006, at 3:00 PM, Kenneth Gonsalves wrote:



hi
what are the best practices for translating content in the database,
and storing that? I feel that for postgres, a separate schema for
each language may be good - that way, just something like
django-admin.py install new language would just duplicate the
necessary tables in a separate schema for that language. Comments
anyone?
--
regards
kg

http://www.livejournal.com/users/lawgon
tally ho! http://avsap.org.in
ಇಂಡ್ಲಿನಕ್ಸ வாழ்க!




Re: best practices for translating content

2006-01-10 Thread Cheng Zhang


We discussed a bit about this topic in our project as well.
Surely that's one way to do it, or maybe the only practical way we  
could come up with. But the problem is once you support more than 2  
languages, keeping schema in sync will become a headache and  
definitely not DRY.


- Cheng Zhang

On Jan 10, 2006, at 3:00 PM, Kenneth Gonsalves wrote:



hi
what are the best practices for translating content in the database,
and storing that? I feel that for postgres, a separate schema for
each language may be good - that way, just something like
django-admin.py install new language would just duplicate the
necessary tables in a separate schema for that language. Comments
anyone?
--
regards
kg

http://www.livejournal.com/users/lawgon
tally ho! http://avsap.org.in
ಇಂಡ್ಲಿನಕ್ಸ வாழ்க!




Re: Django and MS SQL

2006-01-10 Thread Cheng Zhang



On Jan 10, 2006, at 10:21 PM, Adrian Holovaty wrote:



On 1/9/06, Rich Bakos <[EMAIL PROTECTED]> wrote:
I am experimenting with Django and MS SQL and it appears that  
Django is

passing parameters to MS SQL in an incorrect format.

The params are being passed in as a format string style (%s),  
which MS

SQL chokes on.


Hey Rich,

The Django MS SQL support is still in alpha status, mostly because we
don't have many people who've tried to use it with MS SQL. We're very
keen on getting that driver up to speed, though, and you can help.

Could you paste the entire traceback you get? Also, would any other MS
SQL users in the audience be able to help?

Adrian

--
Adrian Holovaty
holovaty.com | djangoproject.com | chicagocrime.org


As matter of fact, I am trying to make pymssql backend for Django  
work since in my current project we have to inherit a MS-SQL  
database. Changing the database is definitely not an option. If  
Django can be used with MS-SQL, then I can convince the team to pick  
it. Otherwise most likely we will have to stuck with Java/Structs/ 
iBatis stack which I am not a fan of.


I get the patch for pymssql from Jakub Labath, who was also in the  
mailing list couple months ago but didn't have time to work more on  
it. The reason for picking pymssql over ado-mysql is that we'd like  
to run Django on Linux instead of Windows.


Anyway, at this point I am kind of walking in the dark, since MS-SQL  
is a new territory to me.


- Cheng



Could django filters be used in its models instead of templates ?

2006-01-10 Thread Qi Cheng

Hi

  I am implementing such a function. I have a textarea that will be
inputted many characters, when they are showed in page, they will be
displayed in one line, very ugly.So I want to change the '\n' in the
texts to ''. I know this can be implemented by wysiwig editor(e.g.
tiny_mce), and I have implemented this.But since i just want to change
'\n' to '', maybe it is not necessary to include such a big vendor
package of tiny_mce in my project.

  I found django has such filters, including escape|linebreaks, that is
just used to change '\n' to  in the template level by the
following lines :{{ text|escape|linebreaks }} . I want to know, could I
implement this kind of function in the model level?
  In django's style, it show all the filef by the following lines :{%
filter_interface_script_maybe bound_field %}, but the tag of
filter_interface_script_maybe can only be used agains filter_interface
parameter, which is just used on many_to_many field. What i want to is
to use such a parameter to a meta.TEXTFIELD. I am not sure wheter this
is possible.

  Thanks for any helps.

Steve



Re: Could django filters be used in its models instead of templates ?

2006-01-10 Thread Qi Cheng

sorry.
I have got it resolved. Seems i was in a totally wrong direction.
please ignore this question.



multiple levels of join

2006-01-11 Thread Cheng Zhang


I'd like to ask a question on multiple levels of join.

My models are:

class Entry(meta.Model):
submission_user = meta.ForeignKey(users.User)

class Friend(meta.Model):
	myself = meta.ForeignKey(users.User, related_name="myself",  
verbose_name="myself")
	friend = meta.ForeignKey(users.User, related_name="friend",  
verbose_name="friend")


How may I get a list of entry whose submission_user is in my friend  
list, which is myself == my_id?


After looking at db api doc for hours, I just can't figure it out.
Thanks for any advice.

- Cheng




Re: multiple levels of join

2006-01-12 Thread Cheng Zhang



On Jan 12, 2006, at 5:38 AM, Adrian Holovaty wrote:



On 1/11/06, Cheng Zhang <[EMAIL PROTECTED]> wrote:

class Entry(meta.Model):
submission_user = meta.ForeignKey(users.User)

class Friend(meta.Model):
myself = meta.ForeignKey(users.User, related_name="myself",
verbose_name="myself")
friend = meta.ForeignKey(users.User, related_name="friend",
verbose_name="friend")

How may I get a list of entry whose submission_user is in my friend
list, which is myself == my_id?


You can do it in two queries:

my_friends = friends.get_list(myself__exact=my_id)
entries.get_list(submission_user__in=[f.id for f in my_friends])

Adrian


Ya, that's Django's 101. I should be more specific that I'd like to  
do it with only one get_list() call.


With the help on IRC, I learned how to use where/table to do this.
entries.get_list(**{'tables' :['friends',], 'where' : 
['friends.friend_id = entrys.submission_user_id AND friends.myself_id  
= my_id']})


- Cheng



Re: Django and MS SQL

2006-01-20 Thread Cheng Zhang


Just a quick report on the status on pymssql backend, after being  
busy for nearly 2 weeks, today I finally found a big trunk of time  
(~10 hrs) to hack it, and the result is that there are only 4 errors  
(shown below) out of all Django doctests left. :-)
Anyway it's late night already and my mind started to blur. I will  
try to finish up tomorrow, clean up, and submit patches.


Please NOTE that this pymssql is different with the existing  
ado_mssql. It can run on *nix, 'coz I am hacking on my Mac.


Cheers.
- Cheng Zhang

-
'basic' module: API test raised an exception

Code: 'a101.save()'
Line: 162
Exception:   File "/Users/czhang/project/workspace/svk/django_trunk/ 
tests/doctest.py", line 1243, in __run

compileflags, 1) in test.globs
  File "", line 1, in ?
a101.save()
  File "/Users/czhang/Library/Python/2.4/site-packages/django/utils/ 
functional.py", line 3, in _curried
return args[0](*(args[1:]+moreargs), **dict(kwargs.items() +  
morekwargs.items()))
  File "/Users/czhang/Library/Python/2.4/site-packages/django/core/ 
meta/__init__.py", line 1029, in method_save

','.join(placeholders)), db_values)
  File "/Users/czhang/Library/Python/2.4/site-packages/django/core/ 
db/base.py", line 15, in execute

raise e
Exception: ("internal error: None (SQL Server message 544, state 1,  
severity 16:\nCannot insert explicit value for identity column in  
table 'basic_articles' when IDENTITY_INSERT is set to OFF.\n),  
sql=INSERT INTO [basic_articles] ([headline],[pub_date],id) VALUES  
('Article 101','2005-07-31 12:30:45',101), operation=INSERT INTO  
[basic_articles] ([headline],[pub_date],id) VALUES (%s,%s,%s), params= 
['Article 101', '2005-07-31 12:30:45', 101]", 'INSERT INTO  
[basic_articles] ([headline],[pub_date],id) VALUES (%s,%s,%s)',  
"['Article 101', '2005-07-31 12:30:45', 101]")



'basic' module: API test raised an exception

Code: 'a101 = articles.get_object(pk=101)'
Line: 163
Exception:   File "/Users/czhang/project/workspace/svk/django_trunk/ 
tests/doctest.py", line 1243, in __run

compileflags, 1) in test.globs
  File "", line 1, in ?
a101 = articles.get_object(pk=101)
  File "/Users/czhang/Library/Python/2.4/site-packages/django/utils/ 
functional.py", line 3, in _curried
return args[0](*(args[1:]+moreargs), **dict(kwargs.items() +  
morekwargs.items()))
  File "/Users/czhang/Library/Python/2.4/site-packages/django/core/ 
meta/__init__.py", line 1360, in function_get_object
raise does_not_exist_exception, "%s does not exist for %s" %  
(opts.object_name, kwargs)

ArticleDoesNotExist: Article does not exist for {'pk': 101}


'subclassing' module: API test failed
=
Code: 'a3.pub_date'
Line: 66
Expected: 'datetime.date(2005, 8, 22)\n'
Got: 'datetime.datetime(2005, 8, 22, 0, 0)\n'

'subclassing' module: API test failed
=
Code: 'a4.pub_date'
Line: 86
Expected: 'datetime.date(2005, 8, 22)\n'
Got: 'datetime.datetime(2005, 8, 22, 0, 0)\n'
4 errors:
-


On Jan 11, 2006, at 4:28 AM, Cheng Zhang wrote:



On Jan 10, 2006, at 10:21 PM, Adrian Holovaty wrote:



On 1/9/06, Rich Bakos <[EMAIL PROTECTED]> wrote:
I am experimenting with Django and MS SQL and it appears that  
Django is

passing parameters to MS SQL in an incorrect format.

The params are being passed in as a format string style (%s),  
which MS

SQL chokes on.


Hey Rich,

The Django MS SQL support is still in alpha status, mostly because we
don't have many people who've tried to use it with MS SQL. We're very
keen on getting that driver up to speed, though, and you can help.

Could you paste the entire traceback you get? Also, would any  
other MS

SQL users in the audience be able to help?

Adrian

--
Adrian Holovaty
holovaty.com | djangoproject.com | chicagocrime.org


As matter of fact, I am trying to make pymssql backend for Django  
work since in my current project we have to inherit a MS-SQL  
database. Changing the database is definitely not an option. If  
Django can be used with MS-SQL, then I can convince the team to  
pick it. Otherwise most likely we will have to stuck with Java/ 
Structs/iBatis stack which I am not a fan of.


I get the patch for pymssql from Jakub Labath, who was also in the  
mailing list couple months ago but didn't have time to work more on  
it. The reason for picking pymssql over ado-mysql is that we'd like  
to run Django on Linux instead of Windows.


Anyway, at this point I am kind of walking in the dark, since MS- 
SQL is a new territory to me.


- Cheng





Re: Django and MS SQL

2006-01-20 Thread Cheng Zhang


Actually that's incorrect. Pymssql is only a thin wrapper around  
FreeTDS library (http://www.freetds.org/).

AFAIK, FreeTDS works with SQL-Server 2000 pretty well.

- Cheng

On Jan 13, 2006, at 12:15 AM, Rich Bakos wrote:


Jeroen Ruigrok van der Werven wrote:

Hi Jeroen,


Can a bunch of us get together to get a/the pymssql driver fully
operational and Django running as it should?


The pymssql driver only supports DB-LIB, which is way outdated and you
wont have access to functionality added to MSSQL after version 6.5.
This is not the best option IMHO.

Rich





Re: Django and MS SQL

2006-01-20 Thread Cheng Zhang



On Jan 13, 2006, at 12:40 AM, Jeremy Dunck wrote:



On 1/12/06, Rich Bakos <[EMAIL PROTECTED]> wrote:
The pymssql driver only supports DB-LIB, which is way outdated and  
you

wont have access to functionality added to MSSQL after version 6.5.
This is not the best option IMHO.


Adapter class over adodbapi where supported, falling back to pymssql?


I think they (ado_mssql and pymssql) are meant for different OS  
platforms, in that ado_mssql is for Django running on Windows to  
connect to SQL Server since it only works on Windows, and pymssql is  
for Django running on Linux/UNIX to connect to SQL Server since it's  
only works on Linux/UNIX.


- Cheng



Re: Django and MS SQL

2006-01-21 Thread Cheng Zhang


Ok, the patch is away [http://code.djangoproject.com/ticket/1258]. :-)

- Cheng Zhang



Re: Django and MS SQL

2006-01-21 Thread Cheng Zhang



On Jan 21, 2006, at 7:12 AM, Jeremy Dunck wrote:



On 1/20/06, Cheng Zhang <[EMAIL PROTECTED]> wrote:
Adapter class over adodbapi where supported, falling back to  
pymssql?


I think they (ado_mssql and pymssql) are meant for different OS
platforms, in that ado_mssql is for Django running on Windows to
connect to SQL Server since it only works on Windows, and pymssql is
for Django running on Linux/UNIX to connect to SQL Server since it's
only works on Linux/UNIX.


Right, my point was that django devs shouldn't have to care about this
too much, and providing a single django DB backend to support both
libs underneath would be nice.

But I'm just talking, you're coding, so do what makes sense to  
you.  ;-)


Actually my previous statement isn't correct, I just realized that  
pymssql also claimed to work on Windows, except it will use M$'s  
native libraries instead of FreeTDS.




Re: recursive template calls

2006-02-07 Thread Cheng Zhang


Please search the previous email archive for discussion on such topic  
like "tree view".

In fact, there is a wiki page for an implementation as well.

On Feb 8, 2006, at 11:31 AM, Shannon -jj Behrens wrote:



Hi,

I'm trying to build ye ol' bulletin board application to try out
Django.  I'm having a hard time outputting the hierarchy of messages.
I can't figure out how to use recursion in templates.  I also need to
be able to treat a template "like a function" passing arguments.  How
should I be thinking about this problem?  Here's the app written in
another framework: .

Thanks!
-jj




Re: Problem and fix with ado_mssql

2006-02-27 Thread Cheng Zhang

On Feb 28, 2006, at 5:48 AM, kent wrote:

> PS I tried submitting this as a patch in the tracker but I didn't see
> any 'attach file' button...

The 'attach file' button will appear after you create the ticket. :-)

- Cheng


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



Re: Class in views.py

2006-02-27 Thread Cheng Zhang


On Feb 28, 2006, at 6:11 AM, Sandro wrote:

>
> I opened up the django shell and wrote some code that I want to place
> in my views.py
> Included in this code is a very simple class.  I get errors if I  
> try to
> run the code, are you not supposed to put classes in views.py?

Nope AFAIK.
Why don't you show the errors you got? It will be easier for others  
to figure out why.

- Cheng


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



Re: caching questions

2006-03-01 Thread Cheng Zhang


On Mar 1, 2006, at 3:57 PM, [EMAIL PROTECTED] wrote:

>
> anyone ?

I guess guys and gals are busy with PyCon Sprint these couple days,  
so they couldn't pay much attention on the mailing list. That's unusual.

Personally I haven't use cache in a production Django site yet, but I  
will try to share my understandings.

>
>> however, there are two things that I haven't been able to sort
>> out on my own:
>>
>> - the admin site is cached too, which makes it a bit hard to use.
>> it might be a middleware ordering problem, but I haven't found a
>> working combination. any ideas?

How about running the admin site with another process, say another  
mod_python configuration, separated with the main site? This way, you  
can have a separate settings for the admin site.

>>
>> - I would like to explicitly remove pages from the cache, based
>> on the URL. is there some public API for this that I haven't found ?

There is a section in the Cache API document called "Controlling  
cache: Using Vary headers" (http://www.djangoproject.com/ 
documentation/cache/#controlling-cache-using-vary-headers). If you  
didn't check it out, it might be useful for you, although I didn't  
have chance to use it yet.

Cheers
- Cheng Zhang


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



Re: An expression tag

2006-03-08 Thread Cheng Zhang


On Mar 4, 2006, at 3:12 PM, limodou wrote:

>
> I'v written a expression tag, it can be used to calculate python
> expression and save the result to a template variable. I think it
> maybe some useful for someone.

Indeed. I just found a place to use it in our app. :-) Thanks.

- Cheng


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



Re: Django API doc

2006-03-23 Thread Cheng Zhang

Very useful. Thanks.

On Mar 23, 2006, at 4:28 AM, Daniel Poelzleithner wrote:

>
> Hi,
>
> i created a css to build a django styled API doc with epydoc.
>
> http://djangoapi.quamquam.org/ Beta Version :)
>
> I hope we can integrate it as http://api.djangoproject.com someday.
>
> kindly regards
>   daniel

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



Too many SQLs in change_list pages

2006-04-03 Thread Qi Cheng

Hi, guys

I have been troubled by a problem for weeks, this maybe very easy for
you guys.

It is about the "list_display" in ADMIN of models, say ModelA. If I add
a method in list_dispaly(not a  field) , which will access other models
data, say ModelB. Then when I acess the modelA's change_list page, for
every recored of modelA, django_admin will submit one sepeate SQL to
database to get the modelB's data out.
So if there are many records in the modelA's  change_list page, there
will be many  SQLs submitted to db to get modelB's data out, and this
page is quite slow.

I know  creating some VIEWs in the database level and then mapping the
view to DJANGO MODELs are somehow resolutions, but this needs a lot of
change to my code.

So could we use django's API and not use so many SQLs to implement such
function in change_list page?

Any suggestions will be greatly appreciated. Thanks in advanve.

BR~

ChengQi


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



[M-R] lookup like Article.objects.filter(id__in = []) will fail

2006-04-29 Thread Cheng Zhang

Hi, folks

I tried lookup like Article.objects.filter(id__in = []), which will  
have SQL statement whose where clause is something like 'WHERE  
("poll_article"."id" IN ())'. Such SQL statement is ok with SQLite  
but invalid for PostgreSQL.

I work around this problem with code like:
if len(id_list) > 0:
   Article.objects.filter(id__in = id_list)
else:
   Article.objects.filter(id__isnull = True)

Should this problem be deal with on the Django framework level,  
instead of application level?

BR,
- Cheng

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



Re: [M-R] lookup like Article.objects.filter(id__in = []) will fail

2006-04-30 Thread Cheng Zhang


On Apr 30, 2006, at 1:31 PM, Ivan Sagalaev wrote:

>
> Cheng Zhang wrote:
>
>> I tried lookup like Article.objects.filter(id__in = []), which will
>> have SQL statement whose where clause is something like 'WHERE
>> ("poll_article"."id" IN ())'. Such SQL statement is ok with SQLite
>> but invalid for PostgreSQL.
>>
>> I work around this problem with code like:
>> if len(id_list) > 0:
>>   Article.objects.filter(id__in = id_list)
>> else:
>>   Article.objects.filter(id__isnull = True)
>>
>> Should this problem be deal with on the Django framework level,
>> instead of application level?
>>
>>
> It shouldn't. Because in defferent situations people need different
> things when the list in the condition is empty. Empty list can mean
> "don't filter, get everything" or "equals to nothing so get empty  
> list".
> And with your workaround user can get some arbitrary set of records
> where the field value happens to be NULL.
>
> So this really should be handled manually.

To elaborate on the question, it should be asked as:
In terms of Django's db-api, what will be in the QuerySet of filter 
(id__in=[])?

I still think it should mean an empty QuerySet. If one want to  
express the meaning of an everything QuerySet, one should use all()  
instead of filter().

- Cheng


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



[M-R] order by on custom SELECT column

2006-05-01 Thread Cheng Zhang

On the models of tutorial 1, I want to get a list of Poll, order by  
how many choices it has.

class Poll(models.Model):
 question = models.CharField(maxlength=200)
 pub_date = models.DateTimeField('date published')

class Choice(models.Model):
 poll = models.ForeignKey(Poll)
 choice = models.CharField(maxlength=200)
 votes = models.IntegerField()

I use a custom SELECT column as:
select = {
'choices': 'SELECT COUNT(*) FROM polls_choice WHERE  
poll_id=polls_poll.id',
}
p = Poll.objects.extra(select=select).order_by('choices')

By trying this, I found out a bug in the ORM layer which I reported  
and submitted a patch as:
http://code.djangoproject.com/ticket/1730

Custom SELECT column is one way, I'd like to know is there any other  
ways to get the same thing, esp. only using db api since I try to  
avoid doing custom SQL as much as possible for portability purpose.

BR,
- Cheng


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



Re: ANN: magic-removal branch merged to trunk

2006-05-01 Thread Cheng Zhang

Fantastic! Django rocks the world.
Thanks for the hard work of Django team and all participant all over  
the world.

On May 2, 2006, at 9:50 AM, Adrian Holovaty wrote:

> We'd like to thank ALL the dozens of people, all over the world, who
> have submitted code, documentation, bug reports and other help in this
> branch. Special thanks go to the magic-removal committers, Joseph
> Kocherans, Russell Keith-Magee and Luke Plant.

We are also busy in converting our code base for http:// 
www.ifaxian.com to use new API lately. :-)

Cheers!
- Cheng Zhang


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



Re: non mod-python deployment...any experiences? (dedicated server)

2006-05-02 Thread Cheng Zhang

That blog is in Russian. ;-)

On May 2, 2006, at 9:49 PM, Dmitry Medvedev wrote:

> about nginx ( http://nginx.org/ ) - this web server is similiar to
> lighttpd and i think results won't really differ a lot. I took
> django+nginx instructions from Igor Goryachev's blog (
> http://goryachev.org/ )


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



Re: non mod-python deployment...any experiences? (dedicated server)

2006-05-02 Thread Cheng Zhang


On May 2, 2006, at 8:46 PM, Gábor Farkas wrote:

> so, are there any people running django sites using non-mod_python?
> any experiences? was it stable?

We run http://www.ifaxian.com (a digg-like site in Chinese) with  
lighttpd + scgi. It's quite easy to setup, easier than Apache +  
mod_python IMHO.
Hugo's Django scgi page (https://simon.bofh.ms/cgi-bin/trac-django- 
projects.cgi/wiki/DjangoScgi) helps a lot.

We are not a high-traffic site yet, but so far, such setup has been  
very stable.

- Cheng Zhang
http://www.ifaxian.com
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: Keep getting TemplateDoesNotExist when unit testing

2012-03-03 Thread Calvin Cheng

Hi Jonas,

I am having exactly the same problem in one of my projects and I am not 
sure why.  Did you manage to solve it in the end?

Would appreciate it if you could share with me your solution if you did.

Regards,
Calvin


On Saturday, December 24, 2011 10:51:27 PM UTC+8, jonas wrote:
>
> Hello,
>
> I'm fairly new to Unit Testing.
>
> As I'm trying to setup a simple unit test in one of my Projects,
> it keeps returning a TemplateDoesNotExist Exception.
>
> It looks like for some reason the unit test framework can't locate my 
> template directory I've correctly defined in settings.py
>
> Here's the traceback:
>
> ==
> ERROR: test_url (gig.tests.GigURLTest)
> --
> Traceback (most recent call last):
>   File "/home/jonasg/dev/wiespeeltwaar/gig/tests.py", line 14, in test_url
> response = c.get('/')
>   File 
> "/home/jonasg/.virtualenvs/wiespeeltwaar/lib/python2.6/site-packages/django/test/client.py",
>  
> line 445, in get
> response = super(Client, self).get(path, data=data, **extra)
>   File 
> "/home/jonasg/.virtualenvs/wiespeeltwaar/lib/python2.6/site-packages/django/test/client.py",
>  
> line 229, in get
> return self.request(**r)
>   File 
> "/home/jonasg/.virtualenvs/wiespeeltwaar/lib/python2.6/site-packages/django/core/handlers/base.py",
>  
> line 111, in get_response
> response = callback(request, *callback_args, **callback_kwargs)
>   File "/home/jonasg/dev/wiespeeltwaar/../wiespeeltwaar/gig/views.py", 
> line 74, in index
> http_res = render_to_response('gig/index.html', c , 
> context_instance=RequestContext(request))
>   File 
> "/home/jonasg/.virtualenvs/wiespeeltwaar/lib/python2.6/site-packages/django/shortcuts/__init__.py",
>  
> line 20, in render_to_response
> return HttpResponse(loader.render_to_string(*args, **kwargs), 
> **httpresponse_kwargs)
>   File 
> "/home/jonasg/.virtualenvs/wiespeeltwaar/lib/python2.6/site-packages/django/template/loader.py",
>  
> line 181, in render_to_string
> t = get_template(template_name)
>   File 
> "/home/jonasg/.virtualenvs/wiespeeltwaar/lib/python2.6/site-packages/django/template/loader.py",
>  
> line 157, in get_template
> template, origin = find_template(template_name)
>   File 
> "/home/jonasg/.virtualenvs/wiespeeltwaar/lib/python2.6/site-packages/django/template/loader.py",
>  
> line 138, in find_template
> raise TemplateDoesNotExist(name)
> TemplateDoesNotExist: gig/index.html
>
>
> The unit test itself is simple:
>
> from django.test import TestCase
> from django.test.client import Client
>
> class GigURLTest(TestCase):
> def test_url(self):
> c = Client()
> response = c.get('/')
> self.assertEqual(response.status_code, 200)   
> 
>  
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/kvcalsd1X_UJ.
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: Various thoughts on authentication, registration and social logins

2012-06-18 Thread Ien Cheng
Mattias, 

It may be worth checking out django-allauth. It doesn't use the flow you 
are proposing -- as register-by-email users do need to enter a password -- 
but it has an nicely integrated one-click login via Facebook/Google/etc. 
alternative option for users. I haven't tried, as I like the default flows, 
but I guess you would be able to modify the code to do what you want pretty 
easily. (If you do try it, 
here'sa
 tip on installation.)

--Ien

On Sunday, June 17, 2012 8:25:15 PM UTC-4, Mattias Linnap wrote:
>
> Hi all, 
>
> I'm trying to build a nice authentication flow for a website. 
>
> In my opinion, a good flow would be: 
> 0. There are no usernames, emails are used instead, 
> 1. User signs up by just entering their email address, 
> 2. An account is created for them, and a temporary plaintext password, 
> along with a sign-in link is sent by email (only its hash, not the 
> plaintext password is stored in the database), 
> 3. If they log in for the first time, they are prompted to, but not 
> forced to change their password (this is not emailed), 
> 4. If they forget their password, a new temporary password along with 
> a sign-in link are sent to them by email. 
> 5. There should be as few intermediate "success confirmation" pages as 
> possible, instead redirecting to an useful page, and showing a 
> temporary message on there. 
>
> I would argue that this is as secure as ordinary password reset emails. 
> Emailing users their passwords is insecure if they *themselves* chose 
> the password - because they often re-use it on multiple sites. 
> As long as it is a randomly generated one, it is no different from 
> emailing them password reset links. 
> Do you agree? 
>
> What would you recommend as the approach to building this with least 
> effort, while keeping the rest of django and django.contrib packages 
> working as expected? 
> I've experimented briefly with django-registration, and it seems that 
> the best approach might be writing a new backend for it. 
> Do you have any other suggestions or packages that I should look at first? 
>
> Thanks, 
>
> Mattias 
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/292FJQwQYzoJ.
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.



pattern validation in QueryDict.get()

2013-06-01 Thread CHI Cheng
In url.py, we could use regex to limit string patterns.

Is there anything similar for QueryDict.get()?

e.g. given

q = request.GET.get(key='q', default=10, *pattern=r'\d+'*)  # new parameter 
pattern

If value of q in //*path?q=xxx* does not match the pattern, then give 
default value.

--
Chi

-- 
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: pattern validation in QueryDict.get()

2013-06-04 Thread CHI Cheng
Seems it should be '^\d+$'.

Nobody likes this idea? Should I submit a ticket and pull request?

On Saturday, June 1, 2013 9:48:17 PM UTC+10, CHI Cheng wrote:
>
> In url.py, we could use regex to limit string patterns.
>
> Is there anything similar for QueryDict.get()?
>
> e.g. given
>
> q = request.GET.get(key='q', default=10, *pattern=r'\d+'*)  # new 
> parameter pattern
>
> If value of q in //*path?q=xxx* does not match the pattern, then give 
> default value.
>
> --
> Chi
>

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




Unicode character in Django project path

2015-01-18 Thread Cheng Guo
Hello everyone,

I am new to this community. I have run into an issue related to Unicode 
character in project path:

http://stackoverflow.com/questions/27996774/unicode-character-in-django-project-path

Another user on StackOverflow provided a detailed analysis of what is 
causing the bug in the link above.

I want to file a bug report but not sure if the same bug has been reported, 
so I hope someone could let me know if I should file it.

Thanks!

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


Re: Unicode character in Django project path

2015-01-18 Thread Cheng Guo
Thank you James. I will create an empty project and see if the error stil 
exists.

On Monday, 19 January 2015 11:21:25 UTC+8, James Schneider wrote:
>
> After a quick search, this bug looks similar, but it's for an ancient 
> version of Django. Might still give you some hints as to where to look.
>
> https://code.djangoproject.com/ticket/8965
>
> If you can replicate the bug with an empty project and your template paths 
> set, I would recommend filing a bug, although there may be some 
> system/Django setting somewhere that can force the correct 
> encoding/decoding that in not aware of. 
>
> Search through https://code.djangoproject.com/search and see if another 
> ticket already exists.
>
> -James
> On Jan 18, 2015 7:05 PM, "Cheng Guo" > 
> wrote:
>
>> Hello everyone,
>>
>> I am new to this community. I have run into an issue related to Unicode 
>> character in project path:
>>
>>
>> http://stackoverflow.com/questions/27996774/unicode-character-in-django-project-path
>>
>> Another user on StackOverflow provided a detailed analysis of what is 
>> causing the bug in the link above.
>>
>> I want to file a bug report but not sure if the same bug has been 
>> reported, so I hope someone could let me know if I should file it.
>>
>> Thanks!
>>
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to django-users...@googlegroups.com .
>> To post to this group, send email to django...@googlegroups.com 
>> .
>> Visit this group at http://groups.google.com/group/django-users.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/django-users/1fc195b7-0596-4bd8-88cd-8c347ba6de88%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/django-users/1fc195b7-0596-4bd8-88cd-8c347ba6de88%40googlegroups.com?utm_medium=email&utm_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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/b30e8593-c5cc-4dd1-bd33-11b9e7ee334d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Newbie question: How to avoid a very long view function?

2015-01-18 Thread Cheng Guo
Hello,

I am new to Django and I have run into an issue with views.py.  I 
understand that there is a function behind each view. For a view that I am 
currently writing, it accepts a file upload from user and stores the file 
on the server. To do that, I need to:

1. check the file extension is correct
2. generate a SHA-1 id for the file based on its content
3. write the file to disk
4. save information about the file to database

(oh, I also created two global variables as well)

As you can see, if more features are added, the list goes on. It makes this 
function very long. As the number of views grow, the views.py file will 
become bloated. I wonder what would be the ideal way to deal with this?

Something that I can think of but not sure if it is correct:

- divide the long function up into smaller functions
- store these smaller functions in a different .py file

Let me know your approach, thanks!

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


Re: Newbie question: How to avoid a very long view function?

2015-01-19 Thread Cheng Guo
Great, thanks!
 

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/3065c69f-2930-43bc-9d12-e8b36a9a63c4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Newbie question: How to avoid a very long view function?

2015-01-19 Thread Cheng Guo
Great, thanks!

On Monday, 19 January 2015 15:46:40 UTC+8, Mike Dewhirst wrote:
>
> On 19/01/2015 6:28 PM, Cheng Guo wrote: 
> > Hello, 
> > 
> > I am new to Django and I have run into an issue with views.py.  I 
> > understand that there is a function behind each view. For a view that I 
> > am currently writing, it accepts a file upload from user and stores the 
> > file on the server. To do that, I need to: 
> > 
> > 1. check the file extension is correct 
> > 2. generate a SHA-1 id for the file based on its content 
> > 3. write the file to disk 
> > 4. save information about the file to database 
> > 
> > (oh, I also created two global variables as well) 
> > 
> > As you can see, if more features are added, the list goes on. It makes 
> > this function very long. As the number of views grow, the views.py file 
> > will become bloated. I wonder what would be the ideal way to deal with 
> this? 
> > 
> > Something that I can think of but not sure if it is correct: 
> > 
> > - divide the long function up into smaller functions 
> > - store these smaller functions in a different .py file 
>
> Absolutely correct. But first create a views directory (complete with 
> __init__.py file therein) to completely replace your views.py file. 
>
> Then any number of files can contain your views ... 
>
> from app.views.this import That 
>
> ... where this.py has a class That 
>
>
> > 
> > Let me know your approach, thanks! 
> > 
> > -- 
> > You received this message because you are subscribed to the Google 
> > Groups "Django users" group. 
> > To unsubscribe from this group and stop receiving emails from it, send 
> > an email to django-users...@googlegroups.com  
> > <mailto:django-users+unsubscr...@googlegroups.com >. 
> > To post to this group, send email to django...@googlegroups.com 
>  
> > <mailto:django...@googlegroups.com >. 
> > Visit this group at http://groups.google.com/group/django-users. 
> > To view this discussion on the web visit 
> > 
> https://groups.google.com/d/msgid/django-users/bf9f6ff3-a35a-4f00-8537-c6fd66d07f8d%40googlegroups.com
>  
> > <
> https://groups.google.com/d/msgid/django-users/bf9f6ff3-a35a-4f00-8537-c6fd66d07f8d%40googlegroups.com?utm_medium=email&utm_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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/6e8cf6a4-1967-495b-bfa4-95f9880b0457%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Newbie question: How to avoid a very long view function?

2015-01-19 Thread Cheng Guo
So in my case, I need to generate a unique id for the file and save it to 
disk.

I have a model called UploadFile, so you recommend to add two class methods 
to the UploadFile model, like the following?

class UploadFile(models.Model):
@classmethod
def generate_id():
pass

@classmethod
def save_to_disk():
pass


On Monday, 19 January 2015 16:12:28 UTC+8, daniel.franca wrote:
>
> If the operations are model related, why don't move some of those 
> functions to models.py.
> On Mon 19 Jan 2015 at 08:46 Mike Dewhirst  > wrote:
>
>> On 19/01/2015 6:28 PM, Cheng Guo wrote:
>> > Hello,
>> >
>> > I am new to Django and I have run into an issue with views.py.  I
>> > understand that there is a function behind each view. For a view that I
>> > am currently writing, it accepts a file upload from user and stores the
>> > file on the server. To do that, I need to:
>> >
>> > 1. check the file extension is correct
>> > 2. generate a SHA-1 id for the file based on its content
>> > 3. write the file to disk
>> > 4. save information about the file to database
>> >
>> > (oh, I also created two global variables as well)
>> >
>> > As you can see, if more features are added, the list goes on. It makes
>> > this function very long. As the number of views grow, the views.py file
>> > will become bloated. I wonder what would be the ideal way to deal with 
>> this?
>> >
>> > Something that I can think of but not sure if it is correct:
>> >
>> > - divide the long function up into smaller functions
>> > - store these smaller functions in a different .py file
>>
>> Absolutely correct. But first create a views directory (complete with
>> __init__.py file therein) to completely replace your views.py file.
>>
>> Then any number of files can contain your views ...
>>
>> from app.views.this import That
>>
>> ... where this.py has a class That
>>
>>
>> >
>> > Let me know your approach, thanks!
>> >
>> > --
>> > You received this message because you are subscribed to the Google
>> > Groups "Django users" group.
>> > To unsubscribe from this group and stop receiving emails from it, send
>> > an email to django-users...@googlegroups.com 
>> > <mailto:django-users+unsubscr...@googlegroups.com >.
>> > To post to this group, send email to django...@googlegroups.com 
>> 
>> > <mailto:django...@googlegroups.com >.
>> > Visit this group at http://groups.google.com/group/django-users.
>> > To view this discussion on the web visit
>> > https://groups.google.com/d/msgid/django-users/bf9f6ff3-
>> a35a-4f00-8537-c6fd66d07f8d%40googlegroups.com
>> > <https://groups.google.com/d/msgid/django-users/bf9f6ff3-
>> a35a-4f00-8537-c6fd66d07f8d%40googlegroups.com?utm_medium=
>> email&utm_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...@googlegroups.com .
>> To post to this group, send email to django...@googlegroups.com 
>> .
>> Visit this group at http://groups.google.com/group/django-users.
>> To view this discussion on the web visit https://groups.google.com/d/
>> msgid/django-users/54BCB642.8040201%40dewhirst.com.au.
>> 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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/80aef78c-9cec-4e50-be11-bc506d019b8c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Newbie question: How to avoid a very long view function?

2015-01-19 Thread Cheng Guo
Hello James:

Thank you very much for spending the time reading and answering this 
question, really appreciated!

I complete understand your suggestion of overriding the "save" method in 
the "UploadFile" to generate the id before saving. Thank you for pointing 
this out.

On the other hand, I read that it is not recommended to store files in 
database. So I decide to only store upload files on disk and save their 
file path and generated id in the database. So here is my model:

class UploadFile(models.Model):
upload_date = models.DateTimeField('timestamp', auto_now_add=True)
original_file_name = models.CharField(max_length=200)
file_id = models.CharField(max_length=40, primary_key=True)
file_path = models.CharField(max_length=500)
owner = models.ForeignKey(User)


I could use your method to override the save method, but the problem I face 
is that to generate the id, I need to pass the "UploadedFile" object to the 
 modal, like this:

class UploadFile(models.Model):

def generate_id(self, uploaded_file):
 import hashlib
 hasher = hashlib.sha1()

 for chunk in uploaded_file.chunks():
 hasher.update(chunk)
 
 self.file_id = hasher.hexdigest()

def save(self, upload_file):<--- this is not gonna work since 
'save' only takes (self) as a parameter
self.generate_id(upload_file)
super(UploadFile, self).save(*args, **kwargs)

So I have two ways to solve this:

1. generate the id in the view, and simply pass it to the UploadFile's 
constructor, then call save
2. create a class variable in UploadFile:

class UploadFile(models.Model):
...
self.file = None

in my view:
  
 def upload_view(request):
 file = request.FILES['file']
 upload_file = UploadFile(...)
 upload_file.file = file
 upload_file.save()

Do you think this is a good solution?


On Monday, 19 January 2015 17:07:12 UTC+8, James Schneider wrote:
>
> I wouldn't decorate them as class methods. You would want to call them 
> from the objects themselves. For the save_to_disk() method, I was actually 
> referring to the Django save() method (
> https://docs.djangoproject.com/en/1.7/topics/db/models/#overriding-predefined-model-methods
> ).
>
> As you have it now, it wouldn't work since you would need to call 
> UploadFile.generate_id(), but you don't have an available argument to pass 
> in the UploadFile object to get the ID for. 
>
> If you remove the decorator, you would call it on the object itself:
> class UploadFile(models.Model):
>
> def generate_id(self):
> # pseudocode to do stuff to generate ID using self
> # import hashlib
> # self.file_hash = hashlib.sha1(self.file, 'rb') 
> # return the ID or None if it fails
> # return self.file_hash or None
>
> # override the model save method to generate the hash ID, then save 
> for real
> def save(self):
> self.generate_id()
> super(UploadFile, self).save(*args, **kwargs)
>
> You probably don't need to change your view logic at all in this case 
> (unless you have code that generates the hash and attaches it to the 
> object, then remove it and let the object handle that itself). Basically, 
> when your UploadFile object is saved, it will call the save() method on the 
> object, which in turn will generate the ID based on the file, attach it to 
> the object, and then save the object to the database.
>
> Note that this will run the hashing mechanism every time the object is 
> saved, whether the file it points at changes or not. If this isn't what you 
> want, I would add an extra checks in generate_id() to account for all of 
> the scenarios where you wan the hash to update (every time the object is 
> saved vs. only when the file changes vs. only generated once even with a 
> file change, etc.). 
>
> In a typical scenario where the hash is run every time the object is 
> saved, the object itself would create the hash. This way you can save the 
> object from any view (or from the shell), and it would always generate a 
> new hash automagically (new meaning recalculated, may end up the same as 
> the previous value). 
>
> TL;DR; The hash shouldn't be calculated external to the file that is 
> attached to the object, it should be calculated by the object itself.
>
> Hope that helps and makes sense...
>
> -James
>
>
> On Jan 19, 2015 12:37 AM, "Cheng Guo" > 
> wrote:
>
>> So in my case, I need to generate a unique id for the file and save it to 
>> disk.
>>
>> I have a model called UploadFile, so you recommend to add two class 
>> methods to the UploadFile 

Re: Newbie question: How to avoid a very long view function?

2015-01-19 Thread Cheng Guo
Hello James:

Thank you very much for spending the time reading and answering this 
question, really appreciated!

I complete understand your suggestion of overriding the "save" method in 
the "UploadFile" to generate the id before saving. Thank you for pointing 
this out.

On the other hand, I read that it is not recommended to store files in 
database. So I decide to only store upload files on disk and save their 
file path and generated id in the database. So here is my model:

class UploadFile(models.Model):
upload_date = models.DateTimeField('timestamp', auto_now_add=True)
original_file_name = models.CharField(max_length=200)
file_id = models.CharField(max_length=40, primary_key=True)
file_path = models.CharField(max_length=500)
owner = models.ForeignKey(User)


I could use your method to override the save method, but the problem I face 
is that to generate the id, I need to pass the "UploadedFile" object to the 
 model, like this:

class UploadFile(models.Model):

def generate_id(self, uploaded_file):
 import hashlib
 hasher = hashlib.sha1()

 for chunk in uploaded_file.chunks():
 hasher.update(chunk)
 
 self.file_id = hasher.hexdigest()

def save(self, upload_file):<--- this is not gonna work since 
'save' only takes (self) as a parameter
self.generate_id(upload_file)
super(UploadFile, self).save(*args, **kwargs)

So I have two ways to solve this:

1. generate the id in the view, and simply pass it to the UploadFile's 
constructor, then call save
2. create a variable in UploadFile:

class UploadFile(models.Model):
...
self.file = None

 def generate_id(self, uploaded_file):
 import hashlib
 hasher = hashlib.sha1()

 for chunk in uploaded_file.chunks():
 hasher.update(chunk)
 
 self.file_id = hasher.hexdigest()

def save(self):
self.generate_id(self.file)
super(UploadFile, self).save(*args, **kwargs)

in my view:
  
 def upload_view(request):
 file = request.FILES['file']
 upload_file = UploadFile(...)
 upload_file.file = file
 upload_file.save()

Do you think this is a good solution?

On Monday, 19 January 2015 17:07:12 UTC+8, James Schneider wrote:
>
> I wouldn't decorate them as class methods. You would want to call them 
> from the objects themselves. For the save_to_disk() method, I was actually 
> referring to the Django save() method (
> https://docs.djangoproject.com/en/1.7/topics/db/models/#overriding-predefined-model-methods
> ).
>
> As you have it now, it wouldn't work since you would need to call 
> UploadFile.generate_id(), but you don't have an available argument to pass 
> in the UploadFile object to get the ID for. 
>
> If you remove the decorator, you would call it on the object itself:
> class UploadFile(models.Model):
>
> def generate_id(self):
> # pseudocode to do stuff to generate ID using self
> # import hashlib
> # self.file_hash = hashlib.sha1(self.file, 'rb') 
> # return the ID or None if it fails
> # return self.file_hash or None
>
> # override the model save method to generate the hash ID, then save 
> for real
> def save(self):
> self.generate_id()
> super(UploadFile, self).save(*args, **kwargs)
>
> You probably don't need to change your view logic at all in this case 
> (unless you have code that generates the hash and attaches it to the 
> object, then remove it and let the object handle that itself). Basically, 
> when your UploadFile object is saved, it will call the save() method on the 
> object, which in turn will generate the ID based on the file, attach it to 
> the object, and then save the object to the database.
>
> Note that this will run the hashing mechanism every time the object is 
> saved, whether the file it points at changes or not. If this isn't what you 
> want, I would add an extra checks in generate_id() to account for all of 
> the scenarios where you wan the hash to update (every time the object is 
> saved vs. only when the file changes vs. only generated once even with a 
> file change, etc.). 
>
> In a typical scenario where the hash is run every time the object is 
> saved, the object itself would create the hash. This way you can save the 
> object from any view (or from the shell), and it would always generate a 
> new hash automagically (new meaning recalculated, may end up the same as 
> the previous value). 
>
> TL;DR; The hash shouldn't be calculated external to the file that is 
> attached to the object, it should be calculated by the object itse

Re: Newbie question: How to avoid a very long view function?

2015-01-19 Thread Cheng Guo
Thank you Daniel, I didn't know this! I am going to lookup how to use 
session. Thanks!

On Monday, 19 January 2015 17:13:10 UTC+8, Daniel Roseman wrote:
>
> On Monday, 19 January 2015 07:28:14 UTC, Cheng Guo wrote:
>>
>> Hello,
>>
>> I am new to Django and I have run into an issue with views.py.  I 
>> understand that there is a function behind each view. For a view that I am 
>> currently writing, it accepts a file upload from user and stores the file 
>> on the server. To do that, I need to:
>>
>> 1. check the file extension is correct
>> 2. generate a SHA-1 id for the file based on its content
>> 3. write the file to disk
>> 4. save information about the file to database
>>
>> (oh, I also created two global variables as well)
>>
>>
> Others have pointed out ways to split this up, but I wanted to pick up on 
> the last sentence. You really really should not be setting global variables 
> in your view, especially in response to user input. Global variables are 
> shared by all requests in a process, and you can't guarantee either that 
> all requests will be from the same user, or even that the same user will 
> hit the same process in subsequent requests. Don't do this: if you need to 
> store state between requests, use the db or the session.
> --
> DR.
>

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


Django formset hidden id field

2015-05-27 Thread Cheng Guo
Hello,

I have a formset and when I render it, Django would include this line in 
the HTML:



I am curious what is the purpose of having an id field here. 

I mean in what situation would you use it. I did look through Django's 
documentation 
on formset 
but 
cannot find much documentation on this.
One answer I got is that this id field is the value of the primary key of 
the model bound to this form. It is there so that when the formset updates, 
people can use it to retrieve the corresponding record from the database.

Is the above explaination correct?

If this explaination is correct, then my next question is, wouldn't it be 
dangerous to expose the primary key like that? I can make a post call to 
your server with a modified pk which can mess up your database.

Thank you!

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/18e0d250-c4a9-4060-ae4f-19afb57566e0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django formset hidden id field

2015-05-27 Thread Cheng Guo
Thank you! Yes, I forgot about the csrf. You are right, it would be 
difficult to fake the CSRF string.

Just in general, is it a good idea to expose primary keys like this? 
sometimes you can see them in urls too, like: www.yoursite/blog/1/,  1 
would be the primary key of a blog.

On Wednesday, 27 May 2015 22:01:37 UTC+8, Matthias Müller wrote:
>
> Without looking at the link I guess that you explantion is more or less 
> correct. 
>
> But it's not a security issue that the database is updated by a form. It 
> has to be updated by a form. To make it a correct django form there is a 
> hidden field with the CSRF token. This protects the database being updated 
> from any illegal source. 
>
> In your example there is this csrf missing, Most probably for didactical 
> reasons. 
>
> Refer to https://docs.djangoproject.com/en/1.8/ref/csrf/
>
> Cheers
> Matthias
>
> 2015-05-27 15:47 GMT+02:00 Cheng Guo >:
>
>> Hello,
>>
>> I have a formset and when I render it, Django would include this line in 
>> the HTML:
>>
>> 
>>
>> I am curious what is the purpose of having an id field here. 
>>
>> I mean in what situation would you use it. I did look through Django's 
>> documentation 
>> on formset 
>> <https://docs.djangoproject.com/en/1.8/topics/forms/formsets/#can-delete>but 
>> cannot find much documentation on this.
>> One answer I got is that this id field is the value of the primary key of 
>> the model bound to this form. It is there so that when the formset updates, 
>> people can use it to retrieve the corresponding record from the database.
>>
>> Is the above explaination correct?
>>
>> If this explaination is correct, then my next question is, wouldn't it be 
>> dangerous to expose the primary key like that? I can make a post call to 
>> your server with a modified pk which can mess up your database.
>>
>> Thank you!
>>
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to django-users...@googlegroups.com .
>> To post to this group, send email to django...@googlegroups.com 
>> .
>> Visit this group at http://groups.google.com/group/django-users.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/django-users/18e0d250-c4a9-4060-ae4f-19afb57566e0%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/django-users/18e0d250-c4a9-4060-ae4f-19afb57566e0%40googlegroups.com?utm_medium=email&utm_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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/285ee494-8b28-42cd-8af9-4cb33983a82c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Import css in Django

2016-09-11 Thread Jonathan Cheng
I use django1.10

i reference the official doc
https://docs.djangoproject.com/en/1.10/intro/tutorial06/

my project name:mysite

structure:
  
- mysite-
   
 - mysite - urls.py

   -views.py

...

 - templates - index.html 
   
 - images 
 - static - mysite - assets - css - main.css
 
- js

...
In my index.html

add

`{% load staticfiles % }
`

it said i have a Invalid block tag about TemplateSyntaxError
``

views.py (about static files part)
```STATICFILES_DIRS = [
os.path.join(BASE_DIR, "static"),
'/mysite/static/',
]
STATIC_URL = '/static/'
STATIC_ROOT='/mysite/static/'```

what's part should i notice?

-- 
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/ef2ea6eb-d1cb-40e2-abef-1af246e02e98%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Import css in Django

2016-09-11 Thread Jonathan Cheng
thx reply,but it just can see the original html with no css,is my path 
setted correct?

ludovic coues於 2016年9月11日星期日 UTC+8下午11時45分24秒寫道:
>
> Have you tried to add a few newlines to be sure about which line is the 
> issue ? 
>
> Also, in you email, there is a space between % and } in the load 
> staticfiles tag 
>
> 2016-09-11 7:29 GMT+02:00 Jonathan Cheng  >: 
> > I use django1.10 
> > 
> > i reference the official doc 
> > https://docs.djangoproject.com/en/1.10/intro/tutorial06/ 
> > 
> > my project name:mysite 
> > 
> > structure: 
> > 
> > - mysite- 
> > 
> >  - mysite - urls.py 
> > 
> >-views.py 
> > 
> > ... 
> > 
> >  - templates - index.html 
> > 
> >  - images 
> >  - static - mysite - assets - css - main.css 
> > 
> > - js 
> > 
> > ... 
> > In my index.html 
> > 
> > add 
> > 
> > `{% load staticfiles % } 
> > ` 
> > 
> > it said i have a Invalid block tag about TemplateSyntaxError 
> > `` 
> > 
> > views.py (about static files part) 
> > ```STATICFILES_DIRS = [ 
> > os.path.join(BASE_DIR, "static"), 
> > '/mysite/static/', 
> > ] 
> > STATIC_URL = '/static/' 
> > STATIC_ROOT='/mysite/static/'``` 
> > 
> > what's part should i notice? 
> > 
> > -- 
> > You received this message because you are subscribed to the Google 
> Groups 
> > "Django users" group. 
> > To unsubscribe from this group and stop receiving emails from it, send 
> an 
> > email to django-users...@googlegroups.com . 
> > To post to this group, send email to django...@googlegroups.com 
> . 
> > Visit this group at https://groups.google.com/group/django-users. 
> > To view this discussion on the web visit 
> > 
> https://groups.google.com/d/msgid/django-users/ef2ea6eb-d1cb-40e2-abef-1af246e02e98%40googlegroups.com.
>  
>
> > For more options, visit https://groups.google.com/d/optout. 
>
>
>
> -- 
>
> Cordialement, Coues Ludovic 
> +336 148 743 42 
>

-- 
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/a699584c-d57f-4b84-a38b-fe03638caefd%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Import css in Django

2016-09-11 Thread Jonathan Cheng

https://gist.github.com/cj10243/fb557903441d4a3e95190b854fbaabe1

ludovic coues於 2016年9月12日星期一 UTC+8上午12時05分12秒寫道:
>
> I have a hard time to read the paths you use. The command tree produce 
> a nice tree view of a directory, it might help. You can also use 
> service like http://paste2.org/ or https://gist.github.com/ to share 
> it 
>
> 2016-09-11 17:58 GMT+02:00 Jonathan Cheng  >: 
> > thx reply,but it just can see the original html with no css,is my path 
> > setted correct? 
> > 
> > ludovic coues於 2016年9月11日星期日 UTC+8下午11時45分24秒寫道: 
> >> 
> >> Have you tried to add a few newlines to be sure about which line is the 
> >> issue ? 
> >> 
> >> Also, in you email, there is a space between % and } in the load 
> >> staticfiles tag 
> >> 
> >> 2016-09-11 7:29 GMT+02:00 Jonathan Cheng : 
> >> > I use django1.10 
> >> > 
> >> > i reference the official doc 
> >> > https://docs.djangoproject.com/en/1.10/intro/tutorial06/ 
> >> > 
> >> > my project name:mysite 
> >> > 
> >> > structure: 
> >> > 
> >> > - mysite- 
> >> > 
> >> >  - mysite - urls.py 
> >> > 
> >> >-views.py 
> >> > 
> >> > ... 
> >> > 
> >> >  - templates - index.html 
> >> > 
> >> >  - images 
> >> >  - static - mysite - assets - css - main.css 
> >> > 
> >> > - js 
> >> > 
> >> > ... 
> >> > In my index.html 
> >> > 
> >> > add 
> >> > 
> >> > `{% load staticfiles % } 
> >> > ` 
> >> > 
> >> > it said i have a Invalid block tag about TemplateSyntaxError 
> >> > `` 
> >> > 
> >> > views.py (about static files part) 
> >> > ```STATICFILES_DIRS = [ 
> >> > os.path.join(BASE_DIR, "static"), 
> >> > '/mysite/static/', 
> >> > ] 
> >> > STATIC_URL = '/static/' 
> >> > STATIC_ROOT='/mysite/static/'``` 
> >> > 
> >> > what's part should i notice? 
> >> > 
> >> > -- 
> >> > You received this message because you are subscribed to the Google 
> >> > Groups 
> >> > "Django users" group. 
> >> > To unsubscribe from this group and stop receiving emails from it, 
> send 
> >> > an 
> >> > email to django-users...@googlegroups.com. 
> >> > To post to this group, send email to django...@googlegroups.com. 
> >> > Visit this group at https://groups.google.com/group/django-users. 
> >> > To view this discussion on the web visit 
> >> > 
> >> > 
> https://groups.google.com/d/msgid/django-users/ef2ea6eb-d1cb-40e2-abef-1af246e02e98%40googlegroups.com.
>  
>
> >> > For more options, visit https://groups.google.com/d/optout. 
> >> 
> >> 
> >> 
> >> -- 
> >> 
> >> Cordialement, Coues Ludovic 
> >> +336 148 743 42 
> > 
> > -- 
> > You received this message because you are subscribed to the Google 
> Groups 
> > "Django users" group. 
> > To unsubscribe from this group and stop receiving emails from it, send 
> an 
> > email to django-users...@googlegroups.com . 
> > To post to this group, send email to django...@googlegroups.com 
> . 
> > Visit this group at https://groups.google.com/group/django-users. 
> > To view this discussion on the web visit 
> > 
> https://groups.google.com/d/msgid/django-users/a699584c-d57f-4b84-a38b-fe03638caefd%40googlegroups.com.
>  
>
> > 
> > For more options, visit https://groups.google.com/d/optout. 
>
>
>
> -- 
>
> Cordialement, Coues Ludovic 
> +336 148 743 42 
>

-- 
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/6e864bf6-c12b-49bc-b906-d2c35a5e884b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Import css in Django

2016-09-11 Thread Jonathan Cheng
here i explain , because  i just test how main.css work, finally i want to 
use the assets and images .
and i use the python mange.py collectstatic
it showed 

ImproperlyConfigured: The STATICFILES_DIRS setting should not contain the 
> STATIC_ROOT setting 
>

ludovic coues於 2016年9月12日星期一 UTC+8上午12時53分08秒寫道:
>
> I mentionned tree because I have doubt about what "static - assets - 
> css - main.css" means. If your path is really 
> /mysite/static/assets/css/main.css, then you want  rel="stylesheet" text = 'html/css' href="{% static 
> 'assets/css/main.css' %}" />. 
>
> At least with a debug configuration, django will search for static 
> file in each apps' static directory for the path you used as arguments 
> for static. 
> With a production configuration, you should use manage.py 
> collectstatic which will grab all static file and copy them in a 
> single directory. 
>
> 2016-09-11 18:18 GMT+02:00 Jonathan Cheng  >: 
> > 
> > https://gist.github.com/cj10243/fb557903441d4a3e95190b854fbaabe1 
> > 
> > ludovic coues於 2016年9月12日星期一 UTC+8上午12時05分12秒寫道: 
> >> 
> >> I have a hard time to read the paths you use. The command tree produce 
> >> a nice tree view of a directory, it might help. You can also use 
> >> service like http://paste2.org/ or https://gist.github.com/ to share 
> >> it 
> >> 
> >> 2016-09-11 17:58 GMT+02:00 Jonathan Cheng : 
> >> > thx reply,but it just can see the original html with no css,is my 
> path 
> >> > setted correct? 
> >> > 
> >> > ludovic coues於 2016年9月11日星期日 UTC+8下午11時45分24秒寫道: 
> >> >> 
> >> >> Have you tried to add a few newlines to be sure about which line is 
> the 
> >> >> issue ? 
> >> >> 
> >> >> Also, in you email, there is a space between % and } in the load 
> >> >> staticfiles tag 
> >> >> 
> >> >> 2016-09-11 7:29 GMT+02:00 Jonathan Cheng : 
> >> >> > I use django1.10 
> >> >> > 
> >> >> > i reference the official doc 
> >> >> > https://docs.djangoproject.com/en/1.10/intro/tutorial06/ 
> >> >> > 
> >> >> > my project name:mysite 
> >> >> > 
> >> >> > structure: 
> >> >> > 
> >> >> > - mysite- 
> >> >> > 
> >> >> >  - mysite - urls.py 
> >> >> > 
> >> >> >-views.py 
> >> >> > 
> >> >> > ... 
> >> >> > 
> >> >> >  - templates - index.html 
> >> >> > 
> >> >> >  - images 
> >> >> >  - static - mysite - assets - css - main.css 
> >> >> > 
> >> >> > - js 
> >> >> > 
> >> >> > ... 
> >> >> > In my index.html 
> >> >> > 
> >> >> > add 
> >> >> > 
> >> >> > `{% load staticfiles % } 
> >> >> > ` 
> >> >> > 
> >> >> > it said i have a Invalid block tag about TemplateSyntaxError 
> >> >> > `` 
> >> >> > 
> >> >> > views.py (about static files part) 
> >> >> > ```STATICFILES_DIRS = [ 
> >> >> > os.path.join(BASE_DIR, "static"), 
> >> >> > '/mysite/static/', 
> >> >> > ] 
> >> >> > STATIC_URL = '/static/' 
> >> >> > STATIC_ROOT='/mysite/static/'``` 
> >> >> > 
> >> >> > what's part should i notice? 
> >> >> > 
> >> >> > -- 
> >> >> > You received this message because you are subscribed to the Google 
> >> >> > Groups 
> >> >> > "Django users" group. 
> >> >> > To unsubscribe from this group and stop receiving emails from it, 
> >> >> > send 
> >> >> > an 
> >> >> > email to django-users...@googlegroups.com. 
> >> >> > To post to this group, send email to django...@googlegroups.com. 
> >> >> > Visit this group at https://groups.google.com/group/django-users. 
> >> >> > 

Re: Import css in Django

2016-09-11 Thread Jonathan Cheng
thx i change into STATIC_ROOT='/static/'
it seems to no error
but when i connect to my runserver
the css of  assets just doesn't work

2016-09-12 0:44 GMT+08:00 ali Eblice :

> your "mysite" folder and "static" folder are in a same directory but in
> your settings.py you wrote "STATIC_ROOT='/mysite/static/'" which says
> that static should be subdirectory of mysite which its not a subdirectory
> its in a same directory of mysite
>
>
> On Sunday, September 11, 2016 at 8:48:57 PM UTC+4:30, Jonathan Cheng wrote:
>>
>>
>> https://gist.github.com/cj10243/fb557903441d4a3e95190b854fbaabe1
>>
>> ludovic coues於 2016年9月12日星期一 UTC+8上午12時05分12秒寫道:
>>>
>>> I have a hard time to read the paths you use. The command tree produce
>>> a nice tree view of a directory, it might help. You can also use
>>> service like http://paste2.org/ or https://gist.github.com/ to share
>>> it
>>>
>>> 2016-09-11 17:58 GMT+02:00 Jonathan Cheng :
>>> > thx reply,but it just can see the original html with no css,is my path
>>> > setted correct?
>>> >
>>> > ludovic coues於 2016年9月11日星期日 UTC+8下午11時45分24秒寫道:
>>> >>
>>> >> Have you tried to add a few newlines to be sure about which line is
>>> the
>>> >> issue ?
>>> >>
>>> >> Also, in you email, there is a space between % and } in the load
>>> >> staticfiles tag
>>> >>
>>> >> 2016-09-11 7:29 GMT+02:00 Jonathan Cheng :
>>> >> > I use django1.10
>>> >> >
>>> >> > i reference the official doc
>>> >> > https://docs.djangoproject.com/en/1.10/intro/tutorial06/
>>> >> >
>>> >> > my project name:mysite
>>> >> >
>>> >> > structure:
>>> >> >
>>> >> > - mysite-
>>> >> >
>>> >> >  - mysite - urls.py
>>> >> >
>>> >> >-views.py
>>> >> >
>>> >> > ...
>>> >> >
>>> >> >  - templates - index.html
>>> >> >
>>> >> >  - images
>>> >> >  - static - mysite - assets - css - main.css
>>> >> >
>>> >> > - js
>>> >> >
>>> >> > ...
>>> >> > In my index.html
>>> >> >
>>> >> > add
>>> >> >
>>> >> > `{% load staticfiles % }
>>> >> > `
>>> >> >
>>> >> > it said i have a Invalid block tag about TemplateSyntaxError
>>> >> > ``
>>> >> >
>>> >> > views.py (about static files part)
>>> >> > ```STATICFILES_DIRS = [
>>> >> > os.path.join(BASE_DIR, "static"),
>>> >> > '/mysite/static/',
>>> >> > ]
>>> >> > STATIC_URL = '/static/'
>>> >> > STATIC_ROOT='/mysite/static/'```
>>> >> >
>>> >> > what's part should i notice?
>>> >> >
>>> >> > --
>>> >> > You received this message because you are subscribed to the Google
>>> >> > Groups
>>> >> > "Django users" group.
>>> >> > To unsubscribe from this group and stop receiving emails from it,
>>> send
>>> >> > an
>>> >> > email to django-users...@googlegroups.com.
>>> >> > To post to this group, send email to django...@googlegroups.com.
>>> >> > Visit this group at https://groups.google.com/group/django-users.
>>> >> > To view this discussion on the web visit
>>> >> >
>>> >> > https://groups.google.com/d/msgid/django-users/ef2ea6eb-d1cb
>>> -40e2-abef-1af246e02e98%40googlegroups.com.
>>> >> > For more options, visit https://groups.google.com/d/optout.
>>> >>
>>> >>
>>> >>
>>> >> --
>>> >>
>>> >> Cordialement, Coues Ludovic
>>> >> +336 148 743 42
>>> >
>>> > --
>>> > You received this message because you are subscribed to th

Re: Import css in Django

2016-09-11 Thread Jonathan Cheng
i fixed usint STATIC_ROOD = '/static/'
it seems to no error
but when i connect to my runserver
the css of  assets just doesn't work


Jonathan Cheng於 2016年9月12日星期一 UTC+8上午1時04分22秒寫道:
>
> here i explain , because  i just test how main.css work, finally i want to 
> use the assets and images .
> and i use the python mange.py collectstatic
> it showed 
>
> ImproperlyConfigured: The STATICFILES_DIRS setting should not contain the 
>> STATIC_ROOT setting 
>>
>
> ludovic coues於 2016年9月12日星期一 UTC+8上午12時53分08秒寫道:
>>
>> I mentionned tree because I have doubt about what "static - assets - 
>> css - main.css" means. If your path is really 
>> /mysite/static/assets/css/main.css, then you want > rel="stylesheet" text = 'html/css' href="{% static 
>> 'assets/css/main.css' %}" />. 
>>
>> At least with a debug configuration, django will search for static 
>> file in each apps' static directory for the path you used as arguments 
>> for static. 
>> With a production configuration, you should use manage.py 
>> collectstatic which will grab all static file and copy them in a 
>> single directory. 
>>
>> 2016-09-11 18:18 GMT+02:00 Jonathan Cheng : 
>> > 
>> > https://gist.github.com/cj10243/fb557903441d4a3e95190b854fbaabe1 
>> > 
>> > ludovic coues於 2016年9月12日星期一 UTC+8上午12時05分12秒寫道: 
>> >> 
>> >> I have a hard time to read the paths you use. The command tree produce 
>> >> a nice tree view of a directory, it might help. You can also use 
>> >> service like http://paste2.org/ or https://gist.github.com/ to share 
>> >> it 
>> >> 
>> >> 2016-09-11 17:58 GMT+02:00 Jonathan Cheng : 
>> >> > thx reply,but it just can see the original html with no css,is my 
>> path 
>> >> > setted correct? 
>> >> > 
>> >> > ludovic coues於 2016年9月11日星期日 UTC+8下午11時45分24秒寫道: 
>> >> >> 
>> >> >> Have you tried to add a few newlines to be sure about which line is 
>> the 
>> >> >> issue ? 
>> >> >> 
>> >> >> Also, in you email, there is a space between % and } in the load 
>> >> >> staticfiles tag 
>> >> >> 
>> >> >> 2016-09-11 7:29 GMT+02:00 Jonathan Cheng : 
>> >> >> > I use django1.10 
>> >> >> > 
>> >> >> > i reference the official doc 
>> >> >> > https://docs.djangoproject.com/en/1.10/intro/tutorial06/ 
>> >> >> > 
>> >> >> > my project name:mysite 
>> >> >> > 
>> >> >> > structure: 
>> >> >> > 
>> >> >> > - mysite- 
>> >> >> > 
>> >> >> >  - mysite - urls.py 
>> >> >> > 
>> >> >> >-views.py 
>> >> >> > 
>> >> >> > ... 
>> >> >> > 
>> >> >> >  - templates - index.html 
>> >> >> > 
>> >> >> >  - images 
>> >> >> >  - static - mysite - assets - css - main.css 
>> >> >> > 
>> >> >> > - js 
>> >> >> > 
>> >> >> > ... 
>> >> >> > In my index.html 
>> >> >> > 
>> >> >> > add 
>> >> >> > 
>> >> >> > `{% load staticfiles % } 
>> >> >> > ` 
>> >> >> > 
>> >> >> > it said i have a Invalid block tag about TemplateSyntaxError 
>> >> >> > `` 
>> >> >> > 
>> >> >> > views.py (about static files part) 
>> >> >> > ```STATICFILES_DIRS = [ 
>> >> >> > os.path.join(BASE_DIR, "static"), 
>> >> >> > '/mysite/static/', 
>> >> >> > ] 
>> >> >> > STATIC_URL = '/static/' 
>> >> >> > STATIC_ROOT='/mysite/static/'``` 
>> >> >> > 
>> >> >> > what's part should i notice? 
>> >> >> > 
>> >> >> > -- 
>&

Re: Import css in Django

2016-09-12 Thread Jonathan Cheng
i use href="{% static '/assets/css/main.css' %}" 
and it worked 
but if i want to use the all files in static
is there any way to do?

ludovic coues於 2016年9月12日星期一 UTC+8上午1時32分42秒寫道:
>
> If you look at the html send by django, what is the href value ?
>
> 2016-09-11 19:15 GMT+02:00 Jonathan Cheng  >:
>
>> i fixed usint STATIC_ROOD = '/static/'
>> it seems to no error
>> but when i connect to my runserver
>> the css of  assets just doesn't work
>>
>>
>> Jonathan Cheng於 2016年9月12日星期一 UTC+8上午1時04分22秒寫道:
>>
>>> here i explain , because  i just test how main.css work, finally i want 
>>> to use the assets and images .
>>> and i use the python mange.py collectstatic
>>> it showed 
>>>
>>> ImproperlyConfigured: The STATICFILES_DIRS setting should not contain 
>>>> the STATIC_ROOT setting 
>>>>
>>>
>>> ludovic coues於 2016年9月12日星期一 UTC+8上午12時53分08秒寫道:
>>>>
>>>> I mentionned tree because I have doubt about what "static - assets - 
>>>> css - main.css" means. If your path is really 
>>>> /mysite/static/assets/css/main.css, then you want >>> rel="stylesheet" text = 'html/css' href="{% static 
>>>> 'assets/css/main.css' %}" />. 
>>>>
>>>> At least with a debug configuration, django will search for static 
>>>> file in each apps' static directory for the path you used as arguments 
>>>> for static. 
>>>> With a production configuration, you should use manage.py 
>>>> collectstatic which will grab all static file and copy them in a 
>>>> single directory. 
>>>>
>>>> 2016-09-11 18:18 GMT+02:00 Jonathan Cheng : 
>>>> > 
>>>> > https://gist.github.com/cj10243/fb557903441d4a3e95190b854fbaabe1 
>>>> > 
>>>> > ludovic coues於 2016年9月12日星期一 UTC+8上午12時05分12秒寫道: 
>>>> >> 
>>>> >> I have a hard time to read the paths you use. The command tree 
>>>> produce 
>>>> >> a nice tree view of a directory, it might help. You can also use 
>>>> >> service like http://paste2.org/ or https://gist.github.com/ to 
>>>> share 
>>>> >> it 
>>>> >> 
>>>> >> 2016-09-11 17:58 GMT+02:00 Jonathan Cheng : 
>>>> >> > thx reply,but it just can see the original html with no css,is my 
>>>> path 
>>>> >> > setted correct? 
>>>> >> > 
>>>> >> > ludovic coues於 2016年9月11日星期日 UTC+8下午11時45分24秒寫道: 
>>>> >> >> 
>>>> >> >> Have you tried to add a few newlines to be sure about which line 
>>>> is the 
>>>> >> >> issue ? 
>>>> >> >> 
>>>> >> >> Also, in you email, there is a space between % and } in the load 
>>>> >> >> staticfiles tag 
>>>> >> >> 
>>>> >> >> 2016-09-11 7:29 GMT+02:00 Jonathan Cheng : 
>>>> >> >> > I use django1.10 
>>>> >> >> > 
>>>> >> >> > i reference the official doc 
>>>> >> >> > https://docs.djangoproject.com/en/1.10/intro/tutorial06/ 
>>>> >> >> > 
>>>> >> >> > my project name:mysite 
>>>> >> >> > 
>>>> >> >> > structure: 
>>>> >> >> > 
>>>> >> >> > - mysite- 
>>>> >> >> > 
>>>> >> >> >  - mysite - urls.py 
>>>> >> >> > 
>>>> >> >> >-views.py 
>>>> >> >> > 
>>>> >> >> > ... 
>>>> >> >> > 
>>>> >> >> >  - templates - index.html 
>>>> >> >> > 
>>>> >> >> >  - images 
>>>> >> >> >  - static - mysite - assets - css - main.css 
>>>> >> >> > 
>>>> >> >> > - js 
>>>> >> >> > 
>>>> >> >> > ... 
>>>> >> >> > In my index.html 
>>>> 

Re: Import css in Django

2016-09-12 Thread Jonathan Cheng
i change into href="{% static '/assets/css/main.css' %}
and it worked
but if i want to use the all files in static
is there any way to do it?

ludovic coues於 2016年9月12日星期一 UTC+8上午1時32分42秒寫道:
>
> If you look at the html send by django, what is the href value ?
>
> 2016-09-11 19:15 GMT+02:00 Jonathan Cheng  >:
>
>> i fixed usint STATIC_ROOD = '/static/'
>> it seems to no error
>> but when i connect to my runserver
>> the css of  assets just doesn't work
>>
>>
>> Jonathan Cheng於 2016年9月12日星期一 UTC+8上午1時04分22秒寫道:
>>
>>> here i explain , because  i just test how main.css work, finally i want 
>>> to use the assets and images .
>>> and i use the python mange.py collectstatic
>>> it showed 
>>>
>>> ImproperlyConfigured: The STATICFILES_DIRS setting should not contain 
>>>> the STATIC_ROOT setting 
>>>>
>>>
>>> ludovic coues於 2016年9月12日星期一 UTC+8上午12時53分08秒寫道:
>>>>
>>>> I mentionned tree because I have doubt about what "static - assets - 
>>>> css - main.css" means. If your path is really 
>>>> /mysite/static/assets/css/main.css, then you want >>> rel="stylesheet" text = 'html/css' href="{% static 
>>>> 'assets/css/main.css' %}" />. 
>>>>
>>>> At least with a debug configuration, django will search for static 
>>>> file in each apps' static directory for the path you used as arguments 
>>>> for static. 
>>>> With a production configuration, you should use manage.py 
>>>> collectstatic which will grab all static file and copy them in a 
>>>> single directory. 
>>>>
>>>> 2016-09-11 18:18 GMT+02:00 Jonathan Cheng : 
>>>> > 
>>>> > https://gist.github.com/cj10243/fb557903441d4a3e95190b854fbaabe1 
>>>> > 
>>>> > ludovic coues於 2016年9月12日星期一 UTC+8上午12時05分12秒寫道: 
>>>> >> 
>>>> >> I have a hard time to read the paths you use. The command tree 
>>>> produce 
>>>> >> a nice tree view of a directory, it might help. You can also use 
>>>> >> service like http://paste2.org/ or https://gist.github.com/ to 
>>>> share 
>>>> >> it 
>>>> >> 
>>>> >> 2016-09-11 17:58 GMT+02:00 Jonathan Cheng : 
>>>> >> > thx reply,but it just can see the original html with no css,is my 
>>>> path 
>>>> >> > setted correct? 
>>>> >> > 
>>>> >> > ludovic coues於 2016年9月11日星期日 UTC+8下午11時45分24秒寫道: 
>>>> >> >> 
>>>> >> >> Have you tried to add a few newlines to be sure about which line 
>>>> is the 
>>>> >> >> issue ? 
>>>> >> >> 
>>>> >> >> Also, in you email, there is a space between % and } in the load 
>>>> >> >> staticfiles tag 
>>>> >> >> 
>>>> >> >> 2016-09-11 7:29 GMT+02:00 Jonathan Cheng : 
>>>> >> >> > I use django1.10 
>>>> >> >> > 
>>>> >> >> > i reference the official doc 
>>>> >> >> > https://docs.djangoproject.com/en/1.10/intro/tutorial06/ 
>>>> >> >> > 
>>>> >> >> > my project name:mysite 
>>>> >> >> > 
>>>> >> >> > structure: 
>>>> >> >> > 
>>>> >> >> > - mysite- 
>>>> >> >> > 
>>>> >> >> >  - mysite - urls.py 
>>>> >> >> > 
>>>> >> >> >-views.py 
>>>> >> >> > 
>>>> >> >> > ... 
>>>> >> >> > 
>>>> >> >> >  - templates - index.html 
>>>> >> >> > 
>>>> >> >> >  - images 
>>>> >> >> >  - static - mysite - assets - css - main.css 
>>>> >> >> > 
>>>> >> >> > - js 
>>>> >> >> > 
>>>> >> >> > ... 
>>>> >> >> > In my index.html 
>>>> >&

Re: Import css in Django

2016-09-12 Thread Jonathan Cheng
i use href="{% static '/assets/css/main.css' %}
and the css worked
but i want to use the all files in assets
is there any other way to do it?

ludovic coues於 2016年9月12日星期一 UTC+8上午1時32分42秒寫道:
>
> If you look at the html send by django, what is the href value ?
>
> 2016-09-11 19:15 GMT+02:00 Jonathan Cheng  >:
>
>> i fixed usint STATIC_ROOD = '/static/'
>> it seems to no error
>> but when i connect to my runserver
>> the css of  assets just doesn't work
>>
>>
>> Jonathan Cheng於 2016年9月12日星期一 UTC+8上午1時04分22秒寫道:
>>
>>> here i explain , because  i just test how main.css work, finally i want 
>>> to use the assets and images .
>>> and i use the python mange.py collectstatic
>>> it showed 
>>>
>>> ImproperlyConfigured: The STATICFILES_DIRS setting should not contain 
>>>> the STATIC_ROOT setting 
>>>>
>>>
>>> ludovic coues於 2016年9月12日星期一 UTC+8上午12時53分08秒寫道:
>>>>
>>>> I mentionned tree because I have doubt about what "static - assets - 
>>>> css - main.css" means. If your path is really 
>>>> /mysite/static/assets/css/main.css, then you want >>> rel="stylesheet" text = 'html/css' href="{% static 
>>>> 'assets/css/main.css' %}" />. 
>>>>
>>>> At least with a debug configuration, django will search for static 
>>>> file in each apps' static directory for the path you used as arguments 
>>>> for static. 
>>>> With a production configuration, you should use manage.py 
>>>> collectstatic which will grab all static file and copy them in a 
>>>> single directory. 
>>>>
>>>> 2016-09-11 18:18 GMT+02:00 Jonathan Cheng : 
>>>> > 
>>>> > https://gist.github.com/cj10243/fb557903441d4a3e95190b854fbaabe1 
>>>> > 
>>>> > ludovic coues於 2016年9月12日星期一 UTC+8上午12時05分12秒寫道: 
>>>> >> 
>>>> >> I have a hard time to read the paths you use. The command tree 
>>>> produce 
>>>> >> a nice tree view of a directory, it might help. You can also use 
>>>> >> service like http://paste2.org/ or https://gist.github.com/ to 
>>>> share 
>>>> >> it 
>>>> >> 
>>>> >> 2016-09-11 17:58 GMT+02:00 Jonathan Cheng : 
>>>> >> > thx reply,but it just can see the original html with no css,is my 
>>>> path 
>>>> >> > setted correct? 
>>>> >> > 
>>>> >> > ludovic coues於 2016年9月11日星期日 UTC+8下午11時45分24秒寫道: 
>>>> >> >> 
>>>> >> >> Have you tried to add a few newlines to be sure about which line 
>>>> is the 
>>>> >> >> issue ? 
>>>> >> >> 
>>>> >> >> Also, in you email, there is a space between % and } in the load 
>>>> >> >> staticfiles tag 
>>>> >> >> 
>>>> >> >> 2016-09-11 7:29 GMT+02:00 Jonathan Cheng : 
>>>> >> >> > I use django1.10 
>>>> >> >> > 
>>>> >> >> > i reference the official doc 
>>>> >> >> > https://docs.djangoproject.com/en/1.10/intro/tutorial06/ 
>>>> >> >> > 
>>>> >> >> > my project name:mysite 
>>>> >> >> > 
>>>> >> >> > structure: 
>>>> >> >> > 
>>>> >> >> > - mysite- 
>>>> >> >> > 
>>>> >> >> >  - mysite - urls.py 
>>>> >> >> > 
>>>> >> >> >-views.py 
>>>> >> >> > 
>>>> >> >> > ... 
>>>> >> >> > 
>>>> >> >> >  - templates - index.html 
>>>> >> >> > 
>>>> >> >> >  - images 
>>>> >> >> >  - static - mysite - assets - css - main.css 
>>>> >> >> > 
>>>> >> >> > - js 
>>>> >> >> > 
>>>> >> >> > ... 
>>>> >> >> > In my index.html 
>>>> >&

Re: Import css in Django

2016-09-15 Thread Jonathan Cheng
thx everyone,all bugs were fixed early.


Jonathan Cheng於 2016年9月11日星期日 UTC+8下午10時59分56秒寫道:
>
> I use django1.10
>
> i reference the official doc
> https://docs.djangoproject.com/en/1.10/intro/tutorial06/
>
> my project name:mysite
>
> structure:
>   
> - mysite-
>
>  - mysite - urls.py
>
>-views.py
>
> ...
>
>  - templates - index.html 
>
>  - images 
>  - static - mysite - assets - css - main.css
>  
> - js
>
> ...
> In my index.html
>
> add
>
> `{% load staticfiles % }
> `
>
> it said i have a Invalid block tag about TemplateSyntaxError
> ``
>
> views.py (about static files part)
> ```STATICFILES_DIRS = [
> os.path.join(BASE_DIR, "static"),
> '/mysite/static/',
> ]
> STATIC_URL = '/static/'
> STATIC_ROOT='/mysite/static/'```
>
> what's part should i notice?
>

-- 
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/8190791f-dbb7-426f-b7d1-d6227f9ffbfa%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Import css in Django

2016-09-15 Thread Jonathan Cheng
thx your code,though i cant run it in cmd

Mike Dewhirst於 2016年9月12日星期一 UTC+8上午10時05分10秒寫道:
>
> Jonathan 
>
> I use the attached announce.py to display exactly where all the 
> directories and URLs are. I had trouble in the beginning getting it 
> straight in my head but seeing it every time I looked at the dev-server 
> output helped a lot. 
>
> Comments in announce.py show how to use it. 
>
> Good luck 
>
> Mike 
>
> On 12/09/2016 1:58 AM, Jonathan Cheng wrote: 
> > thx reply,but it just can see the original html with no css,is my path 
> > setted correct? 
> > 
> > ludovic coues於 2016年9月11日星期日 
> > UTC+8ä¸‹å ˆ11時45分24ç§’å¯«é “ï¼š 
> > 
> > Have you tried to add a few newlines to be sure about which line 
> > is the issue ? 
> > 
> > Also, in you email, there is a space between % and } in the load 
> > staticfiles tag 
> > 
> > 2016-09-11 7:29 GMT+02:00 Jonathan Cheng  > >: 
> > > I use django1.10 
> > > 
> > > i reference the official doc 
> > > https://docs.djangoproject.com/en/1.10/intro/tutorial06/ 
> > <https://docs.djangoproject.com/en/1.10/intro/tutorial06/> 
> > > 
> > > my project name:mysite 
> > > 
> > > structure: 
> > > 
> > > - mysite- 
> > > 
> > > Â  Â  Â  Â  Â  Â  Â - mysite - urls.py 
> > > 
> > > Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â -views.py 
> > > 
> > > Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  ... 
> > > 
> > > Â  Â  Â  Â  Â  Â  Â - templates - index.html 
> > > 
> > > Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â - images 
> > > Â  Â  Â  Â  Â  Â  Â - static - mysite - assets - css - main.css 
> > > 
> > > Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â Â  - js 
> > > 
> > > Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â Â  ... 
> > > In my index.html 
> > > 
> > > add 
> > > 
> > > `{% load staticfiles % } 
> > > Â  Â  Â  Â  ` 
> > > 
> > > it said i have a Invalid block tag about TemplateSyntaxError 
> > > `` 
> > > 
> > > views.py (about static files part) 
> > > ```STATICFILES_DIRS = [ 
> > > Â  Â  os.path.join(BASE_DIR, "static"), 
> > > Â  Â  '/mysite/static/', 
> > > ] 
> > > STATIC_URL = '/static/' 
> > > STATIC_ROOT='/mysite/static/'``` 
> > > 
> > > what's part should i notice? 
> > > 
> > > -- 
> > > You received this message because you are subscribed to the 
> > Google Groups 
> > > "Django users" group. 
> > > To unsubscribe from this group and stop receiving emails from 
> > it, send an 
> > > email to django-users...@googlegroups.com . 
> > > To post to this group, send email to django...@googlegroups.com 
> > . 
> > > Visit this group at https://groups.google.com/group/django-users 
> > <https://groups.google.com/group/django-users>. 
> > > To view this discussion on the web visit 
> > > 
> > 
> https://groups.google.com/d/msgid/django-users/ef2ea6eb-d1cb-40e2-abef-1af246e02e98%40googlegroups.com
>  
> > <
> https://groups.google.com/d/msgid/django-users/ef2ea6eb-d1cb-40e2-abef-1af246e02e98%40googlegroups.com>.
>  
>
> > 
> > > For more options, visit https://groups.google.com/d/optout 
> > <https://groups.google.com/d/optout>. 
> > 
> > 
> > 
> > -- 
> > 
> > Cordialement, Coues Ludovic 
> > +336 148 743 42 
> > 
> > -- 
> > You received this message because you are subscribed to the Google 
> > Groups "Django users" group. 
> > To unsubscribe from this group and stop receiving emails from it, send 
> > an email to django-users...@googlegroups.com  
> > <mailto:django-users+unsubscr...@googlegroups.com >. 
> > To post to this group, send email to django...@googlegroups.com 
>  
> > <mailto:django...@googlegroups.com >. 
> > Visit this group at https://groups.google.com/group/django-users. 
> > To view this discussion on the web visit 
> > 
> https://groups.google.com/d/msgid/django-users/a699584c-d57f-4b84-a38b-fe03638caefd%40googlegroups.com
>  
> > <
> https://groups.google.com/d/msgid/django-users/a699584c-d57f-4b84-a38b-fe03638caefd%40googlegroups.com?utm_medium=email&utm_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/385a4dc3-8f15-4252-bf8a-c9fd41f08a70%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


  1   2   >