How to make generic variables available in settings and contexts?

2015-01-18 Thread ThomasTheDjangoFan
Ladies and gentleman,

I am new to Django and would really love to have a solution for this:

My goal is to share generated settings between my views/models and 
templates, without repeating myself.

Right now I have following code, where the problem appears:

#MY_CONTEXT_PROCESSOR.PY
from django.conf import settings

def setDataToContext (request):
"""
Send settings to context of tempalte
"""

#GENERATED STUFF
#Prepare common Objects
main_category = Category.objects.get(id=1)

return {
'settings': settings, # Global Django Settings
'MAIN_CATEGORY': main_category, # Make category available in 
template - Question: How do I make this available in views/models as 
settings.MAIN_CATEGORY?
}


The main question is:

*How can I make the generic constant MAIN_CATEGORY available in 
views/models as settings.MAIN_CATEGORY without repeating myself?*
I am really looking forward to see your solutions.

Kind regards
Thomas

-- 
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/eb76aeb9-bc51-4b1a-918d-db6d29956d08%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: How to make generic variables available in settings and contexts?

2015-01-18 Thread James Schneider
If I understand you right, you want to set MAIN_CATEGORY as a "global"
variable/setting containing a Category object with an ID of 1. Is that
right? If so...

Rather than populating a "global" variable, I would instead create a custom
model manager for the Category model:

https://docs.djangoproject.com/en/1.7/topics/db/managers/#custom-managers

 It would be a pretty simple override just to add an extra method:

class CategoryManager(models.Manager):
def get_main_category(self):
return Category.objects.get(pk=1)

class Category(models.Model):
<...other fields...>
objects = CategoryManager()


Then, anywhere you needed the value that would be accessed via
MAIN_CATEGORY, you would instead use 'main_category =
Category.objects.get_main_category()'.

If you ever need to change the category that is returned, the only place
you'll need to update the code/PK is in the manager method definition. Much
more flexible than a simple variable in settings.py.

Realize that the example above is quite a naive/simplistic implementation,
and can benefit from other optimizations (such as a basic caching mechanism
in the CategoryManager in the event it is called multiple times during a
request to avoid multiple queries for the same data, among others). Check
out
https://github.com/django/django/blob/master/django/contrib/auth/backends.py#L41
for how Django handles caching for permission checks (which are often
called multiple times per request).

To avoid the dependency on a specific key/PK, you may want to consider
adding a boolean field to Category called 'is_main' that defaults to False.
Then set the field to True for the single category you want to be the main
one. Then your manager query would look like
Category.objects.get(is_main=True). Just make sure you only have one
category with is_main set to True (if you change your mind on which
category will be the main category, set all of the Categories to False, and
then reset the new main category to True). If you are confident that it
will never change, though, you'll probably be fine.

-James


On Jan 18, 2015 2:26 AM, "ThomasTheDjangoFan" <
stefan.eichholz.ber...@googlemail.com> wrote:

> Ladies and gentleman,
>
> I am new to Django and would really love to have a solution for this:
>
> My goal is to share generated settings between my views/models and
> templates, without repeating myself.
>
> Right now I have following code, where the problem appears:
>
> #MY_CONTEXT_PROCESSOR.PY
> from django.conf import settings
>
> def setDataToContext (request):
> """
> Send settings to context of tempalte
> """
>
> #GENERATED STUFF
> #Prepare common Objects
> main_category = Category.objects.get(id=1)
>
> return {
> 'settings': settings, # Global Django Settings
> 'MAIN_CATEGORY': main_category, # Make category available in
> template - Question: How do I make this available in views/models as
> settings.MAIN_CATEGORY?
> }
>
>
> The main question is:
>
> *How can I make the generic constant MAIN_CATEGORY available in
> views/models as settings.MAIN_CATEGORY without repeating myself?*
> I am really looking forward to see your solutions.
>
> Kind regards
> Thomas
>
>  --
> 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/eb76aeb9-bc51-4b1a-918d-db6d29956d08%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%2Be%2BciWthFAetWmx4r1RzrU1v2tOQCqETLk%2BEVxF3t-14mehCA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Question for Django Core Team?

2015-01-18 Thread Petar Pilipovic
Hello there this is maybea of topic but I wont to ask Django Core Team, did 
they now someone who is practising Django in Belgrade-Serbia, or 
Zagreb-Croatia, I now there is a strong Slovenia team there, but I was 
wondering about this area around Bosnia where I live in.
I am asking because I was inspired by this post here
http://blog.djangogirls.org/post/108268319658/django-girls-core-team-grows, 
and mine chat whit Daniel Roy Greenfel @pydanny  
over 
Twitter https://twitter.com/Coopsess/status/556665409693163520.
So do you now eny one? 
Tank you.

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


Re: How to make generic variables available in settings and contexts?

2015-01-18 Thread ThomasTheDjangoFan
Hi James,

thanks a lot for pointing me to the models.Mangager option. Now this is 
really interesting. I will definetly check out how caching works.

Now the question is:
How do I now access the CategoryManager.get_main_category() in my 
template.html? I guess I have to pass it over to context within the view?


