Django Site(s) looks ugly with ?None as query parameter.

2014-03-06 Thread Christian Schmitt
Hello, currently I have some Django sites one of them 
is http://www.schnooge-hansili.de/ if i open it 
with http://www.schnooge-hansili.de/?None It looks really ugly. Currently 
the first site is just a simple CBV view. Nothing really special.

-- 
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/cedd2c00-f95f-4582-b8b4-9845b2f39f75%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Message Framework fails on Django 1.6

2013-11-08 Thread Christian Schmitt
Hello, currently I try to use the Django Message Framework, but it will 
always fail with:

> You cannot add messages without installing 
django.contrib.messages.middleware.MessageMiddleware

My middleware, etc:

MIDDLEWARE_CLASSES = (
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
# Uncomment the next line for simple clickjacking protection:
# 'django.middleware.clickjacking.XFrameOptionsMiddleware',
)

TEMPLATE_CONTEXT_PROCESSORS = (
"django.contrib.auth.context_processors.auth",
"django.core.context_processors.debug",
"django.core.context_processors.i18n",
"django.core.context_processors.media",
"django.core.context_processors.static",
"django.core.context_processors.tz",
"django.contrib.messages.context_processors.messages"
)

INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
# Uncomment the next line to enable the admin:
'django.contrib.admin',
# Uncomment the next line to enable admin documentation:
# 'django.contrib.admindocs',
'south',
'kombu.transport.django',
'djcelery',
...
)

-- 
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/34638999-f278-44d1-bc7a-de05fb3aeb84%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: PDF generator in Django

2013-08-06 Thread Christian Schmitt
We use Weasyprint.
http://weasyprint.org/

Am Montag, 5. August 2013 08:48:40 UTC+2 schrieb navnath gadakh:
>
> Which is best tool to generate PDF in python django
>

-- 
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.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Django App - Accessing Remote MySQL Database

2013-08-02 Thread Christian Schmitt
You could use django's inbuild ORM:
https://docs.djangoproject.com/en/dev/topics/db/multi-db/
And just copy the database.

Am Freitag, 2. August 2013 02:50:35 UTC+2 schrieb Ji Park:
>
> Hello, I'm trying to make an app that can periodically access a remote 
> mysql database.
>
> This app will query the remote database and copy some data to the local 
> postgresql database.
>
> So far I know that celery can be used to schedule periodic tasks, but I'm 
> not sure what to do about querying the remote mysql database server.
>
> Should I just use python's MySQLdb module, does anyone know any other 
> python module that I can use to query mysql db?
>
> Would this even be a good way to access remote database server from a 
> django app? I'll have to be running a function that is within tasks.py 
> periodically (via celery-django), would there be any better way to access 
> remote mysql server from a django app in this case?
>

-- 
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.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Ajax

2013-06-30 Thread Christian Schmitt
Every Framework supports Ajax. But as i already mentioned and as already 
talked about in the django-developers, the support of serialization and 
other things is really really crappy and needs to be fixed.
Especially SPA sites needs some love. I mean in the core Django is cool, 
and since the new cbv's i really love django and the ajax support is better 
now, but some things are still messy.

Am Sonntag, 30. Juni 2013 02:24:30 UTC+2 schrieb Russell Keith-Magee:
>
>
> On Sat, Jun 29, 2013 at 11:51 PM, Gamesbrainiac 
>  > wrote:
>
>> Sorry, was on a mobile phone. Let me give you exact link, please excuse 
>> me being a little stupid.
>>
>> https://code.djangoproject.com/wiki/AJAX -> First line, "Django does not 
>> natively support Ajax". 
>>
>
> That comment is on the wiki. The wiki can be contributed by anybody, and 
> isn't reviewed by the core team. As a result, the advice found there can 
> often be wrong or misleading.
>
>  Allow me to confirm that the advice that Django "doesn't support AJAX" is 
> *incorrect*. I've just corrected the wiki page.
>
> Yours,
> Russ Magee %-)
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Ajax

2013-06-29 Thread Christian Schmitt
It would be great if serializers also supports a single object, that would 
make ajax requests better and / or json support for forms.
like that:
serializers.serialize('json', object) and not [object] and then i need to 
strip the [] tags.
also the serializers is really hard to use to make more objects as a 
response.

