コード例 #1
0
ファイル: company.py プロジェクト: kakabomba/profireader
def user_company_status_changed(target, new_value, old_value, action):

    company = Company.get(target.company_id)

    dict_main = {
        'company': company,
        'url_company_profile': url_for('company.profile', company_id=company.id)
    }

    to_users = [User.get(target.user_id)]

    if new_value == UserCompany.STATUSES['APPLICANT']:
        phrase = "User <a href=\"%(url_profile_from_user)s\">%(from_user.full_name)s</a> want to join to company <a href=\"%(url_company_employees)s\">%(company.name)s</a>"
        dict_main['url_company_employees'] = jinja_utils.grid_url(target.id, 'company.employees', company_id=company.id)
        to_users = company.get_user_with_rights(UserCompany.RIGHT_AT_COMPANY.EMPLOYEE_ENLIST_OR_FIRE)
    elif new_value == UserCompany.STATUSES['ACTIVE'] and old_value != UserCompany.STATUSES['FIRED'] and g.user.id != target.user_id:
        phrase = "Your request to join company company <a href=\"%(url_company_profile)s\">%(company.name)s</a> is accepted"
    elif new_value == UserCompany.STATUSES['ACTIVE'] and old_value == UserCompany.STATUSES['FIRED'] and g.user.id != target.user_id:
        phrase = "You are now enlisted to <a href=\"%(url_company_profile)s\">%(company.name)s</a> company"
    elif new_value == UserCompany.STATUSES['REJECTED'] and g.user.id != target.user_id:
        phrase = "Sorry, but your request to join company company <a href=\"%(url_company_profile)s\">%(company.name)s</a> was rejected"
    elif new_value == UserCompany.STATUSES['FIRED'] and g.user.id != target.user_id:
        phrase = "Sorry, your was fired from company <a href=\"%(url_company_profile)s\">%(company.name)s</a>"
    else:
        phrase = None

    # possible notification - 5
    return Socket.prepare_notifications(to_users, Notification.NOTIFICATION_TYPES['COMPANY_EMPLOYERS_ACTIVITY'], phrase, dict_main)
コード例 #2
0
ファイル: materials.py プロジェクト: kakabomba/profireader
def publication_status_changed(target, new_value, old_value, action):
    from ..models.rights import PublishUnpublishInPortal
    from ..models.messenger import Notification, Socket

    portal_division = target.portal_division if target.portal_division else PortalDivision.get(
        target.portal_division_id)
    portal = portal_division.portal
    material = Material.get(target.material_id)

    dict_main = {
        'portal_division': portal_division,
        'portal': portal,
        'publication': target,
        'material': material,
        'url_publication': '//' + portal.host + url_for('front.article_details', publication_id=target.id,
                                                        publication_title=material.title),
        'url_portal_publications': jinja_utils.grid_url(target.id, 'portal.publications',
                                                        company_id=portal.company_owner_id)
    }

    phrase = new_value
    if new_value == Publication.STATUSES['SUBMITTED'] and not old_value:
        r = PublishUnpublishInPortal.publish_rights
    elif new_value == Publication.STATUSES['PUBLISHED']:
        r = PublishUnpublishInPortal.unpublish_rights
    elif old_value == Publication.STATUSES['PUBLISHED']:
        r = PublishUnpublishInPortal.unpublish_rights
        phrase = Publication.STATUSES['UNPUBLISHED']
    else:
        phrase = None

    if phrase:
        rights_phrase = "User <a href=\"%(url_profile_from_user)s\">%(from_user.full_name)s</a> just <a href=\"%(url_portal_publications)s\">" + \
                        phrase + \
                        "</a> a material named `%(material.title)s` at portal <a class=\"external_link\" target=\"blank_\" href=\"%(url_publication)s\">%(portal.name)s<span class=\"fa fa-external-link pr-external-link\"></span></a>"
        to_users = PublishUnpublishInPortal(target, portal_division, material.company).get_user_with_rights(r)
        if material.editor not in to_users:
            to_users.append(material.editor)
    else:
        to_users = []
        rights_phrase = None

    # possible notification - 3
    return Socket.prepare_notifications(to_users, Notification.NOTIFICATION_TYPES['PUBLICATION_ACTIVITY'],
                                        rights_phrase,
                                        dict_main, except_to_user=[g.user])