Wednesday, June 1, 2011

Re: Auditing Record Changes in All Admin Tables

Ryan- that helps a ton, thanks much. I don't think created_by and
updated_by should be foreign keys, because a user can be deleted but
all of his record adds/updates need to persist. So I replaced those
two lines with:

created_by = models.CharField(blank=True,max_length=20,editable=False)
updated_by = models.CharField(blank=True,max_length=20,editable=False)

This works, but on update the updated_by field is set to the User ID
instead of the User Name.

Also, none of the 4 audit fields are displayed in the browse/list and
change forms. I need to display them read-only on both.

Any ideas on those 2 issues? I think this thread will help a lot of
struggling newbies like me.

Thanks, Lee

On Jun 1, 12:08 am, Ryan <ryan.osb...@live.co.uk> wrote:
> The model code still needs to stay in the model, it is just the save_model
> method had to be moved to the admin.py.  I think the following is what you
> are looking for:
>
> models.py
> ---------------
> from django.db import models
> from django.contrib.auth.models import User
>
> class AuditedTable(models.Model):
>     created = models.DateTimeField(auto_now_add=True)
>     created_by = models.ForeignKey(User, editable=False)
>     updated = models.DateTimeField(auto_now=True)
>     updated_by = models.ForeignKey(User, editable=False)
>
>     class Meta:
>         abstract = True
>
> class Entity1(AuditedTable):
>     title = models.CharField(max_length=20)
>
>     def __unicode__(self):
>         return self.title
>
> admin.py
> -------------
> from django.contrib import admin
> from app.models import Entity1
>
> class AuditAdmin(admin.ModelAdmin):
>     def save_model(self, request, obj, form, change):
>         if change:
>             obj.updated_by = request.user
>         else:
>             obj.created_by = request.user
>         obj.save()
>
> class Entity1Admin(AuditAdmin):
>     pass
>
> admin.site.register(Entity1, Entity1Admin)
>
> Hope that helps,
>
> Ryan

--
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.

Consistent Export

I am using Django as a content admin backend for a desktop
application. The desktop application needs to cache the Django DB
structure and uploaded files directory from the remote server running
Django. This is accomplished with an "export" django app I wrote which
serves up the DB as JSON (using code copy-pasted from the dumpdata
command) and using rsync over ssh to sync the uploaded files directory
to a local location.

The problem is that the state of the DB & uploaded files directory
could change after the JSON is dumped and before the "rsync" finishes.
Maybe it could even change while the JSON is dumping?

I could solve this issue with some sort of distributed locking
mechanism, but I'm wondering if there is a better Django-specific way
to do it? Some sort of DB+files export transaction? Actually, maybe
just DB consistency is the real issue, because worst case with the
files is that I pull down new files not referenced by the seconds-
older JSON?

--
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: Seeking a Django 1.3 and syslog configuration example

This should help out. It's for a file, not SysLogHandler, but the idea
is the same.

Just take any arguments you would normally pass to the handler if you
were creating it programmatically and add them as keys to the dictionary:

'log_file': {
'level': 'DEBUG',
'class': 'logging.handlers.RotatingFileHandler',
'filename': '/tmp/myfilename.log',
'formatter': 'verbose',
'backupCount': 50,
'maxBytes': 2 ** 20,
},

