Skip to content

Commit

Permalink
PEP8ified the source tree before I lost control.
Browse files Browse the repository at this point in the history
- Added contributors list.
  • Loading branch information
justinvh committed Dec 28, 2011
1 parent 3d0cf81 commit de9aa79
Show file tree
Hide file tree
Showing 9 changed files with 49 additions and 40 deletions.
4 changes: 1 addition & 3 deletions AUTHORS.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
Tucson, AZ :: SAIC
==================
- Justin Bruce Van Horne <justin.b.van.horne@siac.com>
Justin Bruce Van Horne <justin.b.van.horne@saic.com>
2 changes: 2 additions & 0 deletions CONTRIBUTORS.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Luke M. <https://github.com/flags>
- Added functionality for anonymous pastes
8 changes: 6 additions & 2 deletions saic/manage.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,14 @@
from django.core.management import execute_manager
import imp
try:
imp.find_module('settings') # Assumed to be in the same directory.
# Assumed to be in the same directory.
imp.find_module('settings')
except ImportError:
import sys
sys.stderr.write("Error: Can't find the file 'settings.py' in the directory containing %r. It appears you've customized things.\nYou'll have to run django-admin.py, passing it your settings module.\n" % __file__)
sys.stderr.write("""Error: Can't find the file 'settings.py' in the\
directory containing %r. It appears you've customized things.\nYou'll\
have to run django-admin.py, passing it your\
settings module.\n""" % __file__)
sys.exit(1)

import settings
Expand Down
10 changes: 5 additions & 5 deletions saic/paste/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@


class CommitMetaForm(forms.Form):
"""These correspond to a particular commit or iteration of a paste."""
"""These correspond to a particular commit or iteration of a paste."""
anonymous = forms.BooleanField(required=False)


Expand All @@ -25,7 +25,7 @@ class SetForm(forms.Form):
widget=forms.widgets.TextInput(attrs={
'default': 'add a paste description...'
}))

def clean_description(self):
d = self.cleaned_data.get('description')
if d is None:
Expand All @@ -52,9 +52,9 @@ def clean_filename(self):

paste = forms.CharField(widget=forms.Textarea, required=False)
language = forms.ChoiceField(
choices=languages,
choices=languages,
required=False,
widget=forms.Select(attrs={ 'tabindex': -1 })
widget=forms.Select(attrs={'tabindex': -1})
)


Expand All @@ -67,7 +67,7 @@ class Meta:
model = User
exclude = ('username', 'date_joined', 'last_login', 'password')

username = forms.EmailField()
username = forms.EmailField()

def save(self, commit=True):
"""See ProfileForm for this error."""
Expand Down
3 changes: 2 additions & 1 deletion saic/paste/models.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from django.db import models
from django.contrib.auth.models import User


class Set(models.Model):
owner = models.ForeignKey(User, null=True, blank=True, default=None)
description = models.CharField(max_length=255)
Expand Down Expand Up @@ -41,7 +42,7 @@ class Paste(models.Model):
paste = models.TextField()
paste_formatted = models.TextField()
language = models.CharField(max_length=100)
revision = models.ForeignKey(Commit)
revision = models.ForeignKey(Commit)

class Meta:
ordering = ['-id']
Expand Down
1 change: 1 addition & 0 deletions saic/paste/search_indexes.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from haystack import site
from models import Paste, Commit


class CommitIndex(RealTimeSearchIndex):
text = CharField(document=True, use_template=True)
commit = CharField(model_attr='commit')
Expand Down
28 changes: 16 additions & 12 deletions saic/paste/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def paste(request):
set_form = SetForm(request.POST)
commit_meta_form = CommitMetaForm(request.POST)

