Questions about setting up my first app in django tutorial

2014-04-17 Thread Xiaofeng Feng
I am now trying to set up my first app using django tutorial. However, I 
was stuck at adding the poll app in part 2. I think I followed all the 
steps and it goes well before this question. After I change admin.py with

from django.contrib import adminfrom polls.models import Poll
admin.site.register(Poll)

as the tutorial says. The admin website does not change at all. Does 
anybody know why this happens? 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/7bdb76f7-caf7-4c44-af6f-05f042494bed%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Questions about setting up my first app in django tutorial

2014-04-17 Thread Jorge Andrés Vergara Ebratt
Did you register the app in settings.py?


2014-04-16 23:03 GMT-05:00 Xiaofeng Feng :

> I am now trying to set up my first app using django tutorial. However, I
> was stuck at adding the poll app in part 2. I think I followed all the
> steps and it goes well before this question. After I change admin.py with
>
> from django.contrib import adminfrom polls.models import Poll
> admin.site.register(Poll)
>
> as the tutorial says. The admin website does not change at all. Does
> anybody know why this happens? 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/7bdb76f7-caf7-4c44-af6f-05f042494bed%40googlegroups.com
> .
> For more options, visit https://groups.google.com/d/optout.
>



-- 
*Jorge Andres Vergara Ebratt*
*#SoftwareDeveloper (Or at least trying to be)*
*@javebratt*
*facebook.com/javebratt *

-- 
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/CAAeX05FKjVzkKy-AnR5-4QCKc4o6T8C%3DwKVcRpNE1qLxjh%3DqEw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: what's the best admin skin (free)

2014-04-17 Thread Majo
Hey Bobby,

I'm using Grappelli for some of my projects and I like it. If you want to 
know about other skins, you should head over to 
https://www.djangopackages.com/grids/g/admin-interface/ and check out what 
they have listed. The best choice for you will depend on how much you 
actually want to customize your Django admin.

Good luck!

On Thursday, April 17, 2014 3:04:11 AM UTC+2, Bobby Roberts wrote:
>
> hey group.   I've been out of the loop for  a few years now.  What is the 
> best skin for admin?  Is Grapelli still good?
>

-- 
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/bade865f-34a0-4e9a-ba2d-dc8f565e98d1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: what's the best admin skin (free)

2014-04-17 Thread Rafael E. Ferrero
+1 Grappelli

--
*RAFAEL FERRERO*

*Chief Officer Technology*
San Francisco Cba. | Argentina
+54 9 356251 4856
www.perseux.com


2014-04-17 10:22 GMT-03:00 Majo :

> Hey Bobby,
>
> I'm using Grappelli for some of my projects and I like it. If you want to
> know about other skins, you should head over to
> https://www.djangopackages.com/grids/g/admin-interface/ and check out
> what they have listed. The best choice for you will depend on how much you
> actually want to customize your Django admin.
>
> Good luck!
>
>
> On Thursday, April 17, 2014 3:04:11 AM UTC+2, Bobby Roberts wrote:
>>
>> hey group.   I've been out of the loop for  a few years now.  What is the
>> best skin for admin?  Is Grapelli still good?
>>
>  --
> 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/bade865f-34a0-4e9a-ba2d-dc8f565e98d1%40googlegroups.com
> .
>
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAJJc_8X3cvv8-DxDXp98daiHY%2B1R7GNB%2BX%3DjJNfzz3EcL_2HBA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: How to create Union in Django queryset

2014-04-17 Thread Thomas Lockhart

On 4/16/14 11:51 PM, Shoaib Ijaz wrote:

I don't want use SQL query in django

OK. You *could* have class B inherit from class A:

class B(A):
  link = models.IntegerField(blank=True, null=True)

and then do your query on A:

ulist = A.objects.all()

hth

- Tom



On Thursday, 17 April 2014 04:39:09 UTC+5, Russell Keith-Magee wrote:

On Wed, Apr 16, 2014 at 9:30 PM, Shoaib Ijaz > wrote:
> Sorry for duplicate post How to create Union
>
> I am using Django REST Framework in project and I want to create
union two
> different Models.
>
> My Models
>
> class A(models.Model):
> name = models.CharField(max_length=240, blank=True)
> geometry = models.GeometryField(blank=True, null=True)
> abwrapper= models.ForeignKey(ABWrapper)
>
> class Meta:
> db_table = 'tbl_a'
>
> class B(models.Model):
> name = models.CharField(max_length=240, blank=True)
> link = models.IntegerField(blank=True, null=True)
> geometry = models.GeometryField(blank=True, null=True)
> abwrapper= models.ForeignKey(ABWrapper)
>
> class Meta:
> db_table = 'tbl_b'
>
> I am trying to create this query
>
> SELECT id,name FROM tbl_a UNION (SELECT b.id
,b.name  From tbl_b b)
>
> My attempt for union
>
> a = A.objects.values_list('id')
> b = B.objects.values_list('id')
> queryset = a | b



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


Re: How to create Union in Django queryset

2014-04-17 Thread Simon Charette
I'm not sure this will work but you could try creating a VIEW on the 
database side that does the union there and access it through an un-managed 
model.

CREATE VIEW *view_name* AS SELECT id, name FROM *a* UNION SELECT id, name 
FROM *b*;

