-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds the option to create static pages with several options to custom…
…ize its behaviour. git-svn-id: http://svn.osqa.net/svnroot/osqa/trunk@381 0cfe37f9-358a-4d5e-be75-b63607b5c754
- Loading branch information
hernani
committed
Jun 7, 2010
1 parent
01eed15
commit 9308d78
Showing
32 changed files
with
433 additions
and
61 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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
from meta import * | ||
from node import * | ||
from user import * | ||
from user import * | ||
from page import * |
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
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,58 @@ | ||
from django.utils.translation import ugettext as _ | ||
from forum.models.action import ActionProxy | ||
from forum.models import Page | ||
|
||
class NewPageAction(ActionProxy): | ||
verb = _("created") | ||
|
||
def process_data(self, **data): | ||
title = data.pop('title') | ||
body = data.pop('content') | ||
|
||
page = Page(author=self.user, title=title, body=body, extra=data) | ||
page.save() | ||
self.node = page | ||
|
||
def describe(self, viewer=None): | ||
return _("%(user)s created a new page titled %(page)s") % { | ||
'user': self.hyperlink(self.user.get_profile_url(), self.friendly_username(viewer, self.user)), | ||
'page': self.hyperlink(self.node.get_absolute_url(), self.node.title) | ||
} | ||
|
||
class EditPageAction(ActionProxy): | ||
verb = _("edited") | ||
|
||
def process_data(self, **data): | ||
title = data.pop('title') | ||
body = data.pop('content') | ||
|
||
if (title != self.node.title) and (body != self.node.body): | ||
self.node.create_revision(self.user, title=title, body=body) | ||
|
||
self.node.extra = data | ||
self.node.save() | ||
|
||
def describe(self, viewer=None): | ||
return _("%(user)s edited the page titled %(page)s") % { | ||
'user': self.hyperlink(self.user.get_profile_url(), self.friendly_username(viewer, self.user)), | ||
'page': self.hyperlink(self.node.get_absolute_url(), self.node.title) | ||
} | ||
|
||
class PublishAction(ActionProxy): | ||
verb = _("published") | ||
|
||
def process_action(self): | ||
self.node.marked = True | ||
self.node.nstate.published = self | ||
self.node.save() | ||
|
||
def cancel_action(self): | ||
self.node.marked = False | ||
self.node.nstate.published = None | ||
self.node.save() | ||
|
||
def describe(self, viewer=None): | ||
return _("%(user)s published a new page titled %(page)s") % { | ||
'user': self.hyperlink(self.user.get_profile_url(), self.friendly_username(viewer, self.user)), | ||
'page': self.hyperlink(self.node.get_absolute_url(), self.node.title) | ||
} |
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
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 qanda import * | ||
from admin import * | ||
from auth import * | ||
from general import * |
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,86 @@ | ||
import socket | ||
from django import forms | ||
from django.utils.translation import ugettext as _ | ||
from qanda import TitleField, EditorField | ||
from forum import settings | ||
|
||
class IPListField(forms.CharField): | ||
def clean(self, value): | ||
ips = [ip.strip() for ip in value.strip().strip(',').split(',')] | ||
iplist = [] | ||
|
||
if len(ips) < 1: | ||
raise forms.ValidationError(_('Please input at least one ip address')) | ||
|
||
for ip in ips: | ||
try: | ||
socket.inet_aton(ip) | ||
except socket.error: | ||
raise forms.ValidationError(_('Invalid ip address: %s' % ip)) | ||
|
||
if not len(ip.split('.')) == 4: | ||
raise forms.ValidationError(_('Please use the dotted quad notation for the ip addresses')) | ||
|
||
iplist.append(ip) | ||
|
||
return iplist | ||
|
||
class MaintenanceModeForm(forms.Form): | ||
ips = IPListField(label=_('Allow ips'), | ||
help_text=_('Comma separated list of ips allowed to access the site while in maintenance'), | ||
required=True, | ||
widget=forms.TextInput(attrs={'class': 'longstring'})) | ||
|
||
message = forms.CharField(label=_('Message'), | ||
help_text=_('A message to display to your site visitors while in maintainance mode'), | ||
widget=forms.Textarea) | ||
|
||
|
||
TEMPLATE_CHOICES = ( | ||
('default', _('Default')), | ||
('sidebar', _('Default with sidebar')), | ||
('none', _('None')), | ||
) | ||
|
||
RENDER_CHOICES = ( | ||
('markdown', _('Markdown')), | ||
('html', _('HTML')), | ||
('escape', _('Escaped')) | ||
) | ||
|
||
class UrlFieldWidget(forms.TextInput): | ||
def render(self, name, value, attrs=None): | ||
if not value: | ||
value = '' | ||
|
||
return """ | ||
<input class="url_field" type="text" name="%(name)s" value="%(value)s" /> | ||
<a class="url_field_anchor" target="_blank" href="%(app_url)s%(script_alias)s"></a> | ||
""" % {'name': name, 'value': value, 'app_url': settings.APP_URL, 'script_alias': settings.FORUM_SCRIPT_ALIAS} | ||
|
||
|
||
class PageForm(forms.Form): | ||
|
||
def __init__(self, page, *args, **kwargs): | ||
if page: | ||
initial = page.extra | ||
initial.update(dict(title=page.title, content=page.body)) | ||
super(PageForm, self).__init__(initial=initial, *args, **kwargs) | ||
else: | ||
super(PageForm, self).__init__(*args, **kwargs) | ||
|
||
|
||
title = forms.CharField(label=_('Title'), max_length=255, widget=forms.TextInput(attrs={'class': 'longstring'}), initial='New page') | ||
path = forms.CharField(label=_('Page URL'), widget=UrlFieldWidget, initial='pages/new/') | ||
|
||
content = forms.CharField(label=_('Page Content'), widget=forms.Textarea(attrs={'rows': 30})) | ||
render = forms.ChoiceField(widget=forms.RadioSelect, choices=RENDER_CHOICES, initial='markdown', label=_('Render Mode')) | ||
|
||
template = forms.ChoiceField(widget=forms.RadioSelect, choices=TEMPLATE_CHOICES, initial='default', label=_('Template')) | ||
sidebar = forms.CharField(label=_('Sidebar Content'), widget=forms.Textarea(attrs={'rows': 20}), required=False) | ||
sidebar_wrap = forms.BooleanField(label=_("Wrap sidebar block"), initial=True, required=False) | ||
sidebar_render = forms.ChoiceField(widget=forms.RadioSelect, choices=RENDER_CHOICES, initial='markdown', label=_('Sidebar Render Mode')) | ||
|
||
comments = forms.BooleanField(label=_("Allow comments"), initial=False, required=False) | ||
|
||
|
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
File renamed without changes.
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
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
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
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
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
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,40 @@ | ||
from base import * | ||
from django.utils.translation import ugettext as _ | ||
|
||
class Page(Node): | ||
friendly_name = _("page") | ||
|
||
@property | ||
def published(self): | ||
return self.marked | ||
|
||
def save(self, *args, **kwargs): | ||
old_options = self._original_state.get('extra', None) | ||
|
||
super(Page, self).save(*args, **kwargs) | ||
|
||
registry = settings.STATIC_PAGE_REGISTRY | ||
|
||
if old_options: | ||
registry.pop(old_options.get('path', ''), None) | ||
|
||
registry[self.extra['path']] = self.id | ||
|
||
|
||
settings.STATIC_PAGE_REGISTRY.set_value(registry) | ||
|
||
@property | ||
def headline(self): | ||
if self.published: | ||
return self.title | ||
else: | ||
return _("[Unpublished] %s") % self.title | ||
|
||
@models.permalink | ||
def get_absolute_url(self): | ||
return ('static_page', (), {'path': self.extra['path']}) | ||
|
||
class Meta(Node.Meta): | ||
proxy = True | ||
|
||
|
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
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
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
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
Oops, something went wrong.