Created
February 6, 2012 20:09
-
-
Save eserge/1754504 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- 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