Ejemplo n.º 1
0
    class Meta:
        model = Milestone
        exclude = ('project', 'author', 'closed', 'dashboard', 'stream')
        widgets = {
            'description': CKEditor(),
            'categories': SelectMultipleAndAddWidget(add_url='/categories/add', with_perms=['taxonomy.add_category']),
            'tags': SelectMultipleAndAddWidget(add_url='/tags/add', with_perms=['taxonomy.add_tag'])
        }
        
class TicketForm(forms.ModelForm):
    """Form for ticket data.
    """
    class Meta:
        model = Ticket
        exclude = ('project', 'code', 'author', 'closed', 'stream')
        widgets = {
            'tasks': SelectMultipleAndAddWidget(add_url='/tasks/add/', with_perms=['todo.add_task']),
            'categories': SelectMultipleAndAddWidget(add_url='/categories/add', with_perms=['taxonomy.add_category']),
            'tags': SelectMultipleAndAddWidget(add_url='/tags/add', with_perms=['taxonomy.add_tag'])
        }
        
    def __init__(self, *args, **kwargs):
        super(TicketForm, self).__init__(*args, **kwargs)
        if self.instance is None or self.instance.pk is None:
            del self.fields['status']
        self.fields['milestone'].queryset = self.instance.project.milestone_set.all()

