コード例 #1
0
ファイル: views_front.py プロジェクト: kakabomba/profireader
def get_company_member_and_division(portal: Portal, company_id, company_name):
    # TODO: OZ by OZ: redirect if name is wrong
    portal_dict = portal_and_settings(portal)
    # TODO: OZ by OZ: heck company is member
    member_company = Company.get(company_id)
    membership = db(MemberCompanyPortal, company_id=member_company.id, portal_id=portal.id).one()
    di = None
    for d_id, d in portal_dict['divisions'].items():
        if 'subportal_company' in d and d['subportal_company'].id == company_id:
            di = g.db().query(PortalDivisionSettingsCompanySubportal). \
                join(MemberCompanyPortal,
                     MemberCompanyPortal.id == PortalDivisionSettingsCompanySubportal.member_company_portal_id). \
                join(PortalDivision,
                     PortalDivision.id == PortalDivisionSettingsCompanySubportal.portal_division_id). \
                filter(MemberCompanyPortal.company_id == member_company.id). \
                filter(PortalDivision.portal_id == portal.id).one().portal_division

    if not di:
        # TODO: YG: by OZ: change all hardcoded portal_division_types_id (like '<here some index>') to PortalDivision.TYPES[<here some index>]
        di = g.db().query(PortalDivision).filter_by(portal_id=portal.id,
                                                    portal_division_type_id=PortalDivision.TYPES[
                                                        'catalog']).first()
    if not di:
        di = g.db().query(PortalDivision).filter_by(portal_id=portal.id,
                                                    portal_division_type_id=PortalDivision.TYPES[
                                                        'index']).one()
    return membership, member_company, di
コード例 #2
0
ファイル: views_front.py プロジェクト: Stevee67/profireader
def details(article_portal_division_id):
    search_text, portal, _ = get_params()
    if search_text:
        return redirect(url_for('front.index', search_text=search_text))
    article = ArticlePortalDivision.get(article_portal_division_id)
    article_dict = article.get_client_side_dict(fields='id, title,short, cr_tm, md_tm, '
                                                       'publishing_tm, keywords, status, long, image_file_id,'
                                                       'division.name, division.portal.id,'
                                                       'company.name|id')
    article_dict['tags'] = article.tags

    division = g.db().query(PortalDivision).filter_by(id=article.portal_division_id).one()

    related_articles = g.db().query(ArticlePortalDivision).filter(
        and_(ArticlePortalDivision.id != article.id,
             ArticlePortalDivision.portal_division_id.in_(
                 db(PortalDivision.id).filter(PortalDivision.portal_id == article.division.portal_id))
             )).order_by(ArticlePortalDivision.cr_tm.desc()).limit(5).all()

    return render_template('front/bird/article_details.html',
                           portal=portal_and_settings(portal),
                           current_division=division.get_client_side_dict(),
                           articles_related={
                               a.id: a.get_client_side_dict(fields='id, title, publishing_tm, company.name|id')
                               for a
                               in related_articles},
                           article=article_dict
                           )
コード例 #3
0
ファイル: views_front.py プロジェクト: thewebarea/profireader
def details(article_portal_division_id):
    search_text, portal, sub_query = get_params()

    article = ArticlePortalDivision.get(article_portal_division_id)
    article_dict = article.to_dict(
        "id, title,short, cr_tm, md_tm, "
        "publishing_tm, keywords, status, long, image_file_id,"
        "division.name, division.portal.id,"
        "company.name"
    )
    article_dict["tags"] = article.tags

    division = g.db().query(PortalDivision).filter_by(id=article.portal_division_id).one()

    related_articles = (
        g.db()
        .query(ArticlePortalDivision)
        .filter(division.portal.id == article.division.portal_id)
        .order_by(ArticlePortalDivision.cr_tm.desc())
        .limit(10)
        .all()
    )

    return render_template(
        "front/bird/article_details.html",
        portal=portal_and_settings(portal),
        current_division=division.get_client_side_dict(),
        articles_related={a.id: a.to_dict("id, title, cr_tm, company.name|id") for a in related_articles},
        article=article_dict,
    )
コード例 #4
0
ファイル: translate.py プロジェクト: kakabomba/profireader
 def insert_record(**values):
     from profapp import utils
     g.db().execute(('INSERT INTO "%s" (template,   name,    portal_id, allow_html,   url,  %s) '
                     'VALUES           (:template, :name, :portal_id, :allow_html, :url,  :%s)') %
                    (TranslateTemplate.__tablename__, ', '.join(TranslateTemplate.languages),
                     ", :".join(TranslateTemplate.languages)),
                    params=utils.dict_merge(a_filter, {'allow_html': allow_html, 'url': url},
                                            {l: phrase for l in TranslateTemplate.languages}, values))
     return db(TranslateTemplate, **a_filter).first()
コード例 #5
0
ファイル: chat.py プロジェクト: kakabomba/profireader
def read_notification(sid, notification_id):
    with controlled_execution():
        notification = Notification.get(notification_id)
        if notification.read_tm is None:
            print("SELECT notification_set_read(ARRAY ['%s']);" % (notification.id,))
            g.db().execute("SELECT notification_set_read(ARRAY ['%s']);" % (notification.id,))
            unread = get_unread(notification.to_user_id)
            for sid_for_receiver in connected_user_id_sids[notification.to_user_id]:
                sio.emit('general_notification', {'unread': unread}, sid_for_receiver)
