Apache environment variables in Django 1.6

2013-11-20 Thread Jon Dufresne
Hi,

I recently upgraded my Django application from 1.5 to 1.6. This
application runs on Apache with mod_wsgi. After upgrading, Django
seems unable to access environment variables set by Apache using
SetEnv and SetEnvIf. Using Django 1.5 I was able to access this using
the following recipe in wsgi.py:

---
import os

from django.core.wsgi import get_wsgi_application
_application = get_wsgi_application()

def application(environ, start_response):
os.environ['MY_SETTING'] = environ['MY_SETTING']
return _application(environ, start_response)
---

Then, in settings.py, I would access MY_SETTING using os.environ['MY_SETTING'].

Is this a bug that this no longer works in Django 1.6? Is there a
better way to access Apache environment variables?

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/CADhq2b5vxuURi4Zq%2B77dL2EAiDzyrA3C9RHwhiTK6dssAkEqYQ%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.


Model Design: Adding Params to Relationship FIelds

2013-11-20 Thread Thomas Murphy
Hi all,

I'm working on a hour-reporting system.

Each Project has many Users, and each User has many Projects(These are
established and working nicely).

My design issue is this:
How can I assign each User an IntegerField "Hours" on each Project
they are assigned to? This Integer Field is personal to them, but must
be able to summed by the Project "Hours" count later(This last part is
trivial to design, just wanted to include)

Here's relevant code:

class Project(models.Model):
client = models.CharField(max_length=500)
name = models.CharField(max_length=500)
campaign_start_date = models.DateField()
hours = models.IntegerField(default=0)
members = models.ManyToManyField(User)
hours = models.IntegerField(default=0)

def __unicode__(self):
return self.name

class UserProfile(models.Model):

user = models.OneToOneField(User)

#Additional Attributes Defined Below
project = models.ManyToManyField(Project)
rate = models.IntegerField(default=0)

def __unicode__(self):
return self.user.username

def project_names(self):
return ', '.join([p.name for p in self.project.all()])

-- 
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/CALgvumX5_9C3pon3ok4ma1s3xRJTeX7RHRcGT%2BWjFVjjTAcUfQ%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: Using Aggregate and Count

2013-11-20 Thread Timothy W. Cook
Does the fact that I use a relat_name on the Review.paper field have
anything to do with it not working?

In the Review model, notice:
paper = models.ForeignKey(Paper, verbose_name=_('Paper'),
related_name="%(app_label)s_%(class)s_related+", null=False,
blank=False, help_text=_("Select a paper."))

In the annotation I tried:
papers =
Paper.objects.filter(project__id=self.kwargs['pk']).annotate(Count('papers_reviews_related+'))

with and without the '+'.   Still get a Field Error.

Thanks,
Tim




