예제 #1
0
 def save(self):
     if self.instance:#update
         photo=self.instance
         old_txt_tags_set=txt2set(photo.get_txt_tags())
         to_remove_tags_set=old_txt_tags_set-self.d_txt_tags_set
         to_add_tags_set=self.d_txt_tags_set-old_txt_tags_set
         photo.add_txt_tags(to_add_tags_set)
         photo.remove_txt_tags(to_remove_tags_set)
         from datetime import datetime
         photo.modification_date=datetime.now()
     else:
         photo = Photo()
         #上传图片
         photo.user=self.user
         filename=upload_photo(self.cleaned_data['photo'],
             self.cleaned_data['photo'].name.split('.')[-1])
         photo.photo_url=filename
     photo.title=self.cleaned_data['title']
     from oldphoto.utils.textconvert import plaintext2html
     photo.descn=plaintext2html(self.cleaned_data['descn'])
     #处理tags,删除删除的tag,添加新增加的tags
     photo.txt_tags=self.cleaned_data['txt_tags']
     photo.save()
     if not self.instance:#update
         photo.add_txt_tags(self.d_txt_tags_set)
         photo.save()
     return photo
예제 #2
0
 def clean_txt_tags(self):
     self.d_txt_tags_set=txt2set(self.cleaned_data['txt_tags'])
     if len(self.d_txt_tags_set)==0:
         raise forms.ValidationError(_('tags不能为空'))
     return ' '.join(self.d_txt_tags_set)
예제 #3
0
 def txt_tag_set(self):
     return txt2set(self.txt_tags)