Am Sonntag, 18. Januar 2015 12:28:30 UTC+1 schrieb James Schneider:
>
> If I understand you right, you want to set MAIN_CATEGORY as a "global" 
> variable/setting containing a Category object with an ID of 1. Is that 
> right? If so...
>
> Rather than populating a "global" variable, I would instead create a 
> custom model manager for the Category model:
>
> https://docs.djangoproject.com/en/1.7/topics/db/managers/#custom-managers
>
>  It would be a pretty simple override just to add an extra method:
>
> class CategoryManager(models.Manager):
> def get_main_category(self):
> return Category.objects.get(pk=1)
>
> class Category(models.Model):
> <...other fields...>
> objects = CategoryManager()
>
>
> Then, anywhere you needed the value that would be accessed via 
> MAIN_CATEGORY, you would instead use 'main_category = 
> Category.objects.get_main_category()'.
>
> If you ever need to change the category that is returned, the only place 
> you'll need to update the code/PK is in the manager method definition. Much 
> more flexible than a simple variable in settings.py.
>
> Realize that the example above is quite a naive/simplistic implementation, 
> and can benefit from other optimizations (such as a basic caching mechanism 
> in the CategoryManager in the event it is called multiple times during a 
> request to avoid multiple queries for the same data, among others). Check 
> out 
> https://github.com/django/django/blob/master/django/contrib/auth/backends.py#L41
>  
> for how Django handles caching for permission checks (which are often 
> called multiple times per request). 
>
> To avoid the dependency on a specific key/PK, you may want to consider 
> adding a boolean field to Category called 'is_main' that defaults to False. 
> Then set the field to True for the single category you want to be the main 
> one. Then your manager query would look like 
> Category.objects.get(is_main=True). Just make sure you only have one 
> category with is_main set to True (if you change your mind on which 
> category will be the main category, set all of the Categories to False, and 
> then reset the new main category to True). If you are confident that it 
> will never change, though, you'll probably be fine.
>
> -James
>
>
> On Jan 18, 2015 2:26 AM, "ThomasTheDjangoFan" <
> stefan.eich...@googlemail.com > wrote:
>
>> Ladies and gentleman,
>>
>> I am new to Django and would really love to have a solution for this:
>>
>> My goal is to share generated settings between my views/models and 
>> templates, without repeating myself.
>>
>> Right now I have following code, where the problem appears:
>>
>> #MY_CONTEXT_PROCESSOR.PY
>> from django.conf import settings
>>
>> def setDataToContext (request):
>> """
>> Send settings to context of tempalte
>> """
>>
>> #GENERATED STUFF
>> #Prepare common Objects
>> main_category = Category.objects.get(id=1)
>>
>> return {
>> 'settings': settings, # Global Django Settings
>> 'MAIN_CATEGORY': main_category, # Make category available in 
>> template - Question: How do I make this available in views/models as 
>> settings.MAIN_CATEGORY?
>> }
>>
>>
>> The main question is:
>>
>> *How can I make the generic constant MAIN_CATEGORY available in 
>> views/models as settings.MAIN_CATEGORY without repeating myself?*
>> I am really looking forward to see your solutions.
>>
>> Kind regards
>> Thomas
>>
>>  -- 
>> 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/eb76aeb9-bc51-4b1a-918d-db6d29956d08%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/b364627d-2a43-4569-81f6-35b31e300390%40go

Re: How to make generic variables available in settings and contexts?

2015-01-18 Thread James Schneider
If you need it in all of (or a large majority of) your templates, stick
with the context processor you originally posted, just replace the
Category.objects.get() call with the custom manager call. Your templates
would then have access to {{ MAIN_CATEGORY }}. And with a context
processor, that literally means every template, including login forms,
password resets, etc. which may or may not be acceptable.

If you don't necessarily need it in all templates, but you are using
class-based views, you can write a custom mixin that overrides
get_context_data() to add in the MAIN_CATEGORY variable for your templates,
but only if you are not using the aforementioned context processor to
populate it (otherwise you are doubling the work to set the same variable).

Templates are the only tricky part here. Everywhere else you can call your
custom manager method directly.

-James
On Jan 18, 2015 4:47 AM, "ThomasTheDjangoFan" <
stefan.eichholz.ber...@googlemail.com> wrote:

> Hi James,
>
> thanks a lot for pointing me to the models.Mangager option. Now this is
> really interesting. I will definetly check out how caching works.
>
> Now the question is:
> How do I now access the CategoryManager.get_main_category() in my
> template.html? I guess I have to pass it over to context within the view?
>
>
> Am Sonntag, 18. Januar 2015 12:28:30 UTC+1 schrieb James Schneider:
>>
>> If I understand you right, you want to set MAIN_CATEGORY as a "global"
>> variable/setting containing a Category object with an ID of 1. Is that
>> right? If so...
>>
>> Rather than populating a "global" variable, I would instead create a
>> custom model manager for the Category model:
>>
>> https://docs.djangoproject.com/en/1.7/topics/db/managers/#custom-managers
>>
>>  It would be a pretty simple override just to add an extra method:
>>
>> class CategoryManager(models.Manager):
>> def get_main_category(self):
>> return Category.objects.get(pk=1)
>>
>> class Category(models.Model):
>> <...other fields...>
>> objects = CategoryManager()
>>
>>
>> Then, anywhere you needed the value that would be accessed via
>> MAIN_CATEGORY, you would instead use 'main_category =
>> Category.objects.get_main_category()'.
>>
>> If you ever need to change the category that is returned, the only place
>> you'll need to update the code/PK is in the manager method definition. Much
>> more flexible than a simple variable in settings.py.
>>
>> Realize that the example above is quite a naive/simplistic
>> implementation, and can benefit from other optimizations (such as a basic
>> caching mechanism in the CategoryManager in the event it is called multiple
>> times during a request to avoid multiple queries for the same data, among
>> others). Check out https://github.com/django/django/blob/master/django/
>> contrib/auth/backends.py#L41 for how Django handles caching for
>> permission checks (which are often called multiple times per request).
>>
>> To avoid the dependency on a specific key/PK, you may want to consider
>> adding a boolean field to Category called 'is_main' that defaults to False.
>> Then set the field to True for the single category you want to be the main
>> one. Then your manager query would look like 
>> Category.objects.get(is_main=True).
>> Just make sure you only have one category with is_main set to True (if you
>> change your mind on which category will be the main category, set all of
>> the Categories to False, and then reset the new main category to True). If
>> you are confident that it will never change, though, you'll probably be
>> fine.
>>
>> -James
>>
>>
>> On Jan 18, 2015 2:26 AM, "ThomasTheDjangoFan" > googlemail.com> wrote:
>>
>>> Ladies and gentleman,
>>>
>>> I am new to Django and would really love to have a solution for this:
>>>
>>> My goal is to share generated settings between my views/models and
>>> templates, without repeating myself.
>>>
>>> Right now I have following code, where the problem appears:
>>>
>>> #MY_CONTEXT_PROCESSOR.PY
>>> from django.conf import settings
>>>
>>> def setDataToContext (request):
>>> """
>>> Send settings to context of tempalte
>>> """
>>>
>>> #GENERATED STUFF
>>> #Prepare common Objects
>>> main_category = Category.objects.get(id=1)
>>>
>>> return {
>>> 'settings': settings, # Global Django Settings
>>> 'MAIN_CATEGORY': main_category, # Make category available in
>>> template - Question: How do I make this available in views/models as
>>> settings.MAIN_CATEGORY?
>>> }
>>>
>>>
>>> The main question is:
>>>
>>> *How can I make the generic constant MAIN_CATEGORY available in
>>> views/models as settings.MAIN_CATEGORY without repeating myself?*
>>> I am really looking forward to see your solutions.
>>>
>>> Kind regards
>>> Thomas
>>>
>>>  --
>>> 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