a datastructure like this:
dict = {
'object1': object ,
'list-of-objects': [object],
}
is really hard to achieve with the current implemented functionallity.

at the moment i need to do the following:
dict = {
'single-object': json.loads(serializers.serialize('json', 
[object]).lstrip('[').rstrip(']'))
'object-list': serializers.serialize('json', object-list)
}
json.dumps(dict)

i don't thinkt it is the best way to do.
Also I think the template engine is really 'outdated' and 'slow' compared 
to closure-templates, which i could use on the server-side and on the 
template side. (but currently i'm planning to make a python/django version 
of them to implement them).

Also SPA sites are coming so maybe a 'good' way to get the current history 
so that you could easily render a page when starting a page from something 
like http://www.page.com/#backend or something like that. maybe this is 
really hard to achieve, since the history is on the client side, but i 
think it would be great to have a better javascript client library for 
django that could do this job like django.contrib.ajax.history which could 
also be called with a jquery plugin.
I mean i can't replace the whole url with javascript/ajax, i can only 
change the last part behind #.
maybe there are a lot of things to do, to make django fully aware of Ajax.

the thing is at the moment there is no good answer to have both worlds. a 
server-side-framework that also has a good client-side-framework. ok there 
a plenty of answers, but not in python, only in java. (gwt, eclipse rap, 
javafx) but in python you can only have one and you need to do both things 
really good. 
so it makes it very hard to write good code, since you always need to 
implement both sides. i mean this wouldn't be a problem when some things 
would be easier.
as already said the serializers needs some work, the template engine and 
many things i don't even have on my mind. but for the start a better 
serializers would be great.

(also you need to return a json object to serializers if you have foreign 
keys to make use of them in some situations or you make dozen of new http 
request for every new object would could be a pain in the a**)

Am Samstag, 29. Juni 2013 12:05:33 UTC+2 schrieb Russell Keith-Magee:
>
>
> Can you provide a little more direction than "The website"? "The website" 
> is a kinda big place… :-)
>
> Yours,
> Russ Magee %-)
>
> On Sat, Jun 29, 2013 at 2:08 PM, Gamesbrainiac 
>  > wrote:
>
>> Then why does itsay on the website that Django does not support Ajax 
>> natively?
>> On Jun 29, 2013 12:03 PM, "Russell Keith-Magee" 
>>  
>> wrote:
>>
>>>
>>> I'm not sure what you mean. Django completely supports AJAX right now. 
>>>
>>> Django is a server-side framework, and the only part of AJAX that is 
>>> server-side is the API call. 
>>>
>>> An API call is just a view that returns JSON/XML instead of HTML. You 
>>> can write that right now in Django.
>>>
>>> If you want a library to make it even easier, there are several options, 
>>> including TastyPie and Django-REST-Framework.
>>>
>>> The client-side part of the AJAX problem is outside the domain of 
>>> Django. There are plenty of good client-side frameworks; pick one, and 
>>> you'll find it can talk perfectly well with Django.
>>>
>>> Yours,
>>> Russ Magee %-)
>>>
>>> On Sat, Jun 29, 2013 at 1:52 PM, Nafiul Islam 
>>> >> > wrote:
>>>
 In which version, will Django natively support Ajax? I'm curious 
 because you need Ajax for almost any site these days, and Django not 
 supporting it natively has become a bit of a hindrance for me. 

 -- 
 You received this message because you are subscribed to the Google 
 Groups "Django users" group.
 To unsubscribe from this group and stop receiving emails from it, send 
 an email to django-users...@googlegroups.com .
 To post to this group, send email to 
 django...@googlegroups.com
 .
 Visit this group at http://groups.google.com/group/django-users.
 For more options, visit https://groups.google.com/groups/opt_out.
  
  

