Skip to content

Commit d41bb88

Browse files
committed
This commit includes the changes to models, forms, and admin interface in order to move whitelisting from the Project model into the UserProfile model.
1 parent af3326b commit d41bb88

File tree

6 files changed

+22
-23
lines changed

6 files changed

+22
-23
lines changed

core/models.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
class UserProfile (models.Model):
55
"""Additional information about a User.
66
"""
7-
user = models.ForeignKey(User, unique=True)
7+
user = models.ForeignKey(User, unique=True, related_name='profile')
88
whitelisted = models.BooleanField()
99
homepage = models.CharField(max_length=100)
1010

projects/admin.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55

66
class ProjectAdmin(admin.ModelAdmin):
77
prepopulated_fields = {'slug': ('name',)}
8-
list_display = ('name', 'repo', 'repo_type', 'theme', 'status', 'whitelisted')
8+
list_display = ('name', 'repo', 'repo_type', 'theme', 'status')
99
search_fields = ('name', 'repo')
10-
list_filter = ('repo_type', 'whitelisted', 'status')
10+
list_filter = ('repo_type', 'status')
1111

1212

1313
class FileAdmin(admin.ModelAdmin):

projects/forms.py

+15-15
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,22 @@ def clean_name(self):
1616
potential_slug = slugify(name)
1717
if Project.objects.filter(slug=potential_slug).count():
1818
raise forms.ValidationError('A project with that name exists already!')
19-
19+
2020
return name
2121

2222

2323
class CreateProjectForm(ProjectForm):
2424
class Meta:
2525
model = Project
26-
exclude = ('skip', 'whitelisted', 'user', 'slug', 'repo',
26+
exclude = ('skip', 'user', 'slug', 'repo',
2727
'docs_directory', 'status', 'repo_type')
2828

2929
def save(self, *args, **kwargs):
3030
created = self.instance.pk is None
31-
31+
3232
# save the project
3333
project = super(CreateProjectForm, self).save(*args, **kwargs)
34-
34+
3535
if created:
3636
# create a couple sample files
3737
for i, (sample_file, template) in enumerate(constants.SAMPLE_FILES):
@@ -42,10 +42,10 @@ def save(self, *args, **kwargs):
4242
ordering=i+1,
4343
)
4444
file.create_revision(old_content='', comment='')
45-
45+
4646
# kick off the celery job
4747
update_docs.delay(pk=project.pk)
48-
48+
4949
return project
5050

5151

@@ -54,8 +54,8 @@ class ImportProjectForm(ProjectForm):
5454
help_text='URL for your code (hg or git). Ex. http://github.com/ericholscher/django-kong.git')
5555
class Meta:
5656
model = Project
57-
exclude = ('skip', 'whitelisted', 'theme', 'docs_directory', 'user', 'slug', 'version', 'copyright', 'status')
58-
57+
exclude = ('skip', 'theme', 'docs_directory', 'user', 'slug', 'version', 'copyright', 'status')
58+
5959
def clean_repo(self):
6060
repo = self.cleaned_data.get('repo', '').strip()
6161
if '&&' in repo or '|' in repo:
@@ -70,15 +70,15 @@ def save(self, *args, **kwargs):
7070

7171
# kick off the celery job
7272
update_docs.delay(pk=project.pk)
73-
73+
7474
return project
7575

7676

7777
class FileForm(forms.ModelForm):
7878
content = forms.CharField(widget=forms.Textarea(attrs={'class': 'editor'}),
7979
help_text='<small><a href="http://sphinx.pocoo.org/rest.html">reStructuredText Primer</a></small>')
8080
revision_comment = forms.CharField(max_length=255, required=False)
81-
81+
8282
class Meta:
8383
model = File
8484
exclude = ('project', 'slug', 'status')
@@ -89,28 +89,28 @@ def __init__(self, instance=None, *args, **kwargs):
8989
file_qs = file_qs.exclude(pk=instance.pk)
9090
self.base_fields['parent'].queryset = file_qs
9191
super(FileForm, self).__init__(instance=instance, *args, **kwargs)
92-
92+
9393
def save(self, *args, **kwargs):
9494
# grab the old content before saving
9595
old_content = self.initial.get('content', '')
96-
96+
9797
# save the file object
9898
file_obj = super(FileForm, self).save(*args, **kwargs)
99-
99+
100100
# create a new revision from the old content -> new
101101
file_obj.create_revision(
102102
old_content,
103103
self.cleaned_data.get('revision_comment', '')
104104
)
105105

106106
update_docs.delay(file_obj.project.pk)
107-
107+
108108
return file_obj
109109

110110

111111
class FileRevisionForm(forms.Form):
112112
revision = forms.ModelChoiceField(queryset=None)
113-
113+
114114
def __init__(self, file, *args, **kwargs):
115115
revision_qs = file.revisions.exclude(pk=file.current_revision.pk)
116116
self.base_fields['revision'].queryset = revision_qs

projects/models.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ class Project(models.Model):
4747
extensions = models.CharField(max_length=255, editable=False, default='')
4848
status = models.PositiveSmallIntegerField(choices=constants.STATUS_CHOICES,
4949
default=constants.LIVE_STATUS)
50-
whitelisted = models.BooleanField()
5150
skip = models.BooleanField()
5251

5352
tags = TaggableManager()
@@ -165,7 +164,7 @@ def get_rendered_conf(self):
165164

166165
def write_to_disk(self):
167166
safe_write(self.conf_filename, self.get_rendered_conf())
168-
167+
169168
def get_latest_build(self):
170169
try:
171170
return self.builds.all()[0]

projects/tasks.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ def build_docs(project):
172172
"""
173173
A helper function for the celery task to do the actual doc building.
174174
"""
175-
if project.whitelisted:
175+
if project.user.get_profile().whitelisted:
176176
sanitize_conf(project.conf_filename)
177177
else:
178178
project.write_to_disk()

projects/utils.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ def safe_write(filename, contents):
6767
fh.close()
6868

6969
def sanitize_conf(conf_filename):
70-
"""Modify the given ``conf.py`` file from a whitelisted project. For now,
71-
this just adds the RTD template directory to ``templates_path``.
70+
"""Modify the given ``conf.py`` file from a whitelisted user's project.
71+
For now, this just adds the RTD template directory to ``templates_path``.
7272
"""
7373
# The template directory for RTD
7474
template_dir = '%s/templates/sphinx' % settings.SITE_ROOT

0 commit comments

Comments
 (0)