class C(models.Model):
name = models.CharField()

class Meta:
db_table = '*view_name*'
managed = False

Le jeudi 17 avril 2014 02:51:34 UTC-4, Shoaib Ijaz a écrit :
>
> I don't want use SQL query in django
>
> On Thursday, 17 April 2014 04:39:09 UTC+5, Russell Keith-Magee wrote:
>>
>> On Wed, Apr 16, 2014 at 9:30 PM, Shoaib Ijaz  
>> wrote: 
>> > Sorry for duplicate post How to create Union 
>> > 
>> > I am using Django REST Framework in project and I want to create union 
>> two 
>> > different Models. 
>> > 
>> > My Models 
>> > 
>> > class A(models.Model): 
>> > name = models.CharField(max_length=240, blank=True) 
>> > geometry = models.GeometryField(blank=True, null=True) 
>> > abwrapper= models.ForeignKey(ABWrapper) 
>> > 
>> > class Meta: 
>> > db_table = 'tbl_a' 
>> > 
>> > class B(models.Model): 
>> > name = models.CharField(max_length=240, blank=True) 
>> > link = models.IntegerField(blank=True, null=True) 
>> > geometry = models.GeometryField(blank=True, null=True) 
>> > abwrapper= models.ForeignKey(ABWrapper) 
>> > 
>> > class Meta: 
>> > db_table = 'tbl_b' 
>> > 
>> > I am trying to create this query 
>> > 
>> > SELECT id,name FROM tbl_a UNION (SELECT b.id,b.name From tbl_b b) 
>> > 
>> > My attempt for union 
>> > 
>> > a = A.objects.values_list('id') 
>> > b = B.objects.values_list('id') 
>> > queryset = a | b 
>> > 
>> > Error: 
>> > AssertionError: Cannot combine queries on two different base models. 
>> > 
>> > Now i tried with parent Model in this way 
>> > 
>> > class ABWrapper(models.Model): 
>> > objects = models.GeoManager() 
>> > class Meta: 
>> > db_table = u'ab_wrapper' 
>> > 
>> > Added this model as ForeignKey above both Models 
>> > 
>> > a = ABWrapper.objects.filter(a__isnull=False).values('a__id') 
>> > b = ABWrapper.objects.filter(b__isnull=False).values('b__id') 
>> > queryset = a | b 
>> > 
>> > Error: 
>> > TypeError: Merging 'GeoValuesQuerySet' classes must involve the same 
>> values 
>> > in each case. 
>> > 
>> > Another attempt by making alias 
>> > 
>> > a = 
>> > 
>> ABWrapper.objects.filter(a__isnull=False).extra(select={'tempID':'a__id'}).values_list('tempID')
>>  
>>
>> > b = 
>> > 
>> ABWrapper.objects.filter(b__isnull=False).extra(select={'tempID':'b__id'}).values_list('tempID')
>>  
>>
>> > queryset = a | b 
>> > 
>> > Error: 
>> > ValueError: When merging querysets using 'or', you cannot have 
>> > extra(select=...) on both sides. 
>> > 
>> > I have searched on it, mostly answered this issue as using list for 
>> both 
>> > models. But I don't want to use list as I am using Django Rest 
>> Framework so 
>> > I need QuerySet. So my question if I use list for union can I convert 
>> > resulting list into QuerySet. 
>> > 
>> > Note: I don't want to use SQL Query in Django 
>>
>> Why not? That would seem to be the exact answer you need. 
>>
>> You appear to have a very specific idea of the SQL query you want to 
>> issue, including UNION clauses (an operator that Django's ORM doesn't 
>> support) and "extra" columns (which means the data you want is outside 
>> your regular Django model). Getting this query in 100% native Django 
>> query sets is going to be somewhere between difficult and impossible. 
>>
>> However, you don't have to drop right back to SQL cursors - Django has 
>> raw query sets for exactly this purpose: 
>>
>> ABWrapper.objects.raw("SELECT …. FROM … WHERE") 
>>
>> This will return ABWrapper objects contained in a query set object 
>> that should be compatible with Django REST Framework, but you get 
>> those objects by providing the exact SQL you want to execute. 
>>
>> See: 
>>
>> https://docs.djangoproject.com/en/dev/topics/db/sql/ 
>>
>> for more details 
>>
>> Yours, 
>> Russ Magee %-) 
>>
>

-- 
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/23604307-43be-45ce-837f-1656ada1863c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Template

2014-04-17 Thread ngangsia akumbo
New to django

I need free template, a variety of them. Any help?

-- 
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/4fb69343-0a8e-42ff-9f82-28e4e1561e5e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Questions about setting up my first app in django tutorial

2014-04-17 Thread Xiaofeng Feng
Yes.
INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'TestApp',
)

The last line TestApp is my first app.

