class ProductOfferForm(BaseForm): id = "ProductOffer" label = "" fields = [ CleanHtmlField("name", "Title", REQUIRED), SanitizedHtmlField("description", "Description", REQUIRED, input_classes='x-high'), DecimalField("price", "Price", REQUIRED), IntField("stock", "Stock") ] @classmethod def on_success(cls, request, values): product = request.context.product offers = map(methodcaller("unwrap", sparse=True), product.Offers) offers.append(values) try: SetProductOffersProc( request, {'Product': { 'token': product.token, 'Offers': offers }}) except DBNotification, e: return {'errors': {'name': e.message}, 'success': False} return { 'success': True, 'redirect': request.resource_url(request.context) }
class CompanyEditForm(BaseForm): id = "CompanyEdit" label = "" fields = [ PictureUploadField('logo', _('CompanyCreate.Form.Label:Logo'), REQUIRED, picWidth=250, picHeight=170), StringField('name', _('CompanyCreate.Form.Label:Name'), REQUIRED), URLField("companyUrl", _('CompanyCreate.Form.Label:Project Website')), CleanHtmlField('pitch', _('CompanyCreate.Form.Label:Slogan'), REQUIRED, max=90), SanitizedHtmlField("description", _('CompanyCreate.Form.Label:Description'), REQUIRED, input_classes='x-high'), PictureGalleryUploadField( 'Pictures', _('CompanyCreate.Form.Label:Drag multiple images into your gallery' )), StringField( "video", _('CompanyCreate.Form.Label:Paste a Vimeo or Youtube Url')), StringField("slideShare", _('CompanyCreate.Form.Label:Paste a Slideshare Url')), URLField("socialMediaUrl", _('CompanyCreate.Form.Label:Project Blog Url')) ] @classmethod def on_success(cls, request, values): company = request.context.company if isinstance(values.get('Pictures'), basestring): values['Pictures'] = [values['Pictures']] values['Pictures'] = [{'url': url} for url in values['Pictures']] values['token'] = company.token try: company = EditCompanyProc(request, values) except DBNotification, e: if e.message == 'Company_Already_Exists': return { 'success': False, 'errors': { 'name': _('CompanyCreate.Form.Error:Already exists') } } else: return { 'success': False, 'message': 'Something went wrong: {}'.format(e.message) } else:
class OfferField(MultipleFormField): template = 'ufostart:templates/common/controls/offers.html' fields = [ CleanHtmlField("name", "Title", REQUIRED), SanitizedHtmlField("description", "Description", REQUIRED, input_classes='x-high'), CurrencyIntField("price", "Price", REQUIRED, input_classes='data-input amount', maxlength=7), IntField("stock", "Stock", REQUIRED) ]
class PostUpdateForm(BaseForm): id = "PostUpdate" fields = [SanitizedHtmlField("text", None, REQUIRED)] @classmethod def on_success(cls, request, values): AddUpdateCompanyProc( request, { 'token': request.context.company.token, 'update': { 'userToken': request.root.user.token, 'text': values['text'] } }) return { 'success': True, 'redirect': request.resource_url(request.context) }
class ProductCreateForm(BaseForm): id = "ProductCreate" label = "" fields = [ StringField('name', "Name", REQUIRED), SanitizedHtmlField("description", "Description", REQUIRED, input_classes='x-high'), OfferField("Offers", "Add Offers"), PictureGalleryUploadField('Pictures', 'Drag multiple images into your gallery'), VideoUrlField("video", "Vimeo/YouTube") ] @classmethod def on_success(cls, request, values): if isinstance(values.get('pictures'), basestring): values['Pictures'] = [values['Pictures']] values['Pictures'] = [{'url': url} for url in values['Pictures']] offers = values.pop('Offers') data = {'token': request.context.round.token, 'Product': values} round = CreateProductProc(request, data) try: SetProductOffersProc( request, {'Product': { 'token': round.Product.token, 'Offers': offers }}) except DBNotification, e: return {'errors': {'name': e.message}, 'success': False} return { 'success': True, 'redirect': request.resource_url(request.context) }
class FundingCreateForm(BaseForm): id = "Funding" label = "" fields = [ SanitizedHtmlField("description", "Deal Description", REQUIRED, input_classes='x-high'), CurrencyIntField('amount', "Funding Amount", REQUIRED, input_classes='data-input amount', maxlength=7), CurrencyIntField('valuation', "Company Valuation", REQUIRED, input_classes='data-input valuation', maxlength=7), FileUploadField("contract", "Contract") ] @classmethod def on_success(cls, request, values): if values['amount'] > values['valuation']: return { 'success': False, 'errors': { 'amount': 'Amount needs to be lower than valuation!' } } data = {'token': request.context.round.token, 'Funding': values} CreateFundingProc(request, data) return { 'success': True, 'redirect': request.resource_url(request.context) }
class CompanyCreateForm(BaseForm): id = "CompanyCreate" label = "" fields = [ PictureUploadField('logo', _('CompanyCreate.Form.Label:Logo'), REQUIRED, picWidth=250, picHeight=170), StringField('name', _('CompanyCreate.Form.Label:Name'), REQUIRED), UniqueNameField("slug", _('CompanyCreate.Form.Label:UFOstart Url'), thing_name='company name'), URLField("companyUrl", _('CompanyCreate.Form.Label:Project Website')), CleanHtmlField('pitch', _('CompanyCreate.Form.Label:Slogan'), REQUIRED, max=90), SanitizedHtmlField("description", _('CompanyCreate.Form.Label:Description'), REQUIRED, input_classes='x-high'), PictureGalleryUploadField( 'Pictures', _('CompanyCreate.Form.Label:Drag multiple images into your gallery' )), StringField( "video", _('CompanyCreate.Form.Label:Paste a Vimeo or Youtube Url')), StringField("slideShare", _('CompanyCreate.Form.Label:Paste a Slideshare Url')), ChoiceField("currency", _('CompanyCreate.Form.Label:Project Currency'), optionGetter=lambda s: [NamedModel(name='EUR'), NamedModel(name='USD')]), URLField("socialMediaUrl", _('CompanyCreate.Form.Label:Project Blog Url')) ] @classmethod def on_success(cls, request, values): templateKey = request.context.__name__ if isinstance(values.get('pictures'), basestring): values['Pictures'] = [values['Pictures']] values['Pictures'] = [{'url': url} for url in values['Pictures']] values['Template'] = {'key': templateKey} al_company = request.session.get(SESSION_SAVE_TOKEN) if al_company: values['angelListId'] = al_company.id values['angelListToken'] = al_company.token del request.session[SESSION_SAVE_TOKEN] try: company = CreateCompanyProc(request, { 'token': request.root.user.token, 'Company': values }) except DBNotification, e: if e.message == 'Company_Already_Exists': return { 'success': False, 'errors': { 'name': _('CompanyCreate.Form.Error:Already exists') } } else: return { 'success': False, 'message': 'Something went wrong: {}'.format(e.message) } else:
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) }