from django import forms
from preferences.models import Preference

class PreferencesForm(forms.Form):
    def __init__(self, *args, **kwargs):
        super(PreferencesForm, self).__init__(*args, **kwargs)
        for preference in Preference.objects.all():
            self.fields[preference.name] = forms.CharField()

import os.path
from django import forms
from preferences.models import Preference

class PreferencesForm(forms.Form):
    def __init__(self, *args, **kwargs):
        super(PreferencesForm, self).__init__(*args, **kwargs)
        for preference in Preference.objects.all():
            self.fields[preference.name] = forms.CharField()

    def clean(self):
        # Apparently clean__projects_directory doesn't work with dynamic forms
        if not self.cleaned_data['projects_directory'].endswith(os.path.sep):
            self.cleaned_data['projects_directory'] += os.path.sep
        return self.cleaned_data

Append a trailing newline to the project directory
Append a trailing newline to the project directory

+ import os.path
  from django import forms
  from preferences.models import Preference
  
  class PreferencesForm(forms.Form):
      def __init__(self, *args, **kwargs):
          super(PreferencesForm, self).__init__(*args, **kwargs)
          for preference in Preference.objects.all():
              self.fields[preference.name] = forms.CharField()
  
+     def clean(self):
+         # Apparently clean__projects_directory doesn't work with dynamic forms
+         if not self.cleaned_data['projects_directory'].endswith(os.path.sep):
+             self.cleaned_data['projects_directory'] += os.path.sep
+         return self.cleaned_data
+ 
Append a trailing newline to the project directory
## Code Before:
from django import forms
from preferences.models import Preference

class PreferencesForm(forms.Form):
    def __init__(self, *args, **kwargs):
        super(PreferencesForm, self).__init__(*args, **kwargs)
        for preference in Preference.objects.all():
            self.fields[preference.name] = forms.CharField()

## Instruction:
Append a trailing newline to the project directory
## Code After:
import os.path
from django import forms
from preferences.models import Preference

class PreferencesForm(forms.Form):
    def __init__(self, *args, **kwargs):
        super(PreferencesForm, self).__init__(*args, **kwargs)
        for preference in Preference.objects.all():
            self.fields[preference.name] = forms.CharField()

    def clean(self):
        # Apparently clean__projects_directory doesn't work with dynamic forms
        if not self.cleaned_data['projects_directory'].endswith(os.path.sep):
            self.cleaned_data['projects_directory'] += os.path.sep
        return self.cleaned_data