コード例 #6
0
ファイル: views_front.py プロジェクト: thewebarea/profireader
def portal_and_settings(portal):
    ret = portal.get_client_side_dict()
    newd = []
    for di in ret["divisions"]:
        if di["portal_division_type_id"] == "company_subportal":
            pdset = g.db().query(PortalDivisionSettings_company_subportal).filter_by(portal_division_id=di["id"]).one()
            com_port = g.db().query(MemberCompanyPortal).get(pdset.member_company_portal_id)
            di["member_company"] = Company.get(com_port.company_id)
        newd.append(di)
    ret["divisions"] = newd
    return ret
コード例 #7
0
def portal_and_settings(portal):
    ret = portal.get_client_side_dict()
    newd = []
    for di in ret['divisions']:
        if di['portal_division_type_id'] == 'company_subportal':
            pdset = g.db().query(PortalDivisionSettings_company_subportal). \
                filter_by(portal_division_id=di['id']).one()
            com_port = g.db().query(MemberCompanyPortal).get(pdset.member_company_portal_id)
            di['member_company'] = Company.get(com_port.company_id)
        newd.append(di)
    ret['divisions'] = newd
    return ret
コード例 #8
0
def portal_and_settings(portal):
    ret = portal.get_client_side_dict()
    newd = []
    for di in ret['divisions']:
        if di['portal_division_type_id'] == 'company_subportal':
            pdset = g.db().query(PortalDivisionSettingsCompanySubportal). \
                filter_by(portal_division_id=di['id']).first()
            com_port = g.db().query(MemberCompanyPortal).get(pdset.member_company_portal_id)
            di['member_company'] = Company.get(com_port.company_id)
        newd.append(di)
    ret['divisions'] = newd
    ret['advs'] = {a.place: a.html for a in portal.advs}
    return ret
コード例 #9
0
ファイル: chat.py プロジェクト: kakabomba/profireader
def read_message(sid, message_id):
    with controlled_execution():
        message = Message.get(message_id)
        contact = Contact.get(message.contact_id)
        if message.read_tm is None:
            another_user_to_notify_unread = contact.user1_id if contact.user2_id == message.from_user_id else contact.user2_id
            print("SELECT message_set_read('%s', ARRAY ['%s']);" % (message.contact_id, message.id))
            g.db().execute("SELECT message_set_read('%s', ARRAY ['%s']);" % (message.contact_id, message.id))
            unread = get_unread(another_user_to_notify_unread, [contact.id])
            for sid_for_receiver in connected_user_id_sids[another_user_to_notify_unread]:
                sio.emit('general_notification', {
                    'unread': unread
                }, sid_for_receiver)
コード例 #10
0
ファイル: views_front.py プロジェクト: alinelle/profireader
def get_division_for_subportal(portal_id, member_company_id):
    q = g.db().query(PortalDivisionSettingsCompanySubportal). \
        join(MemberCompanyPortal,
             MemberCompanyPortal.id == PortalDivisionSettingsCompanySubportal.member_company_portal_id). \
        join(PortalDivision,
             PortalDivision.id == PortalDivisionSettingsCompanySubportal.portal_division_id). \
        filter(MemberCompanyPortal.company_id == member_company_id). \
        filter(PortalDivision.portal_id == portal_id)
    PortalDivisionSettings = q.all()
    if (len(PortalDivisionSettings)):
        return PortalDivisionSettings[0].portal_division
    else:
        return g.db().query(PortalDivision).filter_by(portal_id=portal_id,
                                                      portal_division_type_id='index').one()
コード例 #11
0
def get_division_for_subportal(portal_id, member_company_id):
    q = g.db().query(PortalDivisionSettingsCompanySubportal). \
        join(MemberCompanyPortal,
             MemberCompanyPortal.id == PortalDivisionSettingsCompanySubportal.member_company_portal_id). \
        join(PortalDivision,
             PortalDivision.id == PortalDivisionSettingsCompanySubportal.portal_division_id). \
        filter(MemberCompanyPortal.company_id == member_company_id). \
        filter(PortalDivision.portal_id == portal_id)
    PortalDivisionSettings = q.all()
    if (len(PortalDivisionSettings)):
        return PortalDivisionSettings[0].portal_division
    else:
        return g.db().query(PortalDivision).filter_by(
            portal_id=portal_id, portal_division_type_id='index').one()
コード例 #12
0
ファイル: views_front.py プロジェクト: spaun299/profireader
def details(article_portal_division_id):
    search_text, portal, _ = get_params()
    if search_text:
        return redirect(url_for("front.index", search_text=search_text))
    article = ArticlePortalDivision.get(article_portal_division_id)
    article_visibility = article.article_visibility_details()
    article_dict = article.get_client_side_dict(
        fields="id, title,short, like_count, read_count, cr_tm, "
        "md_tm, visibility,"
        "publishing_tm, keywords, status, long, image_file_id,"
        "division.name, division.portal.id,"
        "company.name|id"
    )
    article_dict["tags"] = article.tags

    division = g.db().query(PortalDivision).filter_by(id=article.portal_division_id).one()
    if article_visibility is not True:
        back_to_url("front.details", host=portal.host, article_portal_division_id=article_portal_division_id)
    else:
        article.add_recently_read_articles_to_session()
    related_articles = (
        g.db()
        .query(ArticlePortalDivision)
        .filter(
            and_(
                ArticlePortalDivision.id != article.id,
                ArticlePortalDivision.portal_division_id.in_(
                    db(PortalDivision.id).filter(PortalDivision.portal_id == article.division.portal_id)
                ),
            )
        )
        .order_by(ArticlePortalDivision.cr_tm.desc())
        .limit(5)
        .all()
    )
    favorite = article.check_favorite_status(user_id=getattr(g.user, "id", None))
    liked = article.article_is_liked(getattr(g.user, "id", None), article_portal_division_id)
    return render_template(
        "front/" + g.portal_layout_path + "article_details.html",
        portal=portal_and_settings(portal),
        current_division=division.get_client_side_dict(),
        articles_related={
            a.id: a.get_client_side_dict(fields="id, title, publishing_tm, company.name|id") for a in related_articles
        },
        article=article_dict,
        favorite=favorite,
        liked=liked,
        article_visibility=article_visibility is True,
        redirect_info=article_visibility,
    )
