##// END OF EJS Templates
Added creating new thread form...
Ilyas -
r14:de1ffcc8 default
parent child Browse files
Show More
@@ -0,0 +1,8 b''
1 from django import forms
2
3 class NewThreadForm(forms.Form):
4 title = forms.CharField(max_length = 100)
5 text = forms.CharField(max_length=150)
6 image = forms.ImageField()
7 tags = forms.CharField(max_length=100)
8
1 NO CONTENT: modified file, binary diff hidden
NO CONTENT: modified file, binary diff hidden
1 NO CONTENT: modified file, binary diff hidden
NO CONTENT: modified file, binary diff hidden
@@ -1,4 +1,5 b''
1 from django.db import models
1 from django.db import models
2 from django.http import Http404
2 from django.utils import timezone
3 from django.utils import timezone
3
4
4 NO_PARENT = -1
5 NO_PARENT = -1
@@ -68,7 +69,7 b' class Post(models.Model):'
68 title = models.CharField(max_length = 100)
69 title = models.CharField(max_length = 100)
69 pub_time = models.DateTimeField()
70 pub_time = models.DateTimeField()
70 text = models.TextField()
71 text = models.TextField()
71 image = models.ImageField(upload_to = DIR_IMAGES)
72 image = models.ImageField(upload_to = DIR_IMAGES, blank = True)
72 poster_ip = models.IPAddressField()
73 poster_ip = models.IPAddressField()
73 poster_user_agent = models.TextField()
74 poster_user_agent = models.TextField()
74 parent = models.BigIntegerField()
75 parent = models.BigIntegerField()
1 NO CONTENT: modified file, binary diff hidden
NO CONTENT: modified file, binary diff hidden
1 NO CONTENT: modified file, binary diff hidden
NO CONTENT: modified file, binary diff hidden
1 NO CONTENT: modified file, binary diff hidden
NO CONTENT: modified file, binary diff hidden
@@ -1,13 +1,20 b''
1 from django.template import RequestContext
1 from django.template import RequestContext
2 from boards import forms
2 from boards.models import Post, Admin
3 from boards.models import Post, Admin
3 from django.shortcuts import render
4 from django.shortcuts import render, get_list_or_404
4 from django.http import HttpResponseRedirect
5 from django.http import HttpResponseRedirect, Http404
5
6
6 def index(request):
7 def index(request):
8 context = RequestContext(request)
9
10 if request.method == 'POST':
11 Post.objects.create_post(request.POST['title'],
12 request.POST['text'], ip = request.META['REMOTE_ADDR'])
13
7 threads = Post.objects.get_threads()
14 threads = Post.objects.get_threads()
8
15
9 context = RequestContext(request)
10 context['threads'] = None if len(threads) == 0 else threads
16 context['threads'] = None if len(threads) == 0 else threads
17 context['form'] = forms.NewThreadForm()
11
18
12 return render(request, 'posting_general.html',
19 return render(request, 'posting_general.html',
13 context)
20 context)
@@ -29,11 +36,9 b' def new_post(request):'
29 def tag(request):
36 def tag(request):
30 """Get all tag threads (posts without a parent)."""
37 """Get all tag threads (posts without a parent)."""
31
38
32 # TODO Show 404 if no such tag
33
34 tag_name = request.GET['tag']
39 tag_name = request.GET['tag']
35
40
36 threads = Post.objects.get_threads(tag = tag_name)
41 threads = get_list_or_404(Post, tag = tag_name)
37
42
38 context = RequestContext(request)
43 context = RequestContext(request)
39 context['threads'] = None if len(threads) == 0 else threads
44 context['threads'] = None if len(threads) == 0 else threads
1 NO CONTENT: modified file, binary diff hidden
NO CONTENT: modified file, binary diff hidden
1 NO CONTENT: modified file, binary diff hidden
NO CONTENT: modified file, binary diff hidden
1 NO CONTENT: modified file, binary diff hidden
NO CONTENT: modified file, binary diff hidden
1 NO CONTENT: modified file, binary diff hidden
NO CONTENT: modified file, binary diff hidden
1 NO CONTENT: modified file, binary diff hidden
NO CONTENT: modified file, binary diff hidden
@@ -2,12 +2,24 b''
2
2
3 {% block content %}
3 {% block content %}
4
4
5 {% if threads %}
5 TODO: Need to implement field checking
6 TODO: need to implement message list
6 <HR />
7 {{ threads }}
7
8 {% else %}
8 {% if threads %}
9 No threads found.
9
10 {% endif %}
10 {% for thread in threads %}
11 {{ thread }} <BR />
12 {% endfor %}
13 {% else %}
14 No threads found.
15 {% endif %}
16
17 <form action="/boards/" method="post">{% csrf_token %}
18 {{ form.as_p }}
19 <input type="submit" value="Submit" />
20 </form>
21
22 <HR />
11
23
12 {% endblock %}
24 {% endblock %}
13
25
General Comments 0
You need to be logged in to leave comments. Login now