Exemple #1
0
class Correlation(Debatable):
    """Correlation class"""
    name = renamer()
    source = SharedUniqueProperty('source', 'source_correlations')
    targets = SharedMultipleProperty('targets', 'target_correlations')
    context = SharedUniqueProperty('context', 'contextualized_correlations')
    author = SharedUniqueProperty('author')
    channels = CompositeMultipleProperty('channels', 'subject')
    comments = CompositeMultipleProperty('comments')

    def __init__(self, **kwargs):
        super(Correlation, self).__init__(**kwargs)
        self.set_data(kwargs)
        self.type = CorrelationType.weak
        self.tags = PersistentList()
        # self.addtoproperty('channels', Channel(title=_("General")))

    @property
    def ends(self):
        """Return the ends of the correlation"""
        result = list(self.targets)
        result.append(self.source)
        return result

    @property
    def channel(self):
        channels = getattr(self, 'channels', [])
        return channels[0] if channels else None

    @property
    def type_name(self):
        return CorrelationType.type_name(self.type)
Exemple #2
0
class Commentable(VisualisableElement, Entity):
    """ A Commentable entity is an entity that can be comment"""

    name = renamer()
    comments = CompositeMultipleProperty('comments')

    def __init__(self, **kwargs):
        super(Commentable, self).__init__(**kwargs)
        self.len_comments = 0

    def update_len_comments(self):
        result = len(self.comments)
        result += sum([c.update_len_comments() for c in self.comments])
        self.len_comments = result
        return self.len_comments

    def addtoproperty(self, name, value, moving=None):
        super(Commentable, self).addtoproperty(name, value, moving)
        if name == 'comments':
            channel = getattr(self, 'channel', self)
            channel.len_comments += 1
            if self is not channel:
                self.len_comments += 1

    def delfromproperty(self, name, value, moving=None):
        super(Commentable, self).delfromproperty(name, value, moving)
        if name == 'comments':
            channel = getattr(self, 'channel', self)
            channel.len_comments -= 1
            if self is not channel:
                self.len_comments -= 1
class PeriodicAdvertising(Advertising):
    """PeriodicAdvertising class"""

    type_title = _('Periodical advertisement')
    icon = 'lac-icon icon-periodic-advertising'
    templates = {
        'default': 'lac:views/templates/periodic_advertisting_result.pt',
        'bloc': 'lac:views/templates/periodic_advertisting_result.pt'
    }
    name = renamer()

    def get_content_data(self, request=None):
        if request is None:
            request = get_current_request()

        result = {'url': '', 'type': 'none'}
        if self.picture:
            result = {
                'url': self.picture.url,
                'filename': self.picture.filename
            }
            if self.picture.mimetype.startswith('application/pdf'):
                result['type'] = 'pdf'
            else:
                #application/quarkxpress, application/x-quark-express
                result['type'] = 'xpress'

        return result
Exemple #4
0
class Brief(SearchableEntity):
    """Brief class"""

    type_title = _('News flash')
    icon = 'lac-icon icon-brief'
    templates = {'default': 'lac:views/templates/brief_result.pt',
                 'bloc': 'lac:views/templates/brief_result_bloc.pt'}
    name = renamer()
    picture = CompositeUniqueProperty('picture')
    author = SharedUniqueProperty('author', 'contents')

    def __init__(self, **kwargs):
        self._presentation_text = None
        super(Brief, self).__init__(**kwargs)
        self.set_data(kwargs)

    def _init_presentation_text(self):
        self._presentation_text = html_to_text(
            getattr(self, 'details', ''))

    def __setattr__(self, name, value):
        super(Brief, self).__setattr__(name, value)
        if name == 'details':
            self._init_presentation_text()

    def presentation_text(self, nb_characters=400):
        text = getattr(self, '_presentation_text', None)
        if text is None:
            self._init_presentation_text()
            text = getattr(self, '_presentation_text', '')

        return text[:nb_characters]+'...'
Exemple #5
0
class Document(Persistent):

    name = renamer()

    def __init__(self, title='', body=''):
        self.title = title
        self.body = body