On Thursday, April 17, 2014 8:24:12 AM UTC-4, Jorge Andrés Vergara Ebratt 
wrote:
>
> Did you register the app in settings.py?
>
>
> 2014-04-16 23:03 GMT-05:00 Xiaofeng Feng >
> :
>
>> I am now trying to set up my first app using django tutorial. However, I 
>> was stuck at adding the poll app in part 2. I think I followed all the 
>> steps and it goes well before this question. After I change admin.py with
>>
>> from django.contrib import adminfrom polls.models import Poll
>> admin.site.register(Poll)
>>
>> as the tutorial says. The admin website does not change at all. Does 
>> anybody know why this happens? 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/7bdb76f7-caf7-4c44-af6f-05f042494bed%40googlegroups.com
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>
>
> -- 
> *Jorge Andres Vergara Ebratt*
> *#SoftwareDeveloper (Or at least trying to be)*
> *@javebratt*
> *facebook.com/javebratt *
>  

-- 
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/36c07290-ff33-4e3d-b142-26efd577c38c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Template

2014-04-17 Thread Andrew Farrell
Do you mean that you are new to the syntax of django templates so you just
want to look at and see what django templates look like? Take a look at the
ones used in the admin of django itself:

https://github.com/django/django/tree/master/django/contrib/admin/templates/admin

index.html is a reasonable one.
https://docs.djangoproject.com/en/dev/ref/templates/builtins/ is useful to
refer to while reading those.

There are a few custom templates that you'll find here:
https://github.com/django/django/tree/master/django/contrib/admin/templatetags/


Anyone have a better template without custom tags?

On Thu, Apr 17, 2014 at 10:44 AM, ngangsia akumbo wrote:

> New to django
>
> I need free template, a variety of them. Any help?
>
> --
> 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/4fb69343-0a8e-42ff-9f82-28e4e1561e5e%40googlegroups.com
> .
> For more options, visit https://groups.google.com/d/optout.
>

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


Re: Template

2014-04-17 Thread ngangsia akumbo
Thanks bro

>
>

-- 
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/e0fd0573-2f68-4a4c-a2b9-7b19871c150b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


views

2014-04-17 Thread ngangsia akumbo
I just created another app within my django project call test_project. 
Within that project i have two apps.

I keep having this error for 

-- 
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/4f476046-32da-47ba-b57b-8ecf3c2b192e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: views

2014-04-17 Thread ngangsia akumbo


On Thursday, April 17, 2014 5:42:30 PM UTC+1, ngangsia akumbo wrote:
>
> I just created another app within my django project call test_project. 
> Within that project i have two apps.
>
> I keep having this error that 
>

name views not define 

-- 
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/207063af-fecc-4ea2-b3bd-b7b73fdba963%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Django app

2014-04-17 Thread ngangsia akumbo
Please m i need just one scenario. I have just been learning small small 
app within a django project.

Please how do i piece up this small small app to come out with a full 
django site or app

please just a guide

-- 
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/1f194931-b619-44ec-8918-482200c7e5fb%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django app

2014-04-17 Thread Andrew Farrell
I'm a bit confused. Are you looking for something other than the Django
Tutorial found here:
https://docs.djangoproject.com/en/1.6/intro/tutorial01/?
It takes you through building up an application. Or is that what you are
looking for?


On Thu, Apr 17, 2014 at 1:25 PM, ngangsia akumbo  wrote:

> Please m i need just one scenario. I have just been learning small small
> app within a django project.
>
> Please how do i piece up this small small app to come out with a full
> django site or app
>
> please just a guide
>
> --
> 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/1f194931-b619-44ec-8918-482200c7e5fb%40googlegroups.com
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CA%2By5TLbyJC-tqt_9e9UBwEXOq7mMzA-6DMt4aP5zH05zaHd-8g%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: views

2014-04-17 Thread Lee
Go through the tutorial linked in the other post before trying to write your 
own apps. That'll cover all the questions you just asked

-- 
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/46e94f4a-882a-41dc-b9d3-8e202a1f400c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Ajax post problem

2014-04-17 Thread willyhakim
Hi everyone?

I am trying to use ajax to do the following

1)User inputs a number.
2) I use ajax to return a query list into the same page.

Here is my code
and I keep getting this error

Page not found (404)  Request Method: GET  Request URL: 
http://127.0.0.1:8000/newmarkets/search/%20method=?csrfmiddlewaretoken=VkKvStx1qGZOM1YxzM8xenGDbYRBnMPA
  
 
Using the URLconf defined in exportAbroad.urls, Django tried these URL 
patterns, in this order: 

   1. ^$ [name='index'] 
   2. ^about/$ [name='about'] 
   3. ^pricing/$ [name='pricing'] 
   4. ^market_research_tool/$ [name='market_research_tool'] 
   5. ^newmarkets/ ^$ [name='index'] 
   6. ^newmarkets/ ^search/$ [name='search'] 
   7. ^admin/ 
   8. ^accounts/ 
   9. ^static/(?P.*)$ 

The current URL, newmarkets/search/ method=, didn't match any of these.

*views.py*
def index(request):
context = RequestContext(request)
return render_to_response('newmarkets/index.html', context)

def search(request):
if request.is_ajax() and request.method=='POST':
UserHSnumber = request.POST['UserHSnumber']
country_list = Imports.objects.filter(hs_number= UserHSnumber)[1:11]
hsdescript = Products.objects.get(hs_number=UserHSnumber) 
data = {'markets': country_list, 'hsdescript': hsdescript}
mimetype='application/json'
else:
raise Http404 
return HttpResponse(json.dumps(data), mimetype)


