Пример #1
0
    def __init__(self, question, user, revision=None, *args, **kwargs):
        super(EditQuestionForm, self).__init__(*args, **kwargs)

        if revision is None:
            revision = question.active_revision

        self.fields['title'].initial = revision.title
        self.fields['text'].initial = revision.body

        self.fields['tags'] = TagNamesField(user)
        self.fields['tags'].initial = revision.tagnames

        if int(user.reputation) < settings.CAPTCHA_IF_REP_LESS_THAN and not (
                user.is_superuser or user.is_staff):
            spam_fields = call_all_handlers('create_anti_spam_field')
            if spam_fields:
                spam_fields = dict(spam_fields)
                for name, field in spam_fields.items():
                    self.fields[name] = field

                self._anti_spam_fields = spam_fields.keys()
            else:
                self._anti_spam_fields = []

        if settings.WIKI_ON:
            self.fields['wiki'] = WikiField(
                disabled=(question.nis.wiki
                          and not user.can_cancel_wiki(question)),
                initial=question.nis.wiki)
Пример #2
0
    def __init__(self, data=None, user=None, *args, **kwargs):
        super(AskForm, self).__init__(data, *args, **kwargs)
        self.fields['category']   = CategoryNameField(user)
        self.fields['tags']   = TagNamesField(user)
        #self.fields['recipients'] = MailNamesField(user)
        #self.fields['defaultrecipients'] = forms.CharField(label=_('Category Mailing List:'), required=False)
       # self.fields['addressbooks'] = AddressBookField(user)
        self.fields['upload_files'] = forms.FileField(required=False,label=_('Upload Files:'),
                                    help_text='Select files to attach')
        self.fields['form_attachments'] = forms.CharField(widget=forms.HiddenInput(),required=False)
        self.fields['attachement_token'] = forms.CharField(required=False,widget=forms.HiddenInput(),initial = int(time.time() * 1000))

        if not user.is_authenticated() or (int(user.reputation) < settings.CAPTCHA_IF_REP_LESS_THAN and not (user.is_superuser or user.is_staff)):
            spam_fields = call_all_handlers('create_anti_spam_field')
            if spam_fields:
                spam_fields = dict(spam_fields)
                for name, field in spam_fields.items():
                    self.fields[name] = field

                self._anti_spam_fields = spam_fields.keys()
            else:
                self._anti_spam_fields = []

        if settings.WIKI_ON:
            self.fields['wiki'] = WikiField()
Пример #3
0
    def __init__(self, question, user, revision=None, *args, **kwargs):
        super(EditQuestionForm, self).__init__(*args, **kwargs)

        if revision is None:
            revision = question.active_revision

        self.fields['title'].initial = revision.title
        self.fields['text'].initial = revision.body

        self.fields['tags'] = TagNamesField(user)
        self.fields['tags'].initial = revision.tagnames

        if int(user.reputation) < settings.CAPTCHA_IF_REP_LESS_THAN and not (user.is_superuser or user.is_staff):
            spam_fields = call_all_handlers('create_anti_spam_field')
            if spam_fields:
                spam_fields = dict(spam_fields)
                for name, field in spam_fields.items():
                    self.fields[name] = field

                self._anti_spam_fields = spam_fields.keys()
            else:
                self._anti_spam_fields = []

        if settings.WIKI_ON:
            self.fields['wiki'] = WikiField(disabled=(question.nis.wiki and not user.can_cancel_wiki(question)), initial=question.nis.wiki)
Пример #4
0
    def __init__(self, answer, user, revision=None, *args, **kwargs):
        super(EditAnswerForm, self).__init__(*args, **kwargs)

        if revision is None:
            revision = answer.active_revision

        self.fields["text"].initial = revision.body

        if not user.is_authenticated() or (
            int(user.reputation) < settings.CAPTCHA_IF_REP_LESS_THAN and not (user.is_superuser or user.is_staff)
        ):
            spam_fields = call_all_handlers("create_anti_spam_field")
            if spam_fields:
                spam_fields = dict(spam_fields)
                for name, field in spam_fields.items():
                    self.fields[name] = field

                self._anti_spam_fields = spam_fields.keys()
            else:
                self._anti_spam_fields = []

        if settings.WIKI_ON:
            self.fields["wiki"] = WikiField(
                disabled=(answer.nis.wiki and not user.can_cancel_wiki(answer)), initial=answer.nis.wiki
            )
