Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit db15874
Showing
28 changed files
with
843 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# Don't put settings_local.py in version control | ||
settings_local.py | ||
settings_local_production.py | ||
|
||
# No shell scripts or conf files? | ||
conf/ | ||
init.sh | ||
nginx.conf | ||
fabfile.py | ||
|
||
# No python compiled files in version control | ||
*.pyc | ||
*.pid | ||
*.socket | ||
|
||
# No files with passwords/etc | ||
htusers | ||
|
||
# No user-uploaded media or static admin symbolic links or files in tmp | ||
media/ | ||
uploads/ | ||
static/admin | ||
tmp/ | ||
|
||
# No packages - better to unpack these files and commit the raw source as Git has its own built in compression methods | ||
*.7z | ||
*.dmg | ||
*.gz | ||
*.iso | ||
*.jar | ||
*.rar | ||
*.tar | ||
*.zip | ||
|
||
# No logs and databases | ||
*.log | ||
*.sql | ||
*.sqlite | ||
*.db | ||
|
||
# No OS generated files | ||
.DS_Store? | ||
ehthumbs.db | ||
Icon? | ||
Thumbs.db |
Empty file.
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,4 @@ | ||
# http://stackoverflow.com/questions/4256145/django-template-tag-to-display-django-version | ||
import django | ||
def django_version(request): | ||
return { 'django_version': django.VERSION } |
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,14 @@ | ||
#!/usr/bin/env python | ||
from django.core.management import execute_manager | ||
import imp | ||
try: | ||
imp.find_module('settings') # Assumed to be in the same directory. | ||
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.exit(1) | ||
|
||
import settings | ||
|
||
if __name__ == "__main__": | ||
execute_manager(settings) |
Empty file.
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,4 @@ | ||
from webnotes.notes.models import Notes | ||
from django.contrib import admin | ||
|
||
admin.site.register(Notes) |
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,39 @@ | ||
# encoding: utf-8 | ||
import datetime | ||
from south.db import db | ||
from south.v2 import SchemaMigration | ||
from django.db import models | ||
|
||
class Migration(SchemaMigration): | ||
|
||
def forwards(self, orm): | ||
|
||
# Adding model 'Notes' | ||
db.create_table('notes_notes', ( | ||
('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)), | ||
('title', self.gf('django.db.models.fields.CharField')(max_length=255)), | ||
('content', self.gf('django.db.models.fields.TextField')()), | ||
('added_at', self.gf('django.db.models.fields.DateTimeField')(auto_now_add=True, blank=True)), | ||
('last_update', self.gf('django.db.models.fields.DateTimeField')(auto_now=True, blank=True)), | ||
)) | ||
db.send_create_signal('notes', ['Notes']) | ||
|
||
|
||
def backwards(self, orm): | ||
|
||
# Deleting model 'Notes' | ||
db.delete_table('notes_notes') | ||
|
||
|
||
models = { | ||
'notes.notes': { | ||
'Meta': {'object_name': 'Notes'}, | ||
'added_at': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}), | ||
'content': ('django.db.models.fields.TextField', [], {}), | ||
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), | ||
'last_update': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}), | ||
'title': ('django.db.models.fields.CharField', [], {'max_length': '255'}) | ||
} | ||
} | ||
|
||
complete_apps = ['notes'] |
Empty file.
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,25 @@ | ||
from django.db import models | ||
from django.db.models import permalink | ||
|
||
class Notes(models.Model): | ||
"""Model to save our note""" | ||
title = models.CharField(max_length=255) | ||
content = models.TextField() | ||
#automatically add timestamps when object is created | ||
added_at = models.DateTimeField(auto_now_add=True) | ||
#automatically add timestamps when object is updated | ||
last_update = models.DateTimeField(auto_now=True) # | ||
|
||
# display correct plural name in admin | ||
class Meta: | ||
verbose_name_plural = "notes" | ||
|
||
# display note title in admin | ||
def __unicode__(self): | ||
return self.title | ||
|
||
# define permalink (not needed?) | ||
# @permalink | ||
# def get_absolute_url(self): | ||
# # return ('collection_detail', None, {'object_id': self.id}) | ||
# return ("note_permalink", (), {'id': self.id}) |
Empty file.
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,12 @@ | ||
# http://www.djangrrl.com/post/custom-template-tags-in-django/ | ||
|
||
from webnotes.notes.models import Notes | ||
from django import template | ||
|
||
register = template.Library() | ||
|
||
def latestnote(): | ||
notes = Notes.objects.all().order_by('-last_update', 'title')[:1] | ||
return {'notes': notes} | ||
|
||
register.inclusion_tag('includes/last_updated_note.html')(latestnote) |
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,16 @@ | ||
""" | ||
This file demonstrates writing tests using the unittest module. These will pass | ||
when you run "manage.py test". | ||
Replace this with more appropriate tests for your application. | ||
""" | ||
|
||
from django.test import TestCase | ||
|
||
|
||
class SimpleTest(TestCase): | ||
def test_basic_addition(self): | ||
""" | ||
Tests that 1 + 1 always equals 2. | ||
""" | ||
self.assertEqual(1 + 1, 2) |
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,12 @@ | ||
from django.conf.urls.defaults import * | ||
|
||
import views | ||
|
||
urlpatterns = patterns('', | ||
|
||
url(r'^list/$', views.notes_list, name='notes_list'), | ||
url(r'^detail/(?P<id>\d+)/$', views.notes_detail, name='notes_detail'), | ||
url(r'^new/$', views.notes_create, name='notes_create'), | ||
url(r'^update/(?P<id>\d+)/$', views.notes_update, name='notes_update'), | ||
url(r'^delete/(?P<id>\d+)/$', views.notes_delete, name='notes_delete'), | ||
) |
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,82 @@ | ||
from django.views.generic.list_detail import object_list | ||
from django.views.generic.list_detail import object_detail | ||
from django.views.generic.create_update import create_object | ||
from django.views.generic.create_update import update_object | ||
from django.views.generic.create_update import delete_object | ||
from django.contrib.auth.decorators import login_required # for @login_required decorator | ||
from django.core.urlresolvers import reverse | ||
|
||
from models import Notes | ||
|
||
# def login_view(request): | ||
# if request.method == 'POST': | ||
# user = authenticate(username = request.POST['login_username'], password = request.POST['login_password']) | ||
# if user is None: | ||
# return direct_to_template(request, 'invalid_login.html') | ||
# if not user.is_active: | ||
# return direct_to_template(request, 'inactive_account.html') | ||
# login(request, user) | ||
# try: | ||
# return HttpResponseRedirect(request.META.get('HTTP_REFERER', None)) | ||
# except KeyError: | ||
# return HttpResponseRedirect('/') | ||
# | ||
# def logout_view(request): | ||
# logout(request) | ||
# try: | ||
# return HttpResponseRedirect(request.META.get('HTTP_REFERER', None)) | ||
# except KeyError: | ||
# return HttpResponseRedirect('/') | ||
|
||
def notes_list(request): | ||
"""Show all notes""" | ||
|
||
return object_list(request, | ||
queryset=Notes.objects.all().order_by('-added_at', 'title'), # https://docs.djangoproject.com/en/dev/ref/models/querysets/#django.db.models.query.QuerySet.order_by | ||
template_name='notes/list.html', | ||
template_object_name='note' | ||
) | ||
|
||
def notes_detail(request, id): | ||
"""View note detail based on note id""" | ||
|
||
return object_detail(request, | ||
queryset=Notes.objects.all(), | ||
object_id=id, | ||
template_name='notes/detail.html', | ||
template_object_name='note' | ||
) | ||
|
||
# see also this alternative: http://djangosnippets.org/snippets/966/ | ||
@login_required | ||
def notes_create(request): | ||
"""Create new note""" | ||
|
||
return create_object(request, | ||
model=Notes, | ||
template_name='notes/create.html', | ||
post_save_redirect=reverse("notes_list") | ||
) | ||
|
||
@login_required | ||
def notes_update(request, id): | ||
"""Update note based on id""" | ||
|
||
return update_object(request, | ||
model=Notes, | ||
object_id=id, | ||
template_name='notes/update.html', | ||
post_save_redirect=reverse("notes_list") | ||
) | ||
|
||
@login_required | ||
def notes_delete(request, id): | ||
"""Delete a note based on id""" | ||
|
||
return delete_object(request, | ||
model=Notes, | ||
object_id=id, | ||
template_object_name='note', | ||
template_name='notes/delete.html', | ||
post_delete_redirect=reverse("notes_list") | ||
) |
Oops, something went wrong.