Linking to multiple dynamic images from same web page

2015-01-18 Thread Derek
I have a situation which is puzzling.

I have a web page that, when generated embeds links that look like:


http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAF1Wu3OfN9rmUKTDO%2BT%3DJan%3DF%3DLKODqQObds-tvME%3DUhL18fMw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Linking to multiple dynamic images from same web page

2015-01-18 Thread Mitesh Patel
Hi Derek,

I face same issue few months ago, what I did is I destroyed plot object
completely everytime the view is called and regenerated new plot everytime.
You can try that. There is an issue with matplotlib memory, which basically
usage same plot.

Another solution could be try different cStringIO to store base64 encoded
image data, send that as response and at browser using javascript (
data:image/png;base64).



Thanks,
With Best Regards,

Mitesh Patel

Senior Product Engineer

Mobile: +91-9970 8575 39
Email: mitesh.patel1...@gmail.com
LinkedIn : http://in.linkedin.com/in/miteshpatel11


On 18 January 2015 at 19:23, Derek  wrote:

> I have a situation which is puzzling.
>
> I have a web page that, when generated embeds links that look like:
>
> 
>  line 1401, in xlabel
> l =  gca().set_xlabel(s, *args, **kwargs)
>   File
> "/home/gamesbook/.virtualenvs/dev/local/lib/python2.7/site-packages/matplotlib/pyplot.py",
> line 803, in gca
> ax =  gcf().gca(**kwargs)
>   File
> "/home/gamesbook/.virtualenvs/dev/local/lib/python2.7/site-packages/matplotlib/figure.py",
> line 1221, in gca
> return self.add_subplot(1, 1, 1, **kwargs)
>   File
> "/home/gamesbook/.virtualenvs/dev/local/lib/python2.7/site-packages/matplotlib/figure.py",
> line 916, in add_subplot
> self._axstack.add(key, a)
>   File
> "/home/gamesbook/.virtualenvs/dev/local/lib/python2.7/site-packages/matplotlib/figure.py",
> line 120, in add
> Stack.remove(self, (key, a_existing))
>   File
> "/home/gamesbook/.virtualenvs/dev/local/lib/python2.7/site-packages/matplotlib/cbook.py",
> line 1343, in remove
> raise ValueError('Unknown element o')
> ValueError: Unknown element o
>
> I have googled for this error, but it seems fairly obscure and I am not
> sure how it relates to my situation.
>
> Any insights welcome!
>
> Thanks
> Derek
>
>  --
> 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/CAF1Wu3OfN9rmUKTDO%2BT%3DJan%3DF%3DLKODqQObds-tvME%3DUhL18fMw%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/CAD3RGrQWey-Yi2W-Qkc8JynCtBgqxQhv8f3rdH8%3DPZ2AsHT_Rg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


How to add my Templates folder to TEMPLATE_DIRS

2015-01-18 Thread Kishan Mehta
Hello all,

> I want to customise how admin page looks 

> I have my template folder in my application folder 
at C:\Users\kishan\Django_App\polls\templates\admin

> In settings.py I have added TEMPLATE_DIRS = 
[os.path.join(BASE_DIR,'C:\Users\kishan\Django_App\polls\templates')] .

> Changes I have made to base_site.html is not reflecting in admin page. 

Please 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/7fad9e76-3bcf-49b3-b45d-cfdec09e8a65%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Help a newb with authentication and registration

2015-01-18 Thread Nelson Varela
Hi,

I don't know what allauth does but you can check the django docs about custom 
auth and user model:

https://docs.djangoproject.com/en/1.7/topics/auth/customizing/

Maybe not what you are looking for but it's a good documentation whichs can 
help you understand more about this topic.

-- 
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/4d3e863d-6047-47ea-9bf2-99538d53e952%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django Admin UI Bug - 1.7.3

2015-01-18 Thread Timothy W. Cook
On Sat, Jan 17, 2015 at 11:49 AM, Collin Anderson 
wrote:

> Hi,
>
> Did you also switch to Python 3?
>

​Yes.

Well, I didn't switch. I have been using Python 3 for quite some time.
Even before it was officially supported.
​


> It doesn't seem to be using your __unicode__ method at all.
> If you query one of these Projects in manage.py shell, do they show the
> project name?
>

​As I said before, my views that use AJAX to return data from queries still
work just as before.  But yes, in the manage.py shell I can import the
models and print the names.

>>> from ccdgen.models import DvBoolean,DvAny, Common, Project
>>> pcts = DvBoolean.objects.all()
>>> for p in pcts:
...   print(p.prj_name.prj_name)

caBIG
caBIG
caBIG
caBIG
caBIG
caBIG
caBIG

...





> Are you sure that the __unicode__ method is actually attached to your
> model?
>
>
I am not exactly sure what you mean by that question; attached?​Here is
the code: ​

