Support an additional variable MY_APP_USE_OTHER_CONSTANT (MY and
MY_APP, are, I hope, not the prefixes you are actually using), which
defaults to False and which the project settings file can override to
True.
On Fri, Jun 29, 2012 at 9:06 AM, Marc Aymerich <glicerinu@gmail.com> wrote:
> On Fri, Jun 29, 2012 at 11:08 AM, Thomas Rega <tr@pyt3ch.com> wrote:
>> Am 28.06.12 17:30, schrieb Marc Aymerich:
>>
>>> Hi,
>>> I'm developing a reusable application and I'm having troubles with
>>> constant values on settings.
>>>
>>> Imagine that the reusable application comes with the following settings.py
>>>
>>> # MY_APP/settings.py
>>> from django.conf import settings
>>> MY_CONSTANT = 'C1'
>>> MY_OTHER_CONSTANT = 'C2'
>>> MY_SETTING = getattr(settings, 'MY_SETTING', CONSTANT)
>>>
>>>
>>> But for your project you want to override the default value of
>>> MY_SETTING by MY_OTHER_CONSTANT. So you edit your project settings.py
>>> and adds these two lines:
>>>
>>> # Project settings.py
>>> ....
>>> from MY_APP.settings import settings as my_app_settings
>>> MY_SETTING = my_app_settings.MY_OTHER_SETTING
>>>
>>>
>>> But this is going to fail because of the import order.
>>>
>>> Is there any consistent way to handle this situation?
>>>
>>> Thanks!
>>
>> Hi,
>>
>> what about the idea to overwrite these values via a 'local_settings.py'
>> file?
>>
>> An example can be found here:
>> https://bitbucket.org/chris1610/satchmo/src/1255b19295c7/satchmo/projects/skeleton/settings.py
>
> Hi thomas, thanks :)
>
> Yeah, actually I'm using a local_settings.py file, but at the end it
> will be the same as using settings.py since local_settings.py is
> imported by settings.py. :(
>
>
> --
> Marc
>
> --
> You received this message because you are subscribed to the Google Groups "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
>
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Saturday, June 30, 2012
Re: javascript in django template not executed when request is sent via ajax
On Sat, Jun 30, 2012 at 11:54 AM, Psamathos <peter.murawski@gmail.com> wrote:
> If your web server is in fact serving the content with the incorrect
> Content-Type header (You can verify this by inspecting the response in the
> Net tab of Firebug or Chrome) jQuery can convert the response regardless of
> the content-type if you specify a two space-separated values in your
> dataType. Try dataType: "text html" in your $.ajax function.
I've been poking around with the debugger. For reference, here's the code:
var $form = $('form.roll');
url = $form.attr('action');
var $report = $('#report');
$.ajax({
url: url,
data: $form.serialize(),
dataType: 'html',
success: function (html, textStatus) {
$report
.html($('#report', html).html())
.css({
opacity: 1.0
});
style_preview_table();
}
The html variable passed into the success function contains the entire
page, including the javascript. I tried doing:
$report.html(html)
But the parts of the page that were not the results (i.e. #report) all
were duplicated (the page was displayed within the page). But even
there, the javascript wasn't included in the page, even though is was
in the html variable.
$('#report', html).html() contained just the html, without the
javascript. What I need is some way to get both the javascript and the
html of $('#report') and then pass that into $report.html(). Are there
javascript or jQuery methods that will allow me to do that?
Alternatively I could extract the javascript from the html variable
passed into the success function. But then how would I make that part
of $report.html()?
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
> If your web server is in fact serving the content with the incorrect
> Content-Type header (You can verify this by inspecting the response in the
> Net tab of Firebug or Chrome) jQuery can convert the response regardless of
> the content-type if you specify a two space-separated values in your
> dataType. Try dataType: "text html" in your $.ajax function.
I've been poking around with the debugger. For reference, here's the code:
var $form = $('form.roll');
url = $form.attr('action');
var $report = $('#report');
$.ajax({
url: url,
data: $form.serialize(),
dataType: 'html',
success: function (html, textStatus) {
$report
.html($('#report', html).html())
.css({
opacity: 1.0
});
style_preview_table();
}
The html variable passed into the success function contains the entire
page, including the javascript. I tried doing:
$report.html(html)
But the parts of the page that were not the results (i.e. #report) all
were duplicated (the page was displayed within the page). But even
there, the javascript wasn't included in the page, even though is was
in the html variable.
$('#report', html).html() contained just the html, without the
javascript. What I need is some way to get both the javascript and the
html of $('#report') and then pass that into $report.html(). Are there
javascript or jQuery methods that will allow me to do that?
Alternatively I could extract the javascript from the html variable
passed into the success function. But then how would I make that part
of $report.html()?
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: javascript in django template not executed when request is sent via ajax
curl (or its windows equivalents) will tell you exactly what django sent, as
would poking around from a suitably placed pdb.set_trace()
On Fri, Jun 29, 2012 at 8:42 PM, Larry Martell <larry.martell@gmail.com> wrote:
> On Fri, Jun 29, 2012 at 4:54 PM, Jani Tiainen <redetin@gmail.com> wrote:
>> I meant that if for some reason Django sends incorrect content type from a
>> view or something like that your javascript framework might guess
>> incorrectly your ajax request content type and not parse script tags.
>
> Is there a way I can test to see if this is occurring?
>
>
>>
>>
>> On Sat, Jun 30, 2012 at 1:51 AM, Jani Tiainen <redetin@gmail.com> wrote:
>>>
>>> It's known limitation of your ajax request and has nothing to do with
>>> Django nor templates. Or well it might do.
>>>
>>> Most of the javascript frameworks can extract script and inject it
>>> correctly to current DOM. Since you mention jquery I guess that you're using
>>> that for ajax queries so make sure that your $.ajax() has dataType attribute
>>> to set as 'html'. It should (according to docs) parse script parts
>>> correctly.
>>>
>>>
>>> On Fri, Jun 29, 2012 at 11:45 PM, Larry Martell <larry.martell@gmail.com>
>>> wrote:
>>>>
>>>> I have a django template that has some javascript/jQuery code in it
>>>> that defines some keyup event handers. If a user goes to the URL
>>>> directly the javascript is executed, and the event handers all work
>>>> fine. There is also a field that they can type in that triggers the
>>>> same URL request to be sent via ajax. When they do this, it seems that
>>>> the html is rendered, but the javascript is not executed. I discovered
>>>> this by noticing that the page was rendered, but none of the
>>>> javascript event handers were being called. I proved this by adding:
>>>>
>>>>
>>>> <script type="text/javascript">
>>>> alert('here we are');
>>>> </script>
>>>>
>>>> to the template, and the alert doesn't show when the request comes
>>>> from ajax. But if I go to the URL directly it does.
>>>>
>>>> Is this a known issue? Is there some way I can get my javascript code
>>>> to run to install my event handlers when the request comes from ajax?
>>>>
>>>> TIA!
>>>> -larry
>>>>
>>>> --
>>>> You received this message because you are subscribed to the Google Groups
>>>> "Django users" group.
>>>> To post to this group, send email to django-users@googlegroups.com.
>>>> To unsubscribe from this group, send email to
>>>> django-users+unsubscribe@googlegroups.com.
>>>> For more options, visit this group at
>>>> http://groups.google.com/group/django-users?hl=en.
>>>>
>>>
>>>
>>>
>>> --
>>> Jani Tiainen
>>>
>>> - Well planned is half done, and a half done has been sufficient before...
>>>
>>
>>
>>
>> --
>> Jani Tiainen
>>
>> - Well planned is half done, and a half done has been sufficient before...
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To post to this group, send email to django-users@googlegroups.com.
>> To unsubscribe from this group, send email to
>> django-users+unsubscribe@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/django-users?hl=en.
>
> --
> You received this message because you are subscribed to the Google Groups "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
>
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
would poking around from a suitably placed pdb.set_trace()
On Fri, Jun 29, 2012 at 8:42 PM, Larry Martell <larry.martell@gmail.com> wrote:
> On Fri, Jun 29, 2012 at 4:54 PM, Jani Tiainen <redetin@gmail.com> wrote:
>> I meant that if for some reason Django sends incorrect content type from a
>> view or something like that your javascript framework might guess
>> incorrectly your ajax request content type and not parse script tags.
>
> Is there a way I can test to see if this is occurring?
>
>
>>
>>
>> On Sat, Jun 30, 2012 at 1:51 AM, Jani Tiainen <redetin@gmail.com> wrote:
>>>
>>> It's known limitation of your ajax request and has nothing to do with
>>> Django nor templates. Or well it might do.
>>>
>>> Most of the javascript frameworks can extract script and inject it
>>> correctly to current DOM. Since you mention jquery I guess that you're using
>>> that for ajax queries so make sure that your $.ajax() has dataType attribute
>>> to set as 'html'. It should (according to docs) parse script parts
>>> correctly.
>>>
>>>
>>> On Fri, Jun 29, 2012 at 11:45 PM, Larry Martell <larry.martell@gmail.com>
>>> wrote:
>>>>
>>>> I have a django template that has some javascript/jQuery code in it
>>>> that defines some keyup event handers. If a user goes to the URL
>>>> directly the javascript is executed, and the event handers all work
>>>> fine. There is also a field that they can type in that triggers the
>>>> same URL request to be sent via ajax. When they do this, it seems that
>>>> the html is rendered, but the javascript is not executed. I discovered
>>>> this by noticing that the page was rendered, but none of the
>>>> javascript event handers were being called. I proved this by adding:
>>>>
>>>>
>>>> <script type="text/javascript">
>>>> alert('here we are');
>>>> </script>
>>>>
>>>> to the template, and the alert doesn't show when the request comes
>>>> from ajax. But if I go to the URL directly it does.
>>>>
>>>> Is this a known issue? Is there some way I can get my javascript code
>>>> to run to install my event handlers when the request comes from ajax?
>>>>
>>>> TIA!
>>>> -larry
>>>>
>>>> --
>>>> You received this message because you are subscribed to the Google Groups
>>>> "Django users" group.
>>>> To post to this group, send email to django-users@googlegroups.com.
>>>> To unsubscribe from this group, send email to
>>>> django-users+unsubscribe@googlegroups.com.
>>>> For more options, visit this group at
>>>> http://groups.google.com/group/django-users?hl=en.
>>>>
>>>
>>>
>>>
>>> --
>>> Jani Tiainen
>>>
>>> - Well planned is half done, and a half done has been sufficient before...
>>>
>>
>>
>>
>> --
>> Jani Tiainen
>>
>> - Well planned is half done, and a half done has been sufficient before...
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To post to this group, send email to django-users@googlegroups.com.
>> To unsubscribe from this group, send email to
>> django-users+unsubscribe@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/django-users?hl=en.
>
> --
> You received this message because you are subscribed to the Google Groups "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
>
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: javascript in django template not executed when request is sent via ajax
If your web server is in fact serving the content with the incorrect Content-Type header (You can verify this by inspecting the response in the Net tab of Firebug or Chrome) jQuery can convert the response regardless of the content-type if you specify a two space-separated values in your dataType. Try dataType: "text html" in your $.ajax function.
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/XB_Q1y7lXlQJ.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/XB_Q1y7lXlQJ.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: adding fields into another apps forms (in plugin style)
I think he wants to load the plugins in a dynamic way. If you look how the admin package of django works you will have the answer:
The class AdminSite has a method register, which adds a model, on which the site builds itself. So each plugin can register its own admin stuff in a admin module.
Your task is to write your own class that registers plugins and to make a global instance of it.
Am Mittwoch, 19. Januar 2011 15:38:07 UTC+1 schrieb Shawn Milochik:
You received this message because you are subscribed to the Google Groups "Django users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/tkvtGsvvXm8J.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
The class AdminSite has a method register, which adds a model, on which the site builds itself. So each plugin can register its own admin stuff in a admin module.
Your task is to write your own class that registers plugins and to make a global instance of it.
Am Mittwoch, 19. Januar 2011 15:38:07 UTC+1 schrieb Shawn Milochik:
You can just subclass the form or modelform.--Shawn
You received this message because you are subscribed to the Google Groups "Django users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/tkvtGsvvXm8J.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: invalid keyword argument for this function
Yes its different.I was trying to say i tried your way and get rid of that error.
Thanks
--
Regards
Nikhil Verma
+91-958-273-3156
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Thanks
On Sat, Jun 30, 2012 at 8:56 PM, Sunny Nanda <snanda85@gmail.com> wrote:
This is a different error, and I don't see anything in the code snippet that might have caused this error (except if you are doing something in the Event model's save method)You would need to debug it further, and pinpoint the location of this error.
On Saturday, June 30, 2012 8:37:34 PM UTC+5:30, Nikhil Verma wrote:Yes its with the braces ")" also.On Sat, Jun 30, 2012 at 8:36 PM, Nikhil Verma <varma.nikhil22@gmail.com> wrote:
Hi Sunny
I am trying with this
event_genre = event_form.cleaned_data['event_genre']
event_public = event_form.cleaned_data['event_public']
event_obj.save()
category_obj.event_genre.add(event_genre),
category_obj.event_public.add(event_public
and getting this traceback:-Exception Value: int() argument must be a string or a number, not 'QuerySet'
Exception Type: TypeError at /event/createevent/On Sat, Jun 30, 2012 at 8:30 PM, Sunny Nanda wrote:
Hi Nikhil,Just to reiterate :), you need to remove both event_public & even_genre while creating the instance of the model, since both of them are M2M Fields. Take a look at the example in my previous mail.If you are getting this exception somewhere else, please send that code snippet so we might able to see the problem.
Thanks,Sandeep
On Saturday, June 30, 2012 8:14:28 PM UTC+5:30, Nikhil Verma wrote:Hi Sunny
I realized that earlier sunny, and cleared that defect but i get stuck into this error
Traceback:
Exception Type: TypeError at /event/createevent/
Exception Value: 'event_genre' is an invalid keyword argument for this function
Any help ?
Thanks in advanceOn Sat, Jun 30, 2012 at 7:08 PM, Sunny Nanda wrote:
Hi Nikhil,--You can not use an object's M2M field until it has been saved to the db.
So, you would have to call the "save" method on the instance, or use "create" method to create the instance.category_obj = Category.objects.create(
type = categoryform.cleaned_data['type']
)
event_public = categoryform.cleaned_data['event_public']
event_genre = categoryform.cleaned_data['event_genre']
category_obj.event_genre.add(event_genre),
category_obj.event_public.add(event_public),
# No need to call save here
# category_obj.save()The reason behind this is that M2M Fields are represented by intermediate tables with references to the two linked objects. If you need to add a row in it, both referenced objects should already be saved in the db with valid primary keys.
H2H-Sandeep
On Saturday, June 30, 2012 1:21:30 PM UTC+5:30, Nikhil Verma wrote:Hi All
I have the following models like this :-
class EventGenre(models.Model):
genre_choices = models.CharField(max_length=255)
def __unicode__(self):
return self.genre_choices
class EventPublic(models.Model):
choicelist = models.CharField(max_length=255)
def __unicode__(self):
return self.choicelist
class Category(models.Model):
"""
Describes the Event Category
"""
type = models.CharField(max_length=20,\
choices=EVENT_TYPE,\
help_text = "type of event"
)
# Genre of event like classical,rock,pop ,indie etc
event_genre = models.ManyToManyField(EventGenre)
# audience for this event like adults ,children etc
event_public = models.ManyToManyField(EventPublic)
def __unicode__(self):
return self.type
This is my category form
class CategoryForm(forms.Form):
type = forms.CharField(max_length=80, \
widget=RadioSelect(choices=EVENT_TYPE)
)
event_genre = forms.ModelMultipleChoiceField(
queryset = EventGenre.objects.all(),
widget=CheckboxSelectMultiple,
required=False
)
event_public = forms.ModelMultipleChoiceField(
queryset = EventPublic.objects.all(),
widget=CheckboxSelectMultiple,
required=False
)
This is my views.py
def eventcreation(request):
if request.method == "POST":
event_form = EventForm(request.POST,request.FILES,prefix="eventform")
categoryform = CategoryForm(request.POST)
if event_form.is_valid():
event_obj = Event(
venue_name = event_form.cleaned_data['venue_name'],
date_created = event_form.cleaned_data['event_start_date'],
date_completed = event_form.cleaned_data['event_end_date'],
event_ticket_price = event_form.cleaned_data['event_ticket_price'],
eventwebsite = event_form.cleaned_data['eventwebsite'],
keyword = event_form.cleaned_data['keyword'],
description = event_form.cleaned_data['description'],
status = event_form.cleaned_data['status'],
event_poster = event_form.cleaned_data['event_poster']
)
if categoryform.is_valid():
category_obj = Category(
type = categoryform.cleaned_data['type'],
event_public = categoryform.cleaned_data['event_public'], # It is giving error
event_genre = categoryform.cleaned_data['event_genre'], # It is giving error
)
category_obj.event_genre.add(event_genre),
category_obj.event_public.add(event_public),
category_obj.save()
else:
print "Form is getting Invalid"
else:
event_form = EventForm()
categoryform = CategoryForm()
return render_to_response('event/event.html',
{
'eventform':event_form,
'categoryform':categoryform,
},
context_instance=RequestContext(request)
)
I am trying to add a ManyToMany Field and gets this traceback :-
Exception Type: TypeError at /event/createevent/
Exception Value: 'event_public' is an invalid keyword argument for this function
Can anybody point out whats going wrong ?
Thanks in advance.
--
Regards
Nikhil Verma
+91-958-273-3156
You received this message because you are subscribed to the Google Groups "Django users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/9y6fVygzELMJ.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
--
Regards
Nikhil Verma
+91-958-273-3156
To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/zrcm159aC3YJ.--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
--
Regards
Nikhil Verma
+91-958-273-3156
--
Regards
Nikhil Verma
+91-958-273-3156
To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/Ft4a4VmU_sgJ.--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
--
Regards
Nikhil Verma
+91-958-273-3156
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Use regular expression to retrieve all image tags from a given content
Why not use html parse lib? BeautifulSoup(http://www.crummy.com/software/BeautifulSoup/) for expample
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/wAd5IjIA8ngJ.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
from BeautifulSoup import BeautifulSoup
soup = BeautifulSoup('put_youp_html_code_as_string')
images = soup.find_all('img')
If you need exactly regular expressions, watch this video: http://www.youtube.com/watch?v=kWyoYtvJpe4
суббота, 30 июня 2012 г., 20:37:13 UTC+8 пользователь mo.mughrabi написал:
суббота, 30 июня 2012 г., 20:37:13 UTC+8 пользователь mo.mughrabi написал:
Hello,am really a noob with regular expressions, I tried to do this on my own but I couldn't understand from the manuals how to approach it. Am trying to find all img tags of a given content, I wrote the below but its returning None
content = i.content[0].value
prog = re.compile(r'^<img')
result = prog.match(content)
print resultany suggestions?
You received this message because you are subscribed to the Google Groups "Django users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/wAd5IjIA8ngJ.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Subscribe to:
Posts (Atom)