enrich_form(ProjectForm)
enrich_form(MilestoneForm)
enrich_form(TicketForm)
Ejemplo n.º 2
0
    """
    class Meta:
        model = SalesInvoice
        exclude = ['document', 'entries']
        widgets = {
            'invoice_addressee':
            SelectAndAddWidget(add_url='/partners/add',
                               with_perms=['partners.add_partner']),
            'shipping_addressee':
            SelectAndAddWidget(add_url='/partners/add',
                               with_perms=['partners.add_partner']),
            'order_ref_date':
            DateWidget(),
            'due_date':
            DateWidget(),
            'bank_account':
            SelectAndAddWidget(add_url='/bankaccounts/add',
                               with_perms=['sales.add_bankaccount'])
        }

    def clean_terms_of_payment(self):
        owner = Partner.objects.get(id=self.data.get('owner', None))
        terms = self.cleaned_data['terms_of_payment']
        if not terms and owner:
            terms = owner.terms_of_payment
        return terms


enrich_form(BankAccountForm)
enrich_form(SalesInvoiceForm)
Ejemplo n.º 3
0
        widgets = {
            'supplier': SelectAndAddWidget(add_url='/partners/add', with_perms=['partners.add_partner']),
            'end_of_life': DateWidget()
        }

    def validate_unique(self):
        exclude = self._get_validation_exclusions()
        exclude.remove('product') # allow checking against the missing attribute

        try:
            self.instance.validate_unique(exclude=exclude)
        except ValidationError, e:
            self._update_errors(e.message_dict)

_ProductEntryFormset = modelformset_factory(ProductEntry, form=ProductEntryForm, can_delete=True, extra=4)

class ProductEntryFormset(_ProductEntryFormset):
    def __init__(self, *args, **kwargs):
        queryset = kwargs.pop('queryset', ProductEntry.objects.none())
        super(ProductEntryFormset, self).__init__(queryset=queryset, *args, **kwargs)
        count = self.initial_form_count()
        for i in range(0, self.total_form_count()-count):
            if i != 0 or count > 0:
                for field in self.forms[i+count].fields.values():
                    field.required = False
                self.forms[i+count].fields['DELETE'].initial = True

enrich_form(ProductForm)
enrich_form(ProductEntryForm)
enrich_form(SupplyForm)
Ejemplo n.º 4
0

class ImportEventsForm(forms.Form):
    """Form to input an .ics file.
    """
    file = forms.FileField(label=_("Select an .ics file"))


class EventForm(forms.ModelForm):
    """Form for event data.
    """
    start = DateTimeField()
    end = DateTimeField(required=False)

    class Meta:
        model = Event
        exclude = ('author', 'stream', 'calendars')
        widgets = {
            'description':
            CKEditor(),
            'categories':
            SelectMultipleAndAddWidget(add_url='/categories/add',
                                       with_perms=['taxonomy.add_category']),
            'tags':
            SelectMultipleAndAddWidget(add_url='/tags/add',
                                       with_perms=['taxonomy.add_tag'])
        }


enrich_form(EventForm)
Ejemplo n.º 5
0
from django import forms as forms
from django.utils.translation import ugettext_lazy as _

from prometeo.core.forms import enrich_form
from prometeo.core.forms.fields import *
from prometeo.core.forms.widgets import *

from models import *

class ImportEventsForm(forms.Form):
    """Form to input an .ics file.
    """
    file  = forms.FileField(label=_("Select an .ics file"))

class EventForm(forms.ModelForm):
    """Form for event data.
    """
    start = DateTimeField()
    end = DateTimeField(required=False)

    class Meta:
        model = Event
        exclude = ('author', 'stream', 'calendars')
        widgets = {
            'description': CKEditor(),
            'categories': SelectMultipleAndAddWidget(add_url='/categories/add', with_perms=['taxonomy.add_category']),
            'tags': SelectMultipleAndAddWidget(add_url='/tags/add', with_perms=['taxonomy.add_tag'])
        }

enrich_form(EventForm)
Ejemplo n.º 6
0
    def __init__(self, *args, **kwargs):
        super(OutgoingMovementForm, self).__init__(*args, **kwargs)
        self.fields['destination'].queryset = Warehouse.objects.exclude(
            pk=self.instance.origin.pk)


class DeliveryNoteForm(forms.ModelForm):
    """Form for delivery note data.
    """
    class Meta:
        model = DeliveryNote
        exclude = ['document', 'entries']
        widgets = {
            'invoice_addressee':
            SelectAndAddWidget(add_url='/partners/add',
                               with_perms=['partners.add_partner']),
            'delivery_addressee':
            SelectAndAddWidget(add_url='/partners/add',
                               with_perms=['partners.add_partner']),
            'order_ref_date':
            DateWidget(),
            'delivery_date':
            DateWidget()
        }


enrich_form(WarehouseForm)
enrich_form(MovementForm)
enrich_form(DeliveryNoteForm)
Ejemplo n.º 7
0
_ExpenseEntryFormset = inlineformset_factory(ExpenseVoucher, ExpenseEntry, form=ExpenseEntryForm, extra=5)

class ExpenseEntryFormset(_ExpenseEntryFormset):
    def __init__(self, *args, **kwargs):
        super(ExpenseEntryFormset, self).__init__(*args, **kwargs)
        count = self.initial_form_count()
        for i in range(0, self.total_form_count()-count):
            if i != 0 or count > 0:
                for field in self.forms[i+count].fields.values():
                    field.required = False
                self.forms[i+count].fields['DELETE'].initial = True

class LeaveRequestForm(forms.ModelForm):
    """Form for LeaveRequest data.
    """
    class Meta:
        model = LeaveRequest
        widgets = {
            'employee': SelectAndAddWidget(add_url='/contacts/add', with_perms=["partners.add_contact"]),
            'start': DateTimeWidget(),
            'end': DateTimeWidget(),
        }

enrich_form(JobForm)
enrich_form(EmployeeForm)
enrich_form(TimesheetForm)
enrich_form(TimesheetEntryForm)
enrich_form(ExpenseVoucherForm)
enrich_form(ExpenseEntryForm)
enrich_form(LeaveRequestForm)
Ejemplo n.º 8
0
from models import *


class AddressForm(forms.ModelForm):
    """Form for a address data.
    """

    class Meta:
        model = Address


class PhoneNumberForm(forms.ModelForm):
    """Form for a phone number data.
    """

    class Meta:
        model = PhoneNumber


class SocialProfileForm(forms.ModelForm):
    """Form for a social profile data.
    """

    class Meta:
        model = SocialProfile


enrich_form(AddressForm)
enrich_form(PhoneNumberForm)
enrich_form(SocialProfile)
Ejemplo n.º 9
0
    """
    class Meta:
        model = BankAccount
        widgets = {
            'owner': SelectAndAddWidget(add_url='/partners/add', with_perms=['partners.add_partner']),
        }
        