*HTML*

{%block body_block%}

 
  What is your product's H.S number?

  
 {% csrf_token %}  
  
  Submit
  







*ajax.js*





*$(document).ready(function() { $('#hs').click(function(){ $.ajax({ 
type:"POST", url:"/newmarkets/search/", 
data:{"userHSnumber":$("#search").val()}, dataType: "json", 
success:function(data){ alert(data.message); } }); });// CSRF code
function getCookie(name) {var cookieValue = null;var i = 
0;if (document.cookie && document.cookie !== '') {var 
cookies = document.cookie.split(';');for (i; i < 
cookies.length; i++) {var cookie = 
jQuery.trim(cookies[i]);// Does this cookie string begin 
with the name we want?if (cookie.substring(0, name.length + 
1) === (name + '=')) {cookieValue = 
decodeURIComponent(cookie.substring(name.length + 1));
break;}}}return cookieValue;
}var csrftoken = getCookie('csrftoken');function 
csrfSafeMethod(method) {// these HTTP methods do not require CSRF 
protectionreturn (/^(GET|HEAD|OPTIONS|TRACE)$/.test(method));}  
  $.ajaxSetup({crossDomain: false, // obviates need for sameOrigin 
testbeforeSend: function(xhr, settings) {if 
(!csrfSafeMethod(settings.type)) {
xhr.setRequestHeader("X-CSRFToken", csrftoken);}}
}); });*




-- 
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/2132e3e5-9795-416d-9306-0b09a1698c6b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Ajax post problem

2014-04-17 Thread Joseph Mutumi
You could try using $("form").serialize() to get the form inputs in
the ajax data. But from the URL it looks like your HTML is somehow
rendering badly. The form action is coming out as '/newmarkets/search/
method='

Kind regards

On 4/17/14, willyhakim  wrote:
> Hi everyone?
>
> I am trying to use ajax to do the following
>
> 1)User inputs a number.
> 2) I use ajax to return a query list into the same page.
>
> Here is my code
> and I keep getting this error
>
> Page not found (404)  Request Method: GET  Request URL:
> http://127.0.0.1:8000/newmarkets/search/%20method=?csrfmiddlewaretoken=VkKvStx1qGZOM1YxzM8xenGDbYRBnMPA
>
>
> Using the URLconf defined in exportAbroad.urls, Django tried these URL
> patterns, in this order:
>
>1. ^$ [name='index']
>2. ^about/$ [name='about']
>3. ^pricing/$ [name='pricing']
>4. ^market_research_tool/$ [name='market_research_tool']
>5. ^newmarkets/ ^$ [name='index']
>6. ^newmarkets/ ^search/$ [name='search']
>7. ^admin/
>8. ^accounts/
>9. ^static/(?P.*)$
>
> The current URL, newmarkets/search/ method=, didn't match any of these.
>
> *views.py*
> def index(request):
> context = RequestContext(request)
> return render_to_response('newmarkets/index.html', context)
>
> def search(request):
> if request.is_ajax() and request.method=='POST':
> UserHSnumber = request.POST['UserHSnumber']
> country_list = Imports.objects.filter(hs_number= UserHSnumber)[1:11]
> hsdescript = Products.objects.get(hs_number=UserHSnumber)
> data = {'markets': country_list, 'hsdescript': hsdescript}
> mimetype='application/json'
> else:
> raise Http404
> return HttpResponse(json.dumps(data), mimetype)
>
>
> *HTML*
>
> {%block body_block%}
> 
>  
>   What is your product's H.S number?
>
> 
>  {% csrf_token %}
>   
>   Submit
> 
> 
> 
> 
> 
> 
>
>
> *ajax.js*
>
>
>
>
>
> *$(document).ready(function() { $('#hs').click(function(){ $.ajax({
> type:"POST", url:"/newmarkets/search/",
> data:{"userHSnumber":$("#search").val()}, dataType: "json",
> success:function(data){ alert(data.message); } }); });// CSRF code
> function getCookie(name) {var cookieValue = null;var i =
> 0;if (document.cookie && document.cookie !== '') {var
> cookies = document.cookie.split(';');for (i; i <
> cookies.length; i++) {var cookie =
> jQuery.trim(cookies[i]);// Does this cookie string begin
> with the name we want?if (cookie.substring(0, name.length +
>
> 1) === (name + '=')) {cookieValue =
> decodeURIComponent(cookie.substring(name.length + 1));
> break;}}}return cookieValue;
>
> }var csrftoken = getCookie('csrftoken');function
> csrfSafeMethod(method) {// these HTTP methods do not require CSRF
> protectionreturn (/^(GET|HEAD|OPTIONS|TRACE)$/.test(method));}
>
>   $.ajaxSetup({crossDomain: false, // obviates need for sameOrigin
> testbeforeSend: function(xhr, settings) {if
> (!csrfSafeMethod(settings.type)) {
> xhr.setRequestHeader("X-CSRFToken", csrftoken);}}
> }); });*
>
>
>
>
> --
> 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/2132e3e5-9795-416d-9306-0b09a1698c6b%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

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


Re: Ajax post problem

2014-04-17 Thread Jonathan Querubkna
Or:

var dataForm = new FormData( $("form")[0] );

