<commit_before>import django.forms
import mysite.profile.models

class ProjectExpForm(django.forms.Form):
    project_name = django.forms.CharField(
        max_length=200,
        label='Project')
    involvement_description = django.forms.CharField(
        widget=django.forms.Textarea,
        required=False,
        label='Describe your involvement')
    citation_url = django.forms.URLField(
        max_length=200,
        label='Cite your involvement')
    
class ProjectExpEditForm(django.forms.Form):
    # FIXME: Make this a ModelForm I guess.
    # FIXME: Align the attribute names with the model.
    involvement_description = django.forms.CharField(
        widget=django.forms.Textarea,
        required=False,
        label='Describe your involvement')
    citation_url = django.forms.URLField(
        required=False,
        max_length=200,
        label='Cite your involvement')
    man_months=django.forms.IntegerField(
        required=False)
    primary_language=django.forms.CharField(
        max_length=200, required=False)
    project_exp_id=django.forms.IntegerField(
        required=False,
        widget=django.forms.widgets.HiddenInput)
    delete_this = django.forms.BooleanField(
        required=False)
    
    def set_user(self, user):
        self.user = user

    def clean_project_exp_id(self):
        '''Note: I will explode violently if you
        have not set self.user.'''
        # Assert that self.user is set
        try:
            self.user
        except AttributeError:
            raise forms.ValidationError("For some reason, the programmer made a mistake, and I will blame you, the user.")
        # Now, check that there is a project_exp that is
        # owned by the user.
        inputted_id = self.cleaned_data['project_exp_id']
        try:
            p_e = mysite.profile.models.ProjectExp.objects.get(
                person__user=self.user, id=inputted_id)
        except mysite.profile.models.ProjectExp.DoesNotExist:
            raise django.forms.ValidationError("Somehow, you submitted regarding a project experience ID you do not own.")

        # so now we have a p_e. Jam it into cleaned_data.
        self.cleaned_data['project_exp'] = p_e
        return inputted_id

class ManuallyAddACitationForm(django.forms.ModelForm):
    portfolio_entry = django.forms.ModelChoiceField(
            queryset=mysite.profile.models.PortfolioEntry.objects.all(), 
            widget=django.forms.HiddenInput())

    # The ID of the element in the portfolio editor that contains this form.
    form_container_element_id = django.forms.CharField(widget=django.forms.HiddenInput())
    #FIXME: Make is_published always true
    class Meta:
        model = mysite.profile.models.Citation
        fields = ('portfolio_entry', 'url', )

# vim: set nu:<commit_msg>Test that we don't allow the logged-in user to save citations for portfolio entries for other users.<commit_after>import django.forms
import mysite.profile.models

class ProjectExpForm(django.forms.Form):
    project_name = django.forms.CharField(
        max_length=200,
        label='Project')
    involvement_description = django.forms.CharField(
        widget=django.forms.Textarea,
        required=False,
        label='Describe your involvement')
    citation_url = django.forms.URLField(
        max_length=200,
        label='Cite your involvement')
    
class ProjectExpEditForm(django.forms.Form):
    # FIXME: Make this a ModelForm I guess.
    # FIXME: Align the attribute names with the model.
    involvement_description = django.forms.CharField(
        widget=django.forms.Textarea,
        required=False,
        label='Describe your involvement')
    citation_url = django.forms.URLField(
        required=False,
        max_length=200,
        label='Cite your involvement')
    man_months=django.forms.IntegerField(
        required=False)
    primary_language=django.forms.CharField(
        max_length=200, required=False)
    project_exp_id=django.forms.IntegerField(
        required=False,
        widget=django.forms.widgets.HiddenInput)
    delete_this = django.forms.BooleanField(
        required=False)
    
    def set_user(self, user):
        self.user = user

    def clean_project_exp_id(self):
        '''Note: I will explode violently if you
        have not set self.user.'''
        # Assert that self.user is set
        try:
            self.user
        except AttributeError:
            raise forms.ValidationError("For some reason, the programmer made a mistake, and I will blame you, the user.")
        # Now, check that there is a project_exp that is
        # owned by the user.
        inputted_id = self.cleaned_data['project_exp_id']
        try:
            p_e = mysite.profile.models.ProjectExp.objects.get(
                person__user=self.user, id=inputted_id)
        except mysite.profile.models.ProjectExp.DoesNotExist:
            raise django.forms.ValidationError("Somehow, you submitted regarding a project experience ID you do not own.")

        # so now we have a p_e. Jam it into cleaned_data.
        self.cleaned_data['project_exp'] = p_e
        return inputted_id

class ManuallyAddACitationForm(django.forms.ModelForm):
    portfolio_entry = django.forms.ModelChoiceField(
            queryset=mysite.profile.models.PortfolioEntry.objects.all(), 
            widget=django.forms.HiddenInput())

    # The ID of the element in the portfolio editor that contains this form.
    form_container_element_id = django.forms.CharField(widget=django.forms.HiddenInput())
    #FIXME: Make is_published always true
    class Meta:
        model = mysite.profile.models.Citation
        fields = ('portfolio_entry', 'url', )

    def set_user(self, user):
        self.user = user

    def clean_portfolio_entry(self):
        '''Note: I will explode violently if you
        have not set self.user.'''
        # Assert that self.user is set
        try:
            self.user
        except AttributeError:
            raise forms.ValidationError("For some reason, the programmer made a mistake, "
                    "and I will blame you, the user.")

        # Check that the user owns this portfolio entry.
        pf_entry_id = self.cleaned_data['portfolio_entry']
        try:
            pf_entry = mysite.profile.models.PortfolioEntry.objects.get(
                person__user=self.user, pk=pf_entry_id)
        except mysite.profile.models.PortfolioEntry.DoesNotExist:
            raise django.forms.ValidationError("Somehow, you submitted "
                    "regarding a portfolio entry that you do not own.")
        return pf_entry_id

# vim: set nu:
{'fraction_non_alphanumeric': 0.08464892497368817, 'fraction_numerical': 0.0036084799278304014, 'mean_word_length': 2.6751381215469614, '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': '1424599', 'n_tokens_mistral': 1861, 'n_tokens_neox': 1826, 'n_words': 476}