>>>
>>>  -- 
>>> You received this message because you are subscribed to a topic in the 
>>> Google Groups "Django users" group.
>>> To unsubscribe from this topic, visit 
>>> https://groups.google.com/d/topic/django-users/2oaiisZw_ZY/unsubscribe.
>>> To unsubscribe from this group and all its topics, send an email to 
>>> django-users...@googlegroups.com .
>>>
>>> To post to this group, send email to django...@googlegroups.com
>>> .
>>> Visit this group at http://groups.google.com/group/django-users.
>>> For 

Re: How to divide my apps? Good practices?

2013-06-21 Thread Christian Schmitt
That is fine in one app. just seperate them. delete models.py and make a 
package named models. import every model in the __init__.py file from 
models.py, make sure u set a class Meta: app_label = 'your app name' to 
every model and you have a very clean app structure.

Am Freitag, 21. Juni 2013 18:29:44 UTC+2 schrieb galgal:
>
> But I can see now that there will be a massive amount of models. Each 
> player should have his own statistics for each games, there will also be a 
> part for referees. Referee work will be rated by users so - many models is 
> planned. If I put it in one app, I will have at least 15 models in it and I 
> think it will increase in some time
>
> Division in my example will clarify it, for example players app with all 
> models for players like player base, player in season, player statistics 
> and of course all logic in it.
>
> In 1 app there will be a many many lines of code and after some time it 
> will be hard to develop I think.
>
>

-- 
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.
For more options, visit https://groups.google.com/groups/opt_out.




Re: How to divide my apps? Good practices?

2013-06-21 Thread Christian Schmitt
You shouldn't divine things that should be together. Better make things 
together like, game, forum, blog. Don't make a app for too many things.

-- 
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.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Object Lookup after Save

2013-05-22 Thread Christian Schmitt
if you want transactions you need to do :

with transaction.atomic():


like described here: 
https://docs.djangoproject.com/en/dev/topics/db/transactions/

Am Mittwoch, 22. Mai 2013 10:40:15 UTC+2 schrieb Christian Schmitt:
>
> In Django the normal behavior should be that when you do a save() it will 
> automatically commit() your query's to the database.
> so that in obj.save() you should just could access the pk with obj.idafter 
> you did a obj.save().
> If you want to maybe stop the commit you need to do a obj = 
> obj.save(commit=False), then you could add some things to your obj and 
> commit/save it later.
> But as i understood you already do a obj.save() but it doesn't commit 
> correctly? Maybe you should just try a PostgreSQL database for testing, 
> since I'm not having trouble looking up objects after i saved it.
>
> I often do things like:
> obj.save()
> return HttpResponseRedirect(reverse('view', {'pk': obj.id}))
> and i never run into any exception
>
>
> Am Dienstag, 21. Mai 2013 23:20:53 UTC+2 schrieb Chris Conover:
>>
>> Calling transaction.commit() after object.save results in 
>> a TransactionManagementError. I mentioned at the end that I am using MySQL 
>> (5.5.27). The issue is not that the Gearman workers are having trouble 
>> saving their transactions, it's that they are having trouble looking up the 
>> incoming object. I'm assuming the view and workers are separate 
>> transactions since I don't see how they could be connected -- though I'm 
>> looking into this. 
>>
>> On Tuesday, May 21, 2013 1:05:54 PM UTC-4, Tom Evans wrote:
>>>
>>> On Tue, May 21, 2013 at 4:23 PM, Chris Conover <clc...@gmail.com> 
>>> wrote: 
>>> > Hello, 
>>> > 
>>> > I'm having an issue looking up objects immediately after they are 
>>> saved and 
>>> > am wondering if anyone has any advice on how to address the problem. 
>>> > Specifically, I'm saving an object in a view (nothing fancy, a simple 
>>> > save()) and then kicking off a Gearman task to do some operations on 
>>> that 
>>> > saved object in the background. I pass the newly created object's PK 
>>> as data 
>>> > to the Gearman worker which then does a simple 
>>> Objects.objects.get(pk=PK). 
>>> > However, almost all of the time this lookup operation fails with an 
>>> > DoesNotExist exception. I believe the problem has to do with 
>>> transactions. 
>>> > Namely, the read in the Gearman worker is happening before the write 
>>> from 
>>> > the view is committed to the database. I've tried several things 
>>> including 
>>> > refactoring the saving code to be wrapped in a 
>>> > @transaction.commit_on_success block, moving the worker submission to 
>>> > post_save and adding a long delay before the Gearman worker does the 
>>> lookup. 
>>> > Nothing really seems to solve the problem completely. Even with a 60 
>>> second 
>>> > delay, the lookup fails with some frequency. Am I missing something 
>>> here? Is 
>>> > there some Django query cache that I can clear? Or should I just 
>>> rewrite all 
>>> > this to just to use a look-back perspective. 
>>> > 
>>> > The stack is Django 1.4 connecting to MySQL 5.5.27. Django is handling 
>>> > 200-1000 requests per second and the database is handling about double 
>>> that. 
>>> > 
>>> > Thanks, 
>>> > Chris 
>>>
>>>   from django import transaction 
>>>   … 
>>>   obj.save() 
>>>   transaction.commit() 
>>>   task.submit(obj.id) 
>>>
>>> You will also need to make sure that gearman is doing things correctly 
>>> as well. You haven't mentioned what database you are using, but if 
>>> gearman's DB connection is in a read repeated mode, you can do 
>>> whatever you like in django but you won't see new data in gearman 
>>> until gearman's current transaction is committed. 
>>>
>>> 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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Object Lookup after Save