That way you can send even file fields. Serialize do not support file fields 
AFAIK

Jonathan
Diretor de Tecnologia
+55(12)98864-1594

Sent from my iPhone

> On Apr 17, 2014, at 17:25, Joseph Mutumi  wrote:
> 
> You could try using $("form").serialize() to get the form inputs in
> the ajax data. But from the URL it looks like your HTML is somehow
> rendering badly. The form action is coming out as '/newmarkets/search/
> method='
> 
> Kind regards
> 
>> On 4/17/14, willyhakim  wrote:
>> Hi everyone?
>> 
>> I am trying to use ajax to do the following
>> 
>> 1)User inputs a number.
>> 2) I use ajax to return a query list into the same page.
>> 
>> Here is my code
>> and I keep getting this error
>> 
>> Page not found (404)  Request Method: GET  Request URL:
>> http://127.0.0.1:8000/newmarkets/search/%20method=?csrfmiddlewaretoken=VkKvStx1qGZOM1YxzM8xenGDbYRBnMPA
>> 
>> 
>> Using the URLconf defined in exportAbroad.urls, Django tried these URL
>> patterns, in this order:
>> 
>>   1. ^$ [name='index']
>>   2. ^about/$ [name='about']
>>   3. ^pricing/$ [name='pricing']
>>   4. ^market_research_tool/$ [name='market_research_tool']
>>   5. ^newmarkets/ ^$ [name='index']
>>   6. ^newmarkets/ ^search/$ [name='search']
>>   7. ^admin/
>>   8. ^accounts/
>>   9. ^static/(?P.*)$
>> 
>> The current URL, newmarkets/search/ method=, didn't match any of these.
>> 
>> *views.py*
>> def index(request):
>> context = RequestContext(request)
>> return render_to_response('newmarkets/index.html', context)
>> 
>> def search(request):
>> if request.is_ajax() and request.method=='POST':
>> UserHSnumber = request.POST['UserHSnumber']
>> country_list = Imports.objects.filter(hs_number= UserHSnumber)[1:11]
>> hsdescript = Products.objects.get(hs_number=UserHSnumber)
>> data = {'markets': country_list, 'hsdescript': hsdescript}
>> mimetype='application/json'
>> else:
>> raise Http404
>> return HttpResponse(json.dumps(data), mimetype)
>> 
>> 
>> *HTML*
>> 
>> {%block body_block%}
>> 
>> 
>>  What is your product's H.S number?
>> 
>>
>> {% csrf_token %}
>>  
>>  Submit
>>
>> 
>> 
>> 
>> 
>> 
>> 
>> 
>> *ajax.js*
>> 
>> 
>> 
>> 
>> 
>> *$(document).ready(function() { $('#hs').click(function(){ $.ajax({
>> type:"POST", url:"/newmarkets/search/",
>> data:{"userHSnumber":$("#search").val()}, dataType: "json",
>> success:function(data){ alert(data.message); } }); });// CSRF code
>> function getCookie(name) {var cookieValue = null;var i =
>> 0;if (document.cookie && document.cookie !== '') {var
>> cookies = document.cookie.split(';');for (i; i <
>> cookies.length; i++) {var cookie =
>> jQuery.trim(cookies[i]);// Does this cookie string begin
>> with the name we want?if (cookie.substring(0, name.length +
>> 
>> 1) === (name + '=')) {cookieValue =
>> decodeURIComponent(cookie.substring(name.length + 1));
>> break;}}}return cookieValue;
>> 
>> }var csrftoken = getCookie('csrftoken');function
>> csrfSafeMethod(method) {// these HTTP methods do not require CSRF
>> protectionreturn (/^(GET|HEAD|OPTIONS|TRACE)$/.test(method));}
>> 
>>  $.ajaxSetup({crossDomain: false, // obviates need for sameOrigin
>> testbeforeSend: function(xhr, settings) {if
>> (!csrfSafeMethod(settings.type)) {
>> xhr.setRequestHeader("X-CSRFToken", csrftoken);}}
>> }); });*
>> 
>> 
>> 
>> 
>> --
>> 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/2132e3e5-9795-416d-9306-0b09a1698c6b%40googlegroups.com.
>> For more options, visit https://groups.google.com/d/optout.
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/django-users/CAN5idp_ENtkVOapK6QjaGPhGUUfbAC8CWxnOg%2BpQFbgZOuMRmQ%40mail.gmail.com.
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to

Deferred reverse geo coding upon record save/update

2014-04-17 Thread Subodh Nijsure
I have application where mobile devices are collecting data from
sensors, and along with sensor reading they also save gps co-ordinates
where the sensor data is taken. This is uploaded to web server using
REST interface on django platform.

But I am trying to figure out how do I reverse geo decode those
lat/lang numbers to actual address using google reverse geo-coder
APIs. I know I could do this in save method but that would make save
operation slower. Is there some way I can queue these operations
within django implementation so the save can proceed but queue up a
job that will reverse geo-decode lat/long and update a record.

Say:

My REST api creates a new record in table sensordata, with lat, long
of (10.1, -120.202) what I want to happen is new record for sensordata
say unique id 1234 gets created. At the same time  job is queued
somewhere that will update record #1234 that will reverse geo-decode
10.1,-120.202 to the street address.