if (not paste_forms.is_valid() or
if (not paste_forms.is_valid() or
not set_form.is_valid() or
not commit_meta_form.is_valid()):
return render_to_response('paste.html', {
Expand All @@ -63,7 +63,7 @@ def paste(request):
owner = None
if request.user.is_authenticated() and not anonymous:
owner = request.user

# Create a new paste set so we can reference our paste.
description = set_form.cleaned_data.get('description')
paste_set = Set.objects.create(
Expand All @@ -80,8 +80,8 @@ def paste(request):

# Initialize a commit, git repository, and pull the current index.
commit = Commit.objects.create(
parent_set=paste_set,
commit='',
parent_set=paste_set,
commit='',
owner=owner
)

Expand All @@ -95,7 +95,7 @@ def paste(request):
filename = data['filename']
language, language_lex = data['language'].split(';')
paste = data['paste']

# If we don't specify a filename, then obviously it is lonely
if not len(filename):
filename = 'a-lonely-file'
Expand Down Expand Up @@ -178,7 +178,8 @@ def paste_view(request, pk):
if requested_commit is None:
commit = latest_commit
else:
commit = get_object_or_404(Commit, parent_set=paste_set, commit=requested_commit)
commit = get_object_or_404(Commit,
parent_set=paste_set, commit=requested_commit)

if request.method != 'POST':
comment_form = CommentForm()
Expand Down Expand Up @@ -209,7 +210,7 @@ def paste_edit(request, pk):
if requested_commit is None:
commit = paste_set.commit_set.latest('id')
else:
commit = get_object_or_404(Commit,
commit = get_object_or_404(Commit,
parent_set=paste_set, commit=requested_commit)

# Populate our initial data
Expand Down Expand Up @@ -253,8 +254,8 @@ def paste_edit(request, pk):
os.environ['USER'] = owner.username

commit = Commit.objects.create(
parent_set=paste_set,
commit='',
parent_set=paste_set,
commit='',
owner=owner
)

Expand Down Expand Up @@ -371,7 +372,8 @@ def paste_fork(request, pk):
if requested_commit is None:
commit = latest_commit
else:
commit = get_object_or_404(Commit, parent_set=paste_set, commit=requested_commit)
commit = get_object_or_404(Commit,
parent_set=paste_set, commit=requested_commit)

# Open the existing repository and navigate to a new head
repo = git.Repo(paste_set.repo)
Expand All @@ -386,18 +388,20 @@ def paste_fork(request, pk):
paste_set.owner = owner
paste_set.save()

# Using list() forces evaluation, i.e. no lazy queries.
# We want data.
for old_commit in old_commits:
pastes = list(old_commit.paste_set.all())
old_commit.pk = None
old_commit.parent_set = paste_set
old_commit.parent_set = paste_set
old_commit.owner = owner
old_commit.save()
for paste in pastes:
paste.revision = old_commit
paste.pk = None
paste.save()
if commit.commit == old_commit.commit:
break;
break

return redirect('paste_view', pk=paste_set.pk)

Expand Down
22 changes: 9 additions & 13 deletions saic/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

REPO_DIR = os.sep.join([os.path.dirname(__file__), 'repositories'])

HAYSTACK_SITECONF = 'saic.search_sites'
HAYSTACK_SITECONF = 'saic.search_sites'
HAYSTACK_SEARCH_ENGINE = 'whoosh'
HAYSTACK_WHOOSH_PATH = os.sep.join([os.path.dirname(__file__),
HAYSTACK_WHOOSH_PATH = os.sep.join([os.path.dirname(__file__),
'whoosh', 'search-index'])

DEBUG = True
Expand All @@ -18,12 +18,12 @@

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': 'paste.db', # Or path to database file if using sqlite3.
'USER': '', # Not used with sqlite3.
'PASSWORD': '', # Not used with sqlite3.
'HOST': '', # Set to empty string for localhost. Not used with sqlite3.
'PORT': '', # Set to empty string for default. Not used with sqlite3.
'ENGINE': 'django.db.backends.sqlite3',
'NAME': 'paste.db',
'USER': '',
'PASSWORD': '',
'HOST': '',
'PORT': '',
}
}

Expand Down Expand Up @@ -109,11 +109,7 @@

ROOT_URLCONF = 'saic.urls'

TEMPLATE_DIRS = (
# Put strings here, like "/home/html/django_templates" or "C:/www/django/templates".
# Always use forward slashes, even on Windows.
# Don't forget to use absolute paths, not relative paths.
)
TEMPLATE_DIRS = ()

INSTALLED_APPS = (
'django.contrib.auth',
Expand Down
11 changes: 7 additions & 4 deletions saic/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,14 @@
urlpatterns = patterns('',
url(r'^paste/', include('saic.paste.urls')),
(r'^search/', include('haystack.urls')),
(r'^', redirect_to, { 'url': '/paste/' }),
(r'^', redirect_to, {'url': '/paste/'}),
url(r'^admin/doc/', include('django.contrib.admindocs.urls')),
url(r'^admin/', include(admin.site.urls)),
url(r'^admin/password_reset/$', 'django.contrib.auth.views.password_reset', name='password_reset'),
(r'^password_reset/done/$', 'django.contrib.auth.views.password_reset_done'),
url(r'^reset/(?P<uidb36>[0-9A-Za-z]+)-(?P<token>.+)/$', 'django.contrib.auth.views.password_reset_confirm'),
url(r'^admin/password_reset/$',
'django.contrib.auth.views.password_reset', name='password_reset'),
(r'^password_reset/done/$',
'django.contrib.auth.views.password_reset_done'),
url(r'^reset/(?P<uidb36>[0-9A-Za-z]+)-(?P<token>.+)/$',
'django.contrib.auth.views.password_reset_confirm'),
(r'^reset/done/$', 'django.contrib.auth.views.password_reset_complete'),
)

0 comments on commit de9aa79

Please sign in to comment.