Exemple #6
0
class Document(Persistent):

    name = renamer()
    body = ''
    body_format = 'rst'
    icon = ''
    image = ''

    def __init__(self,
                 title='',
                 body='',
                 body_format='',
                 icon='',
                 image='',
                 created=None,
                 modified=None,
                 creator=''):
        self.title = title
        self.body = body
        self.body_format = body_format
        self.icon = icon
        self.image = image
        if created is None:
            created = datetime.datetime.today()
        if modified is None:
            modified = datetime.datetime.today()
        self.created = created
        self.modified = modified
        self.creator = creator
Exemple #7
0
class CinemaReview(BaseReview):
    """Review class"""

    type_title = _('Cinema review')
    icon = 'lac-icon icon-reviwe-cinema'
    templates = {
        'default': 'lac:views/templates/review_result.pt',
        'bloc': 'lac:views/templates/review_result_bloc.pt'
    }
    name = renamer()
    directors = SharedMultipleProperty('directors', 'productions')

    @property
    def appreciation_title(self):
        return APPRECIATIONS.get(getattr(self, 'appreciation', ''), '')

    @property
    def directors_ids(self):
        return [str(get_oid(a)) for a in self.directors]

    @property
    def relevant_data(self):
        result = super(CinemaReview, self).relevant_data
        result.extend([', '.join([a.title for a in self.directors])])
        return result
Exemple #8
0
class Binder(Folder):

    name = renamer()

    def __init__(self, title):
        super(Binder, self).__init__()
        self.title = title
Exemple #9
0
class QuitRequest(VisualisableElement, Entity):
    """QuitRequest class"""
    icon = 'typcn typcn-user-add'
    templates = {}
    name = renamer()
    user = SharedUniqueProperty('user')

    def __init__(self, **kwargs):
        super(QuitRequest, self).__init__(**kwargs)
        self.set_data(kwargs)

    def init_deadline(self, date):
        self.deadline_date = date\
            + datetime.timedelta(seconds=DEADLINE_QUIT_REQUEST)
        return self.deadline_date

    def get_deadline_date(self):
        if getattr(self, 'deadline_date', None) is not None:
            return self.deadline_date

        self.deadline_date = self.created_at\
            + datetime.timedelta(seconds=DEADLINE_QUIT_REQUEST)
        return self.deadline_date

    @property
    def is_expired(self):
        return datetime.datetime.now(tz=pytz.UTC) > self.get_deadline_date()
Exemple #10
0
class Binder(Folder):

    name = renamer()
    related = multireference_sourceid_property(BinderToRelated, ordered=True)

    def __init__(self, title):
        super(Binder, self).__init__()
        self.title = title
Exemple #11
0
class Company(StructureBase):
    """Person class"""

    name = renamer()

    def __init__(self, **kwargs):
        super(Company, self).__init__(**kwargs)
        self.set_data(kwargs)
Exemple #12
0
class Directory(Folder):

    name = renamer()

    def __init__(self, title='', description=''):
        Folder.__init__(self)
        self.title = title
        self.description = description
Exemple #13
0
class Report(VisualisableElement, Entity):
    """Report of ballot class"""
    name = renamer()
    electors = SharedMultipleProperty('electors')
    voters = SharedMultipleProperty('voters')
    subjects = SharedMultipleProperty('subjects')
    processes = SharedMultipleProperty('processes')
    ballot = SharedUniqueProperty('ballot', 'report')

    def __init__(self, ballottype, electors, subjects, **kwargs):
        kwargs['subjects'] = subjects
        kwargs['electors'] = electors
        super(Report, self).__init__(**kwargs)
        self.ballottype = BALLOT_TYPES[ballottype](self, **kwargs)
        if 'vote_process_id' in kwargs:
            self.ballottype.vote_process_id = kwargs['vote_process_id']

        self.result = None
        self.calculated = False

    def calculate_votes(self):
        """Return the result of ballot"""

        if not self.calculated:
            votes = self.ballot.ballot_box.votes
            self.result = self.ballottype.calculate_votes(votes)
            self.calculated = True
        else:
            return self.result

    def get_electeds(self):
        """Return the elected subject"""

        if not self.calculated:
            self.calculate_votes()

        return self.ballottype.get_electeds(self.result)

    def he_voted(self, user):
        mask = getattr(user, 'mask', None)
        return user in self.voters or (mask and mask in self.voters)

    def is_elector(self, user):
        mask = getattr(user, 'mask', None)
        return user in self.electors or (mask and mask in self.electors)

    def get_elector(self, user):
        if not self.is_elector(user):
            return None

        if user in self.electors:
            return user

        mask = getattr(user, 'mask', None)
        if mask and mask in self.electors:
            return mask

        return None