class Project(models.Model):
"""
Every item created in CCDGEN must be assigned to a Project when
created. All items (except CCD) may be
reused in multiple CCDs. However, this does not change the original
Project.
The Allowed Groups field contains each of the User Groups allowed to
see each item with this Project name.
The User Group, Open, is assigned to every user. So if you assign the
Open group as one of the allowed groups,
all CCDGEN users will see this item.
"""
pgroup = models.ForeignKey(Group, verbose_name='Primary Group',
related_name='primarygroup', null=True)
prj_name = models.CharField(_("project name"), max_length=110,
unique=True, db_index=True, help_text=_('Enter the name of your project.'))
description = models.TextField(_("project description"), blank=True,
help_text=_('Enter a description or explaination of an acronym of the
project.'))
rm_version = models.ForeignKey(RMversion, verbose_name=_('rm version'),
related_name='%(class)s_related', help_text=_('Choose the version of the
MLHIM Reference Model you are using.'))
allowed_groups = models.ManyToManyField(Group, verbose_name=_('allowed
groups'), related_name='%(class)s_related', help_text=_('Choose the groups
that are allowed to work in this project.'))

def __unicode__(self):
return self.prj_name


class Meta:
verbose_name = _("Project")
verbose_name_plural = _("Projects")
ordering = ['prj_name']




> Also, FYI, to_field="prj_name" means you can't easily change the name of
> the project.
>
>
​Yes, Once created the name cannot be changed, and once an item is assigned
to a project the attached items are immutable.

Thanks,
Tim




> Collin
>
> On Friday, January 16, 2015 at 3:14:55 PM UTC-5, Timothy W. Cook wrote:
>>
>> I should also mention that I have some AJAX calls for the same
>> information and they still work fine.  So I am quite certain it is in the
>> Admin templates or the Admin properties definitions.
>>
>> On Fri, Jan 16, 2015 at 5:56 PM, Timothy W. Cook  wrote:
>>
>>> Is this a bug or did I miss something in the release notes?
>>>
>>> ​Moving from 1.6.4 to 1.7.3  the listing in the Admin UI is not
>>> resolving a related field now.  There are not any model changes involved.
>>>
>>> Attached are two screen shots named for the versions.
>>>
>>> I haven't changed the admin code either.  For the screen shots the admin
>>> code is:
>>>
>>> ​class DvBooleanAdmin(admin.ModelAdmin):
>>> list_filter = ['prj_name__rm_version__version_id','prj_name',]
>>> search_fields = ['data_name','ct_id']
>>> ordering = ['prj_name','data_name']
>>> actions = [make_published, unpublish, copy_dt, republish]
>>> readonly_fields = ['published','schema_code','r_
>>> code','xqr_code','xqw_code',]
>>> def get_form(self, request, obj=None, **kwargs):
>>> try:
>>> if obj.published:
>>> self.readonly_fields = ['prj_name','published','lang'
>>> ,'schema_code','data_name','valid_trues','valid_falses','
>>> description','sem_attr','resource_uri','asserts','xqr_code','xqw_code',]
>>> except (AttributeError, TypeError) as e:
>>> self.readonly_fields = ['published','schema_code','r_
>>> code','xqr_code','xqw_code',]
>>> return super(DvBooleanAdmin, self).get_form(request, obj,
>>> **kwargs)
>>>
>>> fieldsets = (
>>> (None, {'classes':('wide',),
>>>'fields':('published','prj_
>>> name','data_name','lang','valid_trues','valid_falses')}),
>>> ("Additional Information ", {'classes':('wide',),
>>>'fields':('description','sem_
>>> attr','resource_uri','asserts',)}),
>>> ("PCT Code (read-only)", {'classes':('collapse',),
>>>'fields':('schema_code','r_
>>> code','xqr_code','xqw_code',)}),
>>>
>>> )
>>> list_display = ('data_name','prj_name','published',)
>>> admin.site.register(DvBoolean, DvBooleanAdmin)
>>>
>>> ​In the model for the displayed admin:
>>> ​prj_name

Re: Django Admin UI Bug - 1.7.3

2015-01-18 Thread Collin Anderson
Hi,

Rename your __unicode__ to __str__. Python 3 doesn't know what 
"__unicode__" is. :)

You say this works fine:
>>> from ccdgen.models import DvBoolean,DvAny, Common, Project
>>> pcts = DvBoolean.objects.all()
>>> for p in pcts:
...   print(p.prj_name.prj_name)

But django is expecting this also to work:
>>> pcts = DvBoolean.objects.all()
>>> for p in pcts:
...   print(p.prj_name)

Collin

On Sunday, 18 January 2015 12:31:06 UTC-5, Timothy W. Cook wrote:
>
>
> On Sat, Jan 17, 2015 at 11:49 AM, Collin Anderson  > wrote:
>
>> Hi,
>>
>> Did you also switch to Python 3?
>>
>
> ​Yes. 
>
> Well, I didn't switch. I have been using Python 3 for quite some time.  
> Even before it was officially supported. 
> ​
>  
>
>> It doesn't seem to be using your __unicode__ method at all.
>> If you query one of these Projects in manage.py shell, do they show the 
>> project name?
>>
>
> ​As I said before, my views that use AJAX to return data from queries 
> still work just as before.  But yes, in the manage.py shell I can import 
> the models and print the names.
>
> >>> from ccdgen.models import DvBoolean,DvAny, Common, Project
> >>> pcts = DvBoolean.objects.all()
> >>> for p in pcts:
> ...   print(p.prj_name.prj_name)
>  
> caBIG
> caBIG
> caBIG
> caBIG
> caBIG
> caBIG
> caBIG
>
> ... 
>
>
>
>  
>
>> Are you sure that the __unicode__ method is actually attached to your 
>> model?
>>
>>
> I am not exactly sure what you mean by that question; attached?​Here 
> is the code: ​
>
> class Project(models.Model):
> """
> Every item created in CCDGEN must be assigned to a Project when 
> created. All items (except CCD) may be
> reused in multiple CCDs. However, this does not change the original 
> Project.
> The Allowed Groups field contains each of the User Groups allowed to 
> see each item with this Project name.
> The User Group, Open, is assigned to every user. So if you assign the 
> Open group as one of the allowed groups,
> all CCDGEN users will see this item.
> """
> pgroup = models.ForeignKey(Group, verbose_name='Primary Group', 
> related_name='primarygroup', null=True)
> prj_name = models.CharField(_("project name"), max_length=110, 
> unique=True, db_index=True, help_text=_('Enter the name of your project.'))
> description = models.TextField(_("project description"), blank=True, 
> help_text=_('Enter a description or explaination of an acronym of the 
> project.'))
> rm_version = models.ForeignKey(RMversion, verbose_name=_('rm 
> version'), related_name='%(class)s_related', help_text=_('Choose the 
> version of the MLHIM Reference Model you are using.'))
> allowed_groups = models.ManyToManyField(Group, verbose_name=_('allowed 
> groups'), related_name='%(class)s_related', help_text=_('Choose the groups 
> that are allowed to work in this project.'))
>
> def __unicode__(self):
> return self.prj_name
>
>
> class Meta:
> verbose_name = _("Project")
> verbose_name_plural = _("Projects")
> ordering = ['prj_name']
>
>
>  
>
>> Also, FYI, to_field="prj_name" means you can't easily change the name of 
>> the project.
>>
>>
> ​Yes, Once created the name cannot be changed, and once an item is 
> assigned to a project the attached items are immutable. 
>
> Thanks,
> Tim
>
>
>  
>
>> Collin
>>
>> On Friday, January 16, 2015 at 3:14:55 PM UTC-5, Timothy W. Cook wrote:
>>>
>>> I should also mention that I have some AJAX calls for the same 
>>> information and they still work fine.  So I am quite certain it is in the 
>>> Admin templates or the Admin properties definitions. 
>>>
>>> On Fri, Jan 16, 2015 at 5:56 PM, Timothy W. Cook  wrote:
>>>
 Is this a bug or did I miss something in the release notes?  

 ​Moving from 1.6.4 to 1.7.3  the listing in the Admin UI is not 
 resolving a related field now.  There are not any model changes involved. 

 Attached are two screen shots named for the versions.

 I haven't changed the admin code either.  For the screen shots the 
 admin code is:

 ​class DvBooleanAdmin(admin.ModelAdmin):
 list_filter = ['prj_name__rm_version__version_id','prj_name',]
 search_fields = ['data_name','ct_id']
 ordering = ['prj_name','data_name']
 actions = [make_published, unpublish, copy_dt, republish]
 readonly_fields = ['published','schema_code','r_
 code','xqr_code','xqw_code',]
 def get_form(self, request, obj=None, **kwargs):
 try:
 if obj.published:
 self.readonly_fields = ['prj_name','published','lang'
 ,'schema_code','data_name','valid_trues','valid_falses','
 description','sem_attr','resource_uri','asserts','xqr_
 code','xqw_code',]
 except (AttributeError, TypeError) as e:
 self.readonly_fields = ['published','schema_code','r_
 code','xqr_code','xqw_code',]
 return super(DvBooleanAdmin, self).get_form(request,

Internal server error

2015-01-18 Thread Nicky Setia
Hi,
I am following the Django tutorial and after I put my site up using Dreamworks 
hosting, it is giving me internal server error. Has anyone encountered this 
before? Any help would be appreciated!

Thanks,
Nicky

-- 
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/D34A328B-1A3A-41F1-894B-7E79FC3ED817%40gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django Admin UI Bug - 1.7.3

2015-01-18 Thread Timothy W. Cook
On Sun, Jan 18, 2015 at 5:35 PM, Collin Anderson 
wrote:

> Hi,
>
> Rename your __unicode__ to __str__. Python 3 doesn't know what
> "__unicode__" is. :)
>
>
​Yep, that did it.​  Interesting that it was working up until now and that
my AJAX calls worked either way.  



> You say this works fine:
> >>>
> ​​
> from ccdgen.models import DvBoolean,DvAny, Common, Project
> >>> pcts = DvBoolean.objects.all()
> >>> for p in pcts:
> ...   print(p.prj_name.prj_name)
>
> But django is expecting this also to work:
> >>> pcts = DvBoolean.objects.all()
> >>> for p in pcts:
> ...   print(p.prj_name)
>

​It does now.  It did not before the change above.​


​Thanks,
Tim







Timothy Cook
LinkedIn Profile:http://www.linkedin.com/in/timothywaynecook
MLHIM http://www.mlhim.org

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


Re: Internal server error

2015-01-18 Thread Edgar Gabaldi
Nicky, Internal server error means that your application has a programming
error. You can see your webserver log to find the error to fix.

On Sun, Jan 18, 2015 at 5:43 PM, Nicky Setia  wrote:

> Hi,
> I am following the Django tutorial and after I put my site up using
> Dreamworks hosting, it is giving me internal server error. Has anyone
> encountered this before? Any help would be appreciated!
>
> Thanks,
> Nicky
>
> --
> 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/D34A328B-1A3A-41F1-894B-7E79FC3ED817%40gmail.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/CAGjPPH%3DCBGLL_3w55FfeGFjkyCPr4L4%2BwjMJrMttNzJ8aJxB-A%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Queryset .count() breaks when counting distinct values generated by .extra()

2015-01-18 Thread Mattias Linnap
Hi all,

I think I've found a strange case where QuerySet.count() does not match 
len(queryset), and the behaviour is certainly unexpected.
But I'm not sure whether this is a bug, some mistake on my part, or a known 
limitation of combining .extra(), .distinct() and .count().
I am aware of the default ordering interfering with .distinct(), and 
already add .order_by() to get rid of it.

I have a model called RadioSignal, with an integer field "rssi". I'm 
interested in finding out how many distinct values for "rssi / 10" there 
are (-10, -20, -30, etc).

Here is a commented "./manage.py shell" record:

>>> RadioSignal.objects.count()
523 
>>> RadioSignal.objects.order_by().values('rssi').distinct().count() 
49
>>> connection.queries[-1]['sql']
'SELECT COUNT(DISTINCT "maps_radiosignal"."rssi") FROM "maps_radiosignal"'

Looks okay so far. But I'm interested in each distinct tens of RSSI values, 
not every single value. I can compute these with .extra():

>>> len(RadioSignal.objects.order_by().extra({'tens': 'rssi / 
10'}).values('tens').distinct())
6
>>> RadioSignal.objects.order_by().extra({'tens': 'rssi / 
10'}).values('tens').distinct()
[{'tens': -8}, {'tens': -4}, {'tens': -5}, {'tens': -9}, {'tens': -6}, 
{'tens': -7}]
>>> connection.queries[-1]['sql']
'SELECT DISTINCT (rssi / 10) AS "tens" FROM "maps_radiosignal" LIMIT 21'

Also looks good so far. But running len() on a queryset is unnecessary if I 
only need the count.

>>> RadioSignal.objects.order_by().extra({'tens': 'rssi / 
10'}).values('tens').distinct().count()
523
>>> connection.queries[-1]['sql']
'SELECT COUNT(DISTINCT "maps_radiosignal"."id") FROM "maps_radiosignal"'

Uhoh. Somehow .count() keeps the .distinct() part, but replaces the 
.extra() and .values() parts with counting primary keys?

I tried it with values('tens'), values_list('tens'), and 
values_list('tens', flat=True), as well no change.
So far I've tested Django 1.6 with Python 2.7 and PostgreSQL 9.3, and 
Django 1.7 with Python 3.4 and PostgreSQL 9.1, all seem to behave the same.

I can work around this, since the possible resulting querysets are pretty 
small, and evaluating them with len() isn't too slow. But I'm wondering if 
it's a bug in Django, or something else I've missed?

Mattias


-- 
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/21085de5-a899-437c-b13a-8584104df65f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Windows path for django_crontab

2015-01-18 Thread sarfaraz ahmed
Hello All,

I am trying to use django_crontab to run repetitive task. I want to insert 
records to database on a particular time. Also, I am in process of learning 
django hence I m trying to reach every aspect of django. 

The issue i am facing i m able to configure django_crontab but its not able 
to find cron.py. I am using windows 7 and i believe it must be something 
else for windows

CRONJOBS = [
('*/5 * * * *', 'dms.Drop_Slot_Management.cron.my_scheduled_job')
]

dms is my project directory.

When I run the command manage.py crontab add it gives error saying "The 
system cannot find the path specified."

I am using Windows. 

Please help..

Regards,
Sarfaraz Ahmed

-- 
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/9ad0f430-458f-4113-b6be-2d61ab3ec447%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Windows path for django_crontab

2015-01-18 Thread Mike Dewhirst

On 19/01/2015 8:54 AM, sarfaraz ahmed wrote:

Hello All,

I am trying to use django_crontab to run repetitive task. I want to
insert records to database on a particular time. Also, I am in process
of learning django hence I m trying to reach every aspect of django.

The issue i am facing i m able to configure django_crontab but its not
able to find cron.py. I am using windows 7 and i believe it must be
something else for windows


There is no cron/crontab on Windows. You need a Linux operating system 
for crontab and for testing django-crontab.


You could install a Linux machine on Windows using Virtualbox or use 
some other VM hosting solution. Or repurpose an old piece of hardware 
you might have floating about.


If you want to go into production on Windows you will have to manually 
schedule the jobs you want. There may be utilities out there which will 
let you interface with the Windows scheduling system.




CRONJOBS = [
 ('*/5 * * * *', 'dms.Drop_Slot_Management.cron.my_scheduled_job')
]

dms is my project directory.

When I run the command manage.py crontab add it gives error saying "The
system cannot find the path specified."

I am using Windows.

Please help..

Regards,
Sarfaraz Ahmed

--
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/9ad0f430-458f-4113-b6be-2d61ab3ec447%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/54BC40B5.7070704%40dewhirst.com.au.
For more options, visit https://groups.google.com/d/optout.


Re: How to add my Templates folder to TEMPLATE_DIRS

2015-01-18 Thread Mike Dewhirst

On 18/01/2015 5:01 PM, Kishan Mehta wrote:

Hello all,

 > I want to customise how admin page looks

 > I have my template folder in my application folder
at C:\Users\kishan\Django_App\polls\templates\admin

 > In settings.py I have added TEMPLATE_DIRS =
[os.path.join(BASE_DIR,'C:\Users\kishan\Django_App\polls\templates')] .


You template dirs will fail if your BASE_DIR has any path value at all. 
The following is what you really want ...


# if templates are not found here look in app_name/templates
TEMPLATE_DIRS = (
os.path.join(BASE_DIR, 'templates/').replace('\\','/'),
)

... Then in BASE_DIR/templates make a dir /admin and copy the 
../site-packages/django/contrib/admin/templates/admin/.html 
template you want to change into your project.


It should end up in BASE_DIR/templates/admin/.html

As indicated in the comment line above, if Django doesn't find the 
template it is looking for in your project's ../admin dir it will look 
in its own template dir.




 > Changes I have made to base_site.html is not reflecting in admin page.

Please 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/7fad9e76-3bcf-49b3-b45d-cfdec09e8a65%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/54BC43EC.8080603%40dewhirst.com.au.
For more options, visit https://groups.google.com/d/optout.


Re: Windows path for django_crontab

2015-01-18 Thread Edgar Gabaldi
To do periodic tasks you can use celery[1]. I believe that on windows works
fine.

[1] http://celery.readthedocs.org/en/latest/userguide/periodic-tasks.html

On Sun, Jan 18, 2015 at 9:24 PM, Mike Dewhirst 
wrote:

> On 19/01/2015 8:54 AM, sarfaraz ahmed wrote:
>
>> Hello All,
>>
>> I am trying to use django_crontab to run repetitive task. I want to
>> insert records to database on a particular time. Also, I am in process
>> of learning django hence I m trying to reach every aspect of django.
>>
>> The issue i am facing i m able to configure django_crontab but its not
>> able to find cron.py. I am using windows 7 and i believe it must be
>> something else for windows
>>
>
> There is no cron/crontab on Windows. You need a Linux operating system for
> crontab and for testing django-crontab.
>
> You could install a Linux machine on Windows using Virtualbox or use some
> other VM hosting solution. Or repurpose an old piece of hardware you might
> have floating about.
>
> If you want to go into production on Windows you will have to manually
> schedule the jobs you want. There may be utilities out there which will let
> you interface with the Windows scheduling system.
>
>
>> CRONJOBS = [
>>  ('*/5 * * * *', 'dms.Drop_Slot_Management.cron.my_scheduled_job')
>> ]
>>
>> dms is my project directory.
>>
>> When I run the command manage.py crontab add it gives error saying "The
>> system cannot find the path specified."
>>
>> I am using Windows.
>>
>> Please help..
>>
>> Regards,
>> Sarfaraz Ahmed
>>
>> --
>> 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/9ad0f430-
>> 458f-4113-b6be-2d61ab3ec447%40googlegroups.com
>> > 458f-4113-b6be-2d61ab3ec447%40googlegroups.com?utm_medium=
>> email&utm_source=footer>.
>> For more options, visit https://groups.google.com/d/optout.
>>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/django-users/54BC40B5.7070704%40dewhirst.com.au.
>
> For more options, visit https://groups.google.com/d/optout.
>

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


Re: Canvas OAuth2 From Django View

2015-01-18 Thread Henry Versemann
Collin, thanks for the help. My django application as it is already has the 
"requests" library installed within it and I have already registered it 
with the API which I'm trying to authenticate to currently using that API's 
oauth2 web application flow, which is a three step process (see the oauth2 
tab for the  Canvas API). I'm able so far to send a redirect-uri to the 
Canvas Oauth2 api and have it respond back to me with all of the other 
information I need to get my final access token from then. My application 
currently uses Python 2.7.8 and Django 1.7 and the piece of the process 
that I'm having the problem with is sending the final POST request back to 
the Canvas Oauth2 flow API. The response that up to now I've tried to 
return back from my django view  has been an HttpResponse which apparently 
does not allow the sending of a POST request. I've also taken a look at all 
of the shortcut functions that django offers as options to return back from 
django views, and none of them appear at least not obviously to offer any 
options for sending POST requests. Your response below seems to show how I 
might get the access token back from the final POST request which I need to 
make to the Canvas Oauth2 flow. Can you show me how to do that POST, 
and what I need my view to return, to avoid getting and error which says 
that my view did  not return a valid HttpResponse but instead returned 
"None" like I've gotten up until now?
Thanks again for the help.

Henry 

On Saturday, January 17, 2015 at 7:33:40 AM UTC-6, Collin Anderson wrote:

> Hi,
>
> Use urllib/urllib2 or requests to POST to other websites. Python can do it 
> natively.
>
> try:  # Python 3
> from urllib import request as urllib_request
> except ImportError:  # Python 2
> import urllib2 as urllib_request
> from django.utils.http import urlencode
>
> def my_view(request):
> response = urllib_request.urlopen('https://endpoint/', urlencode({
> 'mytoken': '12345'}))
> data = response.read()
> # etc
>
> https://docs.python.org/3/library/urllib.request.html
> https://docs.python.org/2/library/urllib2.html
>
> or install requests, which is friendlier:
> http://docs.python-requests.org/en/latest/
>
> Collin
>
> On Thursday, January 15, 2015 at 11:51:45 AM UTC-5, Henry Versemann wrote:
>>
>> First let me say that I haven't done a lot of stuff with either Python or 
>> Django, but I think I understand most of the basics. 
>> I am trying to get an access token back from the OAuth2 Web Application 
>> Flow of the Canvas' LMS API ( 
>> https://canvas.instructure.com/doc/api/file.oauth.html ). 
>> I have successfully sent the request in step 1 of the flow, and 
>> received back and extracted out of the response all of the data needed for 
>> step 3, which came back in step 2 of the flow.
>> So now in step 3 of the flow my problem is how to send a POST of the 
>> request needed, as described in step 3 of the flow, from a Django View.
>> I've not found anything definitive saying that I absolutely can't do 
>> a POST of a request, from a Django View, and have seen some  items which 
>> seem to indicate that I can do a POST from a view, but none of them seem to 
>> have detailed code examples or explanations of how to do it if it is 
>> possible. 
>> So far I've tried several ways of sending the POST within a 
>> returned HttpResponse and have not been successful, and if I understand 
>> things correctly HttpResponse doesn't allow it. 
>> I have also looked at all of the other Django Shortcut Functions 
>> documentation, and none of them seem to offer any obvious way of POSTing a 
>> request either. 
>> Can someone please point me to a good example of how to do it if it is 
>> possible, and if it is not maybe point me to one or more examples of how I 
>> might be able to successfully go through the Canvas OAuth2 Web Application 
>> Flow using some other module or package, that I can integrate into my 
>> Django application?
>> Thanks for the 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/11c413b5-75e3-4326-aa02-f4ea9d766109%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Canvas OAuth2 From Django View

2015-01-18 Thread Henry Versemann
Sergiy, Yes it is. Thanks. Henry

On Saturday, January 17, 2015 at 10:36:06 AM UTC-6, Sergiy Khohlov wrote:
>
> Is CRFS protection enabled ?
> 15 січ. 2015 18:51, користувач "Henry Versemann"  > написав:
>
>> First let me say that I haven't done a lot of stuff with either Python or 
>> Django, but I think I understand most of the basics. 
>> I am trying to get an access token back from the OAuth2 Web Application 
>> Flow of the Canvas' LMS API ( 
>> https://canvas.instructure.com/doc/api/file.oauth.html ). 
>> I have successfully sent the request in step 1 of the flow, and 
>> received back and extracted out of the response all of the data needed for 
>> step 3, which came back in step 2 of the flow.
>> So now in step 3 of the flow my problem is how to send a POST of the 
>> request needed, as described in step 3 of the flow, from a Django View.
>> I've not found anything definitive saying that I absolutely can't do 
>> a POST of a request, from a Django View, and have seen some  items which 
>> seem to indicate that I can do a POST from a view, but none of them seem to 
>> have detailed code examples or explanations of how to do it if it is 
>> possible. 
>> So far I've tried several ways of sending the POST within a 
>> returned HttpResponse and have not been successful, and if I understand 
>> things correctly HttpResponse doesn't allow it. 
>> I have also looked at all of the other Django Shortcut Functions 
>> documentation, and none of them seem to offer any obvious way of POSTing a 
>> request either. 
>> Can someone please point me to a good example of how to do it if it is 
>> possible, and if it is not maybe point me to one or more examples of how I 
>> might be able to successfully go through the Canvas OAuth2 Web Application 
>> Flow using some other module or package, that I can integrate into my 
>> Django application?
>> Thanks for the 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...@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/298a8f9d-3694-45f8-88c4-d9049a1e68d2%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/93e8bb8b-ecb7-4bfa-907a-eea4517b8edc%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Instructions from Django to run under Python don't work.

2015-01-18 Thread Russell Keith-Magee
On Sun, Jan 18, 2015 at 10:23 AM, Lisa Jennings 
wrote:

> I have been trying for two days to install django with Python 3.4
> operating in windows 7.  Everything I try according to your instructions,
> fails. The command "import django" seems to work but the command "print
> (django.get_version()) does not. I am trting to get this to work so I can
> install ESMPY a version of ESMF. Any help will be appreciated.
> Megan
>

Hi Megan,

It would be helpful to know what "doesn't work" means. Do you get an error
message? If so, what is it? If not, do you get *absolutely nothing*, or do
you get something, but just not what you expect to get? Does the command
return you to the command prompt?

Without more details about what you're seeing, it's almost impossible to
guess the source of the problem you're having.

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


Re: Question for Django Core Team?

2015-01-18 Thread Russell Keith-Magee
On Sun, Jan 18, 2015 at 8:28 PM, Petar Pilipovic  wrote:

> Hello there this is maybea of topic but I wont to ask Django Core Team,
> did they now someone who is practising Django in Belgrade-Serbia, or
> Zagreb-Croatia, I now there is a strong Slovenia team there, but I was
> wondering about this area around Bosnia where I live in.
> I am asking because I was inspired by this post here
> http://blog.djangogirls.org/post/108268319658/django-girls-core-team-grows,
> and mine chat whit Daniel Roy Greenfel @pydanny
>  over Twitter
> https://twitter.com/Coopsess/status/556665409693163520.
> So do you now eny one?
>

Hi Petar,

This isn't really a question for the Django core team, because Django Girls
isn't an official part of the Django project. We're excited to see the
great work that they're doing, and members of the core team help out with
Django Girls events whenever we get a chance - but they're an independent
organisation.

There was an event in Ljubljana on 18 October, but the website doesn't list
any upcoming events in Serbia or Croatia.

http://djangogirls.org/events

If you'd like to organize an event, they're always looking for volunteers -
register your interest here:

http://djangogirls.org/organize/

and I'm sure they'll be in contact soon.

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/CAJxq84-SF6QrVZf-q5EdnLf1%2BWbc0JeqthVW%3DMZ%3DBRtp86%3DwQw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Instructions from Django to run under Python don't work.

2015-01-18 Thread Lisa Jennings
I keep getting syntax errors.

On Saturday, January 17, 2015 at 9:23:25 PM UTC-5, Lisa Jennings wrote:
>
> I have been trying for two days to install django with Python 3.4 
> operating in windows 7.  Everything I try according to your instructions, 
> fails. The command "import django" seems to work but the command "print 
> (django.get_version()) does not. I am trting to get this to work so I can 
> install ESMPY a version of ESMF. Any help will be appreciated.
> Megan
>

-- 
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/2561b393-6273-4ff4-a11f-66b2c618576a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Instructions from Django to run under Python don't work.

2015-01-18 Thread Some Developer

On 19/01/15 00:41, Lisa Jennings wrote:

I keep getting syntax errors.



What syntax errors? Be specific.

--
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/54BC6DF3.7070403%40googlemail.com.
For more options, visit https://groups.google.com/d/optout.


Unicode character in Django project path

2015-01-18 Thread Cheng Guo
Hello everyone,

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

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

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

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

Thanks!

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


Re: Unicode character in Django project path

2015-01-18 Thread James Schneider
After a quick search, this bug looks similar, but it's for an ancient
version of Django. Might still give you some hints as to where to look.

https://code.djangoproject.com/ticket/8965

If you can replicate the bug with an empty project and your template paths
set, I would recommend filing a bug, although there may be some
system/Django setting somewhere that can force the correct
encoding/decoding that in not aware of.

Search through https://code.djangoproject.com/search and see if another
ticket already exists.

-James
On Jan 18, 2015 7:05 PM, "Cheng Guo"  wrote:

> Hello everyone,
>
> I am new to this community. I have run into an issue related to Unicode
> character in project path:
>
>
> http://stackoverflow.com/questions/27996774/unicode-character-in-django-project-path
>
> Another user on StackOverflow provided a detailed analysis of what is
> causing the bug in the link above.
>
> I want to file a bug report but not sure if the same bug has been
> reported, so I hope someone could let me know if I should file it.
>
> Thanks!
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/1fc195b7-0596-4bd8-88cd-8c347ba6de88%40googlegroups.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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%2Be%2BciUFWFHAtaU0mJtA9moXTGkpz857PAv%3DR_-VtEarTpK7Ww%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Windows path for django_crontab

2015-01-18 Thread sarfaraz ahmed
Thanks for replies I really wish people who posted packages should mention 
clearly about which OS it;s going to work. I ended up wasting two workdays 
in experimenting with kronos,DJANGO-CHRONOGRAPH 
,
DJANGO-CRONJOBS 
,DJANGO-CRON .

Surprisingly, DJANGO cron says that it is meant for Windows hosting where 
user does not have access to setup the cron jobs. I tried that to... 
nothing runs 

Regards,
Sarfaraz Ahmed



-- 
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/659ebe89-cb9b-4230-876a-4865a454648f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Instructions from Django to run under Python don't work.

2015-01-18 Thread Vinayak Kaniyarakkal


On Sunday, 18 January 2015 07:53:25 UTC+5:30, Lisa Jennings wrote:
>
> I have been trying for two days to install django with Python 3.4 
> operating in windows 7.  Everything I try according to your instructions, 
> fails. 
>
 

> The command "import django" seems to work
>
That means django is installed properly.
 

> but the command "print (django.get_version()) does not.
>
If you get syntax error for print (django.get_version()), you may be using 
python 2.
Are you sure that you are using python3??

I am trting to get this to work so I can install ESMPY a version of ESMF. 
> Any help will be appreciated.
>
Can you copy paste whatever is there on your python shell?  It would be 
easier for everyone to find the answer.  Mine is a guess.
 

> Megan
>

-- 
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/c64dacfe-2f13-4e1e-afd4-42a093b80187%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Unicode character in Django project path

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

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

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


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

2015-01-18 Thread Cheng Guo
Hello,

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

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

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

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

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

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

Let me know your approach, thanks!

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


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

2015-01-18 Thread Mike Dewhirst

On 19/01/2015 6:28 PM, Cheng Guo wrote:

Hello,

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

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

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

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

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

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


Absolutely correct. But first create a views directory (complete with 
__init__.py file therein) to completely replace your views.py file.


Then any number of files can contain your views ...

from app.views.this import That

... where this.py has a class That




Let me know your approach, thanks!

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


--
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/54BCB642.8040201%40dewhirst.com.au.
For more options, visit https://groups.google.com/d/optout.