Пример #5
0
    def __init__(self, answer, user, revision=None, *args, **kwargs):
        super(EditAnswerForm, self).__init__(*args, **kwargs)

        if revision is None:
            revision = answer.active_revision

        self.fields['text'].initial = revision.body

        if not user.is_authenticated() or (
                int(user.reputation) < settings.CAPTCHA_IF_REP_LESS_THAN
                and not (user.is_superuser or user.is_staff)):
            spam_fields = call_all_handlers('create_anti_spam_field')
            if spam_fields:
                spam_fields = dict(spam_fields)
                for name, field in spam_fields.items():
                    self.fields[name] = field

                self._anti_spam_fields = spam_fields.keys()
            else:
                self._anti_spam_fields = []

        if settings.WIKI_ON:
            self.fields['wiki'] = WikiField(
                disabled=(answer.nis.wiki
                          and not user.can_cancel_wiki(answer)),
                initial=answer.nis.wiki)
Пример #6
0
    def __init__(self, data=None, user=None, *args, **kwargs):
        super(AskForm, self).__init__(data, *args, **kwargs)

        self.fields['tags'] = TagNamesField(user)
        self.fields['invites'] = InviteNamesField(user)
        self.fields['public'] = forms.ChoiceField(widget=forms.RadioSelect,
                                                  choices=((1, _('public')),
                                                           (0, _('private'))),
                                                  initial=1)

        if not user.is_authenticated() or (
                int(user.reputation) < settings.CAPTCHA_IF_REP_LESS_THAN
                and not (user.is_superuser or user.is_staff)):
            spam_fields = call_all_handlers('create_anti_spam_field')
            if spam_fields:
                spam_fields = dict(spam_fields)
                for name, field in spam_fields.items():
                    self.fields[name] = field

                self._anti_spam_fields = spam_fields.keys()
            else:
                self._anti_spam_fields = []

        if settings.WIKI_ON:
            self.fields['wiki'] = WikiField()
Пример #7
0
    def __init__(self, *args, **kwargs):
        spam_fields = call_all_handlers('create_anti_spam_field')
        if spam_fields:
            spam_fields = dict(spam_fields)
            for name, field in spam_fields.items():
                self.fields[name] = field

            self._anti_spam_fields = spam_fields.keys()
        else:
            self._anti_spam_fields = []
Пример #8
0
    def __init__(self, *args, **kwargs):
        spam_fields = call_all_handlers('create_anti_spam_field')
        if spam_fields:
            spam_fields = dict(spam_fields)
            for name, field in spam_fields.items():
                self.fields[name] = field

            self._anti_spam_fields = spam_fields.keys()
        else:
            self._anti_spam_fields = []
Пример #9
0
    def __init__(self, data=None, user=None, custom_badge=None, *args, **kwargs):
        super(AwardBadgeForm, self).__init__(data, *args, **kwargs)
        self.fields['user'] = UserNameField(user, custom_badge)

        if int(user.reputation) < settings.CAPTCHA_IF_REP_LESS_THAN and not (user.is_superuser or user.is_staff):
            spam_fields = call_all_handlers('create_anti_spam_field')
            if spam_fields:
                spam_fields = dict(spam_fields)
                for name, field in spam_fields.items():
                    self.fields[name] = field

                self._anti_spam_fields = spam_fields.keys()
            else:
                self._anti_spam_fields = []
Пример #10
0
    def __init__(self, data=None, user=None, *args, **kwargs):
        super(AnswerForm, self).__init__(data, *args, **kwargs)
        
        if int(user.reputation) < settings.CAPTCHA_IF_REP_LESS_THAN and not (user.is_superuser or user.is_staff):
            spam_fields = call_all_handlers('create_anti_spam_field')
            if spam_fields:
                spam_fields = dict(spam_fields)
                for name, field in spam_fields.items():
                    self.fields[name] = field

                self._anti_spam_fields = spam_fields.keys()
            else:
                self._anti_spam_fields = []

        if settings.WIKI_ON:
            self.fields['wiki'] = WikiField()
Пример #11
0
    def __init__(self, data=None, user=None, *args, **kwargs):
        super(AnswerForm, self).__init__(data, *args, **kwargs)
        
        if not user.is_authenticated() or (int(user.reputation) < settings.CAPTCHA_IF_REP_LESS_THAN and not (user.is_superuser or user.is_staff)):
            spam_fields = call_all_handlers('create_anti_spam_field')
            if spam_fields:
                spam_fields = dict(spam_fields)
                for name, field in spam_fields.items():
                    self.fields[name] = field

                self._anti_spam_fields = spam_fields.keys()
            else:
                self._anti_spam_fields = []

        if settings.WIKI_ON:
            self.fields['wiki'] = WikiField()