class SalesInvoiceForm(forms.ModelForm):
    """Form for sales invoice data.
    """
    class Meta:
        model = SalesInvoice
        exclude = ['document', 'entries']
        widgets = {
            'invoice_addressee': SelectAndAddWidget(add_url='/partners/add', with_perms=['partners.add_partner']),
            'shipping_addressee': SelectAndAddWidget(add_url='/partners/add', with_perms=['partners.add_partner']),
            'order_ref_date': DateWidget(),
            'due_date': DateWidget(),
            'bank_account': SelectAndAddWidget(add_url='/bankaccounts/add', with_perms=['sales.add_bankaccount'])
        }

    def clean_terms_of_payment(self):
        owner = Partner.objects.get(id=self.data.get('owner', None))
        terms = self.cleaned_data['terms_of_payment']
        if not terms and owner:
            terms = owner.terms_of_payment
        return terms

enrich_form(BankAccountForm)
enrich_form(SalesInvoiceForm)
Ejemplo n.º 10
0
    def clean_email(self):
        """Checks if the email address is unique.
        """
        if User.objects.filter(email__iexact=self.cleaned_data["email"]).exclude(pk=self.instance.pk):
            raise forms.ValidationError(
                _(u"This email address is already in use. Please supply a different email address.")
            )
        return self.cleaned_data["email"]

    def save(self, commit=True):
        user = super(UserEditForm, self).save(commit=False)
        if self.cleaned_data["password1"] or not user.password:
            user.set_password(self.cleaned_data["password1"])
        if commit:
            user.save()
            self.save_m2m()
        return user


class UserProfileForm(forms.ModelForm):
    """Form for user's profile data.
    """

    class Meta:
        model = UserProfile
        exclude = ("user", "dashboard", "bookmarks", "calendar")


enrich_form(UserEditForm)
enrich_form(UserProfileForm)
Ejemplo n.º 11
0
            raise forms.ValidationError(_("Origin and destination warehouses can't be the same."))

        return origin
        
class OutgoingMovementForm(MovementForm):
    """Form for outgoing movement data.
    """
    class Meta(MovementForm.Meta):
        exclude = ['product_entry', 'origin', 'author']

    def __init__(self, *args, **kwargs):
        super(OutgoingMovementForm, self).__init__(*args, **kwargs)
        self.fields['destination'].queryset = Warehouse.objects.exclude(pk=self.instance.origin.pk)

class DeliveryNoteForm(forms.ModelForm):
    """Form for delivery note data.
    """
    class Meta:
        model = DeliveryNote
        exclude = ['document', 'entries']
        widgets = {
            'invoice_addressee': SelectAndAddWidget(add_url='/partners/add', with_perms=['partners.add_partner']),
            'delivery_addressee': SelectAndAddWidget(add_url='/partners/add', with_perms=['partners.add_partner']),
            'order_ref_date': DateWidget(),
            'delivery_date': DateWidget()
        }

enrich_form(WarehouseForm)
enrich_form(MovementForm)
enrich_form(DeliveryNoteForm)
Ejemplo n.º 12
0
class DocumentForm(forms.ModelForm):
    """Form for document data.
    """
    class Meta:
        model = Document
        exclude = ['object_id', 'content_type', 'author', 'stream']
        widgets = {
            'owner':
            SelectAndAddWidget(add_url='/partners/add',
                               with_perms=['partners.add_partner']),
            'categories':
            SelectMultipleAndAddWidget(add_url='/categories/add',
                                       with_perms=['taxonomy.add_category']),
            'tags':
            SelectMultipleAndAddWidget(add_url='/tags/add',
                                       with_perms=['taxonomy.add_tag'])
        }