-Subodh

-Subodh

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


Re: Including Page Fragments

2014-04-17 Thread Ramón Carrillo
I guess you are not supposed to use spaces there.

IIRC spaces aren't allowed when using filters, neither  (e.g.
var|filter1 is ok, var | filter1 is not)

You could find the exact reason digging in the template compiler code.
https://github.com/django/django/blob/master/django/template/__init__.py
https://github.com/django/django/blob/master/django/template/base.py

Regards,
Ramon

On Wed, Apr 16, 2014 at 10:21 PM, Venkatraman S  wrote:
> Just saw a weird problem while including template fragments:
>
> Works :
>   {% include "page.html" with one_variable="1" %}
>
> Does not because of the space during the variable assignment :
>{% include "page.html" with one_variable = "1" %}
>
> Regards,
> Venkat
>
> --
> 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/CAN7tdFT-kAGYgw6nioN-JK4a8LSK1_jadx6u0J7fnSt7%2Bo6%3D5g%40mail.gmail.com.
> For more options, visit https://groups.google.com/d/optout.

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


Re: Deferred reverse geo coding upon record save/update

2014-04-17 Thread Ramón Carrillo
Hi Subodh,

I would use use the same model as a queue.

Add a address field to the sensordata model, make it nullable
(null=True). Then write a custom django-admin command [0] that gets
all the records in sensordata with null address, make the request to
the geodecoder and save the result in the address field.

Let's say you name your command 'geodecode':
$ manage.py geodecode
will fill the address for all the sensordata records with null address.

If you're in a Unix environment, you could use cron [1] to run this
command every certain time.

[0] https://docs.djangoproject.com/en/1.6/howto/custom-management-commands/
[1] http://www.thegeekstuff.com/2011/07/cron-every-5-minutes/

Regards,
Ramón

On Thu, Apr 17, 2014 at 6:19 PM, Subodh Nijsure
 wrote:
> I have application where mobile devices are collecting data from
> sensors, and along with sensor reading they also save gps co-ordinates
> where the sensor data is taken. This is uploaded to web server using
> REST interface on django platform.
>
> But I am trying to figure out how do I reverse geo decode those
> lat/lang numbers to actual address using google reverse geo-coder
> APIs. I know I could do this in save method but that would make save
> operation slower. Is there some way I can queue these operations
> within django implementation so the save can proceed but queue up a
> job that will reverse geo-decode lat/long and update a record.
>
> Say:
>
> My REST api creates a new record in table sensordata, with lat, long
> of (10.1, -120.202) what I want to happen is new record for sensordata
> say unique id 1234 gets created. At the same time  job is queued
> somewhere that will update record #1234 that will reverse geo-decode
> 10.1,-120.202 to the street address.
>
> -Subodh
>
> -Subodh
>
> --
> 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/CALr9Q3ZtH_MKKRhddmmRrqW_LAe7nFB6dbQ06TfGO%2B1Fe_BFTA%40mail.gmail.com.
> For more options, visit https://groups.google.com/d/optout.

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


Re: Questions about setting up my first app in django tutorial

2014-04-17 Thread Ramón Carrillo
The file is probably in the wrong directory or you're naming it incorrectly.

It must be project_name/app_name/admin.py

Maybe you're placing it in project_name/admin.py or
project_name/project_name/admin.py

On Thu, Apr 17, 2014 at 9:51 AM, Xiaofeng Feng  wrote:
> Yes.
> INSTALLED_APPS = (
> 'django.contrib.admin',
> 'django.contrib.auth',
> 'django.contrib.contenttypes',
> 'django.contrib.sessions',
> 'django.contrib.messages',
> 'django.contrib.staticfiles',
> 'TestApp',
> )
>
> The last line TestApp is my first app.
>
> On Thursday, April 17, 2014 8:24:12 AM UTC-4, Jorge Andrés Vergara Ebratt
> wrote:
>>
>> Did you register the app in settings.py?
>>
>>
>> 2014-04-16 23:03 GMT-05:00 Xiaofeng Feng :
>>>
>>> I am now trying to set up my first app using django tutorial. However, I
>>> was stuck at adding the poll app in part 2. I think I followed all the steps
>>> and it goes well before this question. After I change admin.py with
>>>
>>> from django.contrib import admin
>>> from polls.models import Poll
>>>
>>> admin.site.register(Poll)
>>>
>>> as the tutorial says. The admin website does not change at all. Does
>>> anybody know why this happens? 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/7bdb76f7-caf7-4c44-af6f-05f042494bed%40googlegroups.com.
>>> For more options, visit https://groups.google.com/d/optout.
>>
>>
>>
>>
>> --
>> Jorge Andres Vergara Ebratt
>> #SoftwareDeveloper (Or at least trying to be)
>> @javebratt
>> facebook.com/javebratt
>
> --
> 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/36c07290-ff33-4e3d-b142-26efd577c38c%40googlegroups.com.
>
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CABoKswgGnKKAO1ob%2B4qyPKVnz%2BvsTta%3Dq0CU6%2BcrWA0f70TXRA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Including Page Fragments

2014-04-17 Thread Venkatraman S
Well, the reason I sent this was due to the fact that while in templates
when you are doing conditionals, the spaces are mandatory.