Пример #12
0
    def __init__(self, user, *args, **kwargs):
        super(FeedbackForm, self).__init__(*args, **kwargs)
        if not user.is_authenticated():
            self.fields['name'] = forms.CharField(label=_('Your name:'), required=False)
            self.fields['email'] = forms.EmailField(label=_('Email (not shared with anyone):'), required=True)

        # Create anti spam fields
        spam_fields = call_all_handlers('create_anti_spam_field')
        if spam_fields:
            spam_fields = dict(spam_fields)
            for name, field in spam_fields.items():
                self.fields[name] = field

            self._anti_spam_fields = spam_fields.keys()
        else:
            self._anti_spam_fields = []
Пример #13
0
    def __init__(self, user, *args, **kwargs):
        super(FeedbackForm, self).__init__(*args, **kwargs)
        if not user.is_authenticated():
            self.fields['name'] = forms.CharField(label=_('Your name:'), required=False)
            self.fields['email'] = forms.EmailField(label=_('Email (not shared with anyone):'), required=True)

        # Create anti spam fields
        spam_fields = call_all_handlers('create_anti_spam_field')
        if spam_fields:
            spam_fields = dict(spam_fields)
            for name, field in spam_fields.items():
                self.fields[name] = field

            self._anti_spam_fields = spam_fields.keys()
        else:
            self._anti_spam_fields = []
Пример #14
0
    def __init__(self, question, user, revision=None, *args, **kwargs):
        super(EditQuestionForm, self).__init__(*args, **kwargs)

        if revision is None:
            revision = question.active_revision

        self.fields['title'].initial = revision.title
        self.fields['text'].initial = revision.body

        self.fields['tags'] = TagNamesField(user)
        self.fields['tags'].initial = revision.tagnames

        # self.fields['public'].initial = revision.public
        # if 'data' in kwargs:
        #     initial_public = kwargs['data'].get('public', 0)
        # else:
        #     initial_public = 0
        #initial_public = revision.public
        if revision.public:
            initial_public = 1
        else:
            initial_public = 0

        print "Leo => edit anchor:", initial_public
        self.fields['public'] = forms.ChoiceField(widget=forms.RadioSelect,
                                                  choices=((1, _('public')),
                                                           (0, _('private'))),
                                                  initial=initial_public)

        if not user.is_authenticated() or (
                int(user.reputation) < settings.CAPTCHA_IF_REP_LESS_THAN
                and not (user.is_superuser or user.is_staff)):
            spam_fields = call_all_handlers('create_anti_spam_field')
            if spam_fields:
                spam_fields = dict(spam_fields)
                for name, field in spam_fields.items():
                    self.fields[name] = field

                self._anti_spam_fields = spam_fields.keys()
            else:
                self._anti_spam_fields = []

        if settings.WIKI_ON:
            self.fields['wiki'] = WikiField(
                disabled=(question.nis.wiki
                          and not user.can_cancel_wiki(question)),
                initial=question.nis.wiki)
Пример #15
0
    def __init__(self, data=None, user=None, *args, **kwargs):
        super(AskForm, self).__init__(data, *args, **kwargs)

        #self.fields['tags']   = TagNamesField(user)
        self.fields['tags'] =  forms.ModelMultipleChoiceField(queryset=Tag.active.all())
        if not user.is_authenticated() or (int(user.reputation) < settings.CAPTCHA_IF_REP_LESS_THAN and not (user.is_superuser or user.is_staff)):
            spam_fields = call_all_handlers('create_anti_spam_field')
            if spam_fields:
                spam_fields = dict(spam_fields)
                for name, field in spam_fields.items():
                    self.fields[name] = field

                self._anti_spam_fields = spam_fields.keys()
            else:
                self._anti_spam_fields = []

        if settings.WIKI_ON:
            self.fields['wiki'] = WikiField()
Пример #16
0
    def __init__(self, question, user, revision=None, *args, **kwargs):
        super(EditQuestionForm, self).__init__(*args, **kwargs)

        if revision is None:
            revision = question.active_revision

        self.fields['title'].initial = revision.title
        self.fields['text'].initial = revision.body

        self.fields['category'] = CategoryNameField(user)
        self.fields['category'].initial = revision.category

        self.fields['tags'] = TagNamesField(user)
        self.fields['tags'].initial = revision.tagnames

        #self.fields['recipients'] = MailNamesField(user)
        #self.fields['recipients'].initial = revision.recipientnames

