Example #1
0
def create_tribe(request):
  form = CreateTribeForm()
  if request.method == "POST":
    form = CreateTribeForm(request.POST)
    if form.is_valid():
      try:
        tribe = form.save(commit=False)
        tribe.user = request.user
        tribe.save()
        messages.info(request, _('info_create_tribe_success') % {'tribe_name': tribe.name})
        write_log('error', 'Saved tribe: {0} with id {1}: success '.format(tribe.name, tribe.id))
        return HttpResponseRedirect('/' + request.LANGUAGE_CODE + '/overview')
      except Exception, e:  # pragma: no cover
        write_log('error', 'Save error: {0} with id {1}: {2} '.format(tribe.name, tribe.id, e))
Example #2
0
def abandon_tribe(request):
  info = []
  tribe_id = request.GET.get('tribe_id', False)
  tribe = get_object_by_id(tribe_id, 'Tribe', request.user)
  confirmed = request.GET.get('confirmed', False)

  if confirmed == 'true':
    show_confirm = 'false'
    tribe.user = None
    try:
      tribe.save()
      write_log('info', "User abandoned tribe {}".format(tribe.id), request)
      messages.info(request, _('info_abandon_tribe_success') % {'tribe_name': tribe.name})
      return HttpResponseRedirect('/' + request.LANGUAGE_CODE + '/overview')
    except:  # pragma: no cover
      pass
  else:
    show_confirm = 'true'

  return render(request, 'stoneball/abandon_tribe.html', {'info': info,
                                                          'show_confirm': show_confirm,
                                                          'tribe': tribe,
                                                          'current_page': 'overview'})