class HardCopyForm(forms.ModelForm):
    """Form for hard copy data.
    """
    class Meta:
        model = HardCopy
        exclude = ['document', 'author']


enrich_form(DocumentForm)
enrich_form(HardCopyForm)
Ejemplo n.º 13
0
__copyright__ = 'Copyright (c) 2011 Emanuele Bertoldi'
__version__ = '0.0.5'

from django import forms

from prometeo.core.forms import enrich_form

from models import *


class LinkForm(forms.ModelForm):
    """Form for link data.
    """
    class Meta:
        model = Link


class BookmarkForm(forms.ModelForm):
    """Form for bookmark data.
    """
    class Meta:
        model = Bookmark
        exclude = [
            'menu', 'slug', 'submenu', 'sort_order', 'only_authenticated',
            'only_staff', 'only_with_perms'
        ]


enrich_form(LinkForm)
enrich_form(BookmarkForm)
Ejemplo n.º 14
0
__author__ = 'Emanuele Bertoldi <*****@*****.**>'
__copyright__ = 'Copyright (c) 2011 Emanuele Bertoldi'
__version__ = '0.0.5'

from django.forms.fields import *
from django.forms.widgets import *

from prometeo.core.forms import enrich_form
from prometeo.core.forms.fields import *
from prometeo.core.forms.widgets import *

from models import *

class TaskForm(forms.ModelForm):
    """Form for Task data.
    """
    start = DateTimeField(required=False)
    end = DateTimeField(required=False)

    class Meta:
        model = Task
        exclude = ('user', 'closed')
        widgets = {
            'description': CKEditor(),
            'categories': SelectMultipleAndAddWidget(add_url='/categories/add', with_perms=['taxonomy.add_category']),
            'tags': SelectMultipleAndAddWidget(add_url='/tags/add', with_perms=['taxonomy.add_tag'])
        }

enrich_form(TaskForm)
Ejemplo n.º 15
0
from prometeo.core.forms.widgets import JsonPairWidget

from models import *
from loading import registry

class WidgetTemplateForm(forms.ModelForm):
    """Form for widget template data.
    """
    class Meta:
        model = WidgetTemplate
        widgets = {'context': JsonPairWidget(), 'source': forms.Select()}

    def __init__(self, *args, **kwargs):
        super(WidgetTemplateForm, self).__init__(*args, **kwargs)
        self.fields['source'].widget.choices = registry.sources

class WidgetForm(forms.ModelForm):
    """Form for widget data.
    """
    class Meta:
        model = Widget
        exclude = ['region', 'slug', 'show_title', 'editable', 'sort_order']
        widgets = {'context': JsonPairWidget()}

    def __init__(self, *args, **kwargs):
        super(WidgetForm, self).__init__(*args, **kwargs)
        self.fields['template'].queryset = WidgetTemplate.objects.filter(public=True)

enrich_form(WidgetForm)
enrich_form(WidgetTemplateForm)
Ejemplo n.º 16
0
    """Form to upload a new file.
    """
    name = forms.CharField(required=False)
    file = forms.FileField()

    def __init__(self, path, *args, **kwargs):
        super(UploadForm, self).__init__(*args, **kwargs)
        self.path = path

    def clean_file(self):
        name = self.cleaned_data.get('name',
                                     None) or self.cleaned_data['file'].name
        path = os.path.join(self.path, name)

        if os.access(path, os.F_OK):
            raise forms.ValidationError(_('The name already exists.'))

        max_filesize = get_max_upload_size()
        filesize = self.cleaned_data['file'].size
        if max_filesize != -1 and filesize > max_filesize:
            raise forms.ValidationError(
                _('The file exceeds the allowed upload size.'))

        return self.cleaned_data['file']


