Skip to content
This repository has been archived by the owner on Feb 22, 2024. It is now read-only.

Commit

Permalink
Reorder imports + add blank lines
Browse files Browse the repository at this point in the history
Where necessary. Issue #138, in progress.
  • Loading branch information
dellsystem committed Jan 2, 2013
1 parent 9576b72 commit 618df57
Show file tree
Hide file tree
Showing 20 changed files with 79 additions and 23 deletions.
2 changes: 1 addition & 1 deletion urls.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from django.conf.urls.defaults import patterns, include, url

from django.contrib import admin

admin.autodiscover()

"""
Expand Down
5 changes: 5 additions & 0 deletions views/news.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
from django.shortcuts import render

from blog.models import BlogPost


def main(request):
data = {
'title': 'News',
'blog_posts': BlogPost.objects.order_by('-timestamp').all(),
}

return render(request, 'news/main.html', data)


def view(request, slug):
post = BlogPost.objects.get(slug=slug)
data = {
'title': post,
'post': post,
}

return render(request, 'news/view.html', data)
38 changes: 27 additions & 11 deletions views/pages.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
from datetime import datetime
import random as random_module

from django.contrib.auth.models import User
from django.http import Http404
from django.shortcuts import render, get_object_or_404, redirect
from wiki.models.courses import Course, CourseSemester, Professor
from wiki.utils.constants import terms, years, exam_types
from wiki.utils.gitutils import Git, NoChangesError
from wiki.utils.pages import page_types
from django.template import RequestContext
from wiki.models.pages import Page
from django.http import Http404
import random as random_module

from views.main import register
from wiki.models.courses import Course, CourseSemester, Professor
from wiki.models.history import HistoryItem
from django.contrib.auth.models import User
from wiki.models.pages import Page
from wiki.utils.constants import terms, years, exam_types
from wiki.utils.currents import current_term, current_year
from views.main import register
from datetime import datetime
from wiki.utils.gitutils import Git, NoChangesError
from wiki.utils.merge3 import Merge3
from wiki.utils.pages import page_types


def show(request, department, number, page_type, term, year, slug, printview=False):
department = department.upper()
Expand Down Expand Up @@ -45,9 +48,11 @@ def show(request, department, number, page_type, term, year, slug, printview=Fal

return render(request, template_file, data)


def printview(request, department, number, page_type, term, year, slug):
return show(request, department, number, page_type, term, year, slug, printview=True)


def history(request, department, number, page_type, term, year, slug):
course = get_object_or_404(Course, department=department.upper(), number=int(number))
course_sem = get_object_or_404(CourseSemester, course=course, term=term, year=year)
Expand Down Expand Up @@ -97,6 +102,7 @@ def commit(request, department, number, page_type, term, year, slug, hash):

return render(request, "pages/commit.html", data)


def edit(request, department, number, page_type, term, year, slug):
if not request.user.is_authenticated():
return register(request)
Expand Down Expand Up @@ -185,6 +191,7 @@ def edit(request, department, number, page_type, term, year, slug):
}
return render(request, "pages/edit.html", data)


# semester should only be filled out if the page doesn't exist and we want to create it
def create(request, department, number, page_type, semester=None):
if not request.user.is_authenticated():
Expand Down Expand Up @@ -266,7 +273,16 @@ def create(request, department, number, page_type, semester=None):

return render(request, 'pages/create.html', data)


def random(request):
pages = Page.objects.all()
random_page = random_module.choice(pages)
return show(request, random_page.course_sem.course.department.short_name.upper(), random_page.course_sem.course.number, random_page.page_type, random_page.course_sem.term, random_page.course_sem.year, random_page.slug)

return show(
request,
random_page.course_sem.course.department.short_name.upper(),
random_page.course_sem.course.number,
random_page.page_type,
random_page.course_sem.term,
random_page.course_sem.year, random_page.slug
)
3 changes: 2 additions & 1 deletion wiki/admin/courses.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from wiki.models.courses import Course, CourseSemester, Professor
from django.contrib import admin

from wiki.models.courses import Course, CourseSemester, Professor


class CourseAdmin(admin.ModelAdmin):
exclude = ('num_watchers', 'latest_activity', 'watchers')
Expand Down
4 changes: 3 additions & 1 deletion wiki/admin/departments.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
from wiki.models.departments import Department
from django.contrib import admin

from wiki.models.departments import Department


admin.site.register(Department)
4 changes: 3 additions & 1 deletion wiki/admin/faculties.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
from wiki.models.faculties import Faculty
from django.contrib import admin

from wiki.models.faculties import Faculty


admin.site.register(Faculty)
4 changes: 3 additions & 1 deletion wiki/admin/pages.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
from wiki.models.pages import Page
from django.contrib import admin

from wiki.models.pages import Page


admin.site.register(Page)
7 changes: 5 additions & 2 deletions wiki/admin/series.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
from wiki.models.series import Series, SeriesPage
from django.contrib import admin

from wiki.models.series import Series, SeriesPage


class SeriesPageInline(admin.TabularInline):
model = SeriesPage


class SeriesAdmin(admin.ModelAdmin):
inlines = [SeriesPageInline]
prepopulated_fields = {"slug": ("name",)}


admin.site.register(Series, SeriesAdmin)
#admin.site.register(SeriesPage)
1 change: 1 addition & 0 deletions wiki/context_processors.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from settings import COMPILE_LESS


def less_compilation(request):
return {'compile_less': COMPILE_LESS}
2 changes: 2 additions & 0 deletions wiki/models/courses.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from wiki.models.history import HistoryItem
from wiki.utils.currents import current_year, current_term


class Course(models.Model):
class Meta:
app_label = 'wiki'
Expand Down Expand Up @@ -61,6 +62,7 @@ def recent_activity(self, limit=5):
else:
return course_history


class CourseSemester(models.Model):
class Meta:
app_label = 'wiki'
Expand Down
1 change: 1 addition & 0 deletions wiki/models/departments.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from django.db import models


class Department(models.Model):
class Meta:
app_label = 'wiki'
Expand Down
1 change: 1 addition & 0 deletions wiki/models/faculties.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from django.db import models


class Faculty(models.Model):
class Meta:
app_label = 'wiki'
Expand Down
8 changes: 8 additions & 0 deletions wiki/models/page_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
# Done this way because it's better than the 4 other possible ways (believe me I tried them all)
# Define all the page types here, and their short names
import re

from django.template.defaultfilters import slugify

from wiki.utils.constants import terms, years, exam_types

""" HOW TO CREATE A NEW PAGE TYPE
Expand All @@ -14,6 +16,7 @@
ALTHOUGH IF YOU HAVE CUSTOM NAMES YOU CAN OVERRIDE ANY OF THE RELEVANT METHODS, ETC
"""


class PageType:
# Defaults - override if necessary
uneditable_fields = ['semester', 'subject']
Expand Down Expand Up @@ -97,6 +100,7 @@ def find_errors(self, data):
else:
return []


class LectureNote(PageType):
short_name = 'lecture-notes'
long_name = 'Lecture notes'
Expand Down Expand Up @@ -125,6 +129,7 @@ def get_validators(self, data):
#(len(data['subject']) > 0, 'Invalid subject'),
]


class PastExam(PageType):
short_name = 'past-exam'
long_name = 'Past exam'
Expand All @@ -146,6 +151,7 @@ def get_validators(self, data):
(data['exam_type'] in exam_types, 'Invalid exam type'),
]


class CourseSummary(PageType):
short_name = 'summary'
long_name = 'Course summary'
Expand All @@ -161,6 +167,7 @@ def get_validators(self, data):
(len(data['subject']) > 0, 'Invalid subject'),
]


class VocabList(PageType):
short_name = 'vocab-list'
long_name = 'Vocabulary list'
Expand All @@ -179,6 +186,7 @@ def get_validators(self, data):
(len(data['subject']) > 0, 'Invalid subject'),
]


class CourseQuiz(PageType):
short_name = 'course-quiz'
long_name = 'Multiple choice quiz'
Expand Down
2 changes: 2 additions & 0 deletions wiki/models/series.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from django.db import models


class Series(models.Model):
class Meta:
app_label = 'wiki'
Expand All @@ -19,6 +20,7 @@ def get_absolute_url(self):
def get_num_total(self):
return self.seriespage_set.count()


class SeriesPage(models.Model):
class Meta:
app_label = 'wiki'
Expand Down
5 changes: 3 additions & 2 deletions wiki/templatetags/wikinotes_markup.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import re

import markdown
from django import template
from django.utils.html import escape
import markdown
import re

register = template.Library()

Expand Down
3 changes: 2 additions & 1 deletion wiki/tests/markdown.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from django.utils import unittest

from wiki.templatetags.wikinotes_markup import wikinotes_markdown as md


class TestMarkdown(unittest.TestCase):

elements = {
"bold" : "**bold**",
"italic" : "*italic*",
Expand Down
7 changes: 5 additions & 2 deletions wiki/utils/gitutils.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import git
import gitdb
import datetime
from math import log
from os import makedirs, environ

import git
import gitdb


class NoChangesError(Exception):
pass


class Git:
def __init__(self, path_to_repo):
self.full_path = path_to_repo.strip('/') # don't need leading/trailing slashes
Expand Down
2 changes: 2 additions & 0 deletions wiki/utils/history.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import datetime


# Put here because, why not
def get_date_x_days_ago(num_days):
return datetime.datetime.now() - datetime.timedelta(days=num_days)


# Used by HistoryItem to output a human-readable timestamp
# More vague than the built-in timesince filter, which is good
# Written by Joey Bratton http://www.joeyb.org/blog/2009/10/08/custom-django-template-filter-for-humanized-timesince
Expand Down
2 changes: 2 additions & 0 deletions wiki/utils/pages.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import inspect

from wiki.models import page_types as types


# A dictionary for reverse lookup of page type by the short name
# So, given "course-quiz", find the CourseQuiz object etc
page_types = {}
Expand Down
1 change: 1 addition & 0 deletions wiki/utils/users.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import re


def validate_username(username):
if re.match('^\w+$', username):
return True
Expand Down

0 comments on commit 618df57

Please sign in to comment.