Grigoriy Petukhov avatar Grigoriy Petukhov committed 9db8a9d

New changes

Comments (0)

Files changed (14)

 # Distutils
 pybb.egg-info/
 dist/
+pybb.old
 
 # Sphinx
 docs/_build/

README

-============================
-PyBB - Python Bulletin Board
-============================
-
-One more time from the scratch!
-
-Questions? lorien@lorien.name
+============================
+PyBB - Python Bulletin Board
+============================
+
+Simple discussion board for your django powered website.
+
+Questions? lorien@lorien.name
+
+Installation
+============
+
+1. Install recent version of pybb from bitbucket repository
+2. Update settings.INSTALLED_APPS::
+
+    'pybb',
+
+3. Update urls.py::
+
+    url(r'^forum/', include('pybb.urls', namespace='pybb')),
+
+4. Put templates/pybb from pybb repository to your templates directory.
+   Use these templates as starting point and change them according to
+   design of your site. Default templates use `django-widget-tweaks <https://bitbucket.org/kmike/django-widget-tweaks>`_ applications.
+
+5. Run command::
+
+   ./manage.py migrate pybb
 PyBB - Django Forum Application
 ===============================
 
-Oficial repository: http://bitbucket.org/lorien/pybb
-Email support: lorien@lorien.name
+Code repository and bug tracker: http://bitbucket.org/lorien/pybb
+Email of main contributor: lorien@lorien.name
 
 .. toctree::
     :maxdepth: 1
 
 
 class Topic(models.Model):
-    name = models.CharField(max_length=100)
+    name = models.CharField(u'Заголовок темы', max_length=100)
     created = models.DateTimeField(blank=True, default=datetime.now)
     forum = models.ForeignKey('pybb.Forum', related_name='topics')
     post_count = models.IntegerField(blank=True, default=0)
 class Post(models.Model):
     created = models.DateTimeField(blank=True, default=datetime.now)
     topic = models.ForeignKey('pybb.Topic', related_name='posts')
-    content = models.TextField()
+    content = models.TextField(u'Сообщение')
     content_html = models.TextField(blank=True)
     user = models.ForeignKey('auth.User')
 
 from django.template.loader import render_to_string
 from django.conf import settings
 from django.contrib.auth.decorators import login_required
+from django.contrib import messages
 
 from common.pagination import paginate
 
 from pybb.models import Category, Forum, Topic, Post
 from pybb.forms import PostForm, TopicForm
 
+
+def get_post_form(request, topic):
+    if request.user.is_authenticated():
+        instance = Post(topic=topic, user=request.user)
+        form = PostForm(request.POST or None, instance=instance)
+        return form
+    else:
+        return None
+
+
 def home_page(request):
     cats = Category.objects.order_by('position')
     context = {'cats': cats,
 def topic_page(request, pk):
     topic = get_object_or_404(Topic, pk=pk)
     posts = Post.objects.filter(topic=topic).order_by('created')
+    post_form = get_post_form(request, topic)
     context = {'topic': topic,
                'posts': posts,
+               'post_form': post_form,
             }
     return render(request, 'pybb/topic_page.html', context)
 
 def post_add(request):
     topic_id = request.GET.get('topic')
     topic = get_object_or_404(Topic, pk=topic_id)
-    instance = Post(topic=topic, user=request.user)
-    form = PostForm(request.POST or None, instance=instance)
+    form = get_post_form(request, topic)
     if form.is_valid():
         form.save()
         return redirect(topic)
             user=request.user,
             content=form.cleaned_data['content'],
         )
