-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1575 from rtfd/add-domain-model
Add Domain model to track project Domains
- Loading branch information
Showing
25 changed files
with
577 additions
and
109 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,29 @@ | ||
''' | ||
""" | ||
Common mixin classes for views | ||
''' | ||
""" | ||
|
||
from django.conf import settings | ||
|
||
from vanilla import ListView | ||
|
||
|
||
class StripeMixin(object): | ||
'''Adds Stripe publishable key to the context data''' | ||
|
||
"""Adds Stripe publishable key to the context data""" | ||
|
||
def get_context_data(self, **kwargs): | ||
context = super(StripeMixin, self).get_context_data(**kwargs) | ||
context.update({ | ||
'publishable': settings.STRIPE_PUBLISHABLE, | ||
}) | ||
return context | ||
|
||
|
||
class ListViewWithForm(ListView): | ||
|
||
"""List view that also exposes a create form""" | ||
|
||
def get_context_data(self, **kwargs): | ||
context = super(ListViewWithForm, self).get_context_data(**kwargs) | ||
context['form'] = self.get_form(data=None, files=None) | ||
return context |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# -*- coding: utf-8 -*- | ||
from __future__ import unicode_literals | ||
|
||
from django.db import models, migrations | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('projects', '0005_sync_project_model'), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='Domain', | ||
fields=[ | ||
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)), | ||
('url', models.URLField(unique=True, verbose_name='URL')), | ||
('machine', models.BooleanField(default=False, help_text='This URL was auto-created')), | ||
('cname', models.BooleanField(default=False, help_text='This URL is a CNAME for the project')), | ||
('canonical', models.BooleanField(default=False, help_text='This URL is the primary one where the documentation is served from.')), | ||
('count', models.IntegerField(default=0, help_text='Number of times this domain has been hit.')), | ||
('project', models.ForeignKey(related_name='domains', to='projects.Project')), | ||
], | ||
options={ | ||
'ordering': ('-canonical', '-machine', 'url'), | ||
}, | ||
), | ||
] |
26 changes: 26 additions & 0 deletions
26
readthedocs/projects/migrations/0007_migrate_canonical_data.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# -*- coding: utf-8 -*- | ||
from __future__ import unicode_literals | ||
|
||
from django.db import migrations | ||
|
||
|
||
def migrate_canonical(apps, schema_editor): | ||
Project = apps.get_model("projects", "Project") | ||
for project in Project.objects.all(): | ||
if project.canonical_url: | ||
domain = project.domains.create( | ||
url=project.canonical_url, | ||
canonical=True, | ||
) | ||
print "Added {url} to {project}".format(url=domain.url, project=project.name) | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('projects', '0006_add_domain_models'), | ||
] | ||
|
||
operations = [ | ||
migrations.RunPython(migrate_canonical) | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.