コード例 #1
0
ファイル: views.py プロジェクト: MartinPeschke/hnctools
    class ContentEditForm(BaseForm):
        label = "Edit Content"
        grid = GRID_BS3
        fields = [
            TextareaField('value',
                          "Full HTML",
                          attrs=HtmlAttrs(important=True, rows=8),
                          if_empty='')
        ]

        @classmethod
        def cancel_url(cls, request):
            return request.fwd_url(request.context.__parent__)

        @classmethod
        def on_success(cls, request, values):
            data = request.context.contentsMap
            data[request.context.content.key] = values['value']

            contents = SetStaticContentProc(
                request,
                {'Static': [{
                    'key': k,
                    'value': v
                } for k, v in data.items()]})
            request._.refresh(request)

            request.session.flash(
                GenericSuccessMessage("Content updated successfully!"),
                "generic_messages")
            return {'success': True, 'redirect': fwd_url(request)}
コード例 #2
0
 def __init__(self, name, label=None, thing_name="name", **kwargs):
     attrs = HtmlAttrs(
         required=True,
         data_rule_remote="/signup/isavailable",
         data_msg_required="Please enter a {} to proceed".format(
             thing_name),
         placeholder="Enter {} here".format(thing_name))
     super(UniqueNameField, self).__init__(name, label, attrs, **kwargs)
コード例 #3
0
ファイル: signup.py プロジェクト: UFOstart/UFOStart
class ExpertForm(BaseForm):
    id = "expert"
    ROLES = ['EXPERT']
    fields = [
        TagSearchField("Skills",
                       "Add your Skills",
                       '/web/tag/search',
                       'Tags',
                       attrs=HtmlAttrs(placeholder="Find Skills"))
    ]
    on_success = classmethod(role_select_on_success)
コード例 #4
0
class TaskCreateForm(BaseForm):
    label = "Create Task"
    fields = [
        StringField('name', "Title", REQUIRED),
        ChoiceField("category", "Category", lambda s: TASK_CATEGORIES),
        TextareaField("summary", "Summary", REQUIRED, input_classes='x-high'),
        TagSearchField("Tags",
                       "Related Tags",
                       '/web/tag/search',
                       'Tags',
                       attrs=HtmlAttrs(required=True,
                                       data_required_min=3,
                                       placeholder="Add Tags")),
        TagSearchField("Services",
                       "Related Web Services",
                       '/web/service/search',
                       'Services',
                       attrs=HtmlAttrs(required=True,
                                       data_required_min=3,
                                       placeholder="Add Services"))
    ]

    @classmethod
    def on_success(cls, request, values):
        try:
            need = AdminNeedCreateProc(request, values)
        except DBNotification, e:
            if e.message == 'Need_Already_Exists':
                return {
                    'success': False,
                    'errors': {
                        'name':
                        "This task already exists, please change the name to a unique name."
                    }
                }
            else:
                return {'success': False, 'message': e.message}
        except DBException, e:
            return {'success': False, 'message': e.message}
コード例 #5
0
ファイル: views.py プロジェクト: MartinPeschke/hnctools
                                        request.globals.is_debug)
        request.pluralize = request._.pluralize

    return add_content_impl


#=================================================== VIEWS =============================================================

CONTENT_FIELDS = [
    MultipleFormField('values',
                      fields=[
                          BS3_NCOL(
                              StringField('key', "Key", REQUIRED),
                              TextareaField('value',
                                            "Full HTML",
                                            attrs=HtmlAttrs(important=True,
                                                            rows=8)))
                      ],
                      add_more_link_label='Add More Fields')
]


def ContentCreationViewFactory(SetStaticContentProc, fwd_url):
    class ContentCreateForm(BaseForm):
        label = "Create Content"
        width_class = "col-lg-12"
        grid = GRID_BS3
        fields = CONTENT_FIELDS

        @classmethod
        def cancel_url(cls, request):
            return request.rld_url()
コード例 #6
0
 def test_field_attrs_data(self):
     output = BeautifulSoup(Field('name', 'label', attrs = HtmlAttrs(placeholder="REAL_PLACEHOLDER", data_target_plan="TARGET_PLAN"), input_classes="SUPER_CLASS").render("FORM", DummyRequest(), {}, {}))
     self.assertEqual(output.find('input', 'SUPER_CLASS')['placeholder'], "REAL_PLACEHOLDER")
     self.assertEqual(output.find('input', 'SUPER_CLASS')['data-target-plan'], "TARGET_PLAN")
コード例 #7
0
ファイル: need.py プロジェクト: UFOstart/UFOStart
class NeedCreateForm(BaseForm):
    id = "NeedCreate"
    label = ""
    fields = [
        PictureUploadField("picture",
                           _("TaskSetup.FormLabel.Picture"),
                           group_classes='file-upload-control'),
        TypeAheadField('name',
                       _("TaskSetup.FormLabel.Title"),
                       '/web/need/name',
                       'Needs',
                       attrs=REQUIRED,
                       js_module="views/company/need_switch",
                       api_allow_new=True),
        CheckboxPostField('parttime', _("TaskSetup.FormLabel.is part time")),
        CurrencyIntField(
            'cash',
            _("TaskSetup.FormLabel.Cash Value"),
            HtmlAttrs(
                required=True,
                data_control_help=_("TaskSetup.FormLabel.Cash Value.Help")),
            input_classes='data-input cash',
            maxlength=8),
        CurrencyIntField(
            'equity',
            _("TaskSetup.FormLabel.Equity Value"),
            HtmlAttrs(
                required=True,
                data_control_help=_("TaskSetup.FormLabel.Equity Value.Help")),
            input_classes='data-input equity',
            maxlength=8),
        SanitizedHtmlField("customText",
                           _("TaskSetup.FormLabel.Description"),
                           REQUIRED,
                           input_classes='x-high'),
        TagSearchField("Tags",
                       _("TaskSetup.FormLabel.Related Tags"),
                       '/web/tag/search',
                       'Tags',
                       attrs=HtmlAttrs(required=True,
                                       data_required_min=3,
                                       placeholder="Add Tags")),
        ServiceSearchField("Services",
                           _("TaskSetup.FormLabel.Related Services"),
                           '/web/service/search',
                           'Services',
                           attrs=HtmlAttrs(placeholder="Add Services")),
        StringField("advisor.name",
                    _("TaskSetup.FormLabel.Advisor.Name"),
                    input_classes="ignore"),
        EmailField("advisor.email",
                   _("TaskSetup.FormLabel.Advisor.EmailAddress"),
                   input_classes="ignore")
    ]

    @classmethod
    def on_success(cls, request, values):
        _ = request._

        try:
            advisor = unpack_advisor(request, values.pop('advisor', {}))
            need = CreateNeedProc(request, {
                'Needs': [values],
                'token': request.context.round.token
            })
        except DBNotification, e:
            if e.message == 'Need_Already_Exists':
                return {
                    'success': False,
                    'errors': {
                        'name':
                        _("TaskSetup.ErrorMessage.This task already exists, if you intend to create this task, please change its name to something less ambiguous!"
                          )
                    }
                }
            else:
                raise e

        if advisor: invite_advisor_to_need(request, need, advisor)

        request.session.flash(
            GenericSuccessMessage(
                _("TaskSetup.SuccessMessage.Task created successfully!")),
            "generic_messages")
        return {
            'success': True,
            'redirect': request.resource_url(request.context)
        }