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

from baseframe import __
import baseframe.forms as forms

from ..models import Assignee, LineItem, Order, ORDER_STATUS

__all__ = ['AssigneeForm']


class AssigneeForm(forms.Form):
    email = forms.EmailField(
        __("Email"),
        validators=[forms.validators.DataRequired(), forms.validators.Length(max=254)],
    )
    fullname = forms.StringField(
        __("Full Name"), validators=[forms.validators.DataRequired()]
    )
    phone = forms.StringField(
        __("Phone number"), validators=[forms.validators.DataRequired()]
    )

    def validate_email(self, field):
        existing_assignees = (
            Assignee.query.filter(LineItem.order == self.edit_parent.order)
            .filter(Order.status != ORDER_STATUS.CANCELLED)
            .filter(Assignee.current == True)
            .filter(Assignee.email == field.data)
        )
        if self.edit_obj is not None:
            existing_assignees = existing_assignees.filter(
                Assignee.id != self.edit_obj.id<commit_msg>assignee email is unique per item (#319)<commit_after># -*- coding: utf-8 -*-

from baseframe import __
import baseframe.forms as forms

from ..models import Assignee, Item, LineItem, Order, ORDER_STATUS

__all__ = ["AssigneeForm"]


class AssigneeForm(forms.Form):
    email = forms.EmailField(
        __("Email"),
        validators=[forms.validators.DataRequired(), forms.validators.Length(max=254)],
    )
    fullname = forms.StringField(
        __("Full Name"), validators=[forms.validators.DataRequired()]
    )
    phone = forms.StringField(
        __("Phone number"), validators=[forms.validators.DataRequired()]
    )

    def validate_email(self, field):
        existing_assignees = (
            Assignee.query.join(LineItem)
            .join(Item)
            .join(Order)
            .filter(LineItem.item_id == self.edit_parent.item_id)
            .filter(Order.status != ORDER_STATUS.CANCELLED)
            .filter(Assignee.current == True)
            .filter(Assignee.email == field.data)
        )
        if self.edit_obj is not None:
            existing_assignees = existing_assignees.filter(
                Assignee.id != self.edit_obj.id
{'fraction_non_alphanumeric': 0.12106210621062106, 'fraction_numerical': 0.0049504950495049506, 'mean_word_length': 2.65625, '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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2988497', 'n_tokens_mistral': 680, 'n_tokens_neox': 646, 'n_words': 123}