Exemple #14
0
class Document(Persistent):
    name = renamer()

    def __init__(self, title, body):
        self.title = title
        self.body = body

    def after_create(self, inst, registry):
        pass
Exemple #15
0
class Interview(BaseReview):
    """Interview class"""

    type_title = _('Interview')
    icon = 'lac-icon icon-interview'
    templates = {'default': 'lac:views/templates/interview_result.pt',
                 'bloc': 'lac:views/templates/interview_result_bloc.pt'}
    name = renamer()
    review = SharedUniqueProperty('review')
Exemple #16
0
class WebAdvertising(Advertising):
    """WebAdvertising class"""

    type_title = _('Web advertisement')
    icon = 'glyphicon glyphicon-picture'
    templates = {
        'default': 'lac:views/templates/web_advertisting_result.pt',
        'bloc': 'lac:views/templates/web_advertisting_result.pt'
    }
    name = renamer()

    def __init__(self, **kwargs):
        self.click = 0
        super(WebAdvertising, self).__init__(**kwargs)

    def _extract_content(self):
        if self.picture:
            if self.picture.mimetype.startswith('image'):
                return {'content': self.picture.url, 'type': 'img'}

            if self.picture.mimetype.startswith(
                    'application/x-shockwave-flash'):
                return {'content': self.picture.url, 'type': 'flash'}

            if self.picture.mimetype.startswith('text/html'):
                blob = self.picture.blob.open()
                blob.seek(0)
                content = blob.read().decode("utf-8")
                blob.seek(0)
                blob.close()
                return {'content': content, 'type': 'html'}

        html_content = getattr(self, 'html_content', '')
        if html_content:
            return {'content': html_content, 'type': 'html'}

        return {'content': '', 'type': 'none'}

    def get_positions(self):
        return [ADVERTISING_CONTAINERS[p]['title'] for p in self.positions]

    def get_content_data(self, request=None):
        if request is None:
            request = get_current_request()

        root = request.root
        data = {
            'url':
            request.resource_url(root,
                                 'banner_click',
                                 query={'ad_oid': getattr(self, '__oid__',
                                                          0)}),
        }

        data.update(self._extract_content())
        return data
Exemple #17
0
class Keyword(VisualisableElement, Entity):
    """Keyword class"""

    name = renamer()
    referenced_elements = SharedMultipleProperty('referenced_elements',
                                                 'keywords')

    def __init__(self, **kwargs):
        super(Keyword, self).__init__(**kwargs)
        self.set_data(kwargs)
Exemple #18
0
class Review(BaseReview):
    """Review class"""

    type_title = _('Review')
    icon = 'glyphicon glyphicon-file'
    templates = {
        'default': 'lac:views/templates/review_result.pt',
        'bloc': 'lac:views/templates/review_result_bloc.pt'
    }
    name = renamer()
class Contact(Persistent):

    name = renamer()
    
    def __init__(self, firstname='', lastname='', email='', telephone='', bio=''):
        self.firstname = firstname
        self.lastname = lastname
        self.email = email
        self.telephone = telephone
        self.bio = bio