2013-05-22 Thread Christian Schmitt
In Django the normal behavior should be that when you do a save() it will 
automatically commit() your query's to the database.
so that in obj.save() you should just could access the pk with obj.id after 
you did a obj.save().
If you want to maybe stop the commit you need to do a obj = 
obj.save(commit=False), then you could add some things to your obj and 
commit/save it later.
But as i understood you already do a obj.save() but it doesn't commit 
correctly? Maybe you should just try a PostgreSQL database for testing, 
since I'm not having trouble looking up objects after i saved it.

I often do things like:
obj.save()
return HttpResponseRedirect(reverse('view', {'pk': obj.id}))
and i never run into any exception


Am Dienstag, 21. Mai 2013 23:20:53 UTC+2 schrieb Chris Conover:
>
> Calling transaction.commit() after object.save results in 
> a TransactionManagementError. I mentioned at the end that I am using MySQL 
> (5.5.27). The issue is not that the Gearman workers are having trouble 
> saving their transactions, it's that they are having trouble looking up the 
> incoming object. I'm assuming the view and workers are separate 
> transactions since I don't see how they could be connected -- though I'm 
> looking into this. 
>
> On Tuesday, May 21, 2013 1:05:54 PM UTC-4, Tom Evans wrote:
>>
>> On Tue, May 21, 2013 at 4:23 PM, Chris Conover  wrote: 
>> > Hello, 
>> > 
>> > I'm having an issue looking up objects immediately after they are saved 
>> and 
>> > am wondering if anyone has any advice on how to address the problem. 
>> > Specifically, I'm saving an object in a view (nothing fancy, a simple 
>> > save()) and then kicking off a Gearman task to do some operations on 
>> that 
>> > saved object in the background. I pass the newly created object's PK as 
>> data 
>> > to the Gearman worker which then does a simple 
>> Objects.objects.get(pk=PK). 
>> > However, almost all of the time this lookup operation fails with an 
>> > DoesNotExist exception. I believe the problem has to do with 
>> transactions. 
>> > Namely, the read in the Gearman worker is happening before the write 
>> from 
>> > the view is committed to the database. I've tried several things 
>> including 
>> > refactoring the saving code to be wrapped in a 
>> > @transaction.commit_on_success block, moving the worker submission to 
>> > post_save and adding a long delay before the Gearman worker does the 
>> lookup. 
>> > Nothing really seems to solve the problem completely. Even with a 60 
>> second 
>> > delay, the lookup fails with some frequency. Am I missing something 
>> here? Is 
>> > there some Django query cache that I can clear? Or should I just 
>> rewrite all 
>> > this to just to use a look-back perspective. 
>> > 
>> > The stack is Django 1.4 connecting to MySQL 5.5.27. Django is handling 
>> > 200-1000 requests per second and the database is handling about double 
>> that. 
>> > 
>> > Thanks, 
>> > Chris 
>>
>>   from django import transaction 
>>   … 
>>   obj.save() 
>>   transaction.commit() 
>>   task.submit(obj.id) 
>>
>> You will also need to make sure that gearman is doing things correctly 
>> as well. You haven't mentioned what database you are using, but if 
>> gearman's DB connection is in a read repeated mode, you can do 
>> whatever you like in django but you won't see new data in gearman 
>> until gearman's current transaction is committed. 
>>
>> 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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Custom RadioSelect() Label from Model Data

