Esempio n. 1
0
    def get_redirect_url(self, *args, **kwargs):
        """Supply the redirect URL in case of successful approval.
        * Creates a new Community object and copy fields, values from RequestCommunity object
        * Sets the requestor as the community admin
        * Sets the RequestCommunity object's is_approved field to True.
        """
        community_request = get_object_or_404(
            RequestCommunity, slug=self.kwargs['slug'])
        new_community = Community()
        community_request_fields = community_request.get_fields()
        self.order_community_request = community_request.order
        self.slug_communtiy_request = community_request.slug
        new_community_fields = [
            field.name for field in new_community._meta.fields]
        fields = [(field_name, field_value) for field_name, field_value in community_request_fields
                  if field_name in new_community_fields]
        for field_name, field_value in fields:
            setattr(new_community, field_name, field_value)

        self.systersuser = community_request.user
        new_community.admin = self.systersuser
        self.admin = get_object_or_404(SystersUser, user=self.request.user)
        status, message, level = self.process_request()
        if status == OK:
            new_community.save()
            community_request.is_approved = True
            community_request.approved_by = self.admin
            community_request.save()
            messages.add_message(self.request, level, message)
            return reverse("view_community_landing", kwargs={"slug": new_community.slug})
        else:
            messages.add_message(self.request, level, message)
            return reverse("edit_community_request", kwargs={"slug": community_request.slug})
Esempio n. 2
0
 def setUp(self):
     self.client = Client()
     user = CustomUser(first_name="Tester",
                       last_name="1",
                       email="*****@*****.**")
     user.save()
     community = Community(author=user,
                           name="Test Community",
                           created_on=datetime.datetime.now(),
                           description="Hi Test")
     community.save()
     self.community = community
Esempio n. 3
0
 def create(self, request):
     attrs = self.flatten_dict(request.POST)
     try:
         title = attrs['title']
         slug = slugify(title)
     except KeyError:
         return "You must write the mandatory arguments"
     
     excerpt = attrs['excerpt']
     description = attrs['description']
     comm = Community(title=title, slug=slug,
                      excerpt=excerpt,
                      description=description)
     comm.save()
     return comm
Esempio n. 4
0
    def get_redirect_url(self, *args, **kwargs):
        """Supply the redirect URL in case of successful approval.
        * Creates a new Community object and copy fields, values from RequestCommunity object
        * Sets the requestor as the community admin
        * Sets the RequestCommunity object's is_approved field to True.
        """
        community_request = get_object_or_404(RequestCommunity,
                                              slug=self.kwargs['slug'])
        new_community = Community()
        community_request_fields = community_request.get_fields()
        self.order_community_request = community_request.order
        self.slug_communtiy_request = community_request.slug
        new_community_fields = [
            field.name for field in new_community._meta.fields
        ]
        fields = [(field_name, field_value)
                  for field_name, field_value in community_request_fields
                  if field_name in new_community_fields]
        for field_name, field_value in fields:
            setattr(new_community, field_name, field_value)

        self.systersuser = community_request.user
        new_community.admin = self.systersuser
        self.admin = get_object_or_404(SystersUser, user=self.request.user)
        status, message, level = self.process_request()
        if status == OK:
            new_community.save()
            community_request.is_approved = True
            community_request.approved_by = self.admin
            community_request.save()
            messages.add_message(self.request, level, message)
            return reverse("view_community_landing",
                           kwargs={"slug": new_community.slug})
        else:
            messages.add_message(self.request, level, message)
            return reverse("edit_community_request",
                           kwargs={"slug": community_request.slug})
Esempio n. 5
0
    def to_object(self):
        if hasattr(self, 'object') and self.object:
            return self.object

        d = self.object_dict
        c = Community()
        for attr in ['name', 'creator', 'description', 'geometry']:
            setattr(c, attr, d[attr])
        if 'population' in d:
            c.population = d['population']
        c.save()

        # m2m relationships
        c.tags.add(*d['tags'])
        c.save()

        self.object = c
        return c
Esempio n. 6
0
def edit_community(request, id='', *args, **kwargs):
    community = get_object_or_404(Community, pk=id) if id else Community()

    geojson = create_geojson([community], convert=False)
    if geojson and geojson.get('features'):
        geojson['features'][0]['properties']['userCanEdit'] = True
    geojson = to_json(geojson)

    def on_get(request, form_community):
        return CommunityForm(instance=community)

    def on_after_save(request, obj):
        versionate(request.user, obj)
        url = reverse('view_community', args=(obj.id, ))
        return {'redirect': url}

    return {
        'on_get': on_get,
        'on_after_save': on_after_save,
        'community': community,
        'geojson': geojson
    }
Esempio n. 7
0
    def to_object(self):
        if hasattr(self, 'object') and self.object:
            return self.object

        d = self.object_dict
        c = Community()
        for attr in ['name', 'creator', 'description', 'geometry']:
            setattr(c, attr, d[attr])
        if 'population' in d:
            c.population = d['population']
        c.save()
        
        # m2m relationships
        c.tags.add(*d['tags'])
        c.save()

        self.object = c
        return c