On Wed, Nov 20, 2013 at 7:43 PM, Timothy W. Cook  wrote:
> Thanks DAniel.
>
> The models:
>
> class Review(models.Model):
> """ A review of one paper."""
> INCLUDE_CHOICES = [(True,'Include'),(False,'Exclude')]
> paper = models.ForeignKey(Paper, verbose_name=_('Paper'),
> related_name="%(app_label)s_%(class)s_related+", null=False,
> blank=False, help_text=_("Select a paper."))
> title_include = models.NullBooleanField("Title",
> choices=INCLUDE_CHOICES,null=False, blank=False, help_text="Select
> Exclude to remove from the study after title review.")
> title_exclusion_choice = models.ForeignKey(Exclusion, null=False,
> blank=False, related_name="%(app_label)s_%(class)s_related+")
> title_exclusion_text = models.TextField(null=False, blank=False)
> abstract_include = models.NullBooleanField("Abstract",
> choices=INCLUDE_CHOICES, null=False, blank=False, help_text="Select
> Exclude to remove from the study after abstract review.")
> abstract_exclusion_choice = models.ForeignKey(Exclusion,
> null=False, blank=False,
> related_name="%(app_label)s_%(class)s_related+")
> abstract_exclusion_text = models.TextField(null=False, blank=False)
> full_text_include = models.NullBooleanField("Fulltext",
> choices=INCLUDE_CHOICES, null=False, blank=False, help_text="Select
> Exclude to remove from the study after full text review.")
> full_text_exclusion_choice = models.ForeignKey(Exclusion,
> null=False, blank=False,
> related_name="%(app_label)s_%(class)s_related+")
> full_text_exclusion_text = models.TextField(null=False, blank=False)
>
> def __str__(self):
> return 'Paper: '+self.paper.title
>
>
> class Paper(models.Model):
>
> STAGES = [('Pre-Selection','Pre-Selection'), ('Selection by
> Title','Selection by Title'),
>   ('Selection by Abstract','Selection by Abstract'),
> ('Selection by Full Text','Selection by Full Text')]
>
> INCLUDE_CHOICES = [(True,'Include'),(False,'Exclude')]
>
> title = models.CharField("Title", max_length=300, help_text="")
> language = models.CharField(_("language"), max_length=400,
> help_text=_('Enter the language of this paper.'))
> repo = models.ForeignKey(Repository,
> related_name="%(app_label)s_%(class)s_related",
> verbose_name=_('Repository'), null=False,
> blank=False,help_text=_("Source repository added when the paper was
> generated."))
> project = models.ForeignKey(Project,
> related_name="%(app_label)s_%(class)s_related", null=True, blank=True)
> current_stage = models.CharField("Current Stage",max_length=30,
> default="Pre-Selection", choices=STAGES, help_text="The current stage
> for this paper.")
> journal = models.ForeignKey(Journal,
> related_name="%(app_label)s_%(class)s_related",
> verbose_name=_('Journal Title'), null=False,
> blank=False,help_text=_("Select a Journal."))
> authors = models.TextField('Authors', help_text="The authors of
> this paper.", null=True, blank=True)
> keywords = models.TextField("Keywords", null=True, blank=True,
> help_text="" )
> doi = models.CharField("DOI", null=True, blank=True,
> max_length=70, help_text="Enter the paper DOI")
> url = models.CharField("URL", null=True, blank=True,
> max_length=255, help_text="Enter the paper URL")
> year_published = models.CharField("Year", db_index=True,
> max_length=400, help_text="" )
> volume = models.CharField("Journal Volume", null=True, blank=True,
> max_length=400, help_text="" )
> issue = models.CharField("Journal Issue", null=True, blank=True,
> max_length=400, help_text="" )
> initial_page = models.CharField("Initial Page/Page Range",
> max_length=200, default=0, help_text="" )
> final_page = models.CharField("Final page", max_length=200,
> null=True, blank=True, default=0, help_text="" )
> abstract = models.TextField("Abstract", null=True, blank=True,
> help_text="Copy/paste the abstract here if it was not provide during
> import.")
> ca_address = models.TextField("Corresponding Author Address", default='' )
> ca_email = models.EmailField("Corresponding Author Email",
> max_length=255, db_index=True, null=True, blank=True, help_text="")
> nonduplicate = models.NullBooleanField("Duplicate", null=True,
> blank=True, choices=INCLUDE_CHOICES, help_text="Select Exclude to
> remove due to duplication of papers.")
> daterange = models.NullBooleanField("Date Range", null=True,
> blank=True, choices=INCLUDE_CHOICES, help_text="Select Exclude t

Re: Using admin views "outside" of admin

2013-11-20 Thread Gonzalo Delgado
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA256

El 20/11/13 12:54, Brad Smith escribió:
> Based on other threads I've read here, it seems that the
> conventional wisdom is that the admin interface is only for
> low-level access to the database, and isn't designed for anything
> "fancy", like users with different levels of administrative rights
> within an app, etc. Ok, I get that, but if I may grasp at some
> straws briefly I'd like to ask one follow-up that I haven't seen
> answered elsewhere: my app has a bunch of objects with complicated
> relationships for which I've devised a reasonably pretty and
> intuitive editing interface using Django's admin and Grappelli. 
> Since this took a nontrivial amount of effort, I wanted to ask here
> if there are any tricks I should know about for re-using *any*
> views, inlines, etc from that admin interface in a more integrated
> editing interface with granular access controls, or do I just need
> to suck it up and rewrite everything from scratch using regular
> Django forms?

The django admin code is very extensible and re-usable. The
documentation may not stress this enough, but it is possible to do
virtually anything you want with it.

If I'm understanding your "outside" of the admin concept correctly,
what you want to do is extend the AdminSite[0] class (or maybe not
even that, just create a new instance) and attach the ModelAdmins you
want to it. I think you can even use autodiscover with a custom
AdminSite instance too if you need to have all models from
settings.INSTALLED_APPS attached to it.


[0]
https://docs.djangoproject.com/en/1.6/ref/contrib/admin/#adminsite-objects

- -- 
Gonzalo Delgado
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.15 (Darwin)
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/

iF4EAREIAAYFAlKNOH4ACgkQzbfdFL5JoUlCVQD6A1TUqYfKbgBDITrpvFblkQfo
nrVMCxnxSPIiREHgJaMBAKTR2auknxE6sX5s62B0j8eiH+AJB1EG1+AxeXoVHlGX
=kthG
-END PGP SIGNATURE-

-- 
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/528D387E.1080804%40gonzalodelgado.com.ar.
For more options, visit https://groups.google.com/groups/opt_out.


Re: Using Aggregate and Count

2013-11-20 Thread Timothy W. Cook
Thanks DAniel.

The models:

class Review(models.Model):
""" A review of one paper."""
INCLUDE_CHOICES = [(True,'Include'),(False,'Exclude')]
paper = models.ForeignKey(Paper, verbose_name=_('Paper'),
related_name="%(app_label)s_%(class)s_related+", null=False,
blank=False, help_text=_("Select a paper."))
title_include = models.NullBooleanField("Title",
choices=INCLUDE_CHOICES,null=False, blank=False, help_text="Select
Exclude to remove from the study after title review.")
title_exclusion_choice = models.ForeignKey(Exclusion, null=False,
blank=False, related_name="%(app_label)s_%(class)s_related+")
title_exclusion_text = models.TextField(null=False, blank=False)
abstract_include = models.NullBooleanField("Abstract",
choices=INCLUDE_CHOICES, null=False, blank=False, help_text="Select
Exclude to remove from the study after abstract review.")
abstract_exclusion_choice = models.ForeignKey(Exclusion,
null=False, blank=False,
related_name="%(app_label)s_%(class)s_related+")
abstract_exclusion_text = models.TextField(null=False, blank=False)
full_text_include = models.NullBooleanField("Fulltext",
choices=INCLUDE_CHOICES, null=False, blank=False, help_text="Select
Exclude to remove from the study after full text review.")
full_text_exclusion_choice = models.ForeignKey(Exclusion,
null=False, blank=False,
related_name="%(app_label)s_%(class)s_related+")
full_text_exclusion_text = models.TextField(null=False, blank=False)

def __str__(self):
return 'Paper: '+self.paper.title


class Paper(models.Model):

STAGES = [('Pre-Selection','Pre-Selection'), ('Selection by
Title','Selection by Title'),
  ('Selection by Abstract','Selection by Abstract'),
('Selection by Full Text','Selection by Full Text')]

INCLUDE_CHOICES = [(True,'Include'),(False,'Exclude')]

title = models.CharField("Title", max_length=300, help_text="")
language = models.CharField(_("language"), max_length=400,
help_text=_('Enter the language of this paper.'))
repo = models.ForeignKey(Repository,
related_name="%(app_label)s_%(class)s_related",
verbose_name=_('Repository'), null=False,
blank=False,help_text=_("Source repository added when the paper was
generated."))
project = models.ForeignKey(Project,
related_name="%(app_label)s_%(class)s_related", null=True, blank=True)
current_stage = models.CharField("Current Stage",max_length=30,
default="Pre-Selection", choices=STAGES, help_text="The current stage
for this paper.")
journal = models.ForeignKey(Journal,
related_name="%(app_label)s_%(class)s_related",
verbose_name=_('Journal Title'), null=False,
blank=False,help_text=_("Select a Journal."))
authors = models.TextField('Authors', help_text="The authors of
this paper.", null=True, blank=True)
keywords = models.TextField("Keywords", null=True, blank=True,
help_text="" )
doi = models.CharField("DOI", null=True, blank=True,
max_length=70, help_text="Enter the paper DOI")
url = models.CharField("URL", null=True, blank=True,
max_length=255, help_text="Enter the paper URL")
year_published = models.CharField("Year", db_index=True,
max_length=400, help_text="" )
volume = models.CharField("Journal Volume", null=True, blank=True,
max_length=400, help_text="" )
issue = models.CharField("Journal Issue", null=True, blank=True,
max_length=400, help_text="" )
initial_page = models.CharField("Initial Page/Page Range",
max_length=200, default=0, help_text="" )
final_page = models.CharField("Final page", max_length=200,
null=True, blank=True, default=0, help_text="" )
abstract = models.TextField("Abstract", null=True, blank=True,
help_text="Copy/paste the abstract here if it was not provide during
import.")
ca_address = models.TextField("Corresponding Author Address", default='' )
ca_email = models.EmailField("Corresponding Author Email",
max_length=255, db_index=True, null=True, blank=True, help_text="")
nonduplicate = models.NullBooleanField("Duplicate", null=True,
blank=True, choices=INCLUDE_CHOICES, help_text="Select Exclude to
remove due to duplication of papers.")
daterange = models.NullBooleanField("Date Range", null=True,
blank=True, choices=INCLUDE_CHOICES, help_text="Select Exclude to
remove due to the date of publication.")
lang_ok = models.NullBooleanField("Language ", null=True,
blank=True, choices=INCLUDE_CHOICES, help_text="Select Exclude to
remove due to the language.")
comments = models.TextField("Comments", null=True, blank=True,
help_text="Enter your comments.")

objects = PaperManager()

def __str__(self):
return self.title


The Paper Manager (used to produce the PApers from imported text files).

class PaperManager(models.Manager):
def create_paper(self, ptitle,rid,jid,jyear,jvol,jissue,lang,pid):
p = self.create(title=ptitle, repo_id=rid, journal_id=jid,
year_published=jyear,
volume=jvol, issue=jissue,language=lang,project_id=pid)
 

Re: Using Aggregate and Count

2013-11-20 Thread Daniel Roseman
On Wednesday, 20 November 2013 20:04:13 UTC, Timothy W. Cook wrote:
>
> Hi Daniel, 
>
> On Wed, Nov 20, 2013 at 5:47 PM, Daniel Roseman 
> > 
> wrote: 
> > On Wednesday, 20 November 2013 19:11:26 UTC, Timothy W. Cook wrote: 
>
> > 
> > You're accessing a `review_count` attribute via each Paper instance, but 
> you 
> > haven't set up anything that would do that - you only have a single 
> > top-level `review_count` dictionary. 
> > 
> > Instead of a separate `aggregate` call, you should be using `annotate` 
> on 
> > the original Paper queryset: 
> > 
> > papers = 
> > 
> Paper.objects.filter(project__id=self.kwargs['pk']).annotate(review_count=Count('review'))
>  
>
> > 
> > Now each element in `papers` has a `review_count` attribute. 
>
> I had actually tried this.  However, this is a reverse relationship 
> The foreignkey is on Review to Paper.  So if I use your suggestion or 
> even: 
> papers = 
> Paper.objects.filter(project__id=self.kwargs['pk']).annotate(review_count=Count('review__paper'))
>  
>
>
> Which I first thought was correct.  I get a FieldError: 
> FieldError at /papers/papers_list/1 
> Cannot resolve keyword 'review' into field. Choices are: abstract, 
> authors, ... 
>
> I thought that the docs at: 
>
> https://docs.djangoproject.com/en/1.6/topics/db/aggregation/#following-relationships-backwards
>  
>
> say this would work but apparently Django can't find the Review->Paper 
> relationship. 
>
> I'm stumped. 
>
> --Tim 
>

Well, it should definitely work. Can you perhaps post your Review and Paper 
models?
--
DR. 

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


Re: Using Aggregate and Count

2013-11-20 Thread Timothy W. Cook
Hi Daniel,

On Wed, Nov 20, 2013 at 5:47 PM, Daniel Roseman  wrote:
> On Wednesday, 20 November 2013 19:11:26 UTC, Timothy W. Cook wrote:

>
> You're accessing a `review_count` attribute via each Paper instance, but you
> haven't set up anything that would do that - you only have a single
> top-level `review_count` dictionary.
>
> Instead of a separate `aggregate` call, you should be using `annotate` on
> the original Paper queryset:
>
> papers =
> Paper.objects.filter(project__id=self.kwargs['pk']).annotate(review_count=Count('review'))
>
> Now each element in `papers` has a `review_count` attribute.

I had actually tried this.  However, this is a reverse relationship
The foreignkey is on Review to Paper.  So if I use your suggestion or
even:
papers = 
Paper.objects.filter(project__id=self.kwargs['pk']).annotate(review_count=Count('review__paper'))

Which I first thought was correct.  I get a FieldError:
FieldError at /papers/papers_list/1
Cannot resolve keyword 'review' into field. Choices are: abstract, authors, ...

I thought that the docs at:
https://docs.djangoproject.com/en/1.6/topics/db/aggregation/#following-relationships-backwards

say this would work but apparently Django can't find the Review->Paper
relationship.

I'm stumped.

--Tim

-- 
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%3DOU3WgyTOLKtPC1Rds3Sxmrwbs%3D3kDeV7t8UXJ0DY9XtWgJA%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: Admin custom template

2013-11-20 Thread Luca Corti

On 19/nov/2013, at 11:29, Mrinmoy Das  wrote:
> I have made a functionality where a user can input address through google map 
> on a site. Now the thing is, how can I enable the same stuff on django admin 
> panel? I am using django-grappelli. Any help guys? 
> 
> I have tried this
> http://stackoverflow.com/questions/20023521/django-admin-insert-custom-html-code-for-specific-model-admin
> 
> its not working. Any help? really stuck at this.

https://github.com/philippbosch/django-geoposition/ does exactely what you are 
doing, and works with the admin. You can take a look at its code.

ciao

Luca


signature.asc
Description: Message signed with OpenPGP using GPGMail


Re: Using Aggregate and Count

2013-11-20 Thread Daniel Roseman
On Wednesday, 20 November 2013 19:11:26 UTC, Timothy W. Cook wrote:
>
> I see there was a similar question on this issue earlier today but 
> alas it didn't answer my question. 
>
> In my app I have models for: 
> Project:  a project (not really part of this question but used for 
> context in the question). 
> Paper: an academic paper description 
> Review: a review of a paper 
> ... other things not pertinent. 
>
> I can list Projects and from there I can list Papers assigned to each 
> project. 
> In the listing of papers I want to show how many reviews there are for 
> each Paper. 
>
> Paper has a ForeignKey to Project and Review has a ForeignKey to Paper. 
>
> I have this code as my view: 
>
> class PapersListView(ListView): 
> model = Paper 
> template_name = 'papers/papers_list.html' 
>
> def get_context_data(self, **kwargs): 
> context = super(PapersListView, self).get_context_data(**kwargs) 
> papers = Paper.objects.filter(project__id=self.kwargs['pk']) 
> review_count = 
> Review.objects.aggregate(review_count=Count('paper')) 
> print(review_count) 
> context['papers'] = papers 
> context['review_count'] = review_count 
> return context 
>
> and this in my template: 
>
> 
>  cellspacing="2"> 
>  
> Title 
> Reviews 
> Year 
> Journal 
> Current Stage 
>  
> {% for p in papers %} 
>  
>  href="#">{{p.title}} 
> {{p.review_count}} 
> {{p.year_published}} 
> {{p.journal}} 
> {{p.current_stage}} 
>  
>{% endfor %} 
>  
>  
>
> The print() inserted in the view gives me this: 
> {'review_count': 2} 
>
> In the rendered template the Reviews column is empty. 
>
> There are two Review instances in the database.  But, they are for two 
> separate Papers in two separate Projects.  So, my guess is that I have 
> two problems but after scouring the docs I can't determine where the 
> mistakes/misunderstandings are. 
>
> Any help is appreciated. 
>
> Cheers, 
> Tim 
>
>
You're accessing a `review_count` attribute via each Paper instance, but 
you haven't set up anything that would do that - you only have a single 
top-level `review_count` dictionary.

Instead of a separate `aggregate` call, you should be using `annotate` on 
the original Paper queryset:

papers = 
Paper.objects.filter(project__id=self.kwargs['pk']).annotate(review_count=Count('review'))

Now each element in `papers` has a `review_count` attribute.
-- 
DR.

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


Using Aggregate and Count

2013-11-20 Thread Timothy W. Cook
I see there was a similar question on this issue earlier today but
alas it didn't answer my question.

In my app I have models for:
Project:  a project (not really part of this question but used for
context in the question).
Paper: an academic paper description
Review: a review of a paper
... other things not pertinent.

I can list Projects and from there I can list Papers assigned to each project.
In the listing of papers I want to show how many reviews there are for
each Paper.

Paper has a ForeignKey to Project and Review has a ForeignKey to Paper.

I have this code as my view:

class PapersListView(ListView):
model = Paper
template_name = 'papers/papers_list.html'

def get_context_data(self, **kwargs):
context = super(PapersListView, self).get_context_data(**kwargs)
papers = Paper.objects.filter(project__id=self.kwargs['pk'])
review_count = Review.objects.aggregate(review_count=Count('paper'))
print(review_count)
context['papers'] = papers
context['review_count'] = review_count
return context

and this in my template:

   


Title
Reviews
Year
Journal
Current Stage

{% for p in papers %}

{{p.title}}
{{p.review_count}}
{{p.year_published}}
{{p.journal}}
{{p.current_stage}}

   {% endfor %}



The print() inserted in the view gives me this:
{'review_count': 2}

In the rendered template the Reviews column is empty.

There are two Review instances in the database.  But, they are for two
separate Papers in two separate Projects.  So, my guess is that I have
two problems but after scouring the docs I can't determine where the
mistakes/misunderstandings are.

Any help is appreciated.

Cheers,
Tim







-- 
MLHIM VIP Signup: http://goo.gl/22B0U

Timothy Cook, MSc   +55 21 94711995
MLHIM http://www.mlhim.org
Like Us on FB: https://www.facebook.com/mlhim2
Circle us on G+: http://goo.gl/44EV5
Google Scholar: http://goo.gl/MMZ1o
LinkedIn Profile:http://www.linkedin.com/in/timothywaynecook

-- 
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%3DOU3U2L%3DxPSxfuFV8RiX6gmnA_qQx7RPrAJhjo6Ee-iRtMPA%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: Writing your first Django app, part 1

2013-11-20 Thread Larry Barnett
Found it.  I had Polls in the wrong place in the settings file.

Thanks!

On Wednesday, November 20, 2013 12:39:14 PM UTC-6, Larry Barnett wrote:
>
> In the tutorial after I enter:
>
> python manage.py sql polls
>
> I get the following error:
>
> CommandError: App with label polls could not be found. Are you sure your 
> INSTALLED_APPS setting is correct?
>
> I have built the site twice with the same results.  I cannot locate any 
> error in the example or the Django environment. Everything worked prior to 
> the attempt to include the app. Any ideas?
>
>

-- 
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/f8bdc998-8fdf-4b84-bc9c-d7a09d85c9ef%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: Writing your first Django app, part 1

2013-11-20 Thread Jonathan Baker
Is "polls" listed in within INSTALLED_APPS of settings.py? If so, does your
polls app have an __init__.py file?


On Wed, Nov 20, 2013 at 11:39 AM, Larry Barnett wrote:

> In the tutorial after I enter:
>
> python manage.py sql polls
>
> I get the following error:
>
> CommandError: App with label polls could not be found. Are you sure your
> INSTALLED_APPS setting is correct?
>
> I have built the site twice with the same results.  I cannot locate any
> error in the example or the Django environment. Everything worked prior to
> the attempt to include the app. Any ideas?
>
>  --
> 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/acbd9f55-f2f7-4b94-beb3-4dc7167fa8e8%40googlegroups.com
> .
> For more options, visit https://groups.google.com/groups/opt_out.
>



-- 
Jonathan D. Baker
Developer
http://jonathandbaker.com

-- 
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/CAPMFOb739HCf4EJHkD7%2B6%3D%2BPa_ewTuqs1ienUxoGc2rAQTnQ2Q%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.


Writing your first Django app, part 1

2013-11-20 Thread Larry Barnett
In the tutorial after I enter:

python manage.py sql polls

I get the following error:

CommandError: App with label polls could not be found. Are you sure your 
INSTALLED_APPS setting is correct?

I have built the site twice with the same results.  I cannot locate any 
error in the example or the Django environment. Everything worked prior to 
the attempt to include the app. Any ideas?

-- 
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/acbd9f55-f2f7-4b94-beb3-4dc7167fa8e8%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: data not saving through a many to many relationship

2013-11-20 Thread MikeKJ
Update:

So editing AdviceLevel with

def edit_advice(request):
if not request.user.is_authenticated():
return HttpResponseRedirect('/user/login/')
this_advice = request.POST.get('advice_id')
sp = Specialism.objects.all().filter(advicelevel=this_advice)
de = CRSDeliveryMethod.objects.all().filter(advicelevel=this_advice)
lo = Location.objects.all().filter(advicelevel=this_advice)
help = OrganisationHelpTexts.objects.all()
advice = request.POST.get('advice')
 #   adv = Advice.objects.get(title=advice)
 #   id_adv = adv.id
this_org = request.session['this_org']
this = Organisation.objects.get(pk=this_org)
id_org = this.id
thisadvlvl = AdviceLevel.objects.get(pk=this_advice)
level_1 = thisadvlvl.level_1
level_2 = thisadvlvl.level_2
level_3 = thisadvlvl.level_3
level_4 = thisadvlvl.level_4

advkey = AdviceLevelKey.objects.all()
if request.POST:
#raise NameError(request.POST)
if 'adviceid' in request.POST:
return HttpResponseRedirect('/directory/delete_advice/')
if 'editform' in request.POST:
editform = EditAdviceLevelForm(request.POST, 
instance=thisadvlvl)
if editform.is_valid():
error = ""
level_1 = editform.cleaned_data['level_1']
level_2 = editform.cleaned_data['level_2']
level_3 = editform.cleaned_data['level_3']
level_4 = editform.cleaned_data['level_4']
service_restriction = 
editform.cleaned_data['service_restriction']
service_supervisor = 
editform.cleaned_data['service_supervisor']
specialism = editform.cleaned_data['specialism']
delivery_method = editform.cleaned_data['delivery_method']
face_to_face_locations = 
editform.cleaned_data['face_to_face_locations']
if (level_3 == 0 and level_4 == 1) or (level_2 == 0 and 
(level_3 == 1 or level_4 == 1)) or (level_1 == 0 and (level_2 == 1 or 
level_3 == 1 or level_4 == 1)):
error = "That isn't a possible combination, the tiers 
are progressive"
editform = EditAdviceLevelForm(request.POST, 
instance=thisadvlvl)
return render_to_response('directory/edit_advice.html', 
{'thisadvlvl': thisadvlvl, 'help': help, 'sp': sp, 'lo': lo, 'de': de, 
'advice': advice, 'advkey': advkey, 'editform': editform, 'level_1': 
level_1, 'level_2': level_2, 'level_3': level_3, 'level_4': level_4, 
'this_advice': this_advice, 'error': error, 
},context_instance=RequestContext(request))
editform.save()
return HttpResponseRedirect('/directory/do_advice/')

else:
editform = EditAdviceLevelForm(request.POST, 
instance=thisadvlvl)
else:
editform = EditAdviceLevelForm(instance=thisadvlvl)
return render_to_response('directory/edit_advice.html', {'thisadvlvl': 
thisadvlvl, 'help': help, 'sp': sp, 'lo': lo, 'de': de, 'advice': advice, 
'advkey': advkey, 'editform': editform, 'level_1': level_1, 'level_2': 
level_2, 'level_3': level_3, 'level_4': level_4, 'this_advice': 
this_advice, },context_instance=RequestContext(request))

works both adding or deleting a many to many related field so the 
difference is in the save methods
editform.save() in this working case and 
af = adviceform.save(commit=False)
af.organisation = organisation
af.save()
which doesn't

Now I deliberately used commit = False because I wanted to prepopulate the 
organisation rather than have the user select(again) the organisation so I 
therefore had to add the value of organisation to the form save hence using 
commit=False, unless someone can spot an error somewhere that is causing 
the problem or knows of a differnt way of accomplishing what commit does.  
Cannot just save the form as adviceform.save() because organisation MUST 
have a value see the Organisation model.
Any ideas?


-- 
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/97de130b-1f4f-492b-938e-e18d28dfd5da%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: AttributeError: 'RegexURLResolver' object has no attribute '_urlconf_module'

2013-11-20 Thread burak . kuyucakli
Hello,

Is there an answer to this problem?

On Tuesday, July 2, 2013 4:56:08 PM UTC+3, Pratik Mandrekar wrote:
>
> Hey Tom,
>
> My ROOT_URLCONF points to 'urls' which is the top level urlconf for my 
> site. Besides all my urls do work. This error keeps coming intermittently 
> but does not affect my application logic in any way I know. So I need to 
> know why this error keeps getting reported and how to fix it.
>
> Thanks,
> Pratik
>
> On Tuesday, July 2, 2013 4:53:09 PM UTC+5:30, Tom Evans wrote:
>>
>> On Tue, Jul 2, 2013 at 12:14 PM, Pratik Mandrekar 
>>  wrote: 
>> > 
>> > Hello, 
>> > 
>> > 
>> > I keep getting the error AttributeError: 'RegexURLResolver' object has 
>> no 
>> > attribute '_urlconf_module' and the only trace available is as shown 
>> below: 
>> > 
>> > 'RegexURLResolver' object has no attribute '_urlconf_module' 
>> > 
>> > My Sentry Error reporting normally shows the above error along with 
>> > another error, both of which seem to happen simultaneously 
>> > 
>> > 
>> > django.core.urlresolvers in urlconf_module 
>> > 
>> > AttributeError: 'RegexURLResolver' object has no attribute 
>> > '_urlconf_module' 
>> > 
>> > 
>> > The trace for which is 
>> > 
>> > 
>> >  @property 
>> > 
>> > def urlconf_module(self): 
>> > 
>> > try: 
>> > 
>> > return self._urlconf_module 
>> > 
>> > except AttributeError: 
>> > 
>> > self._urlconf_module = import_module(self.urlconf_name) 
>> > 
>> > return self._urlconf_module 
>> > 
>> > @property 
>> > 
>> > 
>> > 'self' 
>> > 
>> >  
>> > 
>> > 
>> > I'm on Django 1.4. I have been unable to debug this for weeks. Any help 
>> > would be appreciated. 
>> > 
>> > 
>> > Thanks, 
>> > 
>> > Pratik 
>> > 
>>
>> Sounds like your ROOT_URLCONF is incorrectly specified in settings. 
>>
>> Cheers 
>>
>> Tom 
>>
>

-- 
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/451bd362-f0c2-4d00-a843-1b205880da5c%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Using admin views "outside" of admin

2013-11-20 Thread Brad Smith
Hello all,

Based on other threads I've read here, it seems that the conventional 
wisdom is that the admin interface is only for low-level access to the 
database, and isn't designed for anything "fancy", like users with 
different levels of administrative rights within an app, etc. Ok, I get 
that, but if I may grasp at some straws briefly I'd like to ask one 
follow-up that I haven't seen answered elsewhere: my app has a bunch of 
objects with complicated relationships for which I've devised a reasonably 
pretty and intuitive editing interface using Django's admin and Grappelli. 
Since this took a nontrivial amount of effort, I wanted to ask here if 
there are any tricks I should know about for re-using *any* views, inlines, 
etc from that admin interface in a more integrated editing interface with 
granular access controls, or do I just need to suck it up and rewrite 
everything from scratch using regular Django forms?

Thanks to anyone who can offer some advice. 
--Brad 

-- 
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/e0f27e3a-5c6b-4a92-b6c5-c266323fa118%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: How to test django app

2013-11-20 Thread bobhaugen
Recommend:
https://pycon-2012-notes.readthedocs.org/en/latest/testing_and_django.html
http://webtest.pythonpaste.org/en/latest/

-- 
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/1150354d-fb07-4279-ae4a-c0b610e0caca%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: Django Admin Error: pop-up entry form

2013-11-20 Thread Derek
Solved.  You need to add "u" to the unicode representation of your model's 
record.  As in:

def __unicode__(self):
return u'%s' % self.fieldname

This "error" does not show up in the normal admin page for the model, only 
when its accessed via the pop-up route.

On Tuesday, 19 November 2013 20:42:25 UTC+2, Derek wrote:
>
> Hi
>
> I am using Django 1.5.5.  This error happens while running the dev 
> server.  If I click on the "+" button so I can use the pop-up form to add a 
> new entry to a drop-down list (i.e. FK to another model), I get the 
> following error trace when trying to save that form.
>
> File 
> "/home/derek/.virtualenvs/s2s/local/lib/python2.7/site-packages/django/core/handlers/base.py"
>  
> in get_response
>   115. response = callback(request, 
> *callback_args, **callback_kwargs)
> File 
> "/home/derek/.virtualenvs/s2s/local/lib/python2.7/site-packages/django/contrib/admin/options.py"
>  
> in wrapper
>   372. return self.admin_site.admin_view(view)(*args, 
> **kwargs)
> File 
> "/home/derek/.virtualenvs/s2s/local/lib/python2.7/site-packages/django/utils/decorators.py"
>  
> in _wrapped_view
>   91. response = view_func(request, *args, **kwargs)
> File 
> "/home/derek/.virtualenvs/s2s/local/lib/python2.7/site-packages/django/views/decorators/cache.py"
>  
> in _wrapped_view_func
>   89. response = view_func(request, *args, **kwargs)
> File 
> "/home/derek/.virtualenvs/s2s/local/lib/python2.7/site-packages/django/contrib/admin/sites.py"
>  
> in inner
>   202. return view(request, *args, **kwargs)
> File 
> "/home/derek/.virtualenvs/s2s/local/lib/python2.7/site-packages/django/utils/decorators.py"
>  
> in _wrapper
>   25. return bound_func(*args, **kwargs)
> File 
> "/home/derek/.virtualenvs/s2s/local/lib/python2.7/site-packages/django/utils/decorators.py"
>  
> in _wrapped_view
>   91. response = view_func(request, *args, **kwargs)
> File 
> "/home/derek/.virtualenvs/s2s/local/lib/python2.7/site-packages/django/utils/decorators.py"
>  
> in bound_func
>   21. return func(self, *args2, **kwargs2)
> File 
> "/home/derek/.virtualenvs/s2s/local/lib/python2.7/site-packages/django/db/transaction.py"
>  
> in inner
>   223. return func(*args, **kwargs)
> File 
> "/home/derek/.virtualenvs/s2s/local/lib/python2.7/site-packages/django/contrib/admin/options.py"
>  
> in add_view
>   1010. return self.response_add(request, new_object)
> File 
> "/home/derek/.virtualenvs/s2s/local/lib/python2.7/site-packages/django/contrib/admin/options.py"
>  
> in response_add
>   833. (escape(pk_value), escapejs(obj)))
> File 
> "/home/derek/.virtualenvs/s2s/local/lib/python2.7/site-packages/django/utils/functional.py"
>  
> in wrapper
>   196. return func(*args, **kwargs)
> File 
> "/home/derek/.virtualenvs/s2s/local/lib/python2.7/site-packages/django/utils/html.py"
>  
> in escapejs
>   64. return mark_safe(force_text(value).translate(_js_escapes))
>
> Exception Type: TypeError at /admin/core/item/add/
> Exception Value: expected a character buffer object
>
>
> You can see there are no links to my code, so I am not sure what needs to 
> change or be changed.  Is it Django code itself that is faulty?
>
> 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/6ddf3ada-7307-4156-aca1-f0e1ae7a4ad9%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: How can I forloop this count() in my template code?

2013-11-20 Thread Pepsodent Cola
Thanks Tom it worked! :)


On Wednesday, November 20, 2013 12:18:23 PM UTC+1, Pepsodent Cola wrote:
>
> How can I forloop this count() in my template code?
>
> * I have attached my project files that you might run and see for 
> yourselves.
> * I have attached a screenshot of the table I'm working on.
> * User/Pass = joe/joe
>
>
> def index(request):
> publications = Publication.objects.all()
> articles = Article.objects.all()
>
> *sum_publications = Publication.objects.filter(article__pk=1).count()*
>
> context = {'publications':publications, 'articles':articles, 
> 'sum_publications':sum_publications}
> return render(request, 'magazine/index.html', context)
>
>
>
> 
> How many Publications was each Article in?
>
> {% if articles %}
> 
> 
> Article id
> Article
> Publication
> 
> {% for row in articles %}
> 
> {{ row.id }}
> {{ row.headline }}
> *total*
> 
> {% endfor %}
> 
> {% else %}
> No Articles are available.
> {% endif %}
>
>
> **
> {% if 666sum_publications %}
> 
> {% for row in sum_publications %}
> {{ row }}
> {% endfor %}
> 
> {% else %}
> No sums are available.
> {% endif %}
>
> 
> 
>
>
>

-- 
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/6a99dfe0-15af-48e2-ae32-498dcf782d6c%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: Invalid control character char 30262

2013-11-20 Thread Chi Tak Lam

I end up fix the problem by just passing strict=false to json.loads()...
json.loads(response.read(), strict=False).

The error didn't occur anymore, seem like working fine.

Thanks


On Saturday, November 9, 2013 11:44:53 PM UTC+8, Chi Tak Lam wrote:
>
> Hi,
>
> I have a django-celery task to retrieve data from a third party service 
> and store into my database.
> But I found an error in my log file, which is
> None: Invalid control character at: line 1134 column 14 (char 30262)
>
> Not sure what is char 30262, maybe this?
> http://www.fileformat.info/info/unicode/char/30262/index.htm
>
> My question is, how can i solve this problem without skip this records?
>
> 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/c5b876f9-f776-4c1b-a7e6-7567a001bb59%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: Tango with Django Chapter 7 (Add_page)

2013-11-20 Thread Amimo Benja
Hi Lee,

I have been continuing with the django tutorials and at the moment I am on 
chapter 10 dealing with cookies.

On the exercises when a user logs in and clicks the about page link, mine 
just shows he visited the site 1 time no matter how many times he clicks on 
the about page. Is it supposed to be so or am I missing something? 

On Thursday, November 14, 2013 4:49:13 PM UTC+3, Lee wrote:
>
> No problem at all, glad it worked out for you :-)
>
> Good luck with the rest of the tutorial
>
> Cheers
>
> On Thursday, 14 November 2013 12:16:06 UTC, Amimo Benja wrote:
>>
>> Thanks Lee, it worked. The problem was I had not passed category_name_url 
>> from my view function to the category template. The moment I passed it, it 
>> worked without any problem. Thanks a lot Man. At least I can proceed. 
>> Phee...w!!! Thanks again.
>>
>> On Thursday, November 14, 2013 3:08:27 PM UTC+3, Lee wrote:
>>>
>>> Noob here so I may be way wrong but it looks to me like your problem is 
>>> probably in link in category page when generating the link to add_page, 
>>> given the url in the error is missing the category name in the URL. Have 
>>> you passed category_name_url from your view function to the category 
>>> template? Your views.py link seems to show forms.py rather than the view 
>>> functions so I cant see the view, but my category view looks as follows and 
>>> works:
>>>
>>>  def category(request, category_name_url):
>>> context = RequestContext(request)
>>> category_name = decode_url(category_name_url)
>>> context_dict = {'category_name': category_name, 'category_name_url': 
>>> category_name_url}
>>>
>>> try:
>>> category = Category.objects.get(name=category_name)
>>> pages = Page.objects.filter(category=category)
>>> context_dict['pages'] = pages
>>> context_dict['category'] = category
>>> except Category.DoesNotExist:
>>> pass
>>>
>>> return render_to_response('rango/category.html', context_dict, context)
>>>
>>> And I am also mid way through Tango with Django if you hadn't guessed ;-)
>>>
>>>
>>> On Wednesday, 13 November 2013 12:14:40 UTC, Amimo Benja wrote:

 Hey all,

 Am currently practicing using this tutorial 
 http://www.tangowithdjango.com/book/chapters/forms.html, but I'm 
 constantly getting this error "The current URL, 
 rango/category//add_page/, didn't match any of these." every time I 
 click on the Add a Page 
 link 
 in the Category.html. I don't know how to solve it. Any help? Thanks.

 Here are my 
 1. Views.py http://pastebin.mozilla.org/3595121
 2. rango/urls.py http://pastebin.mozilla.org/3595145
 3. add_page.html http://pastebin.mozilla.org/3595156
 4. category.html http://pastebin.mozilla.org/3595158



-- 
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/d2b32510-a687-41c3-925a-f139759b346d%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: Non-Ascii Characters in URL causes crash

2013-11-20 Thread Rafael E. Ferrero
i try on www.plandroid.com/消防隊員 and get a 500-internal server error..

Im interest on know how you resolve this question, i dont have idea how it
works... i mean... its posible to put a try catch somewhere to pass
silently an error page ?




2013/11/20 Peter 

> I have a slightly weird issue.  Someone is sending http requests with
> Chinese characters in the URL.  Ok, it's probably just Chinese hackers
> trying something.  But it's causing Django to fall over with a
> UnicodeEncodeError in the response.
>
> I'm thinking this must be a bug in Django as the response is generated by
> Django itself.
>
> I have flatpages turned on, and obviously this url doesn't match anything
> I have in flatpages so it's somewhere in the flatpage not found path.  I
> also have I18N turned on.
>
> I'm running Django version 1.4.8.  Below is the traceback.
>
> Should I just ignore this?
>
> Peter
>
> Traceback (most recent call last):
>
>   File "/home/peter/django-ductedit/django/core/handlers/base.py", line 92, 
> in get_response
> response = callback(request, *callback_args, **callback_kwargs)
>
>   File "/home/peter/django-ductedit/django/contrib/flatpages/views.py", line 
> 23, in flatpage
> return HttpResponseRedirect("%s/" % request.path)
>
>   File "*/home/peter/django-ductedit/django/http/*__init__.py", line 407, in 
> __init__
> self['Location'] = redirect_to
>
>   File "*/home/peter/django-ductedit/django/http/*__init__.py", line 320, in 
> __setitem__
> header, value = self._convert_to_ascii(header, value)
>
>   File "*/home/peter/django-ductedit/django/http/*__init__.py", line 309, in 
> _convert_to_ascii
> value = value.encode('us-ascii')
>
> UnicodeEncodeError: 'ascii' codec can't encode characters in position 10-13: 
> ordinal not in range(128), HTTP response headers must be in US-ASCII format
>
>
>  GET:,
> POST:,
> COOKIES:{},
> META:{'DOCUMENT_ROOT': '*/home/peter/public_html/*',
>  'GATEWAY_INTERFACE': 'CGI/1.1',
>  'HTTP_ACCEPT': '*/*',
>  'HTTP_ACCEPT_ENCODING': 'gzip, deflate',
>  'HTTP_HOST': 'www.plandroid.com',
>  'HTTP_REFERER': 'http://www.baidu.com',
>  'HTTP_USER_AGENT': 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:18.0) 
> Gecko/20100101 Firefox/18.0',
>  'HTTP_X_FORWARDED_FOR': '183.60.243.188',
>  'HTTP_X_FORWARDED_PROTO': 'http',
>  'HTTP_X_HOST': 'www.plandroid.com',
>  'PATH_INFO': u'*/template/*\u8bf7\u52ff\u5220\u96646kbbs\u6a21\u677f.txt',
>  'PATH_TRANSLATED': 
> '*/home/peter/public_html//template/*\xe8\xaf\xb7\xe5\x8b\xbf\xe5\x88\xa0\xe9\x99\xa46kbbs\xe6\xa8\xa1\xe6\x9d\xbf.txt',
>  'QUERY_STRING': '',
>  'REDIRECT_STATUS': '200',
>  'REDIRECT_URI': 
> '*/django.fcgi/template/*\xe8\xaf\xb7\xe5\x8b\xbf\xe5\x88\xa0\xe9\x99\xa46kbbs\xe6\xa8\xa1\xe6\x9d\xbf.txt',
>  'REMOTE_ADDR': '183.60.243.188',
>  'REMOTE_PORT': '15624',
>  'REQUEST_METHOD': 'GET',
>  'REQUEST_URI': 
> '*/template/*\xe8\xaf\xb7\xe5\x8b\xbf\xe5\x88\xa0\xe9\x99\xa46kbbs\xe6\xa8\xa1\xe6\x9d\xbf.txt',
>  'SCRIPT_FILENAME': '/home/peter/public_html/django.fcgi',
>  'SCRIPT_NAME': u'',
>  'SERVER_ADDR': '127.0.0.1',
>  'SERVER_NAME': 'www.plandroid.com',
>  'SERVER_PORT': '62305',
>  'SERVER_PROTOCOL': 'HTTP/1.0',
>  'SERVER_SOFTWARE': 'lighttpd',
>  'wsgi.errors': ,
>  'wsgi.input': ,
>  'wsgi.multiprocess': True,
>  'wsgi.multithread': False,
>  'wsgi.run_once': False,
>  'wsgi.url_scheme': 'http',
>  'wsgi.version': (1, 0)}>
>
>
>
>  --
> 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/7428b624-197e-4e03-b78f-f952ae99bd8a%40googlegroups.com
> .
> For more options, visit https://groups.google.com/groups/opt_out.
>



-- 
Rafael E. Ferrero

-- 
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_8XKvVhVAnu9Gkk2iCDmZdbaHyWNCpmpkcumGx2ive%3DSFw%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: data not saving through a many to many relationship

2013-11-20 Thread MikeKJ
Decided that the relationship  advice = models.ManyToManyField(Advice, 
through='AdviceLevel') in the Organsiation model is redundant and removed 
it but it hasn;t made any difference to the now NON intermdiate model 
AdviceLevel


-- 
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/57ddd12c-72cb-4190-9d68-17ad9a62c096%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


data not saving through a many to many relationship

2013-11-20 Thread MikeKJ
In the view do_advice the specialism, delivery_method and 
face_to_face_locations selections are not being saved into the 
corresponding tables
of 
advicelevel_specialism,
 
advicelevel_delivery_methodand
 
advicelevel_face_to_face_locationswhich
 are the fields of advicelevel_id  and x_id where x = specialism etc, 
normal many to many table right? 
The actual AdviceLevel table is properly saved to with the advice_id, 
organisation_id, the selected levels etc everytning that is not a many to 
many effectively

Needless it say it works perfectly in Admin, just this user facing version 
doesnt work

Models:
class Organisation(models.Model):
title = models.CharField(max_length=150)
address1 = models.CharField(max_length=150, null=True, blank=True)
address2 = models.CharField(max_length=150, null=True, blank=True)
place = models.CharField(max_length=150, null=True, blank=True)
postcode = models.CharField(max_length=15, null=True, blank=True)
tel = models.CharField(max_length=30, null=True, blank=True)
fax = models.CharField(max_length=30, null=True, blank=True)
email = models.EmailField(null=True, blank=True)
web = models.URLField()
text = models.TextField()
advice = models.ManyToManyField(Advice, through='AdviceLevel')   // 
note THROUGH
crs = models.BooleanField()
appointment_locations = models.TextField(null=True, blank=True)
drop_in_locations = models.TextField(null=True, blank=True)
def __unicode__(self):
 return u"%s" % self.title
class Meta:
ordering = ('title',)

class AdviceLevelKey(models.Model):
key_level = models.CharField(max_length=150)
key_level_text = models.TextField()
key_level_cab = models.CharField(max_length=15)
def __unicode__(self):
return self.key_level

class AdviceLevel(models.Model):
advice = models.ForeignKey(Advice)
organisation = models.ForeignKey(Organisation)
level_1 = models.BooleanField()
level_2 = models.BooleanField()
level_3 = models.BooleanField()
level_4 = models.BooleanField()
specialism = models.ManyToManyField(Specialism, null=True, blank=True)
service_restriction = models.TextField(null=True, blank=True)
delivery_method = models.ManyToManyField(CRSDeliveryMethod, null=True, 
blank=True)
face_to_face_locations = models.ManyToManyField(Location, null=True, 
blank=True)
service_supervisor = models.CharField(max_length=175, null=True, 
blank=True)
def __unicode__(self):
return u"%s (%s)" % (self.organisation, self.advice)

View // the offending one

class AdviceForm(ModelForm):
class Meta:
model = AdviceLevel
exclude = ('organisation',)

def do_advice(request):
if not request.user.is_authenticated():
return HttpResponseRedirect('/user/login/')
this_org = request.session['this_org']
advkey = AdviceLevelKey.objects.all()
org = Organisation.objects.get(pk=this_org)
orgid = org.id
organisation = ""
help = OrganisationHelpTexts.objects.all()
try:
data_set = AdviceLevel.objects.all().filter(organisation=this_org)
except AdviceLevel.DoesNotExist:
data_set = None

if request.POST:
if 'editadvice' in request.POST:
return HttpResponseRedirect('/directory/edit_advice/')
if 'adviceform' in request.POST:
adviceform = AdviceForm(request.POST)
if adviceform.is_valid():
organisation = org
adv = adviceform.cleaned_data['advice']
service_restriction = 
adviceform.cleaned_data['service_restriction']
service_supervisor = 
adviceform.cleaned_data['service_supervisor']
specialism = adviceform.cleaned_data['specialism']
delivery_method = adviceform.cleaned_data['delivery_method']
face_to_face_locations = 
adviceform.cleaned_data['face_to_face_locations']
level_1 = adviceform.cleaned_data['level_1']
level_2 = adviceform.cleaned_data['level_2']
level_3 = adviceform.cleaned_data['level_3']
level_4 = adviceform.cleaned_data['level_4']
if (level_3 == 0 and level_4 == 1) or (level_2 == 0 and 
(level_3 == 1 or level_4 == 1)) or (level_1 == 0 and (level_2 == 1 or 
level_3 == 1 or level_4 == 1)):
error = "That isn't a possible combination, the

Non-Ascii Characters in URL causes crash

2013-11-20 Thread Peter
I have a slightly weird issue.  Someone is sending http requests with 
Chinese characters in the URL.  Ok, it's probably just Chinese hackers 
trying something.  But it's causing Django to fall over with a 
UnicodeEncodeError in the response.

I'm thinking this must be a bug in Django as the response is generated by 
Django itself.

I have flatpages turned on, and obviously this url doesn't match anything I 
have in flatpages so it's somewhere in the flatpage not found path.  I also 
have I18N turned on.

I'm running Django version 1.4.8.  Below is the traceback.

Should I just ignore this?

Peter

Traceback (most recent call last):

  File "/home/peter/django-ductedit/django/core/handlers/base.py", line 92, in 
get_response
response = callback(request, *callback_args, **callback_kwargs)

  File "/home/peter/django-ductedit/django/contrib/flatpages/views.py", line 
23, in flatpage
return HttpResponseRedirect("%s/" % request.path)

  File "*/home/peter/django-ductedit/django/http/*__init__.py", line 407, in 
__init__
self['Location'] = redirect_to

  File "*/home/peter/django-ductedit/django/http/*__init__.py", line 320, in 
__setitem__
header, value = self._convert_to_ascii(header, value)

  File "*/home/peter/django-ductedit/django/http/*__init__.py", line 309, in 
_convert_to_ascii
value = value.encode('us-ascii')

UnicodeEncodeError: 'ascii' codec can't encode characters in position 10-13: 
ordinal not in range(128), HTTP response headers must be in US-ASCII format


,
POST:,
COOKIES:{},
META:{'DOCUMENT_ROOT': '*/home/peter/public_html/*',
 'GATEWAY_INTERFACE': 'CGI/1.1',
 'HTTP_ACCEPT': '*/*',
 'HTTP_ACCEPT_ENCODING': 'gzip, deflate',
 'HTTP_HOST': 'www.plandroid.com',
 'HTTP_REFERER': 'http://www.baidu.com',
 'HTTP_USER_AGENT': 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:18.0) 
Gecko/20100101 Firefox/18.0',
 'HTTP_X_FORWARDED_FOR': '183.60.243.188',
 'HTTP_X_FORWARDED_PROTO': 'http',
 'HTTP_X_HOST': 'www.plandroid.com',
 'PATH_INFO': u'*/template/*\u8bf7\u52ff\u5220\u96646kbbs\u6a21\u677f.txt',
 'PATH_TRANSLATED': 
'*/home/peter/public_html//template/*\xe8\xaf\xb7\xe5\x8b\xbf\xe5\x88\xa0\xe9\x99\xa46kbbs\xe6\xa8\xa1\xe6\x9d\xbf.txt',
 'QUERY_STRING': '',
 'REDIRECT_STATUS': '200',
 'REDIRECT_URI': 
'*/django.fcgi/template/*\xe8\xaf\xb7\xe5\x8b\xbf\xe5\x88\xa0\xe9\x99\xa46kbbs\xe6\xa8\xa1\xe6\x9d\xbf.txt',
 'REMOTE_ADDR': '183.60.243.188',
 'REMOTE_PORT': '15624',
 'REQUEST_METHOD': 'GET',
 'REQUEST_URI': 
'*/template/*\xe8\xaf\xb7\xe5\x8b\xbf\xe5\x88\xa0\xe9\x99\xa46kbbs\xe6\xa8\xa1\xe6\x9d\xbf.txt',
 'SCRIPT_FILENAME': '/home/peter/public_html/django.fcgi',
 'SCRIPT_NAME': u'',
 'SERVER_ADDR': '127.0.0.1',
 'SERVER_NAME': 'www.plandroid.com',
 'SERVER_PORT': '62305',
 'SERVER_PROTOCOL': 'HTTP/1.0',
 'SERVER_SOFTWARE': 'lighttpd',
 'wsgi.errors': ,
 'wsgi.input': ,
 'wsgi.multiprocess': True,
 'wsgi.multithread': False,
 'wsgi.run_once': False,
 'wsgi.url_scheme': 'http',
 'wsgi.version': (1, 0)}>



-- 
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/7428b624-197e-4e03-b78f-f952ae99bd8a%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: How can I forloop this count() in my template code?

2013-11-20 Thread Tom Evans
On Wed, Nov 20, 2013 at 11:18 AM, Pepsodent Cola
 wrote:
> How can I forloop this count() in my template code?
>
> * I have attached my project files that you might run and see for
> yourselves.
> * I have attached a screenshot of the table I'm working on.
> * User/Pass = joe/joe
>
>
> def index(request):
> publications = Publication.objects.all()
> articles = Article.objects.all()
>
> sum_publications = Publication.objects.filter(article__pk=1).count()
>
> context = {'publications':publications, 'articles':articles,
> 'sum_publications':sum_publications}
> return render(request, 'magazine/index.html', context)

Are you trying to annotate each row in the 'articles' queryset with
the count of the number of publications associated with that article?

from django.db.models import Count
articles = Article.objects.all().annotate(num_publications=Count('publication'))

{% for article in articles %}
{{ article.id }}
{{ article.num_publications }}
{% endfor %}

Cheers

Tom

-- 
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/CAFHbX1L33SMPVHFZZNnuy__sSPb-iy7BKUuVEVWg%2BTNkkyqa2A%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: How to test django app

2013-11-20 Thread Tom Evans
On Wed, Nov 20, 2013 at 5:22 AM, Harjot Mann  wrote:
> To test my django app I got unittest module in Django but what I am
> notiing that it needs to create tests for the functions in views.py
> file. So I need to do lot of coding. Is there any another way to do
> testing or this is the only best way to do it?
> Is anyone using it or can he/she share their experience. I need it urgently.
>

This is to be expected - in order to effectively test your code, you
need to write effective tests, which takes time.

The more tests you write, the better you will become at writing your
code in ways that make it easier to test.

Cheers

Tom

-- 
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/CAFHbX1%2B4dT6c6Q%2BJg2Qgu6sONAtu%2B5A%2BA2ApZtQzMN4Q%3D6w3UA%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: How to test django app

2013-11-20 Thread Pepsodent Cola
I'm interested in this topic too.



On Wednesday, November 20, 2013 6:22:04 AM UTC+1, Harjot Mann wrote:
>
> To test my django app I got unittest module in Django but what I am 
> notiing that it needs to create tests for the functions in views.py 
> file. So I need to do lot of coding. Is there any another way to do 
> testing or this is the only best way to do it? 
> Is anyone using it or can he/she share their experience. I need it 
> urgently. 
>
> -- 
> Harjot Kaur Mann 
> Blog: http://harjotmann.wordpress.com/ 
> Daily Dairy: http://harjotmann.wordpress.com/daily-diary/ 
>

-- 
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/77a04a12-ce9a-4b52-bc0e-90858acb16bb%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.