#        self.fields['addressbooks'] = AddressBookField(user)
#        self.fields['addressbooks'].initial = revision.addressbooks.split(',')

        self.fields['upload_files'] = forms.FileField(required=False,label=_('Upload Files:'),
                                    help_text='Select files to attach')
        self.fields['form_attachments'] = forms.CharField(widget=forms.HiddenInput(),required=False)
        self.fields['attachement_token'] = forms.CharField(required=False,widget=forms.HiddenInput(),initial = int(time.time() * 1000))

        attachments = Attachment.objects.filter(node=question)
        if len(attachments):
             self.fields['attachement_token'].initial = attachments[0].folder_name
             self.fields['form_attachments'].initial = ";".join([a.name  for a in attachments])

        if not user.is_authenticated() or (int(user.reputation) < settings.CAPTCHA_IF_REP_LESS_THAN and not (user.is_superuser or user.is_staff)):
            spam_fields = call_all_handlers('create_anti_spam_field')
            if spam_fields:
                spam_fields = dict(spam_fields)
                for name, field in spam_fields.items():
                    self.fields[name] = field

                self._anti_spam_fields = spam_fields.keys()
            else:
                self._anti_spam_fields = []

        if settings.WIKI_ON:
            self.fields['wiki'] = WikiField(disabled=(question.nis.wiki and not user.can_cancel_wiki(question)), initial=question.nis.wiki)
Пример #17
0
    def __init__(self, data=None, user=None, *args, **kwargs):
        super(AskForm, self).__init__(data, *args, **kwargs)

        self.fields["tags"] = TagNamesField(user)

        if not user.is_authenticated() or (
            int(user.reputation) < settings.CAPTCHA_IF_REP_LESS_THAN and not (user.is_superuser or user.is_staff)
        ):
            spam_fields = call_all_handlers("create_anti_spam_field")
            if spam_fields:
                spam_fields = dict(spam_fields)
                for name, field in spam_fields.items():
                    self.fields[name] = field

                self._anti_spam_fields = spam_fields.keys()
            else:
                self._anti_spam_fields = []

        if settings.WIKI_ON:
            self.fields["wiki"] = WikiField()
Пример #18
0
    def __init__(self,
                 data=None,
                 user=None,
                 custom_badge=None,
                 *args,
                 **kwargs):
        super(AwardBadgeForm, self).__init__(data, *args, **kwargs)
        self.fields['user'] = UserNameField(user, custom_badge)

        if int(user.reputation) < settings.CAPTCHA_IF_REP_LESS_THAN and not (
                user.is_superuser or user.is_staff):
            spam_fields = call_all_handlers('create_anti_spam_field')
            if spam_fields:
                spam_fields = dict(spam_fields)
                for name, field in spam_fields.items():
                    self.fields[name] = field

                self._anti_spam_fields = spam_fields.keys()
            else:
                self._anti_spam_fields = []
Пример #19
0
    def __init__(self, *args, **kwargs):
        super(ClassicRegisterForm, self).__init__(*args, **kwargs)

        # Try importing the ReCapthca public and private keys, Import Error will be raised in case it has been disabled
        try:
            from forum.settings import RECAPTCHA_PUB_KEY, RECAPTCHA_PRIV_KEY
            recaptcha_enabled = len(str(RECAPTCHA_PUB_KEY.value)) > 0 and len(str(RECAPTCHA_PRIV_KEY.value)) > 0
        except ImportError:
            recaptcha_enabled = False

        if recaptcha_enabled:
            spam_fields = call_all_handlers('create_anti_spam_field')
            if spam_fields:
                spam_fields = dict(spam_fields)
                for name, field in spam_fields.items():
                    self.fields[name] = field

                self._anti_spam_fields = spam_fields.keys()
            else:
                self._anti_spam_fields = []
Пример #20
0
    def __init__(self, *args, **kwargs):
        super(ClassicRegisterForm, self).__init__(*args, **kwargs)

        # Try importing the ReCapthca public and private keys, Import Error will be raised in case it has been disabled
        try:
            from forum.settings import RECAPTCHA_PUB_KEY, RECAPTCHA_PRIV_KEY
            recaptcha_enabled = len(str(RECAPTCHA_PUB_KEY.value)) > 0 and len(
                str(RECAPTCHA_PRIV_KEY.value)) > 0
        except ImportError:
            recaptcha_enabled = False

        if recaptcha_enabled:
            spam_fields = call_all_handlers('create_anti_spam_field')
            if spam_fields:
                spam_fields = dict(spam_fields)
                for name, field in spam_fields.items():
                    self.fields[name] = field

                self._anti_spam_fields = spam_fields.keys()
            else:
                self._anti_spam_fields = []