embeded pandora mobile view
This commit is contained in:
commit
b420bf43b7
45 changed files with 3437 additions and 0 deletions
51
app/item/views.py
Normal file
51
app/item/views.py
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
from datetime import date, datetime, timedelta
|
||||
from django.shortcuts import render
|
||||
|
||||
from . import models
|
||||
|
||||
|
||||
def index(request):
|
||||
context = {}
|
||||
week, archive = models.Item.public()
|
||||
context['items'] = week
|
||||
context['archive'] = archive.exists()
|
||||
return render(request, 'index.html', context)
|
||||
|
||||
|
||||
def archive(request):
|
||||
context = {}
|
||||
qs = models.Item.public()
|
||||
week, archive = models.Item.public()
|
||||
context['items'] = archive
|
||||
return render(request, 'archive.html', context)
|
||||
|
||||
def item(request, id):
|
||||
context = {}
|
||||
item = models.Item.objects.get(id=id)
|
||||
context['item'] = item
|
||||
return render(request, 'item.html', context)
|
||||
|
||||
import json
|
||||
from django.http import Http404, HttpResponse
|
||||
|
||||
def render_to_json(response):
|
||||
content = json.dumps(response)
|
||||
return HttpResponse(content, 'application/json; charset=utf-8')
|
||||
|
||||
|
||||
def comment(request):
|
||||
response = {}
|
||||
data = json.loads(request.body)
|
||||
print(data)
|
||||
comment = models.Comment()
|
||||
comment.item = models.Item.objects.get(id=data['item'])
|
||||
if request.user.is_authenticated:
|
||||
comment.user = request.user
|
||||
comment.published = datetime.now()
|
||||
else:
|
||||
comment.name = data['name']
|
||||
comment.email = data['email']
|
||||
comment.text = data['text']
|
||||
comment.save()
|
||||
response = comment.json()
|
||||
return render_to_json(response)
|
||||
Loading…
Add table
Add a link
Reference in a new issue