i.e,
Works : {% if request.session.VARIABLE_NAME == "1"  %}
Doesn't : {% if request.session.VARIABLE_NAME=="1"  %}


On Fri, Apr 18, 2014 at 8:10 AM, Ramón Carrillo wrote:

> I guess you are not supposed to use spaces there.
>
> IIRC spaces aren't allowed when using filters, neither  (e.g.
> var|filter1 is ok, var | filter1 is not)
>
> You could find the exact reason digging in the template compiler code.
> https://github.com/django/django/blob/master/django/template/__init__.py
> https://github.com/django/django/blob/master/django/template/base.py
>
> Regards,
> Ramon
>
> On Wed, Apr 16, 2014 at 10:21 PM, Venkatraman S 
> wrote:
> > Just saw a weird problem while including template fragments:
> >
> > Works :
> >   {% include "page.html" with one_variable="1" %}
> >
> > Does not because of the space during the variable assignment :
> >{% include "page.html" with one_variable = "1" %}
> >
> > Regards,
> > Venkat
> >
> > --
> > 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/CAN7tdFT-kAGYgw6nioN-JK4a8LSK1_jadx6u0J7fnSt7%2Bo6%3D5g%40mail.gmail.com
> .
> > For more options, visit https://groups.google.com/d/optout.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CABoKswjXdwxhiuUHsy_R8Vj28n5EzK%3D2gdS-HEMk0Xx5C8N_Wg%40mail.gmail.com
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAN7tdFQ8Pwe%3DPqW0_OGSi6b5%2Bz5qGBSES%3D3AEg-36d97OPstRA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


VIEW PERMISSION

2014-04-17 Thread Tameen Malik
An old Query / I know that but need assistance! so dear django users see 
what i want to ask and what i did:

*Story:*

