Skip to content

Commit

Permalink
Added a demo mode and command to reset demo user. Closes #139.
Browse files Browse the repository at this point in the history
  • Loading branch information
fgaudin committed May 8, 2011
1 parent 7a29110 commit f69ad6c
Show file tree
Hide file tree
Showing 16 changed files with 782 additions and 308 deletions.
4 changes: 2 additions & 2 deletions backup/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from django.core.files.storage import FileSystemStorage
from django.utils.encoding import smart_unicode
from django.utils.xmlutils import SimplerXMLGenerator
from core.context_processors import version
from core.context_processors import common
from django.db.models.fields.related import ForeignKey, OneToOneField
import os
import errno
Expand Down Expand Up @@ -130,7 +130,7 @@ def backup_objects(self):

self.xml = SimplerXMLGenerator(self.stream, settings.DEFAULT_CHARSET)
self.xml.startDocument()
self.xml.startElement("aemanager", {"version" : version()['version']})
self.xml.startElement("aemanager", {"version" : common()['version']})

for model in models:
for object in model.objects.filter(owner=self.user):
Expand Down
18 changes: 15 additions & 3 deletions bugtracker/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@
from django.core.urlresolvers import reverse
from django.db.transaction import commit_on_success
from django.db.models.aggregates import Count, Max
from core.decorators import settings_required
from core.decorators import settings_required, disabled_for_demo
from django.core.mail import mail_admins, send_mass_mail
from django.contrib.sites.models import Site
from django.conf import settings
from core.templatetags.modeltags import display_name
import datetime

@disabled_for_demo
@settings_required
def issue_list(request):
o = request.GET.get('o', 'last_comment_date')
Expand Down Expand Up @@ -56,6 +57,7 @@ def issue_list(request):
'ot': ot},
context_instance=RequestContext(request))

@disabled_for_demo
@settings_required
def message_list(request):
if request.user.is_superuser:
Expand All @@ -69,6 +71,7 @@ def message_list(request):
'issues': issues},
context_instance=RequestContext(request))

@disabled_for_demo
@settings_required
def closed_issue_list(request):
o = request.GET.get('o', 'last_comment_date')
Expand Down Expand Up @@ -107,7 +110,7 @@ def closed_issue_list(request):
'ot': ot},
context_instance=RequestContext(request))


@disabled_for_demo
@settings_required
@commit_on_success
def issue_create_or_edit(request, id=None):
Expand Down Expand Up @@ -154,6 +157,7 @@ def issue_create_or_edit(request, id=None):
'form': form},
context_instance=RequestContext(request))

@disabled_for_demo
@settings_required
@commit_on_success
def issue_close(request, id):
Expand Down Expand Up @@ -189,6 +193,7 @@ def issue_close(request, id):
'form': commentForm},
context_instance=RequestContext(request))

@disabled_for_demo
@settings_required
@commit_on_success
def issue_reopen(request, id):
Expand Down Expand Up @@ -228,6 +233,7 @@ def issue_reopen(request, id):
'form': commentForm},
context_instance=RequestContext(request))

@disabled_for_demo
@settings_required
def issue_detail(request, id):
issue = get_object_or_404(Issue,
Expand All @@ -247,6 +253,7 @@ def issue_detail(request, id):
'user_votes': user_votes},
context_instance=RequestContext(request))

@disabled_for_demo
@settings_required
def message_detail(request, id):
if request.user.is_superuser:
Expand All @@ -267,6 +274,7 @@ def message_detail(request, id):
'commentForm': commentForm},
context_instance=RequestContext(request))

@disabled_for_demo
@settings_required
@commit_on_success
def issue_delete(request, id):
Expand All @@ -289,6 +297,7 @@ def issue_delete(request, id):
'object_label': 'Issue "%s"' % (issue)},
context_instance=RequestContext(request))

@disabled_for_demo
@settings_required
@commit_on_success
def comment_create_or_edit(request, id=None, issue_id=None):
Expand Down Expand Up @@ -351,6 +360,7 @@ def comment_create_or_edit(request, id=None, issue_id=None):
'form': form},
context_instance=RequestContext(request))

@disabled_for_demo
@settings_required
@commit_on_success
def comment_message_create(request, issue_id=None):
Expand Down Expand Up @@ -398,7 +408,7 @@ def comment_message_create(request, issue_id=None):
'form': form},
context_instance=RequestContext(request))


@disabled_for_demo
@settings_required
@commit_on_success
def comment_delete(request, id):
Expand All @@ -421,6 +431,7 @@ def comment_delete(request, id):
'object_label': 'Comment "%s"' % (comment)},
context_instance=RequestContext(request))

@disabled_for_demo
@settings_required
@commit_on_success
def vote(request, issue_id):
Expand All @@ -439,6 +450,7 @@ def vote(request, issue_id):
messages.error(request, _("No votes for closed issues"))
return redirect(reverse('issue_detail', kwargs={'id': issue.id }))

@disabled_for_demo
@settings_required
@commit_on_success
def unvote(request, issue_id):
Expand Down
12 changes: 5 additions & 7 deletions core/context_processors.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
from django.conf import settings

def parent_site(request):
def common(request=None):
return {'logo_url': settings.LOGO_URL,
'parent_site_url': settings.PARENT_SITE_URL}
'parent_site_url': settings.PARENT_SITE_URL,
'version': '1.2',
'GOOGLE_API_KEY': settings.GOOGLE_API_KEY,
'demo_mode': settings.DEMO}

def version(request=None):
return {'version': '1.2'}

def google_api_key(request):
return {'GOOGLE_API_KEY': settings.GOOGLE_API_KEY}
18 changes: 16 additions & 2 deletions core/decorators.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
from django.contrib.auth import REDIRECT_FIELD_NAME
from django.http import HttpResponseRedirect
from django.http import HttpResponseRedirect, HttpResponseNotAllowed, \
HttpResponseForbidden
from django.core.urlresolvers import reverse
from django.contrib import messages
from django.utils.translation import ugettext_lazy as _
from django.utils.translation import ugettext_lazy as _, ugettext
from django.contrib.auth.decorators import login_required
from django.utils.functional import wraps
from django.utils.decorators import available_attrs
from django.conf import settings

def settings_required(view_func, redirect_field_name=REDIRECT_FIELD_NAME):
"""
Expand All @@ -18,3 +20,15 @@ def decorator(request, *args, **kwargs):
messages.info(request, _('You need to fill these informations to continue'))
return HttpResponseRedirect(reverse('settings_edit'))
return login_required(wraps(view_func, assigned=available_attrs(view_func))(decorator), redirect_field_name=redirect_field_name)

def disabled_for_demo(view_func):
"""
decorator which redirects to settings page if mandatory
values are not set, use login_required.
"""
def decorator(request, *args, **kwargs):
if not settings.DEMO:
return view_func(request, *args, **kwargs)
return HttpResponseForbidden(ugettext("You can't use this feature in demo"))

return wraps(view_func, assigned=available_attrs(view_func))(decorator)
Empty file added core/management/__init__.py
Empty file.
Empty file.
Loading

0 comments on commit f69ad6c

Please sign in to comment.