Exemple #20
0
class Newsletter(VisualisableElement, Entity):
    """Newsletter class"""

    type_title = _('Newsletter')
    icon = 'glyphicon glyphicon-envelope'
    templates = {
        'default': 'lac:views/templates/newsletter_result.pt',
        'bloc': 'lac:views/templates/newsletter_result.pt'
    }
    name = renamer()
    content_template = CompositeUniqueProperty('content_template')
    site = SharedUniqueProperty('site', 'newsletters')

    def __init__(self, **kwargs):
        super(Newsletter, self).__init__(**kwargs)
        self.set_data(kwargs)
        self.subscribed = PersistentDict()

    def get_content_template(self):
        if self.content_template:
            try:
                return self.content_template.fp.readall().decode()
            except Exception as error:
                log.warning(error)

        return ''

    def get_sending_date(self):
        return datetime.datetime.combine(
            getattr(self, 'sending_date', datetime.datetime.now(tz=pytz.UTC)),
            datetime.time(0, 0, 0, tzinfo=pytz.UTC))

    def get_next_sending_date(self, date=None):
        if date is None:
            date = self.get_sending_date()

        default = REC_DEFAULT.get('days')
        nb_rec = getattr(self, 'recurrence_nb', default)
        return (date +
                datetime.timedelta(days=nb_rec)).replace(tzinfo=pytz.UTC)

    def can_send(self):
        template = self.get_content_template()
        content_ = getattr(self, 'content', '')
        return content_ and content_ != template

    def reset_content(self):
        if self.content_template:
            content_ = self.get_content_template()
            if not getattr(self, 'content', ''):
                setattr(self, 'content', content_)

    def is_subscribed(self, user):
        email = getattr(user, 'email', None)
        return email and email in self.subscribed
Exemple #21
0
class Document(Persistent):
    name = renamer()

    refs = multireference_targetid_property("document-ref")

    def __init__(self, title, body):
        self.title = title
        self.body = body

    def after_create(self, inst, registry):
        pass
Exemple #22
0
class BlogEntry(Persistent):
    name = renamer()

    def __init__(self, title='', body='', pub_date=None):
        self.title = title
        self.body = body
        if pub_date is None:
            t = datetime.datetime.now(UTC)
            pub_date = datetime.datetime(
                t.year, t.month, t.day, t.hour, t.minute, t.second, tzinfo=UTC)
        self.pub_date = pub_date
Exemple #23
0
class CreationCulturelleApplication(VisualisableElement, Application):
    """Application root."""

    name = renamer()
    tree = synchronize_tree()
    files = CompositeMultipleProperty('files')
    site_folders = CompositeMultipleProperty('site_folders')
    preregistrations = CompositeMultipleProperty('preregistrations')
    smart_folders = CompositeMultipleProperty('smart_folders')
    cultural_events = CompositeMultipleProperty('cultural_events')
    schedules = CompositeMultipleProperty('schedules')
    film_schedules = CompositeMultipleProperty('film_schedules')
    reviews = CompositeMultipleProperty('reviews')
    advertisings = CompositeMultipleProperty('advertisings')
    games = CompositeMultipleProperty('games')
    pictures = CompositeMultipleProperty('pictures')
    organizations = CompositeMultipleProperty('organizations')
    groups = CompositeMultipleProperty('groups')
    services_definition = CompositeMultipleProperty('services_definition')
    artists = CompositeMultipleProperty('artists')
    venues = CompositeMultipleProperty('venues')
    labels = CompositeMultipleProperty('labels')

    def __init__(self, **kwargs):
        super(CreationCulturelleApplication, self).__init__(**kwargs)
        self.initialization()

    def initialization(self):
        self.titles = DEFAULT_TITLES
        self.ticket_types_values = DEFAULT_TICKET_TYPES_VALUES
        self._tree = PersistentDict()
        self.keywords = PersistentList()
        self.tree = DEFAULT_TREE

    def get_keywords_by_level(self):
        return get_keywords_by_level(dict(self.tree), ROOT_TREE)

    def get_tree_nodes_by_level(self):
        return get_tree_nodes_by_level(dict(self.tree))

    def merge_tree(self, tree):
        self.tree = merge_tree(dict(self.tree), tree)

    @property
    def resourcemanager(self):
        return get_current_registry().getUtility(IResourceManager,
                                                 default_resourcemanager)

    def get_services_definition(self):
        return {
            service.service_id: service
            for service in self.services_definition
        }