コード例 #13
0
def read_notification(sid, notification_id):
    log('read_notification', sid, notification_id)
    with controlled_execution():
        notification = Notification.get(notification_id)
        if notification.read_tm is None:
            log("SELECT notification_set_read(ARRAY ['%s']);" %
                (notification.id, ))
            g.db().execute("SELECT notification_set_read(ARRAY ['%s']);" %
                           (notification.id, ))
            unread = get_unread(notification.to_user_id)
            for sid_for_receiver in connected_user_id_sids[
                    notification.to_user_id]:
                sio.emit('general_notification', {'unread': unread},
                         sid_for_receiver)
コード例 #14
0
def details(article_portal_division_id):
    search_text, portal, _ = get_params()
    if search_text:
        return redirect(url_for('front.index', search_text=search_text))
    article = ArticlePortalDivision.get(article_portal_division_id)
    article_visibility = article.article_visibility_details()
    article_dict = article.get_client_side_dict(
        fields='id, title,short, like_count, read_count, cr_tm, '
        'md_tm, visibility,'
        'publishing_tm, keywords, status, long, image_file_id,'
        'division.name, division.portal.id,'
        'company.name|id')
    article_dict['tags'] = article.tags

    division = g.db().query(PortalDivision).filter_by(
        id=article.portal_division_id).one()
    if article_visibility is not True:
        back_to_url('front.details',
                    host=portal.host,
                    article_portal_division_id=article_portal_division_id)
    else:
        article.add_recently_read_articles_to_session()
    related_articles = g.db().query(ArticlePortalDivision).filter(
        and_(
            ArticlePortalDivision.id != article.id,
            ArticlePortalDivision.portal_division_id.in_(
                db(PortalDivision.id).filter(
                    PortalDivision.portal_id ==
                    article.division.portal_id)))).order_by(
                        ArticlePortalDivision.cr_tm.desc()).limit(5).all()
    favorite = article.check_favorite_status()
    liked = article.check_liked_status()
    liked_count = article.check_liked_count()

    return render_template(
        'front/' + g.portal_layout_path + 'article_details.html',
        portal=portal_and_settings(portal),
        current_division=division.get_client_side_dict(),
        articles_related={
            a.id: a.get_client_side_dict(
                fields='id, title, publishing_tm, company.name|id')
            for a in related_articles
        },
        article=article_dict,
        favorite=favorite,
        liked=liked,
        liked_count=liked_count,
        article_visibility=article_visibility is True,
        redirect_info=article_visibility)
コード例 #15
0
ファイル: messenger.py プロジェクト: kakabomba/profireader
    def get_messages(self, count, get_older=False, than_id=None):
        messages_filter = (Message.contact_id == self.id)
        messages_query = g.db().query(Message)
        if than_id:
            if get_older:
                messages = messages_query.filter(and_(messages_filter, Message.id < than_id)).order_by(
                    expression.desc(Message.cr_tm)).limit(count + 1).all()
                there_is_more = ['there_is_older', len(messages) > count]
                messages = messages[0:count]
                # messages.reverse()

            else:
                messages = messages_query.filter(and_(messages_filter, Message.id > than_id)).order_by(
                    expression.asc(Message.cr_tm)).limit(count + 1).all()
                there_is_more = ['there_is_newer', len(messages) > count]
                messages = messages[0:count]

        else:
            messages = messages_query.filter(messages_filter).order_by(expression.desc(Message.cr_tm)).limit(
                count + 1).all()
            there_is_more = ['there_is_older', len(messages) > count]
            messages = messages[0:count]
            # messages.reverse()

        return {
            there_is_more[0]: there_is_more[1],
            'items': messages
        }
コード例 #16
0
def index(page=1):
    search_text, portal, _ = get_params()
    if not portal:
        return render_template(
            'front/error.html',
            message="No portal found {}".format(request.host),
        )

    division = g.db().query(PortalDivision).filter_by(
        portal_id=portal.id, portal_division_type_id='index').one()
    order = Search.ORDER_POSITION if not search_text else Search.ORDER_RELEVANCE
    page = page if session.get('original_search_text') == search_text else 1
    # portal.config.set_division_page_size(page_size_for_divisions={division.name: 1})
    items_per_page = portal.get_value_from_config(
        key=PortalConfig.PAGE_SIZE_PER_DIVISION, division_name=division.name)
    articles, pages, page = Search().search(
        ArticlePortalDivision().search_filter_default(division.id),
        # {'class': Company, 'filter': Company.name.ilike('ssssssss')},
        search_text=search_text,
        page=page,
        order_by=order,
        pagination=True,
        items_per_page=items_per_page)
    session['original_search_text'] = search_text

    return render_template('front/' + g.portal_layout_path + 'division.html',
                           articles=articles,
                           portal=portal_and_settings(portal),
                           current_division=division.get_client_side_dict(),
                           pages=pages,
                           current_page=page,
                           page_buttons=Config.PAGINATION_BUTTONS,
                           search_text=search_text)
