Re: PyDev users: how do you manage tabs?

2009-07-01 Thread Chris Lawlor

I have the same problem in Komodo Edit - although I the whole filename
does show up in the window title I never think to look there. Anyway,
I partially solved it by adding a comment at the top of the file for
what app the file is for, so I'll see what I'm working on right there
in the editor window.

On Jul 1, 11:41 am, Steve Howell  wrote:
> On Jun 30, 10:42 pm, Rex  wrote:
>
> > Kind of a petty question:
>
> > I've been using PyDev to do my Django work and find it to be great.
> > However, my only gripe is that it's hard to keep track of tabs, since
> > they display only the (non-qualified) file name, which is a problem
> > given Django's very regular naming scheme. So for example I'll often
> > have 4+ tabs that are all named "views.py", and I have to mouse over
> > each to find which one is the one I'm looking for.
>
> I definitely feel your pain.
>
> One thing that you can do is put view code into files that are not
> called "views.py."  It's always a little risky to break the convention
> here, but I have done it in on nontrivial projects without major
> hangups.
>
> On the other hand I don't think you want to mess with conventions on
> models.py and certain other files, but I tend to spend less time
> editing those.
--~--~-~--~~~---~--~~
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: PyDev users: how do you manage tabs?

2009-07-02 Thread Chris Lawlor

Wayne I can't thank you enough!!

As the author notes, the posted code is not cross-platform. I
incorporated the fix recommended in the comments and posted here for
anyone else that might want it:
http://dpaste.com/hold/62468/

works fine on my windows machine, haven't tested on my Linux dev box
yet.

On Jul 1, 12:38 pm, AmanKow  wrote:
> > I have the same problem in Komodo Edit - although I the whole filename
> > does show up in the window title I never think to look there. Anyway,
> > I partially solved it by adding a comment at the top of the file for
> > what app the file is for, so I'll see what I'm working on right there
> > in the editor window.
>
> > On Jul 1, 11:41 am, Steve Howell  wrote:
>
> > > On Jun 30, 10:42 pm, Rex  wrote:
>
> > > > Kind of a petty question:
>
> > > > I've been using PyDev to do my Django work and find it to be great.
> > > > However, my only gripe is that it's hard to keep track of tabs, since
> > > > they display only the (non-qualified) file name, which is a problem
> > > > given Django's very regular naming scheme. So for example I'll often
> > > > have 4+ tabs that are all named "views.py", and I have to mouse over
> > > > each to find which one is the one I'm looking for.
>
> > > I definitely feel your pain.
>
> > > One thing that you can do is put view code into files that are not
> > > called "views.py."  It's always a little risky to break the convention
> > > here, but I have done it in on nontrivial projects without major
> > > hangups.
>
> > > On the other hand I don't think you want to mess with conventions on
> > > models.py and certain other files, but I tend to spend less time
> > > editing those.
>
> http://traviscline.com/blog/2008/04/30/komodo-tab-macro-to-ease-djang...
>
> There are ways to get the behavior you want in Komodo!
>
> Enjoy,
> Wayne
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Installing django

2009-05-21 Thread Chris Lawlor

Just to see what all the fuss is about, most of that video is the guy
configuring his particular application. The actual Django install is
very straightforward.

On May 21, 1:53 am, Kenneth Gonsalves  wrote:
> On Thursday 21 May 2009 11:15:29 LeonTheCleaner wrote:
>
> > @sdc, yeah I plan to try webfaction. The only thing is I just quickly
> > checked out their demo video to setup django and itès 21 mins. I am
> > blown away to see how complicated just setting this up, and I am an
> > experienced windows programmer. Just expected a lot less steps.
>
> why follow their steps? just follow the steps in the django tutorial.
> --
> regards
> kghttp://lawgon.livejournal.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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Format fields in list, but keep sortable?

2009-12-08 Thread Chris Lawlor
You could add a field to store the calculated size, and override the
model's save method to perform the necessary calculation. Something
like:

def save(self, force_insert=False, force_update=False):
self.size_formatted = self.width * self.height // or whatever your
calculation actually is
super(ModelName, self).save(force_insert, force_update)

Be sure to replace 'ModelName' with the name of your model.

On Dec 8, 7:18 am, philomat  wrote:
> Hi,
>
> I keep numeric fields like "size", "width", "height" in my database.
> In the admin, I want to render them in a friendly format and attach
> units like "KiB" or "pixels" to them when showing them in the change
> list. I know this could easily be achieved by adding callables such as
> "size_formatted" etc to list_display. However, these are no longer
> sortable.
>
> Is there a way around this limitation?

--

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




Re: contrib.auth.views - n00b question

2010-07-06 Thread Chris Lawlor
You probably don't want to reference the login view to /accounts. You
probably mean to do this:

(r'^accounts/', include ('django.contrib.auth.urls'),

That will map /accounts/login to django.contrib.views.login, /accounts/
logout to django.contrib.views.logout, etc.

In general, when using an app, you'll add a line to your base URLConf
that includes that app's urls module.

On Jul 6, 9:04 am, Tom Evans  wrote:
> On Tue, Jul 6, 2010 at 2:00 PM, reduxdj  wrote:
> > Hi,
>
> > I have an issue where i am including contrib.auth into my URLs,
> > however, I get this error:
>
> > my url pattern:
>
> > (r'^accounts/', include('django.contrib.auth.views.login')),
>
> django.contrib.auth.views.login is a view, not a url pattern, so you
> don't include it, you reference it:
>
> (r'^accounts/', 'django.contrib.auth.views.login'),
>
> Cheers
>
> Tom

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



Re: contrib.auth.views - n00b question

2010-07-07 Thread Chris Lawlor
;/usr/lib/python2.6/dist-packages/django/template/__init__.py" in
> _render
>   167.         return self.nodelist.render(context)
> File "/usr/lib/python2.6/dist-packages/django/template/__init__.py" in
> render
>   796.                 bits.append(self.render_node(node, context))
> File "/usr/lib/python2.6/dist-packages/django/template/debug.py" in
> render_node
>   72.             result = node.render(context)
> File "/usr/lib/python2.6/dist-packages/django/template/loader_tags.py"
> in render
>   125.         return compiled_parent._render(context)
> File "/usr/lib/python2.6/dist-packages/django/template/__init__.py" in
> _render
>   167.         return self.nodelist.render(context)
> File "/usr/lib/python2.6/dist-packages/django/template/__init__.py" in
> render
>   796.                 bits.append(self.render_node(node, context))
> File "/usr/lib/python2.6/dist-packages/django/template/debug.py" in
> render_node
>   72.             result = node.render(context)
> File "/usr/lib/python2.6/dist-packages/django/template/defaulttags.py"
> in render
>   252.             return self.nodelist_true.render(context)
> File "/usr/lib/python2.6/dist-packages/django/template/__init__.py" in
> render
>   796.                 bits.append(self.render_node(node, context))
> File "/usr/lib/python2.6/dist-packages/django/template/debug.py" in
> render_node
>   72.             result = node.render(context)
> File "/usr/lib/python2.6/dist-packages/django/template/defaulttags.py"
> in render
>   252.             return self.nodelist_true.render(context)
> File "/usr/lib/python2.6/dist-packages/django/template/__init__.py" in
> render
>   796.                 bits.append(self.render_node(node, context))
> File "/usr/lib/python2.6/dist-packages/django/template/debug.py" in
> render_node
>   72.             result = node.render(context)
> File "/usr/lib/python2.6/dist-packages/django/template/loader_tags.py"
> in render
>   62.             result = block.nodelist.render(context)
> File "/usr/lib/python2.6/dist-packages/django/template/__init__.py" in
> render
>   796.                 bits.append(self.render_node(node, context))
> File "/usr/lib/python2.6/dist-packages/django/template/debug.py" in
> render_node
>   72.             result = node.render(context)
> File "/usr/lib/python2.6/dist-packages/django/template/defaulttags.py"
> in render
>   367.             url = reverse(self.view_name, args=args,
> kwargs=kwargs, current_app=context.current_app)
> File "/usr/lib/python2.6/dist-packages/django/core/urlresolvers.py" in
> reverse
>   356.             *args, **kwargs)))
> File "/usr/lib/python2.6/dist-packages/django/core/urlresolvers.py" in
> reverse
>   277.         possibilities = self.reverse_dict.getlist(lookup_view)
> File "/usr/lib/python2.6/dist-packages/django/core/urlresolvers.py" in
> _get_reverse_dict
>   199.             self._populate()
> File "/usr/lib/python2.6/dist-packages/django/core/urlresolvers.py" in
> _populate
>   179.                     for name in pattern.reverse_dict:
> File "/usr/lib/python2.6/dist-packages/django/core/urlresolvers.py" in
> _get_reverse_dict
>   199.             self._populate()
> File "/usr/lib/python2.6/dist-packages/django/core/urlresolvers.py" in
> _populate
>   168.         for pattern in reversed(self.url_patterns):
> File "/usr/lib/python2.6/dist-packages/django/core/urlresolvers.py" in
> _get_url_patterns
>   249.         patterns = getattr(self.urlconf_module, "urlpatterns",
> self.urlconf_module)
> File "/usr/lib/python2.6/dist-packages/django/core/urlresolvers.py" in
> _get_urlconf_module
>   244.             self._urlconf_module =
> import_module(self.urlconf_name)
> File "/usr/lib/python2.6/dist-packages/django/utils/importlib.py" in
> import_module
>   35.     __import__(name)
> File "/django/projects/huntgather/registration/urls.py" in 
>   14. from gather import login,logout
>
> Exception Type: TemplateSyntaxError at /admin/
> Exception Value: Caught ImportError while rendering: cannot import
> name login
>
> On Jul 6, 9:24 am, Chris Lawlor  wrote:> You probably 
> don't want to reference the login view to /accounts. You
> > probably mean to do this:
>
> > (r'^accounts/', include ('django.contrib.auth.urls'),
>
> > That will map /accounts/login to django.contrib.views.login, /accounts/
> > logout to django.contrib.views.logout, etc.
>
> > In general, when using an app, you'll add a line to your base URLConf
> > that includes that app's urls module.
>
> > On Jul 6, 9:04 am, Tom Evans  wrote:
>
> > > On Tue, Jul 6, 2010 at 2:00 PM,reduxdj wrote:
> > > > Hi,
>
> > > > I have an issue where i am including contrib.auth into my URLs,
> > > > however, I get this error:
>
> > > > my url pattern:
>
> > > > (r'^accounts/', include('django.contrib.auth.views.login')),
>
> > > django.contrib.auth.views.login is a view, not a url pattern, so you
> > > don't include it, you reference it:
>
> > > (r'^accounts/', 'django.contrib.auth.views.login'),
>
> > > Cheers
>
> > > Tom

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



Re: www.djangoproject.com

2010-07-14 Thread Chris Lawlor
Nick, thank you so much for figuring this out!!

On Jul 8, 11:12 am, Nick Raptis  wrote:

> In firefox, check your preffered language settings, in the content tab.
>
> If there is a non-standard value there (perhaps "/etc/locale/prefs.conf"
> or something) instead of a locale like en-US,
> some django pages won't ever display.
>
> Nick
>
> On 07/08/2010 04:11 PM, eon wrote:
>
> > Same for me. The problem is in the firefox profile (maybe due to the
> > switch from 3.5 to 3.6 ?)
>
> > Start-up with a new profile (backport plugins, bookmarks argh...)
> > resolves the issue
>
> > On 5 juil, 20:52, Andi  wrote:
>
> >> On Jul 2, 10:44 pm, Bill Freeman  wrote:
>
> >>> What might be of help is adding the IP address to /etc/hosts, if you are
> >>> on linux.
>
> >> I have the same problem regarding djangoproject.com (Firefox 3.6.6 on
> >> Ubuntu).  Everything works but Firefox using my default profile: host
> >> and nslookup succeed in resolving the domain name.  Adding the IP to /
> >> etc/hosts or accessing the IP address directly in firefox doesn't
> >> help.  Opera, chromium, arora, w3m, elinks, lynx and konqueror are not
> >> affected.  Firefoxes on other hosts within the same LAN can connect to
> >> djangoproject.com without a problem.  Disabling all add-ons living in
> >> my Firefox doesn't have an effect -- but starting with a fresh profile
> >> does: djangoproject.com loads successfully.
>
> >> It's a very strange problem, because there is no problem with the
> >> other thousands of websites I've visited during the last days.  It's
> >> the combination djangoproject.com + my main Firefox profile which
> >> produces the problem exclusively.
>
> >> --
> >> Andi

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



Re: newbie question

2010-10-04 Thread Chris Lawlor
Also, one way to integrate scripts like this is to write them as
django management commands, so you can run them as 'python manage.py
yourcommand'. Management commands are pretty well documented in the
django docs, you should have no trouble finding enough info to get
started.


Again, good luck

Chris Lawlor

On Oct 4, 3:29 am, Martin Melin  wrote:
> On Mon, Oct 4, 2010 at 8:25 AM, mark jason  wrote:
> > hi
> > I am quite new to django ..I  have written a web app that takes user
> > input  and adds  customer details to db.
> > I store customer name,email ,a datetime value for each customer.
>
> > When the application starts ,I want a utility program to check the db
> > and if system datetime matches the datetime value stored for each
> > customer, an email is sent to the customer.
>
> > My doubt is ,where and how should I put the db checking and email
> > sending event logic.Should it be when the webserver starts(at python
> > manage.py runserver) ?If so ,where do I put the call to
> > check_db(),send_email() etc
>
> > I know it is a silly one,but please understand that I am a newcomer to
> > django and python..and programming in general
>
> > thanks and hoping for guidance
> > mark
>
> I assume the functionality you're after is that a specific user should
> receive an email as close to the datetime in their profile as
> possible?
>
> In that case, you don't want to run this only at application start.
> Generally it is not recommended to do anything at start, because
> depending on your environment it can be kind of undefined when
> "application start" actually occurs. "python manage.py runserver" is
> the so-called development server, and you should not rely on using it
> in production (when the app is on a server, not your local computer)
>
> A common way to solve problems like the one you're describing is to
> have a standalone script that runs periodically, triggered by cron.
>
> For info on writing scripts that have access to your Django project's
> models etc., have a look at Google's results for "django crontab" or
> similar.
>
> Good luck!
>
> Best regards,
> Martin Melin

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



Re: apache reload

2010-10-04 Thread Chris Lawlor
One approach is to set "MaxRequestsPerChild" to one, basically forcing
the server to reload on every request. Probably not the most efficient
way to accomplish this, but almost certainly the most simple to
implement.

On Oct 3, 5:39 pm, Олег Корсак 
wrote:
> Hello. I'm using mod_wsgi 3.3 + apache 2.2.16 on Gentoo Linux box.
> Is it possible to make apache kinda "reload"/"re-read"/"re-compile"
> python files from my django code every time they are changed?
>
> Thanks
>
>  signature.asc
> < 1KViewDownload

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



Re: help with django comments

2010-11-07 Thread Chris Lawlor

Assuming your app is named 'gallery' with a model named 'photo', I
believe the call should be:

{% get_comment_count for gallery.photo as comment_count %}


On Nov 6, 5:12 pm, Bobby Roberts  wrote:
> howdy -
>
> i'm trying to use comments on my site as follows:
>
> {% get_comment_count for galleryphoto as comment_count %}
>
> this generates the following error:
>
> Caught AttributeError while rendering: 'str' object has no attribute
> '_meta'
>
> any idea what this error means?
>
> I looked in /admin and under comments and in objects, i see "gallery
> photo" (with a space).
>
> when i try to use:
>
> {% get_comment_count for gallery photo as comment_count %}   <<< note
> the space in gallery photo
>
> I get this err:
>
> Third argument in u'get_comment_count' must be in the format
> 'app.model'
>
> any help is appreciated on how to address this issue.

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



Re: How to join a search on user and user profile

2010-11-22 Thread Chris Lawlor
You should be able to do something like:

UserProfile.objects.filter(gender='female',
user__email='some...@mail.com')

Note the double underscore notation, which let's you access attributes
of the related model. This example assumes that UserProfile has a FK
field to User which is named 'user'.

On Nov 21, 10:36 pm, Rogério Carrasqueira
 wrote:
> Hello Folks!
>
> I'm working on my system that has 2 classes to work with user managemet:
> User and UserProfile, and I would like to make on admin an unified search.
> For example I would like to find a user by e-mail at User class and all User
> that is female or something like that. So, Is there anyway to work on this
> direction?
>
> Thanks
>
> Rogério Carrasqueira
>
> ---
> e-mail: rogerio.carrasque...@gmail.com
> skype: rgcarrasqueira
> MSN: rcarrasque...@hotmail.com
> ICQ: 50525616
> Tel.:(11) 7805-0074

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



Re: How do you write a django model that can crunch numbers and automatically populate another field with results?

2012-05-14 Thread Chris Lawlor
Also, you can use aggregate queries to get the tfidf max and min:

from django.db.models import Max, Min

Party.objects.all().aggregate(Max(tfidf'))
{'tfidf__max': 0.5 }

See https://docs.djangoproject.com/en/dev/topics/db/aggregation/#cheat-sheet


On Wednesday, 9 May 2012 01:00:18 UTC-4, Andy McKay wrote:
>
> You can hook into the model signal so that when the model changes, you 
> do you calculation and change your models. 
>
>
> https://docs.djangoproject.com/en/dev/ref/signals/#django.db.models.signals.post_save
>  
>

-- 
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/-/-pW2UGkaJksJ.
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: Ranking Queryset

2012-06-20 Thread Chris Lawlor
If you can use 
.annotate()to
 calculate the rank, you can further filter / order the annotation 
results.

An example:

class Book(models.Model):
title = models.CharField(max_length=120)
...

class Vote(models.Model):
user = models.ForeignKey('User')
score = models.IntegerField(choices=((-1, 'Thumbs Down'), (+1, 'Thumbs 
Up')))
book = models.ForeignKey('Book', related_name='votes')


To rank the Books by the sum of thumbs up and thumbs down votes, you could 
do the following:

Book.objects.all().annotate(rank=Sum('votes__score'))

Each object returned by this QuerySet will now have a 'rank' attribute, 
which is the sum of the Vote scores. You can then filter or order by rank. 
For example, to retrieve only books with a positive overall rank:

Book.objects.all().annotate(rank=Sum('votes__score')).filter(rank__gt=0).order_by('rank')

Hope that helps.

* Code isn't tested

On Tuesday, 19 June 2012 13:27:21 UTC-4, Peter Ung wrote:
>
> Hi All,
>
> I'm trying to do ranking of a QuerySet efficiently (keeping it a QuerySet 
> so I can keep the filter and order_by functions), but cannot seem to find 
> any other way then to iterate through the QuerySet and tack on a rank. I 
> dont want to add rank to my model. 
>
> I know how I can get the values I need through SQL query, but can't seem 
> to translate that into Django:
>
> SET @rank = 0, @prev_val = NULL;
>> SELECT rank, name, school, points FROM
>> (SELECT @rank := IF(@prev_val = points, @rank, @rank+1) AS rank, 
>> @prev_val := points, points, CONCAT(users.first_name, ' ', users.last_name) 
>> as name, school.name as school
>> FROM accounts_collegebrainuserprofile 
>> JOIN schools_school school ON school_id = school.id
>> JOIN auth_user users ON user_id = users.id 
>> ORDER BY points DESC) as profile
>> ORDER BY rank DESC
>>
>
> I found that if I did iterate through the QuerySet and tacked on 'rank' 
> manually and then further filtered the results, my 'rank' would disappear. 
> Is there any other way you can think of to add rank to my QuerySet? Is 
> there any way I could do the above query and get a QuerySet with filter and 
> order_by functions still intact? I'm currently using the jQuery DataTables 
> with Django to generate a leaderboard with pagination (which is why I need 
> to preserver filtering and order_by).
>
> Thanks in advance! Sorry if I did not post my question correctly - any 
> help would be much appreciated.
>
> Peter
>  
>

-- 
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/-/D3KdzJZq8GYJ.
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: need help on set_password()..............

2012-07-29 Thread Chris Lawlor
If you're using the User model from contrib.auth, you can simply use 
User.objects.create_user(username, email=None, password=password). This 
will create a new User object, and then call set_password()

# forms.py
class RegistrationForm(form.Form):
username = forms.CharField()
password = forms.CharField(widget=PasswordInput)

# views.py
def register(request):
if request.method == 'POST':
form = RegistrationForm(request.POST)
if form.is_valid():
# UserManager.create_user() is a convenience method for 
creating a new user, and calling user.set_password()
user = User.objects.create_user(form.cleaned_data['username''], 
password=form.cleaned_data['password'])
else:
form = RegistrationForm()
return render(request, 'your_template.html', {'form': form})

If you're not using Django's User model, you could use one of the password 
hashers from contrib.auth.hashers to create the hashed version of the 
user's password. Something like:


class MyUser(models.Model):
username = models.CharField(...)
password = models.CharField(max_length=128)

# views.py

from django.contrib.auth.hashers import PBKDF2PasswordHasher as hasher

def register(request):
...
user = MyUser.objects.create(username=form.cleaned_data['username'], 
commit=False)
salt = hasher.salt()
user.password = hasher.encode(form.cleaned_data['password'], salt)
user.save()


Or better yet, move the user creation logic into a manager, similar to the 
design of UserManager:

class MyUserManager(models.Manager):
def create_user(self, username, password):
user = self.model.create(username, commit=False)
salt = hasher.salt()
user.password = hasher.encode(password, salt)
return user

class MyUser(models.Model):
...
objects = MyUserManager()

With that, you can do user = MyUser.objects.create_user(username, password).

Looking at the source code for 
contrib.auth.modelsand
 
contrib.auth.hashersmay
 prove helpful.


If you have existing password data that you need to convert to a hashed 
format, you might consider using a South data migration. Conveniently, the 
tutorial on data migrations uses this use case as an example: 
http://south.readthedocs.org/en/latest/tutorial/part3.html#data-migrations.

(Consider all code to be untested pseudo-code)

On Saturday, 28 July 2012 22:14:52 UTC-4, Sajja1260 wrote:
>
> hi every one,
>   i created one external registration form.. all are 
> working good, but when we open the admin sit it showing the password as 
> plain text. how to convert the password into hash formate and save into 
> database.. can any one suggest for the abovt one
>
>
> --
> Thanks in advance 
> yaswanth
>
>  

-- 
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/-/_q7uosZ0VSUJ.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Django development running on 127.0.0.1:8000 not accessible from same machine

2012-08-31 Thread Chris Lawlor
Jirka,

Is your app possibly doing a 301 (Permanent) redirect to www.* ? Or 
possibly some other app you were working on recently? Browsers will cache 
301 redirects and automatically do the redirect WITHOUT making the initial 
request to 127.0.0.1, so if some project you were working on issued that 
redirect at any point, it will keep doing it, even if your current project 
doesn't issue a redirect. Try clearing your browser's cache.

Chris

On Tuesday, 28 August 2012 01:26:20 UTC-4, nav wrote:
>
> Hi Jirka, 
>
> That does not seem to be the case. I set rhe proxy server settings to no 
> proxy and it still prepends a www in front of the IP address. I could 
> investigate this further but I am little pressed for time at present. 
>
> Thanks, 
> nav 
>
> On Tuesday 28 August 2012 10:39 AM, jirka.v...@gmail.com wrote: 
> > Hi nav, 
> > 
> >A long shot - do you happen to have a proxy defined in your browser? 
> It is possible to define a proxy for *all* request (including localhost) - 
> this would have the same effect. 
> > 
> >HTH 
> > 
> >  Jirka 
> > -Original Message- 
> > From: nav > 
> > Sender: django...@googlegroups.com  
> > Date: Mon, 27 Aug 2012 21:00:12 
> > To: Django users> 
> > Reply-To: django...@googlegroups.com  
> > Subject: Re: Django development running on 127.0.0.1:8000 not 
> accessible from 
> >   same machine 
> > 
> > Hi Anton, 
> > 
> > Thank you for your email. 
> > 
> > I have tried all of the methods you had suggested but to no avail. 
> > 
> > In all my years of Django development the localhost address has worked 
> > flawlessly. I have also tried with multiple Django projects and other 
> > Linux installations and the problem persists. This makes me think this 
> > is a DNS issue that may be due to a network related problem. In which 
> > case I will have to investigate. I will post once I find a work around 
> > or solution. 
> > 
> > Cheers, 
> > nav 
> > 
> > On Aug 27, 5:36 pm, Anton Baklanov  wrote: 
> >> oh, i misunderstood your question. 
> >> 
> >> try to type url with schema into browser's address bar. i mean, use '
> http://localhost:8000/'instead of 'localhost:8000'. 
> >> also it's possible that some browser extension does this, try disabling 
> >> them all. 
> >> 
> >> 
> >> 
> >> 
> >> 
> >> 
> >> 
> >> 
> >> 
> >> On Mon, Aug 27, 2012 at 10:53 AM, nav  wrote: 
> >>> Dear Folks, 
> >> 
> >>> I am running my django development server on 127.0.0.1:8000 and 
> accessing 
> >>> this address from my web browser on the same machine. In the past few 
> days 
> >>> I have found thet the web browsers keep prepending the address with 
> "www." 
> >>> when using the above address. 127.0.0.1 without the prot number works 
> fine 
> >>> but the django development server requires a port number. 
> >> 
> >>> I have not encountered this problem before and am puzzled by what is 
> >>> happening. I am working on a Kubuntu 12.04 linux box and my 
> /etc/hosts/ 
> >>> file is below if that helps: 
> >> 
> >>>  
> >>> 127.0.0.1   localhost 
> >>> 127.0.1.1
> >> 
> >>> # The following lines are desirable for IPv6 capable hosts 
> >>> ::1 ip6-localhost ip6-loopback 
> >>> fe00::0 ip6-localnet 
> >>> ff00::0 ip6-mcastprefix 
> >>> ff02::1 ip6-allnodes 
> >>> ff02::2 ip6-allrouters 
> >>>  
> >> 
> >>> TIA 
> >>> Cheers, 
> >>> nav 
> >> 
> >>> -- 
> >>> 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/-/EZzlz6iQOGoJ.> To post 
> to this group, send email todjang...@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. 
> >> 
> >> -- 
> >> Regards, 
> >> Anton Baklanov 
> > 
>
>

-- 
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/-/dRWXRh3NMl0J.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Django development running on 127.0.0.1:8000 not accessible from same machine

2012-08-31 Thread Chris Lawlor
Oops that should have been addressed to nav, sorry

On Friday, 31 August 2012 11:57:03 UTC-4, Chris Lawlor wrote:
>
> Jirka,
>
> Is your app possibly doing a 301 (Permanent) redirect to www.* ? Or 
> possibly some other app you were working on recently? Browsers will cache 
> 301 redirects and automatically do the redirect WITHOUT making the initial 
> request to 127.0.0.1, so if some project you were working on issued that 
> redirect at any point, it will keep doing it, even if your current project 
> doesn't issue a redirect. Try clearing your browser's cache.
>
> Chris
>
> On Tuesday, 28 August 2012 01:26:20 UTC-4, nav wrote:
>>
>> Hi Jirka, 
>>
>> That does not seem to be the case. I set rhe proxy server settings to no 
>> proxy and it still prepends a www in front of the IP address. I could 
>> investigate this further but I am little pressed for time at present. 
>>
>> Thanks, 
>> nav 
>>
>> On Tuesday 28 August 2012 10:39 AM, jirka.v...@gmail.com wrote: 
>> > Hi nav, 
>> > 
>> >A long shot - do you happen to have a proxy defined in your browser? 
>> It is possible to define a proxy for *all* request (including localhost) - 
>> this would have the same effect. 
>> > 
>> >HTH 
>> > 
>> >  Jirka 
>> > -Original Message- 
>> > From: nav  
>> > Sender: django...@googlegroups.com 
>> > Date: Mon, 27 Aug 2012 21:00:12 
>> > To: Django users 
>> > Reply-To: django...@googlegroups.com 
>> > Subject: Re: Django development running on 127.0.0.1:8000 not 
>> accessible from 
>> >   same machine 
>> > 
>> > Hi Anton, 
>> > 
>> > Thank you for your email. 
>> > 
>> > I have tried all of the methods you had suggested but to no avail. 
>> > 
>> > In all my years of Django development the localhost address has worked 
>> > flawlessly. I have also tried with multiple Django projects and other 
>> > Linux installations and the problem persists. This makes me think this 
>> > is a DNS issue that may be due to a network related problem. In which 
>> > case I will have to investigate. I will post once I find a work around 
>> > or solution. 
>> > 
>> > Cheers, 
>> > nav 
>> > 
>> > On Aug 27, 5:36 pm, Anton Baklanov  wrote: 
>> >> oh, i misunderstood your question. 
>> >> 
>> >> try to type url with schema into browser's address bar. i mean, use '
>> http://localhost:8000/'instead of 'localhost:8000'. 
>> >> also it's possible that some browser extension does this, try 
>> disabling 
>> >> them all. 
>> >> 
>> >> 
>> >> 
>> >> 
>> >> 
>> >> 
>> >> 
>> >> 
>> >> 
>> >> On Mon, Aug 27, 2012 at 10:53 AM, nav  
>> wrote: 
>> >>> Dear Folks, 
>> >> 
>> >>> I am running my django development server on 127.0.0.1:8000 and 
>> accessing 
>> >>> this address from my web browser on the same machine. In the past few 
>> days 
>> >>> I have found thet the web browsers keep prepending the address with 
>> "www." 
>> >>> when using the above address. 127.0.0.1 without the prot number works 
>> fine 
>> >>> but the django development server requires a port number. 
>> >> 
>> >>> I have not encountered this problem before and am puzzled by what is 
>> >>> happening. I am working on a Kubuntu 12.04 linux box and my 
>> /etc/hosts/ 
>> >>> file is below if that helps: 
>> >> 
>> >>>  
>> >>> 127.0.0.1   localhost 
>> >>> 127.0.1.1
>> >> 
>> >>> # The following lines are desirable for IPv6 capable hosts 
>> >>> ::1 ip6-localhost ip6-loopback 
>> >>> fe00::0 ip6-localnet 
>> >>> ff00::0 ip6-mcastprefix 
>> >>> ff02::1 ip6-allnodes 
>> >>> ff02::2 ip6-allrouters 
>> >>>  
>> >> 
>> >>> TIA 
>> >>> Cheers, 
>> >>> nav 
>> >> 
>> >>> -- 
>> >>> 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/-/EZzlz6iQOGoJ.> To 
>> post to this group, send email todjang...@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. 
>> >> 
>> >> -- 
>> >> Regards, 
>> >> Anton Baklanov 
>> > 
>>
>>

-- 
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/-/J-wSSpx9UcQJ.
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: Am I using static files "wrong"?

2012-10-04 Thread Chris Lawlor
Micah,

Here's a summary of how staticfiles works:

1. You place your static files, which are under version control, in 
app/static folders, or any directory defined in STATICFILES_DIRS. This is 
configurable, and works very similarly to how templates are placed in a 
project. The important thing to note is that your 'source' static files can 
be scattered among several directories, all of which are under version 
control.
2. You define STATIC_ROOT, which is the absolute path to some directory on 
your filesystem where you want the static files to be collected 
to. STATIC_ROOT would not be under version control, although some 
developers like to add an empty '_static' folder to version control so you 
don't have to manually create the STATIC_ROOT folder when deploying the 
project to a new machine.
3. Running 'collectstatic' collects all of your static files, and copies 
them to STATIC_ROOT.
4. You configure your production webserver to serve '/static/' (or whatever 
STATIC_URL is set to) from STATIC_ROOT. If you add staticfiles_urlpatterns 
to your URL config, the development server will serve your static files if 
DEBUG=True.


The template context processor django.core.context_processors.static, which 
provides STATIC_URL, is not deprecated. Feel free to use either that or the 
template tag.


Hope that helps,

Chris
On Thursday, 4 October 2012 10:59:02 UTC-4, Micah Carrick wrote:
>
> Regarding Django 1.4...
>
> I recently came across a post that suggests that the way I'm managing 
> static files is "wrong". I wanted to make sure I'm clear on things.
>
> In development, static files are in the "static" folders both within apps 
> at the project level. STATIC_URL = '/static/'
>
> When I deploy a project, the collectstatic command copies *from* these 
> directories to a public folder on my static asset domain. STATIC_URL = '
> http://static.foobar.com/', STATIC_ROOT = "/var/www/static.foobar.com"
>
> Therefore, the "static" folder in my project directory is added to 
> STATICFILES_DIRS. Is that wrong? It was suggested that I'm supposed to be 
> collecting static files *to* the "static" folder--but that seems strange to 
> me as I don't want to collect static assets into my version controlled 
> source tree.
>
> Secondly, I've heard that we should be using the static template tag and 
> not the STATIC_URL context variable. I see the advantages of using the 
> template tag, but, it's not wrong to use STATIC_URL right? It's not 
> deprecated or anything?
>
> Cheers,
> - Micah
>
>
>  

-- 
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/-/6WZ-dz-uZScJ.
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: Calling Jquery or javascript function based on an if condition

2013-04-26 Thread Chris Lawlor
A slight variation of this approach is to map some Django template context 
info to Javascript variables in one of your templates, making that data 
accessible to your compressed / minified JS code:

# in a template, "base.html" perhaps..


window.DjangoContext = {
  userLoggedIn: {{ user.is_authenticated|yesno:"true,false" }}
}


Note the use of the 'yesno' filter to convert "True" to "true" to match JS 
syntax.

Now you can access DjangoContext.userLoggedIn anywhere in your JS.


** It's important to note that users can modify any JS variable they wish, 
so don't rely on something like this for security **

On Tuesday, 23 April 2013 16:45:20 UTC-4, Сергей Костюченко wrote:
>
>  {% if condition %}
>
> 
>
> some_function(params);
>
> 
>
> {% endif %}
>
> Sarfraz ahmad wrote at 23 апреля 2013 13:30:38:
>
> Guys, is it possible to call a javascript function in django templates 
> based on an if condition...?? What i want to do is that in 
> django templates if a given if condition is true i want to call a 
> javascript function automatically
>
> tell me guys if it is possible or not
>
>
>
>

-- 
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: django development server timeout too quick

2013-04-26 Thread Chris Lawlor
Hadi,

What is your SESSION_COOKIE_AGE set to? This setting controls session 
expiry. The default is 2 weeks. If you are not setting SESSION_COOKIE_AGE, 
check that your code is not calling request.session.set_expiry() anywhere.

For light use, the default session backend (db) should meet your needs. 
Have a look at the warning 
here: 
https://docs.djangoproject.com/en/dev/topics/http/sessions/#using-cached-sessions
 
(Note link to dev version of docs). Using the cached_db session engine with 
a file based cache isn't buying you anything but extra complexity.

On Wednesday, 24 April 2013 02:27:20 UTC-4, Hadi Sunyoto wrote:
>
> The problem is like this:
>
> i am using django admin, and in several forms, it might take around 10-20 
> minutes to fill up.
> By the time save button is pressed, i am always redirected to login page.
>
> The question is: how can i make the timeout longer (or maybe last forever)
>
> I set the cache to file and session_engine to db
>
> CACHES = {
> 'default': {
> 'BACKEND': 'django.core.cache.backends.filebased.FileBasedCache',
> 'LOCATION': 'some/path',
> 'TIMEOUT': 10,
> }
> }
> SESSION_ENGINE = "django.contrib.sessions.backends.cached_db"
>
> What else am i missing here? any direction will be much appreciated
>
> i also have tried to set --noreload in runserver so that file changed does 
> not get reloaded, but i still get the same problem.
>
> i don't plan on using apache/ngix/etc because this is only for my personal 
> use
>

-- 
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: Template Caching with Messages

2013-04-26 Thread Chris Lawlor
V,

You're exactly correct - make sure you only cache what you actually want 
cached : ) Anything that should only be visible for one page view isn't a 
good candidate for caching. If your page has any sort of content that is 
specific to the current user - login state, etc., you probably don't want 
to cache that part of the page either, if there's a chance that a user with 
a different state can hit the same template.

Caching bugs can be subtle. I'd suggest writing some comprehensive 
integration tests for anything more than the most trivial caching 
strategies.

Chris


On Wednesday, 24 April 2013 04:02:15 UTC-4, Venkatraman.S. wrote:
>
>
> It looks to me that when i use a file based caching, and if append 
> messages in my templates(based on user action), that particular page(with 
> message) also gets cached. Since 'these' pages would never be created 
> again, what is the best possible option? (Well, i just used file-based 
> cache to quickly see what was happening, but i guess the same happens for 
> any other cache mode too)
>
> One thing that i could think of is use cache-fragments for the rest of the 
> sections in the template and leave out the 'div' which displays the 
> messages.
>
> Any other solutions or comments?
>
> -V
> @venkasub 
>
>  

-- 
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: linux or windows

2013-05-31 Thread Chris Lawlor
Django itself is completely platform agnostic. Years ago I used to develop 
on Windows, and typically where I would run into problems was trying to 
find binaries for third party libraries like PIL and psycopg2. They'd 
usually be available from somewhere or another, thanks to some kindhearted 
soul who managed to build them and shared the binaries online, just 
difficult to track down. Building from source is certainly possible, but 
setting up the correct toolchain for a successful build is a non-trivial 
endeavor. This may have improved in the last few years though, I couldn't 
say.

Also (and this isn't directly related), the awesome virtualenvwrapper, 
which is a core part of my workflow nowadays, is not available in Windows, 
Virtualenv itself does work on Windows though.

Personally, I think it is best to develop on a system as close to your 
production environment as possible. It's certainly possible to develop on 
Windows, and deploy to Linux (or vice-versa), but you increase your risk of 
encountering bugs that only occur on one platform, which can be difficult 
to troubleshoot.

On Friday, 31 May 2013 07:11:23 UTC-4, Kakar wrote:
>
> Hi!
> I know this question is one absurd question, but just out of curiosity, is 
> it important to use linux other than the windows, related to django. Cause 
> i'm in windows, and if it is, then i was thinking to use Ubuntu. Please 
> advise.
>  

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




Developing Django Apps - best practices?

2013-05-31 Thread Chris Lawlor
All,

I'd like to get some feedback from the community on the current best 
practices for developing standalone Django apps. To clarify, by 
'standalone' I mean a codebase that is just the application itself, to be 
installed into a Django project via setup.py / pip, not working on the app 
directly within a Django project. It seems that people love to discuss 
ideas related to projects (layout, settings, etc.), but I haven't seen much 
discussion focusing on app development.

For example, do you have some boilerplate that you use when starting a new 
app? For projects, we have project templates, but as far as I'm aware there 
is no particular application boilerplate that is in wide use.

Here are some other questions you might consider:

* How do you organize tests? Do you include a test project?

* How do you link your standalone apps to your current projects? Install 
via pip, add the app src directory to your PYTHONPATH, something else?

* What tools / libraries / other resources do you find most useful?

There is some documentation on the topic here (
https://docs.djangoproject.com/en/dev/intro/reusable-apps/), which is a 
great start, but it glosses over deployment and completely ignores testing.

My goal here is simply to start a discussion. Hopefully, if some general 
consensus emerges, we might identify some ideas that could possibly be 
documented elsewhere, whether we inspire a blog post or add to the Django 
documentation itself.

Thank you,

Chris

-- 
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: django , python and ides

2013-05-31 Thread Chris Lawlor
Joey,

Would you be interested in sharing your virtualenvwrapper setup? I assume 
you're using some custom postactivate hooks, looks nice.

Chris

On Friday, 31 May 2013 14:23:23 UTC-4, JoeLinux wrote:
>
> I've used both PyCharm and SublimeText extensively for months each at a 
> time,
> and I swap back and forth every now and then just to see how the other is 
> doing.
>
> PyCharm:
>
> Pros vs Sublime:
>
> - Everything in one package (almost)
>
> - Debugging capabilities are excellent and built-in
>
> - 
> Virtualenv support and library inspection
>
> Sublime:
>
> Pros vs PyCharm:
>
> - Fast. Fast, fast, fast! Almost every 
> shortcut/function/correction/refactoring/feature happens faster in Sublime 
> than PyCharm (sometimes by orders of magnitude)
>
> - Vintage (Sublime's Vim keymap) is WAY better than IdeaVIM (PyCharm's). 
> Vim support is crucial for me.
>
> - Fonts and colors and animations and basically anything your eyes can 
> look at is ten times more pleasing to the eyes than in PyCharm (Java font 
> rendering is laughably bad)
>
>
> PyCharm cons:
>
> - Slow
>
> - If you quit/close/upgrade/kill while it's indexing, you'll screw it up 
> and have to select "Invalidate Caches"
>
> - Environment variables are not always handled correctly (this will really 
> frustrate you sometimes), and you'll have to define them yourself, or toss 
> them in your virtualenv's postactivate script
>
> - Costs $99, with a $59 annual renewal fee
>
>
> Sublime cons:
>
> - You are responsible for your own environment (this means runserver, 
> debugging, etc)
>
> - Autocompletion does not always work the way you want it to (I've had 
> snippets, Emmet, and CodeIntel conflict with each other many times)
>
> - Costs $70 (though it's a one-time fee, compared to PyCharm... and you 
> don't HAVE to pay to use it, as long as you ignore the occasional prompt)
>
>
> One note about Sublime: the first "con" is a big one, because most people 
> don't want to set up their development environment in pieces (I felt the 
> same way at first). However, over time I've learned to love that very 
> aspect, and I appreciate how everything works together better now. I am 
> more content now to leave those programs that are good at something to do 
> what they're good at, rather than let an IDE like PyCharm do it not-as-good 
> (Mercurial support is virtually unusable, for instance). Instead, I've 
> grabbed a few tips from around the web, come up with a few of my own, and 
> now when I drop to the command line and type "workon ", I'll 
> be greeted with a custom prompt, and a GNU Screen session with several open 
> (and labeled) windows indicating to me what is available in each one 
> (including a runserver, and a Python shell with my virtualenv/Django 
> environment loaded and every installed app/model automatically imported). 
> Looks something like this:
>
>
> [image: Inline image 1]
>
> (I blurred a few things out because I'm working on a project that isn't 
> public yet)
>
>
> The prompt shows me my user account and computer name, my current 
> directory, and my current branch (works on both Mercurial and Git, so I 
> don't have to do anything special depending on the scm tool I'm using). A 
> little lightning bolt will show up next to the branch name to indicate that 
> I have uncommitted changes, which is pretty cool. Also, it's multi-line, so 
> I have the entire width of the terminal to work on.
>
> The bottom bar is my "info bar". It has the name of the project on the 
> left (or initials or whatever), then a list of windows and their names, my 
> computer name, my system load, the date, and time.
>
>
> So day-to-day, I now use SublimeText pretty much exclusively. Sometimes 
> (rarely, but it does happen), I open up PyCharm, but usually only if I 
> desperately need to debug Python variables in the middle of rendering a 
> Django template. It's pretty good for that. Otherwise, Sublime is amazing.
>
>
> Especially amazing if you watch this video in its entirety and learn about 
> SublimeText thoroughly: http://www.youtube.com/watch?v=TZ-bgcJ6fQo
>
> HTH
>
> --
> Joey "JoeLinux" Espinosa
> Python Developer
> http://about.me/joelinux
> On May 31, 2013 1:23 PM, "Nikolas Stevenson-Molnar" 
> > 
> wrote:
>
>> +1 for PyCharm. I know many here like Sublime Text also (though it's a
>> super text editor, not an IDE). Neither are open source, but both work
>> hard to earn the $$ you spend on them.
>>
>> _Nik
>>
>> On 5/31/2013 7:19 AM, Masklinn wrote:
>> > On 2013-05-31, at 12:54 , tony gair wrote:
>> >> Python and Django are not my first languages and currently I am using 
>> it
>> >> like I would a compiled language inside gedit on debian wheezy. I was
>> >> actually quite surprised to find a lot of people using it on windows 
>> and
>> >> macs when I went to my local python user group but enough digression!.
>> >> I was wondering if anyone using debian wheezy can recommend a nice ide
>> >> (hopefully opensource but if not then relatively 

Re: django , python and ides

2013-06-01 Thread Chris Lawlor
Cool, thank you!

On Friday, 31 May 2013 16:10:12 UTC-4, JoeLinux wrote:
>
> Sure thing :) I'll even give you the stuff that makes my prompt and all 
> that:
>
> $HOME/.bashrc (partial): http://collabedit.com/bnxfx
>
> /bin/postactivate: http://collabedit.com/6bvfr
>
> $HOME/.screenrc-: http://collabedit.com/kuj8d
>
> Enjoy!
>
> --
> Joey "JoeLinux" Espinosa*
> *
> <http://therealjoelinux.blogspot.com> 
> <http://twitter.com/therealjoelinux><http://about.me/joelinux>
>  
>
> On Fri, May 31, 2013 at 2:39 PM, Chris Lawlor 
> 
> > wrote:
>
>> Joey,
>>
>> Would you be interested in sharing your virtualenvwrapper setup? I assume 
>> you're using some custom postactivate hooks, looks nice.
>>
>> Chris
>>
>>
>> On Friday, 31 May 2013 14:23:23 UTC-4, JoeLinux wrote:
>>
>>> I've used both PyCharm and SublimeText extensively for months each at a 
>>> time,
>>>  and I swap back and forth every now and then just to see how the other 
>>> is doing.
>>>
>>> PyCharm:
>>>
>>> Pros vs Sublime:
>>>
>>> - Everything in one package (almost)
>>>
>>> - Debugging capabilities are excellent and built-in
>>>
>>> - 
>>> Virtualenv support and library inspection
>>>
>>> Sublime:
>>>
>>> Pros vs PyCharm:
>>>
>>> - Fast. Fast, fast, fast! Almost every 
>>> shortcut/function/correction/**refactoring/feature 
>>> happens faster in Sublime than PyCharm (sometimes by orders of magnitude)
>>>
>>> - Vintage (Sublime's Vim keymap) is WAY better than IdeaVIM (PyCharm's). 
>>> Vim support is crucial for me.
>>>
>>> - Fonts and colors and animations and basically anything your eyes can 
>>> look at is ten times more pleasing to the eyes than in PyCharm (Java font 
>>> rendering is laughably bad)
>>>
>>>
>>> PyCharm cons:
>>>
>>> - Slow
>>>
>>> - If you quit/close/upgrade/kill while it's indexing, you'll screw it up 
>>> and have to select "Invalidate Caches"
>>>
>>> - Environment variables are not always handled correctly (this will 
>>> really frustrate you sometimes), and you'll have to define them yourself, 
>>> or toss them in your virtualenv's postactivate script
>>>
>>> - Costs $99, with a $59 annual renewal fee
>>>
>>>
>>> Sublime cons:
>>>
>>> - You are responsible for your own environment (this means runserver, 
>>> debugging, etc)
>>>
>>> - Autocompletion does not always work the way you want it to (I've had 
>>> snippets, Emmet, and CodeIntel conflict with each other many times)
>>>
>>> - Costs $70 (though it's a one-time fee, compared to PyCharm... and you 
>>> don't HAVE to pay to use it, as long as you ignore the occasional prompt)
>>>
>>>
>>> One note about Sublime: the first "con" is a big one, because most 
>>> people don't want to set up their development environment in pieces (I felt 
>>> the same way at first). However, over time I've learned to love that very 
>>> aspect, and I appreciate how everything works together better now. I am 
>>> more content now to leave those programs that are good at something to do 
>>> what they're good at, rather than let an IDE like PyCharm do it not-as-good 
>>> (Mercurial support is virtually unusable, for instance). Instead, I've 
>>> grabbed a few tips from around the web, come up with a few of my own, and 
>>> now when I drop to the command line and type "workon ", I'll 
>>> be greeted with a custom prompt, and a GNU Screen session with several open 
>>> (and labeled) windows indicating to me what is available in each one 
>>> (including a runserver, and a Python shell with my virtualenv/Django 
>>> environment loaded and every installed app/model automatically imported). 
>>> Looks something like this:
>>>
>>>
>>> [image: Inline image 1]
>>>
>>> (I blurred a few things out because I'm working on a project that isn't 
>>> public yet)
>>>
>>>
>>> The prompt shows me my user account and computer name, my current 
>>> directory, and my current branch (works on both Mercurial and Git, so I 
>>> don't have to do anything special depending on the scm tool I'm usin

Re: Passing variables to css file in django

2013-08-26 Thread Chris Lawlor
The simplest solution is probably to keep all of the CSS that users can't 
customize in an external file (to be served as a static asset), but move 
anything that's user customizable to the  of your base template, in a 

Re: Parsing feeds that are imported

2011-06-07 Thread Chris Lawlor


I've not used the django community aggregator, so I'm making some
assumptions about it's functionality. If that app were to emit a
signal for each feed entry that it processed, it would be fairly
simple to write a signal handler that would create the associations
that you want. With this approach, you wouldn't need another cron job,
your processing would be done at the same time as django community
aggregator's.

If you do need to do some manual feed parsing, you might try using the
Universal Feed Parser python module: http://feedparser.org/. It's
specifically designed for parsing RSS / Atom feeds, and so may be
somewhat more useful than BeautifulSoup.

On Jun 6, 10:59 pm, Chris McComas  wrote:
> Also, using the update_feeds that's part of the Django Community
> Aggregator worked initially, but I started over adding a m2m field on
> the Feed model for Sites. I'll have several "sites" as part of the
> Django app, like team1.mysite.com, team2.mysite.com, etc.
>
> When I added that field to the models and tried to run the
> update_feeds script it did nothing. It didn't import the feeds, didn't
> throw an error, etc.
>
> update_feeds:https://github.com/django/djangoproject.com/blob/master/django_websit...
> my models:http://dpaste.com/551322/
>
> Thanks,
>
> On Jun 6, 4:55 pm, Chris McComas  wrote:
>
>
>
>
>
>
>
> > This could be the wrong place to ask (maybe a BeautifulSoup)
> > question...
>
> > I have a Django app that is based around the Django Community
> > Aggregator, it gets feeds from various sites and displays them on my
> > site. What I am wanting to do, if possible, is when it gets a feed if
> > a certain zip code is the feed Title or Summary then I want to create
> > a entry for that zipcode with that feed?
>
> > I have a model for the zip codes, so the list to compare should be
> > pulled from that. There'd be a cron that'd run to do this, so for
> > example if one of the zip codes is 12345 and one of the feeds it gets
> > on the hourly cron has 12345 in the summary, then it'd go to the model
> > linking the two and create/save an entry.
>
> > Here are the pertinent models:http://dpaste.com/551223/
>
> > Thanks,

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



Re: VERY cheap django hosting?

2011-06-08 Thread Chris Lawlor
Always Data (http://www.alwaysdata.com) has a free plan, but it is
quite limited (you only get 10 MB disk space).

On Jun 8, 2:39 am, Maksymus007  wrote:
> megiteam.pl is 24PLN which is about 8usd a month:)
>
> Pozdrawiam, Maksymilian Pawlak
> 08-06-2011 08:30 użytkownik "raj"  napisał:> Hey guys,
> > Just wondering if you could give me some hosts that are very cheap for
> > django hosting? Is hostgator any good? I really don't know what to
> > look for in a host. A lot of people are recommending web faction, but
> > its around $9 bucks a month. I was looking in the $5 bucks a month
> > range. Any ideas? Thank you.
> > -Raj
>
> > --
> > 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.
>
>
>
>
>
>
>
>

-- 
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: 3rd party Apps in Django

2011-08-15 Thread Chris Lawlor
+1 for using virtualenv. Indispensable for working on more than one dingo 
project on the same development machine. If you're developing on Linux or Mac, 
take a look at virtualenvwrapper. It makes working with virtual environments 
practically painless.

-- 
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/-/xfaJGZITKWIJ.
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: more than one querys LIKE in the same field

2010-12-14 Thread Chris Lawlor
Not to second guess your intent, but are you sure you don't mean to OR
the two? Your current SQL / Django query will only return tags that
have both 'candy' and 'milk' in the tags string.

If you do want to OR the queries, you can use Q objects:

from django.db.models import Q
table.objects.filter(Q(tags__icontains='milk') |
Q(tags__icontains='candy'))

Also note that, if you're using sqlite, case-insensitive string
lookups are not supported (see 
http://docs.djangoproject.com/en/dev/ref/databases/#sqlite-string-matching).

Hope this is helpful,

Chris

On Dec 14, 3:10 am, marcoarreguin  wrote:
> Hi friends!
>
> I mean do something like this:
>
> SELECT * FROM table WHERE tags LIKE '%candy%' AND  tags LIKE '%milk%'
>
> I've tried:
>
> table.objects.filter(tags__icontains='candy', tags__icontains='milk')
>
> I've tried too:
>
> list = ['candy', 'milk']
> table.objects.filter(tags__icontains=list
>
> And nothing work. Help me please :s
>
> Thanks bros!

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



Re: Load file into a FileField

2010-12-21 Thread Chris Lawlor
Liriela,

AFAIK it is not possible to programmatically populate a file input
field, due to the many security exploits this would enable. If it were
possible, it would be trivial to write a malicious script that would
upload any file from a user's PC, so long as you knew the path.

There are browser-specific exceptions, for example, in Netscape-based
browsers you can call
netscape.security.PrivilegeManager.enablePrivilege("UniversalFileRead")
(see 
http://www.mozilla.org/projects/security/components/signed-script-example.html).
This needs to be called from a signed script, and I believe will still
trigger a pop-up dialog to confirm the enhanced permission request. I
imagine this might be more trouble than it's worth though.

As an alternative testing method, you might consider using curl. You'd
do something like:

curl http://localhost:8000/submit/test -F id_title=Test -F
id_email=em...@test.org -F id_file=@/path/to/test.txt -u
username:password

Note the @ symbol in front of the value for file_id - that tells curl
that the value is a file, not a string.

I've only really used this method when testing an API which returned
JSON data, which is easily viewable in the console. If your view is
returning HTML, you might pipe the output to a file to open in a
browser.

Hope that helps,

Chris

On Dec 21, 5:14 am, Liriela  wrote:
> Hi there,
>
> I am working now on a web server and come up with a problem. I want to
> have on my site a button which will load test data into a form -> for
> example -> a form has fileds: name and email -> the button will load
> into the fields values defined by me. That is not a problem for all
> the data that is served by request.POST. But the problem shows up when
> I have a FileField in my forms and I want to load a file into that
> field. The solution that I have found probably loads somehow the file
> into request.FILES dictionary (so the file is bound to the form) -
> because there is no non-field error shown, but after pressing the
> submit button the non field error occurs (so the file is lost). And
> the name of the file is not shown in the form. (I am using django
> version 1.2.3 and python version 2.6.6 )
>
>  Here are my forms, views and template for that:
>
> forms.py
> (...)
> class Test(forms.Form):
>     ''
>
>     title          = forms.CharField(max_length = 30, required = True)
>     email       = forms.EmailField(required=False)
>     test_file    = forms.FileField()
>
> views.py
>
> from django.core.files.uploadedfile import SimpleUploadedFile
> (...)
> def load_test_analysis(request):
>     """ """
>     f = open('/path/test.txt','r')
>    post_data =  {'title':'Test ',
>                         'email' : 't...@test.org'}
>     file_data = {'alignment': SimpleUploadedFile('test.txt',
> f.read())}
>     form = Test(post_data, file_data)
>     return render_to_response('test.html', {'form': form})
>
> test.html
>
> {% extends 'master.html' %}
>
> {% block content %}
>
> 
>
> 
>     
>         
>             Teste
>         
>         
>              
>         
>     
> 
>
>  action="/submit/test/">
>
> Title: {{ form.title }}
> {{ form.title.errors }}
> 
>
> File: {{ form.file }}
> {{ form.file.errors }}
> {{ form.non_field_errors }}
>
> Email: {{ form.email }}
>  {{form.email.errors}} 
> 
>
> 
> 
> 
>
> 
>
> {% endblock %}
>
> Hope someone will be able to help me with that.
>
> Best,
> Liriela

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



Re: loading the external css file

2010-12-27 Thread Chris Lawlor
Django doesn't server static files (like your CSS file) by default -
but you can configure the development server to do so:
http://docs.djangoproject.com/en/dev/howto/static-files/

Note that this has changed a lot in Django 1.3, so be sure to view the
correct version of that page for the version of Django that you are
using.

In production, you should almost always configure another server to
serve static files.

On Dec 27, 8:29 am, Bithu  wrote:
> When i was trying to load an external stylesheet it was not working.
> But the internal css is working nicely.
>
> What should i do to link my .css file to my html template which is
> inside my template folder.

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



Re: ModelForm Field not display choice text

2010-12-27 Thread Chris Lawlor
Michael,

In one of my projects, I did something like this:


{% for field in rating_form %}
{{ field}}
{% endfor %}



$('#stars').children().not(":radio").hide()
$('#stars').stars({
cancelShow: false,
callback: function(ui, type, value){
ajaxVote(value);
}
});

function ajaxVote(value) {
$.ajax({ url: '{% url plugin-rate object.slug %}',
 type: 'POST',
 data: { rating: value },
 dataType: 'json',
 success: function(data){
var avg_rating = data['avg_rating']
var votes = data['votes']
$('#rating_display').html(avg_rating +" out of 5 (Rated " +
votes + " times)")
 },
});
}

The key to hiding the other form elements (like the labels) is the $
('#stars').children().not(":radio").hide() call, which basically hides
everything but the actual stars. If the use doesn't have JS enabled,
they should still see the radio buttons with the associated labels.

Hope that helps,

Chris

On Dec 27, 6:48 am, Michael Thamm  wrote:
> One thought, and this maybe the whole issue, is that the radio button
> is using labels for the text and not titles.
> I would expect the output to be something like this:
> 
> but instead the output is like this:
> 
>     
>   1
> 
>
> Is this something that anyone else has had to deal with?
>
> Thanks
> Michael
>
> On Dec 27, 6:39 am, Michael Thamm  wrote:
>
>
>
>
>
>
>
> > Hi,
> > I am using the jQuery stars on a radio field as a custom renderer. The
> > stars come up nicely but the
> > choice text still displays to the side of the stars.
> > How can I not show the choice text but still populate the field with
> > the choice result?
> > I am displaying the field in the template like this:
> > {{ userForm.fitStars }}
>
> > BTW - I am not talking about the label text. For example,
> > How was your meal?
>
> > But rather the radio button choices.
>
> > The radio button text I want to not display.
>
> > Thanks
> > Michael

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



Re: loading the external css file

2011-01-03 Thread Chris Lawlor
If you don't have a staticfiles module, you most likely aren't using
Django 1.3. Make sure you select the correct version of Django when
viewing the docs, as things are often done differently in older
versions, but the doc pages usually default to the latest SVN release.

On Dec 27 2010, 10:43 pm, Bithu  wrote:
> When i was trying to set my static files. When i added the
> 'django.contrib.staticfiles' into INSTALLED_APP in my setting.py the
> development server was not running showing an error  Error: No module
> named staticfiles.
>
> On Dec 27, 7:07 pm, Chris Lawlor  wrote:
>
>
>
>
>
>
>
> > Django doesn't server static files (like your CSS file) by default -
> > but you can configure the development server to do 
> > so:http://docs.djangoproject.com/en/dev/howto/static-files/
>
> > Note that this has changed a lot in Django 1.3, so be sure to view the
> > correct version of that page for the version of Django that you are
> > using.
>
> > In production, you should almost always configure another server to
> > serve static files.
>
> > On Dec 27, 8:29 am, Bithu  wrote:
>
> > > When i was trying to load an external stylesheet it was not working.
> > > But the internal css is working nicely.
>
> > > What should i do to link my .css file to my html template which is
> > > inside my template folder.

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



Re: cannot login to admin site using admin credentials

2011-02-07 Thread Chris Lawlor
Try running 'python manage.py createsuperuser' on your production
server to create a new superuser account. You should have full
privileges to log in to the admin and make changes using this account.

On Feb 7, 8:15 am, xpanta  wrote:
> Hi,
>
> it seems that my problem is a bit complicated. I have tried much but
> to no avail. So, please help me!
>
> Some time ago I migrated to postgresql from mysql. I don't know if I
> did something wrong. Anyway, my webapp works "almost" flawlessly.
>
> Since then I never needed to login using admin rights (either using
> the admin panel or my web site). Some weeks ago I tried and I noticed
> that I can't login (to both admin site and web page) using admin
> credentials.
>
> I have tried dozens of various tricks but I still can't login.
>
> I tried adding user.set_password()  to my views.py in order to replace
> admin password with a new simpler one ('123') but nothing. I even
> registered a new user from my web page and changed its fields directly
> in the DB (is_staff, is_active, is_superuser) to 'True'. This let me
> login to the admin site but gave me no permission to change anything.
> I even tried to create various admin users with the help of django
> shell but none of them gives me a login. Interestingly whenever I do
> something to change admin password, I always see a different hashed
> password value in my DB. This means that all my approaches succeed in
> changing the admin password. However I can't login.
>
> Normal users work fine. Problem appears only when the user is an
> administrator.
>
> Any help would be greatly appreciated.

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