class EngagementSchema(ContentSchema): """ Schema for CustomContent. """ engagement_code = colander.SchemaNode( colander.String(), title=_(u"Engagement Code")) customer_id = colander.SchemaNode( colander.Integer(), title=_(u'Customer'), widget=deferred_company_select_widget )
class ActivityAddForm(AddFormView): """ Form to add a new instance of Activity. """ item_type = _(u"Activity") def schema_factory(self): tmpstore = FileUploadTempStore(self.request) return ActivitySchema(tmpstore) def add(self, **appstruct): title = '%s (%s to %s)' % ( self.request.user.name, appstruct['start_dt'].strftime('%Y-%m-%d %H:%M'), appstruct['end_dt'].strftime('%Y-%m-%d %H:%M')) appstruct['title'] = title return Activity(**appstruct) def find_name(self, appstruct): appstruct.setdefault('uuid', str(uuid4())) return appstruct['uuid'] def save_success(self, appstruct): appstruct['start_dt'] = appstruct['start_dt'].replace(minute=0) appstruct['end_dt'] = appstruct['end_dt'].replace(minute=0) result = super(ActivityAddForm, self).save_success(appstruct) name = appstruct['uuid'] new_item = get_root()[name] = self.context[name] location = self.request.application_url + '/activities' return HTTPFound(location=location)
def pwd_login(context, request): """ Login view. Renders either the login or password forgot form templates or handles their form submission and redirects to came_from on success. :result: Either a redirect response or a dictionary passed to the template for rendering :rtype: pyramid.httpexceptions.HTTPFound or dict """ principals = get_principals() came_from = request.params.get('came_from', request.resource_url(context)) login, password = u'', u'' if 'submit' in request.POST: login = request.params['login'].lower() password = request.params['password'] user = _find_user(login) if (user is not None and user.active and principals.validate_password(password, user.password)): return get_settings()['kotti.login_success_callback'][0](request, user, came_from) request.session.flash(_(u"Login failed."), 'error') if 'reset-password' in request.POST: login = request.params['login'] user = _find_user(login) if user is not None and user.active: return get_settings()['kotti.reset_password_callback'][0](request, user) else: request.session.flash( _(u"That username or email is not known by this system."), 'error') return { 'url': request.application_url + '/@@pwd_login', 'came_from': came_from, 'login': login, 'password': password, }
def default_view(self): """ Default view for :class:`episkopos.resources.Company` :result: Dictionary needed to render the template. :rtype: dict """ return { 'foo': _(u'bar'), }
class Engagement(Content): """ A company content type. """ __versioned__ = {} __tablename__ = 'engagements' implements(IDefaultWorkflow) id = Column(Integer, ForeignKey('contents.id'), primary_key=True) engagement_code = Column(Unicode(1000)) customer_id = Column(Integer, ForeignKey('companies.id')) customer = relationship('Company', primaryjoin='Engagement.customer_id==Company.id') uuid = Column(Unicode(50)) type_info = Content.type_info.copy( name=u'Engagement', title=_(u'Engagement'), add_view=u'add_engagement', addable_to=[u'Document'], add_permission='episkopos.add_engagement', selectable_default_views=[ # ("alternative-view", _(u"Alternative view")), ], ) def __init__(self, engagement_code=None, customer_id=None, uuid=None, **kwargs): """ Constructor :param custom_attribute: A very custom attribute :type custom_attribute: unicode :param **kwargs: Arguments that are passed to the base class(es) :type **kwargs: see :class:`kotti.resources.Content` """ super(Engagement, self).__init__(**kwargs) self.engagement_code = engagement_code self.customer_id = customer_id self.uuid = uuid or str(uuid4()) @property def in_navigation(self): return False @in_navigation.setter def in_navigation(self, value): pass
class Activity(Content): __tablename__ = 'activities' implements(IDefaultWorkflow) id = Column(Integer, ForeignKey('contents.id'), primary_key=True) engagement_id = Column(Integer, ForeignKey('engagements.id')) engagement = relationship('Engagement', primaryjoin='Activity.engagement_id==Engagement.id') start_dt = Column(UTCDateTime()) end_dt = Column(UTCDateTime()) summary = Column(UnicodeText()) issues = Column(UnicodeText()) in_navigation = Column(Boolean, default=False) uuid = Column(Unicode(50)) type_info = Content.type_info.copy( name=u'Activity', title=_(u'Activity'), add_view=u'add_activity', addable_to=[u'Document'], add_permission='episkopos.add_activity', selectable_default_views=[ # ("alternative-view", _(u"Alternative view")), ], ) def __init__(self, engagement_id=None, start_dt=None, end_dt=None, uuid=None, issues=None, **kwargs): """ Constructor :param custom_attribute: A very custom attribute :type custom_attribute: unicode :param **kwargs: Arguments that are passed to the base class(es) :type **kwargs: see :class:`kotti.resources.Content` """ super(Activity, self).__init__(**kwargs) self.uuid = uuid or str(uuid4()) self.engagement_id = engagement_id self.start_dt = start_dt self.end_dt = end_dt self.issues = issues @property def in_navigation(self): return False @in_navigation.setter def in_navigation(self, value): pass
class EngagementAddForm(AddFormView): """ Form to add a new instance of Engagement. """ item_type = _(u"Engagement") def schema_factory(self): tmpstore = FileUploadTempStore(self.request) return EngagementSchema(tmpstore) def add(self, **appstruct): return Engagement(**appstruct) def find_name(self, appstruct): appstruct.setdefault('uuid', str(uuid4())) return appstruct['uuid'] def save_success(self, appstruct): result = super(EngagementAddForm, self).save_success(appstruct) name = appstruct['uuid'] new_item = get_root()[name] = self.context[name] location = self.success_url or self.request.resource_url(new_item) return HTTPFound(location=location)
def set_username(context, request): came_from = request.params.get('came_from', request.resource_url(context)) login = (request.params.get('login') or '').strip() fullname = (request.params.get('fullname') or '').strip() if (fullname and login) and not get_principals().search(name=login).first(): cred = request.session.pop('velruse.credentials') appstruct = { 'name': login, 'password': uuid4().hex, 'title': fullname, 'email': cred['profile']['verifiedEmail'], 'active': True, 'confirm_token': None, 'groups': None } # FIXME: make this generic if appstruct['email'].lower().endswith('@abyres.net'): appstruct['groups'] = ['role:staff'] get_principals()[login] = appstruct return login_success_callback(request, get_principals()[login], came_from) elif login and get_principals().search(name=login).first(): request.session.flash(_(u"Username already taken."), 'error') cred = request.session.get('velruse.credentials', None) if not fullname: fullname = ( request.params.get('fullname') or (cred['profile']['displayName'] if cred else '') or (cred['profile']['verifiedEmail'].split('@')[0].capitalize() if cred else '')) if not login: login = (cred['profile']['verifiedEmail'].split('@')[0] if cred else '') return { 'url': request.url, 'came_from': came_from, 'login': login, 'fullname': fullname }
class CompanyAddForm(AddFormView): """ Form to add a new instance of Company. """ item_type = _(u"Company") def schema_factory(self): tmpstore = FileUploadTempStore(self.request) return CompanySchema(tmpstore) def find_name(self, appstruct): appstruct.setdefault('uuid', str(uuid4())) return appstruct['uuid'] def save_success(self, appstruct): result = super(CompanyAddForm, self).save_success(appstruct) name = appstruct['uuid'] new_item = get_root()[name] = self.context[name] location = self.success_url or self.request.resource_url(new_item) return HTTPFound(location=location) def add(self, **appstruct): # appstruct['logo'] = _to_fieldstorage(**appstruct['logo']) return Company(**appstruct)
class ActivitySchema(colander.MappingSchema): """ Schema for CustomContent. """ engagement_id = colander.SchemaNode( colander.Integer(), title=_(u"Engagement"), widget=deferred_engagement_select_widget) start_dt = colander.SchemaNode( colander.DateTime( default_tzinfo=FixedOffset(8, 0, 'Asia/Kuala_Lumpur')), title=_(u'Start'), widget=DateTimeInputWidget(time_options=(('format', 'h:i A'), ('interval', 60))), default=deferred_default_dt) end_dt = colander.SchemaNode( colander.DateTime( default_tzinfo=FixedOffset(8, 0, 'Asia/Kuala_Lumpur')), title=_(u'End'), widget=DateTimeInputWidget(time_options=(('format', 'h:i A'), ('interval', 60))), default=deferred_default_dt) summary = colander.SchemaNode( colander.String(), title=_('Activity Summary'), widget=RichTextWidget(), missing=u"", ) issues = colander.SchemaNode( colander.String(), title=_('Issues Faced'), widget=RichTextWidget(), missing=u"", ) tags = colander.SchemaNode( ObjectType(), title=_('Tags'), widget=deferred_tag_it_widget, missing=[], )
class CompanySchema(ContentSchema): """ Schema for CustomContent. """ registration_number = colander.SchemaNode( colander.String(), title=_(u"Registration Number"))
def calendar(self): fullcalendar.need() return { 'foo': _(u'bar'), }
def activities(self): row_size_per_page = 15 cur_page = 1 total_rows = DBSession.query(func.count(Activity.id)).scalar() total_page_num = int( math.ceil(float(total_rows) / float(row_size_per_page))) location = '/activities' param = 'page' if self.request.params.keys(): cur_page = int(self.request.params.values()[0]) def get_date(d): return d.strftime('%Y-%m-%d %H:%M') if d else '' def pagination_data(): end = total_page_num + 1 data = [] for x in range(1, end): data.append({ 'val': x, 'url': '%s?%s=%d' % (location, param, x) }) return data return { 'headers': [{ 'key': 'owner', 'label': _(u'Owner'), 'structure': False }, { 'key': 'start_dt', 'label': _(u'Start Date'), 'structure': False }, { 'key': 'end_dt', 'label': _(u'End Date'), 'structure': False }, { 'key': 'summary', 'label': _(u'Summary'), 'structure': True }, { 'key': 'issues', 'label': _(u'Issues'), 'structure': True }, { 'key': 'engagement', 'label': _(u'Engagement'), 'structure': False }], 'data': [{ 'url': self.request.resource_url(i), 'start_dt': get_date(i.start_dt), 'end_dt': get_date(i.end_dt), 'owner': i.owner, 'summary': i.summary, 'issues': i.issues, 'engagement': i.engagement.title } for i in DBSession.query(Activity).order_by( desc(Activity.start_dt)).slice( row_size_per_page * (cur_page - 1), row_size_per_page * (cur_page)).all()], 'pagination': pagination_data(), 'navigation': { 'cur_page': cur_page, 'total_page': total_page_num, 'prev': '%s?%s=%d' % (location, param, cur_page - 1), 'next': '%s?%s=%d' % (location, param, cur_page + 1) } }