コード例 #17
0
ファイル: messenger.py プロジェクト: kakabomba/profireader
    def get_notifications(count, to_user_id, get_older=False, than_id=None):
        notification_query = g.db().query(Notification).filter(Notification.to_user_id == to_user_id)
        if than_id:
            if get_older:
                notifications = notification_query.filter(Notification.id < than_id).order_by(
                    expression.desc(Notification.cr_tm)).limit(count + 1).all()
                there_is_more = ['there_is_older', len(notifications) > count]
                notifications = notifications[0:count]
                # notifications.reverse()
            else:
                notifications = notification_query.filter(Notification.id > than_id).order_by(
                    expression.asc(Notification.cr_tm)).limit(count + 1).all()
                there_is_more = ['there_is_newer', len(notifications) > count]
                notifications = notifications[0:count]

        else:
            notifications = notification_query.order_by(expression.desc(Notification.cr_tm)).limit(
                count + 1).all()
            there_is_more = ['there_is_older', len(notifications) > count]
            notifications = notifications[0:count]
            # notifications.reverse()

        return {
            there_is_more[0]: there_is_more[1],
            'items': notifications
        }
コード例 #18
0
ファイル: views_front.py プロジェクト: alinelle/profireader
def index(page=1):
    search_text, portal, _ = get_params()
    if not portal:
        return render_template('front/error.html',
                           message="No portal found {}".format(request.host),
                           )

    division = g.db().query(PortalDivision).filter_by(portal_id=portal.id,
                                                      portal_division_type_id='index').one()
    order = Search.ORDER_POSITION if not search_text else Search.ORDER_RELEVANCE
    page = page if session.get('original_search_text') == search_text else 1
    # portal.config.set_division_page_size(page_size_for_divisions={division.name: 1})
    items_per_page = portal.get_value_from_config(key=PortalConfig.PAGE_SIZE_PER_DIVISION,
                                                  division_name=division.name)
    articles, pages, page = Search().search(
        ArticlePortalDivision().search_filter_default(division.id),
        # {'class': Company, 'filter': Company.name.ilike('ssssssss')},
        search_text=search_text, page=page, order_by=order, pagination=True,
        items_per_page=items_per_page)
    session['original_search_text'] = search_text

    return render_template('front/' + g.portal_layout_path + 'index.html',
                           articles=articles,
                           portal=portal_and_settings(portal),
                           current_division=division.get_client_side_dict(),
                           pages=pages,
                           current_page=page,
                           page_buttons=Config.PAGINATION_BUTTONS,
                           search_text=search_text)
コード例 #19
0
def sitemap(portal):
    print(portal)
    from sqlalchemy import desc

    return render_template('front/sitemap.xml', portal=portal,
                           divisions=[{
                                          'loc': portal.host + url_for('front.division',
                                                                       division_id=d.id,
                                                                       division_name=d.get_url()),
                                          'lastmod': max(d.md_tm, (g.db().query(Publication).filter_by(
                                              portal_division_id=d.id).order_by(
                                              desc(Publication.md_tm)).first() or d).md_tm)
                                      } for d in portal.divisions],
                           companies=[{
                                          'loc': url_for('front.company_page', member_company_name=m.company.name,
                                                         member_company_id=m.company.id),
                                          'lastmod': m.company.md_tm
                                      } for m in portal.company_memberships if
                                      m.status == MemberCompanyPortal.STATUSES['MEMBERSHIP_ACTIVE']],
                           articles=[{
                                         'loc': url_for('front.article_details', publication_id=p.id,
                                                        publication_title=p.material.title),
                                         'lastmod': p.md_tm
                                     } for p in portal.publications if
                                     p.status == Publication.STATUSES['PUBLISHED'] and not p.material.external_url]
                           )
コード例 #20
0
    def get_messages(self, count, get_older=False, than_id=None):
        messages_filter = (Message.contact_id == self.id)
        messages_query = g.db().query(Message)
        if than_id:
            if get_older:
                messages = messages_query.filter(and_(messages_filter, Message.id < than_id)).order_by(
                    expression.desc(Message.cr_tm)).limit(count + 1).all()
                there_is_more = ['there_is_older', len(messages) > count]
                messages = messages[0:count]
                # messages.reverse()

            else:
                messages = messages_query.filter(and_(messages_filter, Message.id > than_id)).order_by(
                    expression.asc(Message.cr_tm)).limit(count + 1).all()
                there_is_more = ['there_is_newer', len(messages) > count]
                messages = messages[0:count]

        else:
            messages = messages_query.filter(messages_filter).order_by(expression.desc(Message.cr_tm)).limit(
                count + 1).all()
            there_is_more = ['there_is_older', len(messages) > count]
            messages = messages[0:count]
            # messages.reverse()

        return {
            there_is_more[0]: there_is_more[1],
            'items': messages
        }
コード例 #21
0
ファイル: views_front.py プロジェクト: thewebarea/profireader
def get_params(**argv):
    search_text = request.args.get("search_text") if request.args.get("search_text") else ""
    app = current_app._get_current_object()
    portal = g.db().query(Portal).filter_by(host=app.config["SERVER_NAME"]).one()

    sub_query = Article.subquery_articles_at_portal(search_text=search_text, portal_id=portal.id)
    return search_text, portal, sub_query