enrich_form(NameForm)
enrich_form(DestinationForm)
enrich_form(NameDestinationForm)
enrich_form(UploadForm)
Ejemplo n.º 17
0
        try:
            self.instance.validate_unique(exclude=exclude)
        except ValidationError, e:
            self._update_errors(e.message_dict)


_ProductEntryFormset = modelformset_factory(ProductEntry,
                                            form=ProductEntryForm,
                                            can_delete=True,
                                            extra=4)


class ProductEntryFormset(_ProductEntryFormset):
    def __init__(self, *args, **kwargs):
        queryset = kwargs.pop('queryset', ProductEntry.objects.none())
        super(ProductEntryFormset, self).__init__(queryset=queryset,
                                                  *args,
                                                  **kwargs)
        count = self.initial_form_count()
        for i in range(0, self.total_form_count() - count):
            if i != 0 or count > 0:
                for field in self.forms[i + count].fields.values():
                    field.required = False
                self.forms[i + count].fields['DELETE'].initial = True


enrich_form(ProductForm)
enrich_form(ProductEntryForm)
enrich_form(SupplyForm)
Ejemplo n.º 18
0
class PartnerJobForm(forms.ModelForm):
    """Form for job data from a partner point of view.
    """
    class Meta:
        model = Job
        exclude = ['partner', 'created']
        widgets = {
            'started': DateWidget(),
            'ended': DateWidget(),
            'contact': SelectAndAddWidget(add_url='/contacts/add/', with_perms=['partners.add_contact']),
        }     
        
class LetterForm(forms.ModelForm):
    """Form for letter data.
    """
    class Meta:
        model = Letter
        widgets = {
            'date': DateWidget(),
            'target_ref_date': DateWidget(),
            'target': SelectAndAddWidget(add_url='/partners/add/', with_perms=['partners.add_partner']),
            'to': SelectAndAddWidget(add_url='/contacts/add/', with_perms=['partners.add_contact']),
            'body': CKEditor(),
        }

enrich_form(ContactForm)
enrich_form(ContactJobForm)
enrich_form(PartnerForm)
enrich_form(PartnerJobForm)
enrich_form(LetterForm)
Ejemplo n.º 19
0
more details.

You should have received a copy of the GNU Lesser General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>
"""

__author__ = 'Emanuele Bertoldi <*****@*****.**>'
__copyright__ = 'Copyright (c) 2011 Emanuele Bertoldi'
__version__ = '0.0.5'

from django import forms

from prometeo.core.forms import enrich_form

from models import *

class CategoryForm(forms.ModelForm):
    """Form for category data.
    """
    class Meta:
        model = Category

class TagForm(forms.ModelForm):
    """Form for tag data.
    """
    class Meta:
        model = Tag

enrich_form(CategoryForm)
enrich_form(TagForm)
Ejemplo n.º 20
0
        if not (password2 or self.instance.pk):
            raise forms.ValidationError(_('This field is required.'))
            
        return password2
        
    def clean_email(self):
        """Checks if the email address is unique.
        """
        if User.objects.filter(email__iexact=self.cleaned_data['email']).exclude(pk=self.instance.pk):
            raise forms.ValidationError(_(u'This email address is already in use. Please supply a different email address.'))
        return self.cleaned_data['email']

    def save(self, commit=True):
        user = super(UserEditForm, self).save(commit=False)
        if self.cleaned_data['password1'] or not user.password:
            user.set_password(self.cleaned_data["password1"])
        if commit:
            user.save()
            self.save_m2m()   
        return user

class UserProfileForm(forms.ModelForm):
    """Form for user's profile data.
    """
    class Meta:
        model = UserProfile
        exclude = ('user', 'dashboard', 'bookmarks', 'calendar')

enrich_form(UserEditForm)
enrich_form(UserProfileForm)
Ejemplo n.º 21
0
    """Form for notification subscriptions.
    """
    def __init__(self, *args, **kwargs):
        try:
            self.user = kwargs.pop('user')
        except KeyError:
            self.user = None
        super(SubscriptionsForm, self).__init__(*args, **kwargs)
        signatures = Signature.objects.all()
        for signature in signatures:
            name = signature.slug
            is_subscriber = (Subscription.objects.filter(signature=signature, user=self.user).count() > 0)
            send_email = (Subscription.objects.filter(signature=signature, user=self.user, send_email=True).count() > 0)
            field = SubscriptionField(label=_(signature.title), initial={'subscribe': is_subscriber, 'email': send_email})
            self.fields[name] = field
            
    def save(self):
        data = self.cleaned_data
        for key, (subscribe, email) in data.iteritems():
            signature = Signature.objects.get(slug=key)
            is_subscriber = (self.user in signature.subscribers.all())
            if subscribe:
                subscription = Subscription.objects.get_or_create(user=self.user, signature=signature)[0]
                subscription.send_email = email
                subscription.save()
            elif is_subscriber and not subscribe:
                Subscription.objects.filter(user=self.user, signature=signature).delete()
                self.fields[key].initial = (False, False)
                 
enrich_form(SubscriptionsForm)
Ejemplo n.º 22
0
You should have received a copy of the GNU Lesser General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>
"""

