TEMPLATE_CHOICES = (
- ('default', _('Default')),
- ('sidebar', _('Default with sidebar')),
- ('none', _('None')),
+('default', _('Default')),
+('sidebar', _('Default with sidebar')),
+('none', _('None')),
)
RENDER_CHOICES = (
- ('markdown', _('Markdown')),
- ('html', _('HTML')),
- ('escape', _('Escaped'))
+('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}
+ """ % {'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
super(PageForm, self).__init__(*args, **kwargs)
- title = forms.CharField(label=_('Title'), max_length=255, widget=forms.TextInput(attrs={'class': 'longstring'}), initial='New page')
+ 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'))
+ mimetype = forms.CharField(label=_('Mime Type'), initial='text/html')
+
+ 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'))
+ 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'))
+ 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)
STATIC_PAGE_REGISTRY = Setting('STATIC_PAGE_REGISTRY', {})
-CSS_SET = SettingSet('css', 'Custom CSS', "Define some custom css you can use to override the default css.", 2000, can_preview=True)
+CSS_SET = SettingSet('css', 'Custom CSS', "Define some custom css you can use to override the default css.", 2000,
+ can_preview=True)
USE_CUSTOM_CSS = Setting('USE_CUSTOM_CSS', False, CSS_SET, dict(
-label = _("Use custom CSS"),
-help_text = _("Do you want to use custom CSS."),
-required=False))
+ label = _("Use custom CSS"),
+ help_text = _("Do you want to use custom CSS."),
+ required=False))
CUSTOM_CSS = Setting('CUSTOM_CSS', '', CSS_SET, dict(
-label = _("Custom CSS"),
-help_text = _("Your custom CSS."),
-widget=Textarea(attrs={'rows': '25'}),
-required=False))
+ label = _("Custom CSS"),
+ help_text = _("Your custom CSS."),
+ widget=Textarea(attrs={'rows': '25'}),
+ required=False))
-
-HEAD_AND_FOOT_SET = SettingSet('headandfoot', 'Header and Footer', "Adds a custom header and/or footer to your page", 2000, can_preview=True)
+HEAD_AND_FOOT_SET = SettingSet('headandfoot', 'Header and Footer', "Adds a custom header and/or footer to your page",
+ 2000, can_preview=True)
USE_CUSTOM_HEADER = Setting('USE_CUSTOM_HEADER', False, HEAD_AND_FOOT_SET, dict(
-label = _("Use custom header"),
-help_text = _("Do you want to use a custom header."),
-required=False))
+ label = _("Use custom header"),
+ help_text = _("Do you want to use a custom header."),
+ required=False))
CUSTOM_HEADER = Setting('CUSTOM_HEADER', '', HEAD_AND_FOOT_SET, dict(
-label = _("Custom Header"),
-help_text = _("Your custom header."),
-widget=Textarea(attrs={'rows': '25'}),
-required=False))
+ label = _("Custom Header"),
+ help_text = _("Your custom header."),
+ widget=Textarea(attrs={'rows': '25'}),
+ required=False))
USE_CUSTOM_FOOTER = Setting('USE_CUSTOM_FOOTER', False, HEAD_AND_FOOT_SET, dict(
-label = _("Use custom footer"),
-help_text = _("Do you want to use a custom footer."),
-required=False))
+ label = _("Use custom footer"),
+ help_text = _("Do you want to use a custom footer."),
+ required=False))
CUSTOM_FOOTER = Setting('CUSTOM_FOOTER', '', HEAD_AND_FOOT_SET, dict(
-label = _("Custom Footer"),
-help_text = _("Your custom footer."),
-widget=Textarea(attrs={'rows': '25'}),
-required=False))
+ label = _("Custom Footer"),
+ help_text = _("Your custom footer."),
+ widget=Textarea(attrs={'rows': '25'}),
+ required=False))
CUSTOM_FOOTER_MODE_CHOICES = (
- ('replace', _('Replace default footer')),
- ('above', _('Above default footer')),
- ('below', _('Below default footer')),
+('replace', _('Replace default footer')),
+('above', _('Above default footer')),
+('below', _('Below default footer')),
)
CUSTOM_FOOTER_MODE = Setting('CUSTOM_FOOTER_MODE', 'replace', HEAD_AND_FOOT_SET, dict(
-label = _("Custom Footer Mode"),
-help_text = _("How your custom footer will appear."),
-widget=RadioSelect,
-choices=CUSTOM_FOOTER_MODE_CHOICES,
-required=False))
\ No newline at end of file
+ label = _("Custom Footer Mode"),
+ help_text = _("How your custom footer will appear."),
+ widget=RadioSelect,
+ choices=CUSTOM_FOOTER_MODE_CHOICES,
+ required=False))
+
+HEAD_SET = SettingSet('head', '<head>', "Define some custom elements to include in the head section of every page.",
+ 2000, can_preview=True)
+
+USE_CUSTOM_HEAD = Setting('USE_CUSTOM_HEAD', False, HEAD_SET, dict(
+ label = _("Use custom Head elements"),
+ help_text = _("Do you want to use custom head elements."),
+ required=False))
+
+CUSTOM_HEAD = Setting('CUSTOM_HEAD', '', HEAD_SET, dict(
+ label = _("Custom Head"),
+ help_text = _("Your custom Head elements."),
+ widget=Textarea(attrs={'rows': '25'}),
+ required=False))
\ No newline at end of file
});
</script>
{% endif %}
+ {% if settings.USE_CUSTOM_HEAD|or_preview:request %}
+ {{ settings.CUSTOM_HEAD|or_preview:request|safe }}
+ {% endif %}
{% block forejs %}{% endblock %}
<link rel="search" type="application/opensearchdescription+xml" href="{% url opensearch %}" title="{{ settings.APP_SHORT_NAME }} Search" />
</head>
<a href="{% url admin_set allsets.headandfoot.name %}">{{ allsets.headandfoot.title }}</a>
{% if "headandfoot" in unsaved %}<img width="12" height="12" src="{{ settings.ADMIN_MEDIA_PREFIX }}img/admin/icon_alert.gif" alt="{% trans "Unsaved changes" %}" />{% endif %}
</li>
+ <li>
+ <a href="{% url admin_set allsets.head.name %}">{{ allsets.head.title }}</a>
+ {% if "head" in unsaved %}<img width="12" height="12" src="{{ settings.ADMIN_MEDIA_PREFIX }}img/admin/icon_alert.gif" alt="{% trans "Unsaved changes" %}" />{% endif %}
+ </li>
</ul>
</div>
<div id="other-sets-menu" class="module">
context['othersets'] = sorted(
[s for s in Setting.sets.values() if not s.name in
('basic', 'users', 'email', 'paths', 'extkeys', 'repgain', 'minrep', 'voting', 'badges', 'about', 'faq', 'sidebar',
- 'form', 'moderation', 'css', 'headandfoot')]
+ 'form', 'moderation', 'css', 'headandfoot', 'head')]
, lambda s1, s2: s1.weight - s2.weight)
unsaved = request.session.get('previewing_settings', {})
context['unsaved'] = set([getattr(settings, s).set.name for s in unsaved.keys() if hasattr(settings, s)])
-
return render_to_response(template, context, context_instance=RequestContext(request))
else:
return res
@admin_page
def dashboard(request):
return ('osqaadmin/dashboard.html', {
- 'settings_pack': unicode(settings.SETTINGS_PACK),
- 'statistics': get_statistics(),
- 'recent_activity': get_recent_activity(),
- 'flagged_posts': get_flagged_posts(),
+ 'settings_pack': unicode(settings.SETTINGS_PACK),
+ 'statistics': get_statistics(),
+ 'recent_activity': get_recent_activity(),
+ 'flagged_posts': get_flagged_posts(),
})
@super_user_required
last_month = today - timedelta(days=30)
last_month_questions = Question.objects.filter_state(deleted=False).filter(added_at__gt=last_month
- ).order_by('added_at').values_list('added_at', flat=True)
+ ).order_by('added_at').values_list(
+ 'added_at', flat=True)
last_month_n_questions = Question.objects.filter_state(deleted=False).filter(added_at__lt=last_month).count()
qgraph_data = simplejson.dumps([
- (time.mktime(d.timetuple()) * 1000, i + last_month_n_questions)
- for i, d in enumerate(last_month_questions)
+ (time.mktime(d.timetuple()) * 1000, i + last_month_n_questions)
+ for i, d in enumerate(last_month_questions)
])
last_month_users = User.objects.filter(date_joined__gt=last_month
- ).order_by('date_joined').values_list('date_joined', flat=True)
+ ).order_by('date_joined').values_list('date_joined', flat=True)
last_month_n_users = User.objects.filter(date_joined__lt=last_month).count()
ugraph_data = simplejson.dumps([
- (time.mktime(d.timetuple()) * 1000, i + last_month_n_users)
- for i, d in enumerate(last_month_users)
+ (time.mktime(d.timetuple()) * 1000, i + last_month_n_users)
+ for i, d in enumerate(last_month_users)
])
return 'osqaadmin/statistics.html', {
- 'graphs': [
+ 'graphs': [
{
- 'id': 'questions_graph',
- 'caption': _("Questions Graph"),
- 'data': qgraph_data
- },{
- 'id': 'userss_graph',
- 'caption': _("Users Graph"),
- 'data': ugraph_data
+ 'id': 'questions_graph',
+ 'caption': _("Questions Graph"),
+ 'data': qgraph_data
+ }, {
+ 'id': 'userss_graph',
+ 'caption': _("Users Graph"),
+ 'data': ugraph_data
}
- ]
+ ]
}
form = SettingsSetForm(set, unsaved=current_preview)
return 'osqaadmin/set.html', {
- 'form': form,
- 'markdown': set.markdown,
+ 'form': form,
+ 'markdown': set.markdown,
}
@super_user_required
def get_statistics():
return {
- 'total_users': User.objects.all().count(),
- 'users_last_24': User.objects.filter(date_joined__gt=(datetime.now() - timedelta(days=1))).count(),
- 'total_questions': Question.objects.filter_state(deleted=False).count(),
- 'questions_last_24': Question.objects.filter_state(deleted=False).filter(added_at__gt=(datetime.now() - timedelta(days=1))).count(),
- 'total_answers': Answer.objects.filter_state(deleted=False).count(),
- 'answers_last_24': Answer.objects.filter_state(deleted=False).filter(added_at__gt=(datetime.now() - timedelta(days=1))).count(),
+ 'total_users': User.objects.all().count(),
+ 'users_last_24': User.objects.filter(date_joined__gt=(datetime.now() - timedelta(days=1))).count(),
+ 'total_questions': Question.objects.filter_state(deleted=False).count(),
+ 'questions_last_24': Question.objects.filter_state(deleted=False).filter(
+ added_at__gt=(datetime.now() - timedelta(days=1))).count(),
+ 'total_answers': Answer.objects.filter_state(deleted=False).count(),
+ 'answers_last_24': Answer.objects.filter_state(deleted=False).filter(
+ added_at__gt=(datetime.now() - timedelta(days=1))).count(),
}
@super_user_required
def go_bootstrap(request):
- #todo: this is the quick and dirty way of implementing a bootstrap mode
+#todo: this is the quick and dirty way of implementing a bootstrap mode
try:
from forum_modules.default_badges import settings as dbsets
dbsets.POPULAR_QUESTION_VIEWS.set_value(100)
if form.is_valid():
settings.MAINTAINANCE_MODE.set_value({
- 'allow_ips': form.cleaned_data['ips'],
- 'message': form.cleaned_data['message']})
+ 'allow_ips': form.cleaned_data['ips'],
+ 'message': form.cleaned_data['message']})
if 'close' in request.POST:
message = _('Maintenance mode enabled')
form = MaintenanceModeForm(initial={'ips': request.META['REMOTE_ADDR'],
'message': _('Currently down for maintenance. We\'ll be back soon')})
- return ('osqaadmin/maintenance.html', {'form': form, 'in_maintenance': settings.MAINTAINANCE_MODE.value is not None})
+ return ('osqaadmin/maintenance.html', {'form': form, 'in_maintenance': settings.MAINTAINANCE_MODE.value is not None
+ })
@admin_page
def flagged_posts(request):
return ('osqaadmin/flagged_posts.html', {
- 'flagged_posts': get_flagged_posts(),
+ 'flagged_posts': get_flagged_posts(),
})
@admin_page
pages = Page.objects.all()
return ('osqaadmin/static_pages.html', {
- 'pages': pages,
+ 'pages': pages,
})
@admin_page
if form.is_valid():
if form.has_changed():
if not page:
- page = NewPageAction(user=request.user, ip=request.META['REMOTE_ADDR']).save(data=form.cleaned_data).node
+ page = NewPageAction(user=request.user, ip=request.META['REMOTE_ADDR']).save(data=form.cleaned_data
+ ).node
else:
- EditPageAction(user=request.user, node=page, ip=request.META['REMOTE_ADDR']).save(data=form.cleaned_data)
+ EditPageAction(user=request.user, node=page, ip=request.META['REMOTE_ADDR']).save(
+ data=form.cleaned_data)
if ('publish' in request.POST) and (not page.published):
PublishAction(user=request.user, node=page, ip=request.META['REMOTE_ADDR']).save()
published = False
return ('osqaadmin/edit_page.html', {
- 'page': page,
- 'form': form,
- 'published': published
+ 'page': page,
+ 'form': form,
+ 'published': published
})
return HttpResponse(or_preview(settings.CUSTOM_CSS, request), mimetype="text/css")
def static(request, title, content):
- return render_to_response('static.html', {'content' : content, 'title': title}, context_instance=RequestContext(request))
+ return render_to_response('static.html', {'content' : content, 'title': title},
+ context_instance=RequestContext(request))
def media(request, skin, path):
- return serve(request, "%s/media/%s" % (skin, path),
- document_root=os.path.join(os.path.dirname(os.path.dirname(__file__)),'skins').replace('\\','/'))
+ return serve(request, "%s/media/%s" % (skin, path),
+ document_root=os.path.join(os.path.dirname(os.path.dirname(__file__)), 'skins').replace('\\', '/'))
def markdown_help(request):
return render_to_response('markdown_help.html', context_instance=RequestContext(request))
-def opensearch(request):
+def opensearch(request):
return render_to_response('opensearch.html', {'settings' : settings}, context_instance=RequestContext(request))
-
+
def feedback(request):
if request.method == "POST":
context = {'user': request.user}
if not request.user.is_authenticated:
- context['email'] = form.cleaned_data.get('email',None)
+ context['email'] = form.cleaned_data.get('email', None)
context['message'] = form.cleaned_data['message']
- context['name'] = form.cleaned_data.get('name',None)
+ context['name'] = form.cleaned_data.get('name', None)
context['ip'] = request.META['REMOTE_ADDR']
recipients = User.objects.filter(is_superuser=True)
send_template_email(recipients, "notifications/feedback.html", context)
-
+
msg = _('Thanks for the feedback!')
request.user.message_set.create(message=msg)
return HttpResponseRedirect(get_next_url(request))
form = FeedbackForm(initial={'next':get_next_url(request)})
return render_to_response('feedback.html', {'form': form}, context_instance=RequestContext(request))
+
feedback.CANCEL_MESSAGE=_('We look forward to hearing your feedback! Please, give it next time :)')
def privacy(request):
def logout(request):
return render_to_response('logout.html', {
- 'next' : get_next_url(request),
+ 'next' : get_next_url(request),
}, context_instance=RequestContext(request))
def badges(request):
badges = [b.ondb for b in sorted(BadgesMeta.by_id.values(), lambda b1, b2: cmp(b1.name, b2.name))]
-
+
if request.user.is_authenticated():
my_badges = Award.objects.filter(user=request.user).values('badge_id').distinct()
else:
my_badges = []
return render_to_response('badges.html', {
- 'badges' : badges,
- 'mybadges' : my_badges,
+ 'badges' : badges,
+ 'mybadges' : my_badges,
}, context_instance=RequestContext(request))
def badge(request, id, slug):
badge = Badge.objects.get(id=id)
awards = list(Award.objects.filter(badge=badge).order_by('user', 'awarded_at'))
award_count = len(awards)
-
+
awards = sorted([dict(count=len(list(g)), user=k) for k, g in groupby(awards, lambda a: a.user)],
lambda c1, c2: c2['count'] - c1['count'])
return render_to_response('badge.html', {
- 'award_count': award_count,
- 'awards' : awards,
- 'badge' : badge,
+ 'award_count': award_count,
+ 'awards' : awards,
+ 'badge' : badge,
}, context_instance=RequestContext(request))
def page(request, path):
try:
page = Page.objects.get(id=settings.STATIC_PAGE_REGISTRY[path])
- if not page.published or request.user.is_superuser:
+ if (not page.published) and (not request.user.is_superuser):
raise Http404
except:
raise Http404
sidebar = mark_safe(sidebar)
else:
- return HttpResponse(page.body)
+ return HttpResponse(page.body, mimetype=page.extra.get('mimetype', 'text/html'))
render = page.extra.get('render', 'markdown')
body = page.body
return render_to_response('page.html', {
- 'page' : page,
- 'body' : body,
- 'sidebar': sidebar,
- 'base': base,
- }, context_instance=RequestContext(request))
+ 'page' : page,
+ 'body' : body,
+ 'sidebar': sidebar,
+ 'base': base,
+ }, context_instance=RequestContext(request))