forked from 0x2620/pandora
add some text
This commit is contained in:
parent
c955215c17
commit
c1f8c10e10
5 changed files with 145 additions and 0 deletions
|
@ -121,6 +121,7 @@ INSTALLED_APPS = (
|
||||||
'item',
|
'item',
|
||||||
'archive',
|
'archive',
|
||||||
'user',
|
'user',
|
||||||
|
'text',
|
||||||
'torrent',
|
'torrent',
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
0
pandora/text/__init__.py
Normal file
0
pandora/text/__init__.py
Normal file
62
pandora/text/models.py
Normal file
62
pandora/text/models.py
Normal file
|
@ -0,0 +1,62 @@
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
# vi:si:et:sw=4:sts=4:ts=4
|
||||||
|
from __future__ import division, with_statement
|
||||||
|
from datetime import datetime
|
||||||
|
|
||||||
|
from django.db import models
|
||||||
|
from django.contrib.auth.models import User
|
||||||
|
from django.conf import settings
|
||||||
|
|
||||||
|
import ox
|
||||||
|
from ox.django import fields
|
||||||
|
from ox.utils import json
|
||||||
|
|
||||||
|
|
||||||
|
class News(models.Model):
|
||||||
|
created = models.DateTimeField(auto_now_add=True)
|
||||||
|
modified = models.DateTimeField(auto_now=True)
|
||||||
|
published = models.DateTimeField(default=datetime.now, editable=False)
|
||||||
|
public = models.BooleanField(default=False)
|
||||||
|
|
||||||
|
user = models.ForeignKey(User)
|
||||||
|
slug = models.SlugField()
|
||||||
|
title = models.CharField(null=True, max_length=255)
|
||||||
|
body = models.TextField(default='')
|
||||||
|
|
||||||
|
def __unicode__(self):
|
||||||
|
return u"%s <%s>" % (self.title, self.slug)
|
||||||
|
|
||||||
|
def get_absolute_url(self):
|
||||||
|
return '/text/%s' % self.slug
|
||||||
|
|
||||||
|
class Text(models.Model):
|
||||||
|
created = models.DateTimeField(auto_now_add=True)
|
||||||
|
modified = models.DateTimeField(auto_now=True)
|
||||||
|
published = models.DateTimeField(default=datetime.now, editable=False)
|
||||||
|
public = models.BooleanField(default=False)
|
||||||
|
|
||||||
|
user = models.ForeignKey(User)
|
||||||
|
slug = models.SlugField()
|
||||||
|
title = models.CharField(null=True, max_length=255)
|
||||||
|
body = models.TextField(default='')
|
||||||
|
|
||||||
|
def __unicode__(self):
|
||||||
|
return u"%s <%s>" % (self.title, self.slug)
|
||||||
|
|
||||||
|
def get_absolute_url(self):
|
||||||
|
return '/text/%s' % self.slug
|
||||||
|
|
||||||
|
class Image(models.Model):
|
||||||
|
image = models.ImageField(upload_to='text/image')
|
||||||
|
caption = models.CharField(max_length=255, default="")
|
||||||
|
|
||||||
|
def get_absolute_url(self):
|
||||||
|
return self.image.url
|
||||||
|
|
||||||
|
class Attachment(models.Model):
|
||||||
|
file = models.FileField(upload_to='text/attachment')
|
||||||
|
caption = models.CharField(max_length=255, default="")
|
||||||
|
|
||||||
|
def get_absolute_url(self):
|
||||||
|
return self.file.url
|
||||||
|
|
23
pandora/text/tests.py
Normal file
23
pandora/text/tests.py
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
"""
|
||||||
|
This file demonstrates two different styles of tests (one doctest and one
|
||||||
|
unittest). These will both pass when you run "manage.py test".
|
||||||
|
|
||||||
|
Replace these 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.failUnlessEqual(1 + 1, 2)
|
||||||
|
|
||||||
|
__test__ = {"doctest": """
|
||||||
|
Another way to test that 1 + 1 is equal to 2.
|
||||||
|
|
||||||
|
>>> 1 + 1 == 2
|
||||||
|
True
|
||||||
|
"""}
|
||||||
|
|
59
pandora/text/views.py
Normal file
59
pandora/text/views.py
Normal file
|
@ -0,0 +1,59 @@
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
# vi:si:et:sw=4:sts=4:ts=4
|
||||||
|
from __future__ import division
|
||||||
|
|
||||||
|
from django.contrib.auth.decorators import login_required
|
||||||
|
from django.contrib.auth.models import User
|
||||||
|
from django.db.models import Q, Avg, Count, Sum
|
||||||
|
from django.http import HttpResponse, Http404
|
||||||
|
from django.shortcuts import render_to_response, get_object_or_404, get_list_or_404, redirect
|
||||||
|
from django.template import RequestContext
|
||||||
|
from django.conf import settings
|
||||||
|
|
||||||
|
from ox.utils import json
|
||||||
|
from ox.django.decorators import login_required_json
|
||||||
|
from ox.django.shortcuts import render_to_json_response, get_object_or_404_json, json_response
|
||||||
|
from ox.django.http import HttpFileResponse
|
||||||
|
import ox
|
||||||
|
|
||||||
|
import models
|
||||||
|
|
||||||
|
|
||||||
|
def api_getNews(request):
|
||||||
|
'''
|
||||||
|
param data
|
||||||
|
string id
|
||||||
|
|
||||||
|
return page
|
||||||
|
'''
|
||||||
|
response = json_response({})
|
||||||
|
itemId = json.loads(request.POST['data'])
|
||||||
|
item = get_object_or_404_json(models.News, pk=itemId)
|
||||||
|
response['data']['page'] = item.html()
|
||||||
|
return render_to_json_response(response)
|
||||||
|
|
||||||
|
def api_findNews(request):
|
||||||
|
'''
|
||||||
|
'''
|
||||||
|
response = json_response({})
|
||||||
|
return render_to_json_response(response)
|
||||||
|
|
||||||
|
def api_getText(request):
|
||||||
|
'''
|
||||||
|
param data
|
||||||
|
string id
|
||||||
|
|
||||||
|
return page
|
||||||
|
'''
|
||||||
|
response = json_response({})
|
||||||
|
itemId = json.loads(request.POST['data'])
|
||||||
|
item = get_object_or_404_json(models.Text, pk=itemId)
|
||||||
|
response['data']['page'] = item.html()
|
||||||
|
return render_to_json_response(response)
|
||||||
|
|
||||||
|
def api_findText(request):
|
||||||
|
'''
|
||||||
|
'''
|
||||||
|
response = json_response({})
|
||||||
|
return render_to_json_response(response)
|
||||||
|
|
Loading…
Reference in a new issue