2013-05-21 Thread Christian Schmitt
Hello, is there a way to get a Custom Label for a RadioSelect() widget?

I have a Model and wanted to get a label like:

'
 
{{ customer.name }}
{{ customer.address.city }}
{{ customer.address.zip }}
'

Is there a way to get certain output?
I heard about the RadioSelect Renderer but i can only access the 
__unicode__ output i definied for the model. Is there a better / other way 
to implement such functionallity?

-- 
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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: ajax get json not receive data from django

2013-05-17 Thread Christian Schmitt
Its better to use json instead of simplejosn : json.dumps() also csrf 
shouldn't be your case else you would've get an 405 error. 200 requests are 
fine, what does firebug says about the request? normally there would be a 
tab called json where you could see the values that got through the 
request. 
Also parseJSON makes no sense since you've already got json. try something 
like alert(data.key1) or alert(data);

Am Donnerstag, 16. Mai 2013 17:26:44 UTC+2 schrieb Alex Chiaranda:
>
> aren't you missing the csrf_token ?
>
> https://docs.djangoproject.com/en/dev/ref/contrib/csrf/#ajax
>
> On Thursday, May 16, 2013 8:53:36 AM UTC-3, Hai Nguyen wrote:
>>
>> Thanks you for your answer.
>> I'm trying to change  mimetype="application/json; charset=utf-8" but 
>> could not resolve problem
>>
>> On Thursday, May 16, 2013 3:02:52 PM UTC+7, Zoltán Bege wrote:
>>>
>>> I mean HttpResponse. Sorry! :)
>>>
>>> Hi,

 You should change the mimetype on HttpResponse from 
 mimetype="application/
 javascript;charset=UTF-8" to mimetype="application/json; charset=utf-8".



-- 
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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




ModelForm localize on Select()??

2013-05-15 Thread Christian Schmitt
Hello,

I have a problem with localization and Select() Box, I have the values:
2.00
2.40
3.20
4.00
in my Database, but in Germany we use the number format:
2,00
2,40
3,20
4,00
Now I tried to Localize my modelform with:

class LocalizedModelForm(django.forms.ModelForm):
def __new__(cls, *args, **kwargs):
new_class = super(LocalizedModelForm, cls).__new__(cls)
for field in new_class.base_fields.values():
if isinstance(field, django.forms.DecimalField):
field.localize = True
field.widget.is_localized = True
if isinstance(field, django.forms.Select):
field.localize = True
field.widget.is_localized = True
return new_class

or even an __init__ with the following:
self.fields['endintensity'].localize = True
self.fields['endintensity'].widget.is_localized = True

But i still don't get the localized numbers?
How could i do this correctly??

-- 
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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Creating Tables w/o SyncDB (Django ORM)

2013-05-03 Thread Christian Schmitt
Hi there,
is there a possible way of creating tables with Django's ORM w/o SyncDB. It 
would be really helpfull, to make new tables while doing some UI 
interactions.

-- 
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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Django 1.5 CBV - DeleteView - CustomQuery

2013-03-21 Thread Christian Schmitt
Oh, yeah you gave me a good idea, but no, DELETE is fine. Since I wanted to 
do an ajax request anyway.

