Exemplo n.º 1
0
def site_create(request):
    if not request.user.has_perm('tracker.add_site'):
        messages.error(request, 'Unfortunately, you do not have access to create a new site.')
        return redirect('sites')

    new_user = not Visit.objects.filter(site_user__site__users=request.user).exists()

    if request.method == 'POST':
        form = SiteForm(request.POST)

        if form.is_valid():
            site = form.save()

            site.identifier = Site.generate_identifier()
            site.secret_key = Site.generate_identifier()
            site.users.add(request.user)
            site.save()

            if new_user:
                return redirect(reverse('site', args=[site.identifier]))

            messages.info(request, "'%s' was created." % (site.name))
            return redirect('sites')
    else:
        form = SiteForm()

    return {
        'TEMPLATE': 'www/site_update.html',
        'form': form,
        'new_user': new_user,
    }
Exemplo n.º 2
0
def site_update(request, site_identifier):
    if not request.user.has_perm('tracker.change_site'):
        messages.error(request, 'Unfortunately, you do not have access to edit the site.')
        return redirect('sites')

    site = Site.get_by_site_identifier(site_identifier)
    form = SiteForm(instance=site)

    if request.method == 'POST':
        form = SiteForm(request.POST, instance=site)

        if form.is_valid():
            site = form.save()
            messages.info(request, "<em>%s</em> was updated." % (site.name))
            return redirect('sites')

    return {
        'TEMPLATE': 'www/site_update.html',
        'form': form,
    }