<commit_before>from django.views.generic import CreateView

from braces.views import FormValidMessageMixin

from livinglots_genericviews import AddGenericMixin


class AddContentView(FormValidMessageMixin, AddGenericMixin, CreateView):

    def _get_content_name(self):
        return self.form_class._meta.model._meta.object_name

    def get_form_valid_message(self):
        return '%s added successfully.' % self._get_content_name()

    def get_success_url(self):
        return self.get_content_object().get_absolute_url()

    def get_template_names(self):
        return [
            'livinglots/usercontent/add_%s.html' % self._get_content_name().lower(),
        ]

    def form_valid(self, form):
        """
        Save the content and notify participants who are following the target
        lot.
        """
        self.object = form.save()

        # NB: Notifications are sent to followers using a descendant of
        # NotifyParticipantsOnCreationForm 
        return super(AddContentView, self).form_valid(form)
<commit_msg>Set added_by_name if we can<commit_after>from django.views.generic import CreateView

from braces.views import FormValidMessageMixin

from livinglots_genericviews import AddGenericMixin


class AddContentView(FormValidMessageMixin, AddGenericMixin, CreateView):

    def _get_content_name(self):
        return self.form_class._meta.model._meta.object_name

    def get_form_valid_message(self):
        return '%s added successfully.' % self._get_content_name()

    def get_initial(self):
        initial = super(AddContentView, self).get_initial()
        user = self.request.user

        # If user has name, set that for them
        try:
            initial['added_by_name'] = user.first_name or user.username
        except AttributeError:
            pass
        return initial

    def get_success_url(self):
        return self.get_content_object().get_absolute_url()

    def get_template_names(self):
        return [
            'livinglots/usercontent/add_%s.html' % self._get_content_name().lower(),
        ]

    def form_valid(self, form):
        """
        Save the content and notify participants who are following the target
        lot.
        """
        self.object = form.save()

        # NB: Notifications are sent to followers using a descendant of
        # NotifyParticipantsOnCreationForm 
        return super(AddContentView, self).form_valid(form)

{'fraction_non_alphanumeric': 0.078125, 'fraction_numerical': 0.0, 'mean_word_length': 3.021487603305785, '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': '7534357', 'n_tokens_mistral': 690, 'n_tokens_neox': 663, 'n_words': 163}