Am Donnerstag, 21. März 2013 14:22:59 UTC+1 schrieb Tom Christie:
>
> Actually you'll probably want the `delete` method to be a `post` instead,
> but either way hopefully it'll give you the right idea.
>
> On Thursday, 21 March 2013 13:11:44 UTC, Tom Christie wrote:
>>
>> In cases like this, rather than rely on overriding the default behavior 
>> of the DeleteView,
>> I'd recommend writing your own base class.
>>
>> It'll be more explicit and more obvious exactly what is going on...
>>
>> from django.views.generic import View
>>
>> class MarkDeletedView(View):
>> """
>> Base class for marking a model instance as deleted.
>> """
>> model = None
>> redirect_url = None
>>
>> def delete(self, request, *args, **kwargs):
>> assert self.model, "model attribute must be set"
>> assert self. redirect_url, "redirect_url attribute must be 
>> set"
>>
>> object = get_object_or_404(self.model, pk=kwargs['pk'])
>> if object.date_deleted is not None:
>> raise Http404
>> now = datetime.datetime.utcnow().replace(tzinfo=utc)
>> object.date_deleted = now.strftime("%Y-%m-%d %H:%M:%S")
>> object.save()
>> return HttpResponseRedirect(self.redirect_url)
>>
>> Then you can create a different view for each model you need this 
>> behavior on, like so...
>>
>> class CustomerDeleteView(MarkDeletedView):
>> model = Customer
>> redirect_view = reverse('customer-list')
>>
>> Hope that helps.
>>
>>   Tom
>>
>> On Thursday, 21 March 2013 12:39:34 UTC, Christian Schmitt wrote:
>>
>>> Hello guys,
>>> I have a question about the django CBV DeleteView, I want to use it but 
>>> not delete the element, i just want to set a delete_date so that it isn't 
>>> visible anymore.
>>>
>>> With FBV my view looked like this:
>>>
>>> def delete(request, customer_id):
>>> customer = get_object_or_404(Customer, pk=customer_id)
>>> if customer.date_deleted is not None:
>>> raise Http404
>>> now = datetime.datetime.utcnow().replace(tzinfo=utc)
>>> customer.date_deleted = now.strftime("%Y-%m-%d %H:%M:%S")
>>> customer.save()
>>> return HttpResponseRedirect()
>>>
>>> but know I want to change all my Views with CBVs but I really don't 
>>> understand how I could change the default query on DeleteView. Is there 
>>> somebody who could help me with it?
>>>
>>> I mean it is way easier than to Delete items, since I have one 
>>> DeleteView where I could use to Delete all items.
>>>
>>

-- 
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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Django 1.5 CBV - DeleteView - CustomQuery

2013-03-21 Thread Christian Schmitt
Hi, yeah that definitly helps.
I didn't found a good site where CBVs getting described in that way.
Is there a site, where I can found such things like

What happens in a CBV View? It's way easier to understand the whole CBV 
thing. 
Btw. FBVs are way easier than CBVs but with FBVs I need to copy & paste 
things like the MarkDeleteClass while in CBVs I could inherit from it.

Am Donnerstag, 21. März 2013 14:11:44 UTC+1 schrieb Tom Christie:
>
> In cases like this, rather than rely on overriding the default behavior of 
> the DeleteView,
> I'd recommend writing your own base class.
>
> It'll be more explicit and more obvious exactly what is going on...
>
> from django.views.generic import View
>
> class MarkDeletedView(View):
> """
> Base class for marking a model instance as deleted.
> """
> model = None
> redirect_url = None
>
> def delete(self, request, *args, **kwargs):
> assert self.model, "model attribute must be set"
> assert self. redirect_url, "redirect_url attribute must be set"
>
> object = get_object_or_404(self.model, pk=kwargs['pk'])
> if object.date_deleted is not None:
> raise Http404
> now = datetime.datetime.utcnow().replace(tzinfo=utc)
> object.date_deleted = now.strftime("%Y-%m-%d %H:%M:%S")
> object.save()
> return HttpResponseRedirect(self.redirect_url)
>
> Then you can create a different view for each model you need this behavior 
> on, like so...
>
> class CustomerDeleteView(MarkDeletedView):
>     model = Customer
> redirect_view = reverse('customer-list')
>
> Hope that helps.
>
>   Tom
>
> On Thursday, 21 March 2013 12:39:34 UTC, Christian Schmitt wrote:
>
>> Hello guys,
>> I have a question about the django CBV DeleteView, I want to use it but 
>> not delete the element, i just want to set a delete_date so that it isn't 
>> visible anymore.
>>
>> With FBV my view looked like this:
>>
>> def delete(request, customer_id):
>> customer = get_object_or_404(Customer, pk=customer_id)
>> if customer.date_deleted is not None:
>> raise Http404
>> now = datetime.datetime.utcnow().replace(tzinfo=utc)
>> customer.date_deleted = now.strftime("%Y-%m-%d %H:%M:%S")
>> customer.save()
>> return HttpResponseRedirect()
>>
>> but know I want to change all my Views with CBVs but I really don't 
>> understand how I could change the default query on DeleteView. Is there 
>> somebody who could help me with it?
>>
>> I mean it is way easier than to Delete items, since I have one DeleteView 
>> where I could use to Delete all items.
>>
>