Exemple #24
0
class Database(Folder):
    implements(IAttributeAnnotatable, IDatabasable)

    name = renamer()

    def __init__(self, title=''):
        Folder.__init__(self)
        self.title = title

    def create_form(self, settings, code, html):
        form_id = settings['id']
        self[form_id] = Form(form_id, settings['title'])
        form_obj = self[form_id]
        form = IForm(form_obj)
        form.assign_rules(settings['assigned_rules'])
        form.set_code(code)
        form.set_layout(html)
        for (field_id, field_settings) in settings['fields'].items():
            form.set_field(
                field_id, {
                    'type': field_settings['type'],
                    'index_type': field_settings.get('index_type', ''),
                })

    def current_user(self):
        return get_current_request().user.__name__

    def current_user_groups(self):
        return [group.__name__ for group in get_current_request().user.groups]

    @property
    def uid(self):
        return get_oid(self)

    @property
    def path(self):
        return resource_path(self)

    def url(self):
        request = get_current_request()
        return request.resource_url(self)[:-1]

    @property
    def root(self):
        return self.__parent__

    @property
    def forms(self):
        catalog = find_catalog(self, 'system')
        content_type = catalog['content_type']
        path = catalog['path']
        q = content_type.eq('Form') & path.eq(self.path)
        return q.execute()
Exemple #25
0
class Form(Persistent):
    implements(IAttributeAnnotatable, IFormable)

    name = renamer()

    def __init__(self, id, title=''):
        self.id = id
        self.title = title

    @property
    def path(self):
        return resource_path(self)
Exemple #26
0
class Book(Persistent):
    """
    Use the content decorator to define the book content type.
    """

    isbn = renamer()

    def __init__(self, isbn='', title='', author=(), publisher='', year=2000):
        self.title = title
        self.author = author
        self.publisher = publisher
        self.year = year
Exemple #27
0
class BallotBox(VisualisableElement, Entity):
    """Ballot box class"""
    name = renamer()
    votes = CompositeMultipleProperty('votes')

    def __init__(self, **kwargs):
        super(BallotBox, self).__init__(**kwargs)
        self.vote_len = 0

    def addtoproperty(self, name, value, moving=None):
        super(BallotBox, self).addtoproperty(name, value, moving)
        if name == 'votes':
            self.vote_len += 1
Exemple #28
0
class ReferendumVote(Vote):
    """Referendum vote"""
    name = renamer()
    templates = {
        'default': 'novaideo:views/templates/vote/referendum_vote_result.pt',
        'bloc': 'novaideo:views/templates/vote/referendum_vote_result.pt',
        'small': 'novaideo:views/templates/vote/referendum_vote_result.pt',
        'popover': 'novaideo:views/templates/vote/referendum_vote_result.pt'
    }

    def __init__(self, value=None, **kwargs):
        super(ReferendumVote, self).__init__(**kwargs)
        self.value = value
Exemple #29
0
class FPTPVote(Vote):
    """FPTP vote class"""
    name = renamer()
    templates = {
        'default': 'novaideo:views/templates/vote/fptp_vote_result.pt',
        'bloc': 'novaideo:views/templates/vote/fptp_vote_result.pt',
        'small': 'novaideo:views/templates/vote/fptp_vote_result.pt',
        'popover': 'novaideo:views/templates/vote/fptp_vote_result.pt'
    }

    def __init__(self, value=None, **kwargs):
        super(FPTPVote, self).__init__(**kwargs)
        self.value = value
Exemple #30
0
class MajorityJudgmentVote(Vote):
    """Majority judgment vote"""
    name = renamer()
    templates = {
        'default': 'novaideo:views/templates/vote/mj_vote_result.pt',
        'bloc': 'novaideo:views/templates/vote/mj_vote_result.pt',
        'small': 'novaideo:views/templates/vote/mj_vote_result.pt',
        'popover': 'novaideo:views/templates/vote/mj_vote_result.pt'
    }

    def __init__(self, value=None, **kwargs):
        super(MajorityJudgmentVote, self).__init__(**kwargs)
        self.value = value