django-views

'Invalid Syntax' error with two methods in Django views.py

I have two methods defined in views.py. the first one calls the second one: @login_required def form1(request): if request.method == 'POST': form = JobForm(request.POST) if form.is_valid(): obj = form.save(commit=False) obj.user = request.user obj.save() return HttpResponseRed...

Jquery datatable pagination

In the below code ,the html loads up and will call group_map set python function.My question is that there is pagination enabled in the system so if a user in page 3 deletes a entry the page reloads and brings back to page 1.How to make the user stay on the same page after deleting an entry Datatable used is from http://www.datatables....

Output of proc.communicate() does not format newlines in django python

I have a subprocess using communicate to get the output ans saving it to my database: p = Popen([str(pre_sync), '-avu', str(src), str(dest)], stdout=PIPE) syncoutput = p.communicate() check.log = syncoutput It all works fine, but the output from communicate looks like this: ('sending incremental file list\n\nsent 89 bytes rece...

Django Order_by blank

Hi, I have a simple model title = models.CharField(max_length=250) url = models.CharField(max_length=250) title_french = models.CharField(max_length=250) I want to order it via title_french, however when it orders in A-Z in this way, all the blank values are at the top. In the case ot blank values I display the English title. So I g...

Decode values of a tuple in django template

if(len(f1) > 0): for qs in profile_map: up = Profile.objects.get(pk=qs.emp.id) t_name = up.first_name + up.last_name t_arr.append((q.profile.id,emp_name)) response_dictionary.update({'tarr':t_arr}) render_to_response('project/profile_table.html',context_instance=RequestContext(request,{'response_dict...

Django: Count objects in a particular month

I have this model: class Person(models.Model): city = models.CharField(max_length=20, blank=True) added_date = models.DateField(default=datetime.date.today) I want to create a template/view that has a table of months and the number of people added that month (ie, 5 in january, 10 in february, 8 in march, etc.). I have a similar ...

Abstract Django Application from "Project"

Hi All, I'm struggling to work out how best to do what I think I want to do - now it may be I don't have a correct understanding of what's best practice, so if not, feel free to howl at me etc. Basically, my question is, how do I abstract application functionality correctly, said functionality being found in an application that is part...

Is it possible to pass SafeData instances to Django templates?

I know that it's possible to have a template filter return a SafeData instance by doing something similar to the following. from fictitious import guaranteed_safe from django.utils.safestring import mark_safe def myfilter(text): return mark_safe(guaranteed_safe(text)) My question is whether it's possible to "mark as safe" variab...

Django Testing: determine which view was executed

In the Django testing documentation they promise that you can "Test that the correct view is executed for a given URL." However I didn't find any possibility how to test which view was executed. I would expect that in the Response class but there's nothing about the executed view. Thanks in advance. ...

Django, how to update fields in a model without creating a new record?

I have a model in django that I want to update only, that is, when I call it and set the data, it will not create a new record, only update the existing one. How can I do this? Here is what I have: class TemperatureData(models.Model): date = models.DateTimeField() value = models.PositiveIntegerField() alert = models.Boole...

Deletion of a particular record in django

If a model exist like class Empprofile(models.Model): name= models.CharField(max_length=255) group = models.CharField(max_length=255) description = models.CharField(max_length=1024) class Details(Empprofile): address1=models.CharField(max_length=255) address2=models.CharField(max_lengt...

django query using and clause

How to use and clause in Django For ex: select Date(timestamp) from userlog where (Date(timestamp) >= "2008-01-02" and Date(timestamp) <= "2009-01-02") and ipaddress != "192.168.2.211"; Django query: userlog.objects.filter(timestamp__range=(startdate,enddate),ipaddress !="192.168.2.211") In the above there is an error ...

Django restart server or httpd

In django framework,When there are changes in urls.py or model.py or views.py .We would restart httpd. But as the documentation says we could restart runserver to get the latest changes. Which is the best efficient way for doing the above ...

How can I start a python subprocess command on linux shell from within Django web app?

Hi, I have a web app which reads and displays log files generated by python test files. Currently I can launch the python files from cli and it works fine. However I would like to be able to launch python tests from within the application. At the minute I have a "Launch test" button which calls a function in the views.py file def lau...

Two foreign keys and a value in django template

I am a newbie to django, so the question might be dumb, but please feel free to teach me the right way if you know it. I tried googling the issue, but I am still at loss. Here's my problem: I have a class in my model that has two foreign keys: class X(models.Model): name = models.CharField(max_length=30) def __unicode__(self): ...

How to capture multiple arguments using a single RegEx in my Django urls.py?

I've got an application that allows you to filter data via 3 fields. I'm trying to write a RegEx in my urls.py that can capture multiple combinations without having to write-out each possible combination it it's own URL. Here's my urls.py: #urls.py urlpatterns = patterns('', # Uncomment the next line to enable the admin: (r...

Refreshing table with Dajaxice in Django

I'm monitoring the temperature for different locations. I have the data stored in a model and have set my views.py, but I would like to refresh the table every 5 minutes. I'm new to ajax and dajaxice, how can I write the function so it displays in html? this is my views.py: def temperature(request): temperature_dict = {} for filter_...

Django string in unicode pattern

Django when i send the following string from an ajax submit i get the following string in unicode.How to decode this $.post("/records/save_t/",snddata, function(data){ if(data == 0 ){ } },"json"); In django def save_t(request): if request.method == 'GET': qd = request.GET elif request.method =...

add request.GET variable using django.shortcuts.redirect

Is possible to add GET variables in a redirect ? (Without having to modifiy my urls.py) If I do redirect('url-name', x) I get HttpResponseRedirect('/my_long_url/%s/', x) I don't have complains using HttpResponseRedirect('/my_long_url/%s/?q=something', x) instead, but just wondering... ...

Refresh div using JQuery in Django while using the template system

I want to refresh a in django that contains temperature data. The data is fetched every 20 seconds. So far I have achieved this using these functions: function refresh() { $.ajax({ url: '{% url monitor-test %}', success: function(data) { $('#test').html(data); } }); }; $(function(){ refresh(); var int = setInterval("ref...