-- 
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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Django 1.5 CBV - DeleteView - CustomQuery

2013-03-21 Thread Christian Schmitt
Hello guys,
I have a question about the django CBV DeleteView, I want to use it but not 
delete the element, i just want to set a delete_date so that it isn't 
visible anymore.

With FBV my view looked like this:

def delete(request, customer_id):
customer = get_object_or_404(Customer, pk=customer_id)
if customer.date_deleted is not None:
raise Http404
now = datetime.datetime.utcnow().replace(tzinfo=utc)
customer.date_deleted = now.strftime("%Y-%m-%d %H:%M:%S")
customer.save()
return HttpResponseRedirect()

but know I want to change all my Views with CBVs but I really don't 
understand how I could change the default query on DeleteView. Is there 
somebody who could help me with it?

I mean it is way easier than to Delete items, since I have one DeleteView 
where I could use to Delete all items.

-- 
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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: django generate pdf with tables and charts

2013-02-15 Thread Christian Schmitt
Maybe this Issue could help you 
http://code.google.com/p/wkhtmltopdf/issues/detail?id=948
Also pass --enable javascript and the javascript delay to wkhtmltopdf

Am Donnerstag, 14. Februar 2013 15:45:38 UTC+1 schrieb Jaimin Patel:
>
> Sure.
>
> I had tried to render PDF with pisa,
>
> template = get_template(template_src)
> context = Context(context_dict)
> html  = template.render(context)
> result = StringIO.StringIO()
>
> pdf = pisa.pisaDocument(StringIO.StringIO(html.encode("ISO-8859-1")), 
> result, link_callback=fetch_resources)
> if not pdf.err:
> return HttpResponse(result.getvalue(), mimetype='application/pdf')
> return HttpResponse('Errors%s' % escape(html))
>
> Also tried with wkhtmltopdf -
>
> from wkhtmltopdf.views import PDFTemplateResponse
> ..
> return PDFTemplateResponse(request, 'pdf/pdftemplate.html', {
> 'pagesize':'A4',
>'user': results['user'],
>'question': results['question_obj'],
>})
>
> In both cases it doesn't render the elements which I am populating with 
> help of onload javascript function.
>
> On Wednesday, February 13, 2013 10:45:40 PM UTC-5, ovnicraft wrote:
>>
>>
>>
>>
>> On Sun, Feb 10, 2013 at 11:10 AM, Jaimin Patel wrote:
>>
>>> I am trying to generate pdf using django template, also need some 
>>> support of javascript code. I have tried PISA, ReportLib and wkhtmltopdf 
>>> but it seems that it doesn't wait for Javascript. 
>>
>>
>> Hello, can you explain us better what you means with *does not wait for 
>> JS* ? 
>> I understand you say: pdf is rendered w/o running JS code.
>>
>> Regards, 
>>
>>>
>>> Can someone suggest good solution or example?
>>>
>>> -- 
>>> You received this message because you are subscribed to the Google 
>>> Groups "Django users" group.
>>> To unsubscribe from this group and stop receiving emails from it, send 
>>> an email to django-users...@googlegroups.com.
>>> To post to this group, send email to django...@googlegroups.com.
>>> Visit this group at http://groups.google.com/group/django-users?hl=en.
>>> For more options, visit https://groups.google.com/groups/opt_out.
>>>  
>>>  
>>>
>>
>>
>>
>> -- 
>> Cristian Salamea
>> @ovnicraft 
>>
>

-- 
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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.