As demonstrated here, filename, backupCount, and maxBytes (used by the
RotatingFileHandler but not in Django's default logging dict) were just
added and given values. Do the same for SysLogHandler parameters and it
should work.

I had the same difficulty you were having in figuring this out; we
should update the documentation to mention this. I'll open a ticket.

Shawn


--
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.

mod_wsgi on cPanel/WHM gets easier

If you run a cPanel/WHM server, and have manually compiled mod_wsgi in
the past, you know that updating apache/php for the rest of your
server is a pain, since the easy_apache build script is unaware of the
custom mod_wsgi module and discards it during compilation. And since
you have enabled mod_wsgi in your httpd.conf headers, the build script
fails at the end of the process since it can no longer find the
referenced module.

All of this just got a lot easier - there is now an official mod_wsgi
add-on for easy_apache, making the whole process wsgi-aware.

http://code.google.com/p/modwsgi/issues/detail?id=214

I have not yet tested it but early reports are positive.

Also, if you want to see cPanel systems with native Django support
(much like the native Rails support that's there now), please log your
interest in this thread - official cPanel devs are watching and
seeking input from the community about how it should work:

http://forums.cpanel.net/f145/django-support-146541.html

All of this may sound obscure, but the difficulty of deployment on
standard web hosts is one of the biggest barriers to wider Django
adoption. cPanel is the most common web hosting system in the world,
period. Getting good Django support into WHM/cPanel would be great for
Django's popularity.

Scot

--
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.

Seeking a Django 1.3 and syslog configuration example

I'm having no luck finding any information on setting up syslog
logging with Django 1.3 dictionary configuration. The Django documents
don't cover syslog and the python documentation is less than clear and
doesn't cover dictionary config at all. I've started with the
following but I'm stuck on how to configure the SysLogHandler.

LOGGING = {
'version': 1,
'disable_existing_loggers': True,
'formatters': {
'verbose': {
'format': '%(levelname)s %(asctime)s %(module)s %
(process)d %(thread)d %(message)s'
},
'simple': {
'format': '%(levelname)s %(message)s'
},
},
'handlers': {
'syslog':{
'level':'DEBUG',
'class':'logging.handlers.SysLogHandler',
'formatter': 'verbose'
},

},
'loggers': {
'django': {
'handlers':['syslog'],
'propagate': True,
'level':'INFO',
},
'myapp': {
'handlers': ['syslog'],
'propagate': True,
'level': 'DEBUG',
},
},
}

--
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: adding objects via admin section from ipad/iphone

On Wed, Jun 1, 2011 at 4:07 PM, info@webbricks.co.uk
<info@webbricks.co.uk> wrote:
> i wonder if anyone has any suggestions around this issue.
>
> I'm using zinnia blog engine in a couple of sites. customer has had
> his head turned by an SEO genius (!) who reckons wordpress is far
> better for google search results than zinnia. customer starts thinking
> about moving back to wordpress. im not too chuffed about this.
> customer starts playing with wordpress and realises he can use his
> ipad/iphone (via bespoke apps) to create blog posts. tries on his
> zinnia blog, no can do. this is because the choose file buttons in the
> forms are greyed out, since you cant just access the ipads filesystem.
>
> the wordpress apps are native on the device so know how to get into
> the photo library to upload images.
>
> so if i wanted to be able to create a blog post on the ipad, im
> looking at having to create a custom app and getting it through the
> app store.
>
> unless there is some framework like phone gap that allows access?
>
> has anyone come ancross and solved this issue before?
>

I would have thought it would be easier to mimic wordpress's web
service API, and re-use the same app, than to write a new app.

Alternatively, send your customer for re-education.

Cheers

Tom

--
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.

adding objects via admin section from ipad/iphone

i wonder if anyone has any suggestions around this issue.

I'm using zinnia blog engine in a couple of sites. customer has had
his head turned by an SEO genius (!) who reckons wordpress is far
better for google search results than zinnia. customer starts thinking
about moving back to wordpress. im not too chuffed about this.
customer starts playing with wordpress and realises he can use his
ipad/iphone (via bespoke apps) to create blog posts. tries on his
zinnia blog, no can do. this is because the choose file buttons in the
forms are greyed out, since you cant just access the ipads filesystem.

the wordpress apps are native on the device so know how to get into
the photo library to upload images.

so if i wanted to be able to create a blog post on the ipad, im
looking at having to create a custom app and getting it through the
app store.

unless there is some framework like phone gap that allows access?

has anyone come ancross and solved this issue 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.