__author__ = 'Emanuele Bertoldi <*****@*****.**>'
__copyright__ = 'Copyright (c) 2011 Emanuele Bertoldi'
__version__ = '0.0.5'

from django import forms

from prometeo.core.forms import enrich_form

from models import *

class LinkForm(forms.ModelForm):
    """Form for link data.
    """
    class Meta:
        model = Link

class BookmarkForm(forms.ModelForm):
    """Form for bookmark data.
    """
    class Meta:
        model = Bookmark
        exclude = ['menu', 'slug', 'submenu', 'sort_order', 'only_authenticated', 'only_staff', 'only_with_perms']

enrich_form(LinkForm)
enrich_form(BookmarkForm)
Ejemplo n.º 23
0
from django import forms
from django.utils.translation import ugettext_lazy as _

from prometeo.core.forms import enrich_form
from prometeo.core.forms.widgets import *

from models import *

class DocumentForm(forms.ModelForm):
    """Form for document data.
    """
    class Meta:
        model = Document
        exclude = ['object_id', 'content_type', 'author', 'stream']
        widgets = {
            'owner': SelectAndAddWidget(add_url='/partners/add', with_perms=['partners.add_partner']),
            'categories': SelectMultipleAndAddWidget(add_url='/categories/add', with_perms=['taxonomy.add_category']),
            'tags': SelectMultipleAndAddWidget(add_url='/tags/add', with_perms=['taxonomy.add_tag'])
        }

class HardCopyForm(forms.ModelForm):
    """Form for hard copy data.
    """
    class Meta:
        model = HardCopy
        exclude = ['document', 'author']

enrich_form(DocumentForm)
enrich_form(HardCopyForm)
Ejemplo n.º 24
0
            name = signature.slug
            is_subscriber = (Subscription.objects.filter(
                signature=signature, user=self.user).count() > 0)
            send_email = (Subscription.objects.filter(
                signature=signature, user=self.user, send_email=True).count() >
                          0)
            field = SubscriptionField(label=_(signature.title),
                                      initial={
                                          'subscribe': is_subscriber,
                                          'email': send_email
                                      })
            self.fields[name] = field

    def save(self):
        data = self.cleaned_data
        for key, (subscribe, email) in data.iteritems():
            signature = Signature.objects.get(slug=key)
            is_subscriber = (self.user in signature.subscribers.all())
            if subscribe:
                subscription = Subscription.objects.get_or_create(
                    user=self.user, signature=signature)[0]
                subscription.send_email = email
                subscription.save()
            elif is_subscriber and not subscribe:
                Subscription.objects.filter(user=self.user,
                                            signature=signature).delete()
                self.fields[key].initial = (False, False)