As django admin has three permissions in it's auth : add, change, delete! I 
want to add view permission in this auth in admin panel.I know i have to 
customize permissions to add view permission in 'auth|permission|can view 
permission' to view all entries! but how ! for this i followed several 
patches uploaded by django project. one is 8 years old 
(https://code.djangoproject.com/ticket/820)  and this one 
https://code.djangoproject.com/ticket/8936  is for databrowse functionality 
which i really don't need!.. finally i find this one see below:

*NEEDED PATCH:*




*[X] 1. Added 'view' to default permission list*
#./contrib/auth/management/init.py
def _get_all_permissions(opts):

"Returns (codename, name) for all permissions in the given opts."
perms = []
for action in ('add', 'change', 'delete', 'view'):

perms.append((_get_permission_codename(action, opts), u'Can %s 
%s' % (action, opts.verbose_name_raw)))

return perms + list(opts.permissions)

*[X] 2. Test the 'view' permission is added to all models*

run manage.py syncdb

I confirmed that view permission is now added for all tables in the 
auth_permissions table

*[X] 3. Add "get\_view_permission" to default model class.*

Added get\_view_permission to the model class. You can find this in the 
file ./db/models/options.py This is used by the admin class in the next 
step.

def get_view_permission(self):

return 'view_%s' % self.object_name.lower()

*[X] 4. Add "has\_view_permission" to default admin class*

Just to be consistent I'm going to add "has\_view_permission" to the 
system. Looks like it should be somewhere in *contrib/admin/options.py*. 
Made sure if the user has has change permission, then view permissions are 
automatically implied.

# /contrib/admin/options.py
# Added has_view_permissions
def has_view_permission(self, request, obj=None):

"""
Returns True if the given request has permission to change or view
the given Django model instance.


If obj is None, this should return True if the given request has
permission to change *any* object of the given type.
"""
opts = self.opts
return self.has_change_permission(request, obj) or \

request.user.has_perm(opts.app_label + '.' + 
opts.get_view_permission())


# modified get_model_perms to include 'view' too.
# No idea where this may be used, but trying to stay consistent
def get_model_perms(self, request):

"""
Returns a dict of all perms for this model. This dict has the keys
add, change, and delete and view mapping to the True/False
for each of those actions.
"""
return {

'add': self.has_add_permission(request),
'change': self.has_change_permission(request),
'delete': self.has_delete_permission(request),
'view': self.has_view_permission(request),

}


# modified response_add function to return the user to the mode list
# if they added a unit and have view rights
...

else:

self.message_user(request, msg)

# Figure out where to redirect. If the user has change 
permission,
# redirect to the change-list page for this object. Otherwise,
# redirect to the admin index.
#if self.has_change_permission(request, None):
if self.has_change_permission(request, None) or 
self.has_view_permission(request, None):

post_url = '../'

else:

post_url = '../../../'

return HttpResponseRedirect(post_url)

# modified the change_view function so it becomes the details
# for users with view permission

#if not self.has_change_permission(request, obj):
if not (self.has_change_permission(request, obj) or 
(self.has_view_permission(request, obj) and not request.POST)):

raise PermissionDenied

# modified the changelist_view function so it shows the list of 
items
# if you have view permissions

def changelist_view(self, request, extra_context=None):

"The 'change list' admin view for this model."
from django.contrib.admin.views.main import ChangeList, 
ERROR_FLAG
opts = self.model._meta
app_label = opts.app_label
#if not self.has_change_permission(request, None):
if not (self.has_change_permission(request, None) or 
self.has_view_permission(request, None)):

raise PermissionDenied


*[X] 5. Update default template to list models if user has view permission*

I modified the default template in 
contrib/admin/templates/admin/index.html. This could also be handled by 
copying the file 

View Permissions -- DJANGO

2014-04-17 Thread Tameen Malik
An old Query / I know that but need assistance! so dear django users see 
what i want to ask and what i did:

*Story:*

As django admin has three permissions in it's auth : add, change, delete! I 
want to add view permission in this auth in admin panel.I know i have to 
customize permissions to add view permission in 'auth|permission|can view 
permission' to view all entries! but how ! for this i followed several 
patches uploaded by django project. one is 8 years old (
https://code.djangoproject.com/ticket/820)  and this one 
https://code.djangoproject.com/ticket/8936  is for databrowse functionality 
which i really don't need!.. finally i find this one see below:

*NEEDED PATCH:*




*[X] 1. Added 'view' to default permission list*
#./contrib/auth/management/init.py
def _get_all_permissions(opts):

"Returns (codename, name) for all permissions in the given opts."
perms = []
for action in ('add', 'change', 'delete', 'view'):

perms.append((_get_permission_codename(action, opts), u'Can %s 
%s' % (action, opts.verbose_name_raw)))

return perms + list(opts.permissions)

*[X] 2. Test the 'view' permission is added to all models*

run manage.py syncdb

I confirmed that view permission is now added for all tables in the 
auth_permissions table

*[X] 3. Add "get\_view_permission" to default model class.*

Added get\_view_permission to the model class. You can find this in the 
file ./db/models/options.py This is used by the admin class in the next 
step.

def get_view_permission(self):

return 'view_%s' % self.object_name.lower()

*[X] 4. Add "has\_view_permission" to default admin class*

Just to be consistent I'm going to add "has\_view_permission" to the 
system. Looks like it should be somewhere in *contrib/admin/options.py*. 
Made sure if the user has has change permission, then view permissions are 
automatically implied.

# /contrib/admin/options.py
# Added has_view_permissions
def has_view_permission(self, request, obj=None):

"""
Returns True if the given request has permission to change or view
the given Django model instance.


If obj is None, this should return True if the given request has
permission to change *any* object of the given type.
"""
opts = self.opts
return self.has_change_permission(request, obj) or \

request.user.has_perm(opts.app_label + '.' + 
opts.get_view_permission())


# modified get_model_perms to include 'view' too.
# No idea where this may be used, but trying to stay consistent
def get_model_perms(self, request):

"""
Returns a dict of all perms for this model. This dict has the keys
add, change, and delete and view mapping to the True/False
for each of those actions.
"""
return {

'add': self.has_add_permission(request),
'change': self.has_change_permission(request),
'delete': self.has_delete_permission(request),
'view': self.has_view_permission(request),

}


# modified response_add function to return the user to the mode list
# if they added a unit and have view rights
...

else:

self.message_user(request, msg)

# Figure out where to redirect. If the user has change 
permission,
# redirect to the change-list page for this object. Otherwise,
# redirect to the admin index.
#if self.has_change_permission(request, None):
if self.has_change_permission(request, None) or 
self.has_view_permission(request, None):

post_url = '../'

else:

post_url = '../../../'

return HttpResponseRedirect(post_url)

# modified the change_view function so it becomes the details
# for users with view permission

#if not self.has_change_permission(request, obj):
if not (self.has_change_permission(request, obj) or 
(self.has_view_permission(request, obj) and not request.POST)):

raise PermissionDenied

# modified the changelist_view function so it shows the list of 
items
# if you have view permissions

def changelist_view(self, request, extra_context=None):

"The 'change list' admin view for this model."
from django.contrib.admin.views.main import ChangeList, 
ERROR_FLAG
opts = self.model._meta
app_label = opts.app_label
#if not self.has_change_permission(request, None):
if not (self.has_change_permission(request, None) or 
self.has_view_permission(request, None)):

raise PermissionDenied


*[X] 5. Update default template to list models if user has view permission*

I modified the default template in contrib/admin/templates/admin/
index.html. This could also be handled by copying the file t

Re: I can't connect Django with SQL Anywhere 11 Database

2014-04-17 Thread Tameen Malik
Elio -- Have you used  UTF-8


*By default, with a UTF-8 database, MySQL will use the utf8_general_ci 
collation. This results in all string equality comparisons being done in a 
case-insensitive manner. That is, "Fred" and "freD" are considered equal at 
the database level. If you have a unique constraint on a field, it would be 
illegal to try to insert both "aa" and "AA" into the same column, since 
they compare as equal (and, hence, non-unique) with the default collation *



*Collation settings*   in 
https://docs.djangoproject.com/en/dev/ref/databases/

-- 
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/ae11c3fc-16fc-4e73-b32c-3725c6731788%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


How to create an admin editable list?

2014-04-17 Thread radsepvj
Any suggestion on how to create an admin editable list? either using django 
or python? Thank you for your time. Regards,
Rads 

-- 
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/38d1b8c6-bd3b-43a3-a91c-026df7f95913%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.