Login

Snippets by sleytr

Snippet List

automatic urlpattern creator

This method creates urlpatterns based on view functions that have 'request' as their first parameter. See docstring for details.

  • url
  • urlconf
  • patterns
  • auto
  • urlpattern
Read More

Regrouping admin models

This is modification of Django's original adminapplist template tag. You can move your models from one app to other or completely hide them with this mod. Copy django_dir/contrib/admin/templates/admin/index.html file to your templates/admin folder, open it, then change {% load adminapplist %} to {% load custom_adminapplist %} (or whatever you named the templatetag file) After that, write your regrouping schema to settings.py file like this; UPDATED, now using tupples instead of dicts in APP_SCHEMA to make it more DRY. ` APP_SCHEMA=[ ( ['Model','List'], 'From App', 'To App', ), ( ['FlatPage'], 'Flatpages', 'Site Content', ), ( ['Product'] 'Product', 'Shop', ), ( ['Site'] 'Sites', #We are hiding Site model by not defining a target. ), ] `

  • templatetag
  • models
  • admin
  • app
Read More

Send information mails to related staff members.

You can use this method to send information mails to the related staff members about section specific site activity. All users which explicitly permitted to 'change' given object will be informed about activity. If you defined get_absolute_url in your model then you can simply use it like this; ` obj=form.save() mail2perm(obj) ` Or you can define your custom urls ; ` from util.mail2perm import mail2perm,domain reply=get_object_or_404(Reply,user=request.user,pk=id) mail2perm(reply,url='http://%s/admin/support/show/?id=%s'%(domain,reply.id)) `

  • mail
  • permission
Read More

Sending html emails with images using Django templates

I have not extensively test this yet. But working for templates with embedded images. If you want to use Django template system use `msg` and optionally `textmsg` as template context (dict) and define `template` and optionally `texttemplate` variables. Otherwise msg and textmsg variables are used as html and text message sources. If you want to use images in html message, define physical paths and ids in tuples. (image paths are relative to MEDIA_ROOT) example: images=(('email_images/logo.gif','img1'),('email_images/footer.gif','img2')) use them in html like this: `<img src="cid:img1"><br><img src="cid:img2">` stripogram and feedparser modules are used for extract plain text from html message source. If you are going to define text partition explicitly, than you can comment out line 10,11 and 48.

  • template
  • email
  • mail
  • html
Read More

sleytr has posted 4 snippets.