enrich_form(SubscriptionsForm)
Ejemplo n.º 25
0

class ChoiceForm(forms.ModelForm):
    """Form for choice data.
    """
    class Meta:
        models = Choice
        exclude = [
            'poll',
        ]


_ChoiceFormset = inlineformset_factory(Poll, Choice, form=ChoiceForm, extra=4)


class ChoiceFormset(_ChoiceFormset):
    def __init__(self, *args, **kwargs):
        super(ChoiceFormset, self).__init__(*args, **kwargs)
        count = self.initial_form_count()
        for i in range(0, self.total_form_count() - count):
            if i > 1 or count > 0:
                for field in self.forms[i + count].fields.values():
                    field.required = False
                self.forms[i + count].fields['DELETE'].initial = True


enrich_form(WikiPageForm)
enrich_form(FaqForm)
enrich_form(PollForm)
enrich_form(ChoiceForm)
Ejemplo n.º 26
0
        return destination

class UploadForm(forms.Form):
    """Form to upload a new file.
    """
    name = forms.CharField(required=False)
    file = forms.FileField()

    def __init__(self, path, *args, **kwargs):
        super(UploadForm, self).__init__(*args, **kwargs)
        self.path = path

    def clean_file(self):
        name = self.cleaned_data.get('name', None) or self.cleaned_data['file'].name
        path = os.path.join(self.path, name)

        if os.access(path, os.F_OK):
            raise forms.ValidationError(_('The name already exists.')) 

        max_filesize = get_max_upload_size()
        filesize = self.cleaned_data['file'].size
        if max_filesize != -1 and filesize > max_filesize:
            raise forms.ValidationError(_('The file exceeds the allowed upload size.'))

        return self.cleaned_data['file']

enrich_form(NameForm)
enrich_form(DestinationForm)
enrich_form(NameDestinationForm)
enrich_form(UploadForm)
Ejemplo n.º 27
0
        exclude = ['author', 'created', 'stream']
        widgets = {
            'due_date': DateWidget(),
            'categories': SelectMultipleAndAddWidget(add_url='/categories/add', with_perms=['taxonomy.add_category']),
            'tags': SelectMultipleAndAddWidget(add_url='/tags/add', with_perms=['taxonomy.add_tag'])
        }

class ChoiceForm(forms.ModelForm):
    """Form for choice data.
    """
    class Meta:
        models = Choice
        exclude = ['poll',]

_ChoiceFormset = inlineformset_factory(Poll, Choice, form=ChoiceForm, extra=4)

class ChoiceFormset(_ChoiceFormset):
    def __init__(self, *args, **kwargs):
        super(ChoiceFormset, self).__init__(*args, **kwargs)
        count = self.initial_form_count()
        for i in range(0, self.total_form_count()-count):
            if i > 1 or count > 0:
                for field in self.forms[i+count].fields.values():
                    field.required = False
                self.forms[i+count].fields['DELETE'].initial = True

enrich_form(WikiPageForm)
enrich_form(FaqForm)
enrich_form(PollForm)
enrich_form(ChoiceForm)
Ejemplo n.º 28
0
                               with_perms=['partners.add_contact']),
        }


class LetterForm(forms.ModelForm):
    """Form for letter data.
    """
    class Meta:
        model = Letter
        widgets = {
            'date':
            DateWidget(),
            'target_ref_date':
            DateWidget(),
            'target':
            SelectAndAddWidget(add_url='/partners/add/',
                               with_perms=['partners.add_partner']),
            'to':
            SelectAndAddWidget(add_url='/contacts/add/',
                               with_perms=['partners.add_contact']),
            'body':
            CKEditor(),
        }


enrich_form(ContactForm)
enrich_form(ContactJobForm)
enrich_form(PartnerForm)
enrich_form(PartnerJobForm)
enrich_form(LetterForm)