<commit_before># -*- coding: utf-8 -*-

import json
import httplib
import logging

from modularodm import Q
from modularodm.exceptions import ModularOdmException

from framework.exceptions import HTTPError

from website import settings
from website.models import Node
from website.util import web_url_for
from website.mails import send_mail, CONFERENCE_SUBMITTED, CONFERENCE_FAILED

from website.conferences import utils
from website.conferences.message import ConferenceMessage, ConferenceError
from website.conferences.model import Conference


logger = logging.getLogger(__name__)


def meeting_hook():
    """View function for email conference submission.
    """
    message = ConferenceMessage()

    try:
        message.verify()
    except ConferenceError as error:
        logger.error(error)
        raise HTTPError(httplib.NOT_ACCEPTABLE)

    try:
        conference = Conference.get_by_endpoint(message.conference_name)
    except ConferenceError as error:
        logger.error(error)
        raise HTTPError(httplib.NOT_ACCEPTABLE)

    add_poster_by_email(conference=conference, message=message)


def add_poster_by_email(conference, message):
    """
    :param Conference conference:
    :param ConferenceMessage message:
    """
    # Fail if no attachments
    if not message.attachments:
        return send_mail(
            message.sender_email,
            CONFERENCE_FAILED,
            fullname=message.sender_display,
        )

    created = []

    user, user_created = utils.get_or_create_user(
        message.sender_display,
        message.sender_email,
        message.is_spam,
    )
    if user_created:
        created.append(user)

    if user_created:
        created.append(user)
        set_password_url = web_url_for(
            'reset_password',
            verification_key=user.verification_key,
            _absolute=True,
        )
    else:
        set_password_url = None

    node, node_created = utils.get_or_create_node(message.subject, user)
    if node_created:
        created.append(node)

    utils.provision_node(conference, message, node, user)
    utils.record_message(message, created)

    download_url = node.web_url_for(
        'osf_storage_view_file',
        path=message.attachments[0].filename,
        action='download',
        _absolute=True,
    )

    # Send confirmation email
    send_mail(
        message.sender_email,
        CONFERENCE_SUBMITTED,
        conf_full_name=conference.name,
        conf_view_url=web_url_for(
            'conference_results',
            meeting=message.conference_name,
            _absolute=True,
        ),
        fullname=message.sender_display,
        user_created=user_created,
        set_password_url=set_password_url,
        profile_url=user.absolute_url,
        node_url=node.absolute_url,
        file_url=download_url,
        presentation_type=message.conference_category,
        is_spam=message.is_spam,
    )


def _render_conference_node(node, idx):
    storage_settings = node.get_addon('osfstorage')
    if storage_settings.file_tree and storage_settings.file_tree.children:
        record = storage_settings.file_tree.children[0]
        download_count = record.get_download_count()
        download_url = node.web_url_for(
            'osf_storage_view_file',
            path=record.path,
            action='download',
        )
    else:
        download_url = ''
        download_count = 0

    author = node.visible_contributors[0]

    return {
        'id': idx,
        'title': node.title,
        'nodeUrl': node.url,
        'author': author.family_name,<commit_msg>Show first non-deleted file in conference table.<commit_after># -*- coding: utf-8 -*-

import json
import httplib
import logging

from modularodm import Q
from modularodm.exceptions import ModularOdmException

from framework.exceptions import HTTPError

from website import settings
from website.models import Node
from website.util import web_url_for
from website.mails import send_mail, CONFERENCE_SUBMITTED, CONFERENCE_FAILED

from website.conferences import utils
from website.conferences.message import ConferenceMessage, ConferenceError
from website.conferences.model import Conference


logger = logging.getLogger(__name__)


def meeting_hook():
    """View function for email conference submission.
    """
    message = ConferenceMessage()

    try:
        message.verify()
    except ConferenceError as error:
        logger.error(error)
        raise HTTPError(httplib.NOT_ACCEPTABLE)

    try:
        conference = Conference.get_by_endpoint(message.conference_name)
    except ConferenceError as error:
        logger.error(error)
        raise HTTPError(httplib.NOT_ACCEPTABLE)

    add_poster_by_email(conference=conference, message=message)


def add_poster_by_email(conference, message):
    """
    :param Conference conference:
    :param ConferenceMessage message:
    """
    # Fail if no attachments
    if not message.attachments:
        return send_mail(
            message.sender_email,
            CONFERENCE_FAILED,
            fullname=message.sender_display,
        )

    created = []

    user, user_created = utils.get_or_create_user(
        message.sender_display,
        message.sender_email,
        message.is_spam,
    )
    if user_created:
        created.append(user)

    if user_created:
        created.append(user)
        set_password_url = web_url_for(
            'reset_password',
            verification_key=user.verification_key,
            _absolute=True,
        )
    else:
        set_password_url = None

    node, node_created = utils.get_or_create_node(message.subject, user)
    if node_created:
        created.append(node)

    utils.provision_node(conference, message, node, user)
    utils.record_message(message, created)

    download_url = node.web_url_for(
        'osf_storage_view_file',
        path=message.attachments[0].filename,
        action='download',
        _absolute=True,
    )

    # Send confirmation email
    send_mail(
        message.sender_email,
        CONFERENCE_SUBMITTED,
        conf_full_name=conference.name,
        conf_view_url=web_url_for(
            'conference_results',
            meeting=message.conference_name,
            _absolute=True,
        ),
        fullname=message.sender_display,
        user_created=user_created,
        set_password_url=set_password_url,
        profile_url=user.absolute_url,
        node_url=node.absolute_url,
        file_url=download_url,
        presentation_type=message.conference_category,
        is_spam=message.is_spam,
    )


def _render_conference_node(node, idx):
    storage_settings = node.get_addon('osfstorage')
    records = storage_settings.file_tree.children if storage_settings.file_tree else []
    try:
        record = next(
            each for each in records
            if not each.is_deleted,
        )
        download_count = record.get_download_count()
        download_url = node.web_url_for(
            'osf_storage_view_file',
            path=record.path,
            action='download',
        )
    except StopIteration:
        download_url = ''
        download_count = 0

    author = node.visible_contributors[0]

    return {
        'id': idx,
        'title': node.title,
        'nodeUrl': node.url,
        'author': author.family_name,
{'fraction_non_alphanumeric': 0.07665078284547311, 'fraction_numerical': 0.0012253233492171545, 'mean_word_length': 2.7517875383043924, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 18, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6512836', 'n_tokens_mistral': 2144, 'n_tokens_neox': 2127, 'n_words': 412}