+        messages.success(request, u'Обсуждение успешно создано')
         return redirect(topic)
     context = {'form': form,
                'forum': forum,
     name = 'pybb',
     version = '0.1.10',
     description = 'Django forum application',
-    long_description = open('README').read(),
+    long_description = open('README.rst').read(),
     author = 'Grigoriy Petukhov',
     author_email = 'lorien@lorien.name',
     url = 'http://pybb.org',

templates/pybb/base.html

+{% extends 'base.html' %}
+
+{% block meta_description%}{% block pybb_meta_description %}{% endblock %}{% endblock %}
+{% block meta_keywords %}{% block pybb_meta_keywords %}{% endblock %}{% endblock %}
+{% block title %}{% block pybb_title %}{% endblock %}{% endblock %}
+
+{% block extra_js %}
+    {% block pybb_extra_js %}{% endblock %}
+{% endblock %}
+
+{% block crumbs %}
+<ul class="breadcrumb">
+    <li><a href="/">Начало</a> <span class="divider">/</span></li>
+    <li><a href="{% url pybb:home_page %}">Форум</a> <span class="divider">/</span></li>
+    {% block pybb_crumbs %}{% endblock %}
+</ul>
+{% endblock %}
+
+{% block content %}
+    {% block pybb_content %}{% endblock %}
+{% endblock %}

templates/pybb/form_field.html

+{% load widget_tweaks %}
+
+<p class="field">
+    {{ field.errors }}
+    <label for="id_subject">{{ field.label }}:</label>
+    {{ field|add_class:"input-xxlarge"|attr:"rows:5" }}
+</p>

templates/pybb/forum_page.html

+{% extends 'pybb/base.html' %}
+
+{% block pybb_crumbs %}{{ forum }}{% endblock %}
+
+{% block content %}
+<h1>{{ forum }}</h1>
+<table class="table table-bordered table-striped">
+    <thead>
+        <tr>
+            <th>Тема</th>
+            <th>Создана</th>
+            <th>Сообщений</th>
+        </tr>
+    </thead>
+    <tbody>
+        {% for topic in forum.topics.all %}
+        <tr>
+            <td><a href="{{ topic.get_absolute_url }}">{{ topic }}</a></td>
+            <td>{{ topic.created|date:"d F, Y H:i" }}</td>
+            <td>{{ topic.post_count }}</td>
+        </tr>
+        {% endfor %}
+    </tbody>
+</table>
+<p>
+    <a class="btn btn-info" href="{% url pybb:topic_add %}?forum={{ forum.pk }}">Создать тему</a>
+</p>
+{% endblock %}

templates/pybb/home_page.html

+{% extends 'pybb/base.html' %}
+
+{% block pybb_crumbs %}Главная страница{% endblock %}
+
+{% block content %}
+{% for cat in cats %}
+<h3>{{ cat }}</h3>
+<table class="table table-bordered table-striped">
+    <thead>
+        <tr>
+            <th>Форум</th>
+            <th>Тем</th>
+            <th>Сообщений</th>
+        </tr>
+    </thead>
+    <tbody>
+        {% for forum in cat.forums.all %}
+        <tr>
+            <td><a href="{{ forum.get_absolute_url }}">{{ forum }}</a></td>
+            <td>{{ forum.topic_count }}</td>
+            <td>{{ forum.post_count }}</td>
+        </tr>
+        {% endfor %}
+    </tbody>
+</table>
+{% endfor %}
+{% endblock %}

templates/pybb/post_add.html

+{% extends 'pybb/base.html' %}
+
+{% block pybb_crumbs %}
+<li><a href="{{ topic.forum.get_absolute_url }}">{{ topic.forum }}</a> <span class="divider">/</span></li>
+<li><a href="{{ topic.get_absolute_url }}">{{ topic }}</a></li>
+{% endblock %}
+
+{% block content %}
+<h1>Ответ в тему {{ topic }}</h1>
+<form method="post">
+    {% csrf_token %}
+    {{ form.as_p }}
+    <p><input type="submit" value="Отправить" /></p>
+</form>
+{% endblock %}

templates/pybb/topic_add.html

+{% extends 'pybb/base.html' %}
+
+{% block pybb_crumbs %}
+<li><a href="{{ forum.get_absolute_url }}">{{ forum }}</a></li>
+{% endblock %}
+
+{% block content %}
+<h1>Создание топика в форуме {{ forum }}</h1>
+<form method="post">
+    {% csrf_token %}
+    {% include "pybb/form_field.html" with field=form.name %}
+    {% include "pybb/form_field.html" with field=form.content %}
+    <p><input type="submit" value="Написать" /></p>
+</form>
+{% endblock %}

templates/pybb/topic_page.html

+{% extends 'pybb/base.html' %}
+
+{% block pybb_crumbs %}
+<li><a href="{{ topic.forum.get_absolute_url }}">{{ topic.forum }}</a></li>
+{% endblock %}
+
+{% block content %}
+<h1>{{ topic }}</h1>
+<table class="table table-bordered table-striped">
+    <thead>
+        <tr>
+            <th>Автор</th>
+            <th>Сообщение</th>
+        </tr>
+    </thead>
+    <tbody>
+        {% for post in posts %}
+        <tr>
+            <td>
+                <a href="#"><i class="icon-user"></i> {{ post.user }}</a>
+                <div class="muted"><i class="icon-time"></i> {{ post.created|date:"d M, Y H:i" }}</div>
+            </td>
+            <td>{{ post.content|linebreaks }}</td>
+        </tr>
+        {% endfor %}
+    </tbody>
+</table>
+<p>
+    {% if user.is_authenticated %}
+    <form method="post" action="{% url pybb:post_add %}?topic={{ topic.pk }}">
+        {% csrf_token %}
+        {% include "pybb/form_field.html" with field=post_form.content %}
+        <p>
+            <button class="btn">Ответить</button>
+        </a>
+    </form>
+    {% else %}
+    <a class="btn btn-info" href="{% url pybb:post_add %}?topic={{ topic.pk }}">Ответить</a>
+    {% endif %}
+</p>
+{% endblock %}
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.