コード例 #22
0
ファイル: views_front.py プロジェクト: thewebarea/profireader
def subportal_division(division_name, member_company_id, member_company_name, page=1):
    member_company = Company.get(member_company_id)

    search_text, portal, sub_query = get_params()

    division = get_division_for_subportal(portal.id, member_company_id)

    subportal_division = g.db().query(PortalDivision).filter_by(portal_id=portal.id, name=division_name).one()

    sub_query = Article.subquery_articles_at_portal(
        search_text=search_text, portal_division_id=subportal_division.id
    ).filter(db(ArticleCompany, company_id=member_company_id, id=ArticlePortalDivision.article_company_id).exists())
    # filter(Company.id == member_company_id)

    articles, pages, page = pagination(query=sub_query, page=page)
    ordered_articles = collections.OrderedDict()
    for a in articles:
        ordered_articles[a.id] = a.get_client_side_dict()

    return render_template(
        "front/bird/subportal_division.html",
        articles=ordered_articles,
        subportal=True,
        portal=portal_and_settings(portal),
        current_division=division.get_client_side_dict(),
        current_subportal_division=subportal_division.get_client_side_dict(),
        member_company=member_company.get_client_side_dict(),
        pages=False,
        current_page=page,
        page_buttons=Config.PAGINATION_BUTTONS,
        search_text=search_text,
    )
コード例 #23
0
ファイル: views_front.py プロジェクト: thewebarea/profireader
def subportal(member_company_id, member_company_name, page=1):
    search_text, portal, sub_query = get_params()
    if search_text:
        return redirect(url_for("front.index", search_text=search_text))

    member_company = Company.get(member_company_id)

    division = get_division_for_subportal(portal.id, member_company_id)

    subportal_division = (
        g.db().query(PortalDivision).filter_by(portal_id=portal.id, portal_division_type_id="index").one()
    )

    return render_template(
        "front/bird/subportal.html",
        subportal=True,
        portal=portal_and_settings(portal),
        current_division=division.get_client_side_dict(),
        current_subportal_division=subportal_division.get_client_side_dict(),
        member_company=member_company.get_client_side_dict(),
        current_subportal_division_name="index",
        pages=False,
        # current_page=page,
        # page_buttons=Config.PAGINATION_BUTTONS,
        # search_text=search_text
    )
コード例 #24
0
def contact_action(json):
    action = json['action']

    user1_id = min([g.user.id, json['user_id']])
    user2_id = max([g.user.id, json['user_id']])
    contact = g.db().query(Contact).filter_by(user1_id=user1_id, user2_id=user2_id).first()

    if contact:
        old_status_for_g_user = contact.get_status_for_user(g.user.id)

        if action == 'add' and old_status_for_g_user in [contact.STATUSES['ANY_REVOKED'],
                                                         contact.STATUSES['REVOKED_ANY']]:
            contact.set_status_for_user(g.user.id, contact.STATUSES['REQUESTED_UNCONFIRMED'])
        elif action == 'remove' and old_status_for_g_user == contact.STATUSES['ACTIVE_ACTIVE']:
            contact.set_status_for_user(g.user.id, contact.STATUSES['REVOKED_ANY'])
        elif action == 'revoke' and old_status_for_g_user == contact.STATUSES['REQUESTED_UNCONFIRMED']:
            contact.set_status_for_user(g.user.id, contact.STATUSES['REVOKED_ANY'])
        elif action == 'confirm' and old_status_for_g_user == contact.STATUSES['UNCONFIRMED_REQUESTED']:
            contact.set_status_for_user(g.user.id, contact.STATUSES['ACTIVE_ACTIVE'])
        elif action == 'unban' and old_status_for_g_user == contact.STATUSES['BANNED_ACTIVE']:
            contact.set_status_for_user(g.user.id, contact.STATUSES['ACTIVE_ACTIVE'])
        else:
            raise BadDataProvided(
                "Wrong action `%s` for status `%s=>%s`" % (action, contact.status, old_status_for_g_user))
    else:
        if action == 'add':
            contact = Contact(user1_id=user1_id, user2_id=user2_id)
            contact.set_status_for_user(g.user.id, contact.STATUSES['REQUESTED_UNCONFIRMED'])
        else:
            raise BadDataProvided("Wrong action `add` for no contact")

    contact.save()
    # g.db.commit()

    return {'contact_status': contact.get_status_for_user(g.user.id)}
コード例 #25
0
ファイル: views_front.py プロジェクト: Stevee67/profireader
def get_params(**argv):
    search_text = request.args.get('search_text') if request.args.get('search_text') else ''
    app = current_app._get_current_object()
    portal = g.db().query(Portal).filter_by(host=request.host).one()

    sub_query = Article.subquery_articles_at_portal(search_text=search_text, portal_id=portal.id)
    return search_text, portal, sub_query
コード例 #26
0
def read_message(sid, message_id):
    log('read_message', sid, message_id)
    with controlled_execution():
        message = Message.get(message_id)
        contact = Contact.get(message.contact_id)
        if message.read_tm is None:
            another_user_to_notify_unread = contact.user1_id if contact.user2_id == message.from_user_id else contact.user2_id
            log("SELECT message_set_read('%s', ARRAY ['%s']);" %
                (message.contact_id, message.id))
            g.db().execute("SELECT message_set_read('%s', ARRAY ['%s']);" %
                           (message.contact_id, message.id))
            unread = get_unread(another_user_to_notify_unread, [contact.id])
            for sid_for_receiver in connected_user_id_sids[
                    another_user_to_notify_unread]:
                sio.emit('general_notification', {'unread': unread},
                         sid_for_receiver)
コード例 #27
0
ファイル: views_front.py プロジェクト: CNazar/profireader
def article_details(portal, publication_id, publication_title):
    # TODO: OZ by OZ: redirect if title is wrong
    publication = Publication.get(publication_id)
    articles_related = publication.get_related_articles()
    article_visibility = publication.article_visibility_details()
    article_dict = publication_id_to_article(publication.id)

    division = g.db().query(PortalDivision).filter_by(id=publication.portal_division_id).one()
    if article_visibility is True:
        publication.add_recently_read_articles_to_session()
    else:
        back_to_url('front.article_details', host=portal.host, publication_id=publication_id)

    def url_toggle_tag(toggle_tag):
        return url_for('front.division', tags=toggle_tag)

    return render_template('front/' + g.portal_layout_path + 'article_details.html',
                           portal=portal_and_settings(portal),
                           division=division.get_client_side_dict(),
                           article=article_dict,
                           article_visibility=article_visibility,
                           articles_related=articles_related,
                           tags={'all': [], 'selected_names': [],
                                 'url_construct_toggle': url_toggle_tag},
                           article_social_activity={
                               'favorite': publication.check_favorite_status(),
                               'liked': publication.check_liked_status(),
                               'liked_count': publication.check_liked_count()
                           },
                           url_toggle_tag=url_toggle_tag,
                           )
コード例 #28
0
    def get_notifications(count, to_user_id, get_older=False, than_id=None):
        notification_query = g.db().query(Notification).filter(Notification.to_user_id == to_user_id)
        if than_id:
            if get_older:
                notifications = notification_query.filter(Notification.id < than_id).order_by(
                    expression.desc(Notification.cr_tm)).limit(count + 1).all()
                there_is_more = ['there_is_older', len(notifications) > count]
                notifications = notifications[0:count]
                # notifications.reverse()
            else:
                notifications = notification_query.filter(Notification.id > than_id).order_by(
                    expression.asc(Notification.cr_tm)).limit(count + 1).all()
                there_is_more = ['there_is_newer', len(notifications) > count]
                notifications = notifications[0:count]

        else:
            notifications = notification_query.order_by(expression.desc(Notification.cr_tm)).limit(
                count + 1).all()
            there_is_more = ['there_is_older', len(notifications) > count]
            notifications = notifications[0:count]
            # notifications.reverse()

        return {
            there_is_more[0]: there_is_more[1],
            'items': notifications
        }
コード例 #29
0
def old_get_search_text_and_division(portal, division_name=None):
    search_text = request.args.get('search') or ''
    dvsns = g.db().query(PortalDivision).filter_by(portal_id=portal.id)
    dvsn = \
        dvsns.filter_by(portal_division_type_id='index').first() if division_name is None else \
            next(filter(lambda x: x.get_url == division_name, dvsns.all()), None)

    return search_text, dvsn
コード例 #30
0
ファイル: views_front.py プロジェクト: CNazar/profireader
def portal_and_settings(portal):
    # TODO OZ by OZ: use polymorphic association and return object here (maybe we even will not need  this function)
    ret = portal.get_client_side_dict()
    newd = OrderedDict()
    subportals_by_companies_id = OrderedDict()
    for di in ret['divisions']:
        if di['portal_division_type_id'] == 'company_subportal':
            pdset = g.db().query(PortalDivisionSettingsCompanySubportal). \
                filter_by(portal_division_id=di['id']).first()
            com_port = g.db().query(MemberCompanyPortal).get(pdset.member_company_portal_id)
            di['subportal_company'] = Company.get(com_port.company_id)
            subportals_by_companies_id[com_port.company_id] = di
        newd[di['id']] = di
    ret['divisions'] = newd
    ret['subportals_by_companies_id'] = subportals_by_companies_id
    ret['advs'] = {a.place: a.html for a in portal.advs}
    return ret
コード例 #31
0
ファイル: views_front.py プロジェクト: kakabomba/profireader
def portal_and_settings(portal):
    # TODO OZ by OZ: use polymorphic association and return object here (maybe we even will not need  this function)
    ret = portal.get_client_side_dict()
    newd = OrderedDict()
    subportals_by_companies_id = OrderedDict()
    for di in ret['divisions']:
        if di['portal_division_type_id'] == PortalDivision.TYPES['company_subportal']:
            pdset = g.db().query(PortalDivisionSettingsCompanySubportal). \
                filter_by(portal_division_id=di['id']).first()
            com_port = g.db().query(MemberCompanyPortal).get(pdset.member_company_portal_id)
            di['subportal_company'] = Company.get(com_port.company_id)
            subportals_by_companies_id[com_port.company_id] = di
        newd[di['id']] = di
    ret['divisions'] = newd
    ret['subportals_by_companies_id'] = subportals_by_companies_id
    ret['advs'] = {a.place: a.html for a in portal.advs}
    return ret
コード例 #32
0
ファイル: materials.py プロジェクト: CNazar/profireader
    def get_related_articles(self, count=5):
        from sqlalchemy.sql import func

        return g.db().query(Publication).filter(
            and_(Publication.id != self.id,
                 Publication.portal_division_id.in_(
                     db(PortalDivision.id).filter(PortalDivision.portal_id == self.division.portal_id))
                 )).order_by(func.random()).limit(count).all()
