Skip to content

Instantly share code, notes, and snippets.

@eserge
Created February 6, 2012 20:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eserge/1754504 to your computer and use it in GitHub Desktop.
Save eserge/1754504 to your computer and use it in GitHub Desktop.
# -*- coding: utf-8 -*-
from django.forms.models import ModelForm
from django import forms
from models import Profile
import bleach
class EditProfileForm(ModelForm):
phone = forms.CharField(required=False,
help_text=u"Рекомендуемый формат: +74951234567")
def __init__(self, *args, **kwargs):
networks_profile = kwargs.get('instance').user.usermap_set.all()
if not networks_profile:
self.base_fields['show_networks_profile'].widget = self.base_fields['show_networks_profile'].hidden_widget()
super(EditProfileForm, self).__init__(*args, **kwargs)
def clean_about(self):
tags = [
'span',
'strong',
'b',
'em',
'i',
'u',
'strike',
's',
'li',
'ol',
'ul',
'p',
'br',
]
attributes= {
'span': ['style'],
}
styles = [
'text-decoration',
]
return bleach.clean(self.cleaned_data['about'], tags=tags, attributes=attributes, styles=styles, strip=True)
class Meta:
model = Profile
exclude = ('user',)
class Media:
js = ('/static/libs/tiny_mce/tiny_mce.js',)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment