Ejemplo n.º 1
0
def edit(request, society_name, worker_id):
    """
    Former utilised view function.
    """
    society = get_object_or_404(Society, shortname=society_name)
    if not user_allowed_society(request.user, society):
        return render(request, "errors/unauthorized.jinja")

    worker = get_object_or_404(Worker, id=worker_id)
    worker_form = WorkerEditForm(request.POST or None, instance=worker)

    if worker_form.is_valid():
        worker_form.save()
        return redirect(index, society_name=society.shortname)

    return render(request, "workers/edit.jinja", {'form': worker_form})
Ejemplo n.º 2
0
def index(request, society_name):
    society = get_object_or_404(Society, shortname=society_name)
    if not user_allowed_society(request.user, society):
        return render(request, "errors/unauthorized.jinja")

    workers = Worker.objects.filter(society=society).order_by("norlonn_number")
    inactive_workers = workers.filter(active=False)
    workers = workers.filter(active=True)
    return render(
        request, "workers/index.jinja", {
            'workers': workers,
            'cur_page': 'workers',
            'form': WorkerForm(),
            'post_url': 'add/',
            'old_workers': inactive_workers,
            'society': society
        })
Ejemplo n.º 3
0
def add(request, society_name):
    society = get_object_or_404(Society, shortname=society_name)
    if not user_allowed_society(request.user, society):
        return render(request, "errors/unauthorized.jinja")

    worker = WorkerForm(request.POST)

    if worker.is_valid():
        worker_model = worker.save(commit=False)
        worker_model.society = society
        worker_model.save()
        return redirect(index, society_name=society_name)

    workers = Worker.objects.filter(society=society)
    return render(request, "workers/index.jinja", {
        'workers': workers,
        'cur_page': 'workers',
        'form': worker,
        'post_url': ''
    })
Ejemplo n.º 4
0
 def has_permission(self):
     return self.request.user.has_perm('society.delete_worker') \
            and user_allowed_society(self.request.user, self.get_object().societies)
Ejemplo n.º 5
0
 def has_permission(self):
     # FIXME: Creates an overhead of two extra queries per viewing :(
     return user_allowed_society(self.request.user,
                                 self.get_object().societies)
Ejemplo n.º 6
0
 def has_permission(self):
     return user_allowed_society(self.request.user,
                                 self.get_object().society)