Esempio n. 1
0
    def form_valid(self, form):
        """Checks for permission issues before validating the form as normal.
        """
        # Add author and founder information to the object.
        entity = form.save(commit=False)
        entity.owner = self.request.user
        entity.founder = self.request.user

        # If the user has permission to submit the entity, save it!
        if not has_submit_perms(self.request.user, entity):
            return self.error_page

        # Create and save an initial version.
        version = utility.create_entity_version(entity, self.request.user, first=True)

        entity.save()
        version.entity = entity
        version.save()

        # Now that the version has an id, re-save the entity.
        entity.active_version = version
        entity.save()

        # Set success_url to be based on the new entity and redirect.
        self.success_url = reverse("build_world:entity", kwargs={"etype": entity.etype, "pk": entity.id})
        return HttpResponseRedirect(self.success_url)
Esempio n. 2
0
 def get_context_data(self, **kwargs):
     context = super(EntityDetailView, self).get_context_data(**kwargs)
     # Query for all people's relations to the current Entity.
     entity = kwargs["object"]
     relations = Relation.objects.filter(entity=entity)
     context["relations"] = relations
     context["user_can_promote"] = has_promote_perms(self.request.user, entity)
     context["user_can_edit"] = has_edit_perms(self.request.user, entity)
     context["user_can_submit"] = has_submit_perms(self.request.user, entity)
     return context