mirror of
https://github.com/haiwen/seahub.git
synced 2025-09-23 12:27:48 +00:00
Refactor contacts app.
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
# encoding: utf-8
|
||||
from django import forms
|
||||
from django.db import models
|
||||
from django.forms import ModelForm
|
||||
|
||||
@@ -9,6 +11,32 @@ class Contact(models.Model):
|
||||
contact_name = models.CharField(max_length=255, blank=True, null=True)
|
||||
note = models.CharField(max_length=255, blank=True, null=True)
|
||||
|
||||
class AddContactForm(ModelForm):
|
||||
class Meta:
|
||||
unique_together = ("user_email", "contact_email")
|
||||
|
||||
class ContactAddForm(ModelForm):
|
||||
class Meta:
|
||||
model = Contact
|
||||
|
||||
def clean(self):
|
||||
user_email = self.cleaned_data['user_email']
|
||||
contact_email = self.cleaned_data['contact_email']
|
||||
if user_email == contact_email:
|
||||
raise forms.ValidationError('不能添加自己为联系人')
|
||||
elif Contact.objects.filter(user_email=user_email,
|
||||
contact_email=contact_email).count() > 0:
|
||||
raise forms.ValidationError('联系人列表中已有该用户')
|
||||
else:
|
||||
return self.cleaned_data
|
||||
|
||||
class ContactEditForm(ModelForm):
|
||||
class Meta:
|
||||
model = Contact
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super(ContactEditForm, self).__init__(*args, **kwargs)
|
||||
self.fields['contact_email'].widget.attrs['readonly'] = True
|
||||
|
||||
def clean(self):
|
||||
# This is used to override unique index check
|
||||
return self.cleaned_data
|
||||
|
Reference in New Issue
Block a user