コード例 #33
0
def division(division_name, page=1):
    search_text, portal, _ = get_params()
    division = g.db().query(PortalDivision).filter_by(
        portal_id=portal.id, name=division_name).one()
    print(division.portal_division_type_id)
    items_per_page = portal.get_value_from_config(
        key=PortalConfig.PAGE_SIZE_PER_DIVISION, division_name=division.name)
    if division.portal_division_type_id == 'catalog' and search_text:
        return redirect(url_for('front.index', search_text=search_text))
    if division.portal_division_type_id == 'news' or division.portal_division_type_id == 'events':
        order = Search.ORDER_POSITION if not search_text else Search.ORDER_RELEVANCE
        articles, pages, page = Search().search(
            ArticlePortalDivision().search_filter_default(division.id),
            search_text=search_text,
            page=page,
            order_by=order,
            pagination=True,
            items_per_page=items_per_page)

        current_division = division.get_client_side_dict()

        def url_page_division(page=1, search_text='', **kwargs):
            return url_for('front.division',
                           division_name=current_division['name'],
                           page=page,
                           search_text=search_text)

        return render_template('front/' + g.portal_layout_path +
                               'division.html',
                               articles=articles,
                               current_division=current_division,
                               portal=portal_and_settings(portal),
                               pages=pages,
                               url_page=url_page_division,
                               current_page=page,
                               page_buttons=Config.PAGINATION_BUTTONS,
                               search_text=search_text)

    elif division.portal_division_type_id == 'catalog':

        # sub_query = Article.subquery_articles_at_portal(search_text=search_text,
        # articles, pages, page = pagination(query=sub_query, page=page)

        members = {
            member.id: member.company.get_client_side_dict()
            for member in division.portal.company_members
        }

        return render_template(
            'front/' + g.portal_layout_path + 'catalog.html',
            members=members,
            current_division=division.get_client_side_dict(),
            portal=portal_and_settings(portal))

    else:
        return 'unknown division.portal_division_type_id = %s' % (
            division.portal_division_type_id, )
コード例 #34
0
ファイル: views_front.py プロジェクト: thewebarea/profireader
def get_division_for_subportal(portal_id, member_company_id):
    q = (
        g.db()
        .query(PortalDivisionSettings_company_subportal)
        .join(
            MemberCompanyPortal,
            MemberCompanyPortal.id == PortalDivisionSettings_company_subportal.member_company_portal_id,
        )
        .join(PortalDivision, PortalDivision.id == PortalDivisionSettings_company_subportal.portal_division_id)
        .filter(MemberCompanyPortal.company_id == member_company_id)
        .filter(PortalDivision.portal_id == portal_id)
    )

    PortalDivisionSettings = q.all()
    if len(PortalDivisionSettings):
        return PortalDivisionSettings[0]
    else:
        return g.db().query(PortalDivision).filter_by(portal_id=portal_id, portal_division_type_id="index").one()
コード例 #35
0
ファイル: views_front.py プロジェクト: spaun299/profireader
def get_params(**argv):
    search_text = request.args.get("search_text") or ""
    app = current_app._get_current_object()
    portal = g.db().query(Portal).filter_by(host=request.host).first()
    if portal:
        sub_query = Article.subquery_articles_at_portal(search_text=search_text, portal_id=portal.id)
        return search_text, portal, sub_query
    else:
        return None, None, None
コード例 #36
0
def get_params(**argv):
    search_text = request.args.get('search_text') or ''
    app = current_app._get_current_object()
    portal = g.db().query(Portal).filter_by(host=request.host).first()
    if portal:
        sub_query = Article.subquery_articles_at_portal(search_text=search_text, portal_id=portal.id)
        return search_text, portal, sub_query
    else:
        return None, None, None
コード例 #37
0
ファイル: views_front.py プロジェクト: CNazar/profireader
def get_search_text_and_division(portal, division_name):
    search_text = request.args.get('search') or ''

    dvsn = g.db().query(PortalDivision).filter_by(**utils.dict_merge(
        {'portal_id': portal.id},
        {'portal_division_type_id': 'index'} if division_name is None else {'name': division_name})).one()

    # TODO: OZ by OZ: 404 if no company

    return search_text, dvsn
コード例 #38
0
def division(division_name, search_text, page=1):

    app = current_app._get_current_object()
    portal = g.db().query(Portal).filter_by(host=app.config['SERVER_NAME']).one()
    search_text = search_text if not request.args.get(
        'search_text') else request.args.get('search_text')
    division = g.db().query(PortalDivision).filter_by(portal_id=portal.id, name=division_name).one()

    sub_query = Article.subquery_articles_at_portal(search_text=search_text,
                                                    portal_division_id=division.id)
    articles, pages, page = pagination(query=sub_query, page=page)
    return render_template('front/bird/division.html',
                           articles={a.id: a.get_client_side_dict() for
                                     a in articles},
                           division=division.get_client_side_dict(),
                           portal=portal,
                           pages=pages,
                           current_page=page,
                           page_buttons=Config.PAGINATION_BUTTONS,
                           search_text=search_text)
コード例 #39
0
ファイル: chat.py プロジェクト: kakabomba/profireader
def load_notifications(sid, event_data):
    with controlled_execution():
        print('load_notifications', event_data)
        user_id = connected_sid_user_id[sid]

        older = event_data.get('older', False)
        ret = Notification.get_notifications(50, user_id, older, event_data.get('first_id' if older else 'last_id', None))
        print(ret)

        read_ids = [n.id for n in ret['items'] if not n.read_tm]
        if len(read_ids):
            g.db().execute("SELECT notification_set_read(ARRAY ['%s']);" % ("', '".join(read_ids)))
            unread = get_unread(user_id)
            for sid_for_receiver in connected_user_id_sids[user_id]:
                sio.emit('general_notification', {
                    'unread': unread
                }, sid_for_receiver)

        ret['items'] = [n.client_message() for n in ret['items']]
        return ret
コード例 #40
0
def subscribe_to_portal():
    portal = g.db().query(Portal).filter_by(host=request.host).first()
    if g.user:
        portals = UserPortalReader.get_portals_for_user()
        if portal in portals:
            redirect(url_for('reader.list_reader'))
        else:
            url = '//profireader.com/subscribe/' + portal.id
            print(url)
            redirect(url)
    return ''
コード例 #41
0
ファイル: portal.py プロジェクト: kakabomba/profireader
 def __init__(self, user_id=None, portal_id=None, status='active', portal_plan_id=None, start_tm=None,
              end_tm=None, amount=None, show_divisions_and_comments=None):
     super(UserPortalReader, self).__init__()
     self.user_id = user_id
     self.portal_id = portal_id
     self.status = status
     self.start_tm = start_tm
     self.end_tm = end_tm
     self.amount = amount
     self.show_divisions_and_comments = show_divisions_and_comments
     self.portal_plan_id = portal_plan_id or g.db(ReaderUserPortalPlan.id).filter_by(name='free').one()[0]
コード例 #42
0
def subportal_division(division_name,
                       member_company_id,
                       member_company_name,
                       page=1):
    member_company = Company.get(member_company_id)
    search_text, portal, _ = get_params()
    division = get_division_for_subportal(portal.id, member_company_id)
    subportal_division = g.db().query(PortalDivision).filter_by(
        portal_id=portal.id, name=division_name).one()
    order = Search.ORDER_POSITION if not search_text else Search.ORDER_RELEVANCE
    items_per_page = portal.get_value_from_config(
        key=PortalConfig.PAGE_SIZE_PER_DIVISION,
        division_name=subportal_division.name)
    articles, pages, page = Search().search(
        ArticlePortalDivision().search_filter_default(
            subportal_division.id, company_id=member_company_id),
        search_text=search_text,
        page=page,
        order_by=order,
        pagination=True,
        items_per_page=items_per_page)

    # sub_query = Article.subquery_articles_at_portal(
    #     search_text=search_text,
    #     portal_division_id=subportal_division.id). \
    #     filter(db(ArticleCompany,
    #               company_id=member_company_id,
    #               id=ArticlePortalDivision.article_company_id).exists())
    # filter(Company.id == member_company_id)

    # articles, pages, page = pagination(query=sub_query, page=page)

    def url_page_division(page=1, search_text='', **kwargs):
        return url_for('front.subportal_division',
                       division_name=division_name,
                       member_company_id=member_company_id,
                       member_company_name=member_company_name,
                       page=page,
                       search_text=search_text)

    return render_template(
        'front/' + g.portal_layout_path + 'subportal_division.html',
        articles=articles,
        subportal=True,
        portal=portal_and_settings(portal),
        current_division=division.get_client_side_dict(),
        current_subportal_division=subportal_division.get_client_side_dict(),
        member_company=member_company.get_client_side_dict(),
        pages=pages,
        page=page,
        current_page=page,
        page_buttons=Config.PAGINATION_BUTTONS,
        search_text=search_text,
        url_page=url_page_division)
コード例 #43
0
ファイル: chat.py プロジェクト: kakabomba/profireader
def load_messages(sid, event_data):
    with controlled_execution():
        import time
        # time.sleep(2)  # delays for 5 seconds
        print('load_messages', event_data)
        user_id = connected_sid_user_id[sid]
        contact = Contact.get(event_data['chat_room_id'])
        older = event_data.get('older', False)
        ret = contact.get_messages(50, older, event_data.get('first_id' if older else 'last_id', None))

        read_ids = [m.id for m in ret['items'] if m.from_user_id != user_id and not m.read_tm]
        if len(read_ids):
            g.db().execute("SELECT message_set_read('%s', ARRAY ['%s']);" % (contact.id, "', '".join(read_ids)))
            unread = get_unread(user_id, [contact.id])
            for sid_for_receiver in connected_user_id_sids[user_id]:
                sio.emit('general_notification', {
                    'unread': unread
                }, sid_for_receiver)

        ret['items'] = [m.client_message() for m in ret['items']]
        return ret
コード例 #44
0
def subportal(member_company_id, member_company_name, page=1):
    search_text, portal, _ = get_params()
    if search_text:
        return redirect(url_for('front.index', search_text=search_text))
    member_company = Company.get(member_company_id)
    division = get_division_for_subportal(portal.id, member_company_id)
    subportal_division = g.db().query(PortalDivision).filter_by(portal_id=portal.id,
                                                                portal_division_type_id='index').one()
    return render_template('front/' + g.portal_layout_path + 'subportal.html',
                           subportal=True,
                           portal=portal_and_settings(portal),
                           current_division=division.get_client_side_dict(),
                           current_subportal_division=subportal_division.get_client_side_dict(),
                           member_company=member_company.get_client_side_dict(),
                           current_subportal_division_name='index',
                           pages=False,
                           # current_page=page,
                           # page_buttons=Config.PAGINATION_BUTTONS,
                           # search_text=search_text
                           )