Exemple #1
0
class Idea(Item):
    name = models.CharField(max_length=120,
                            default='Can i haz cheezburger, pls?')
    description = RichTextField(verbose_name='Description', blank=True)
    point = map_fields.PointField(blank=True)
    point_label = models.CharField(
        blank=True,
        default='',
        max_length=255,
        verbose_name='Label of the ideas location',
        help_text='This could be an address or the name of a landmark.',
    )
    comments = GenericRelation(Comment,
                               related_query_name='question',
                               object_id_field='object_pk')

    ratings = GenericRelation(Rating,
                              related_query_name='question',
                              object_id_field='object_pk')
    category = CategoryField()

    objects = IdeaQuerySet.as_manager()

    def get_absolute_url(self):
        return '/idea/%s/' % self.pk
Exemple #2
0
class MapIdea(idea_models.Idea):
    point = map_fields.PointField(
        verbose_name=_('Where can your idea be located on a map?'),
        help_text=_('Click inside marked area to set a marker. '
                    'Drag and drop marker to change place.'))

    objects = idea_models.IdeaQuerySet.as_manager()

    def get_absolute_url(self):
        from django.core.urlresolvers import reverse
        return reverse('map-idea-detail', args=[str(self.slug)])
Exemple #3
0
class AbstractMapIdea(idea_models.AbstractIdea):
    point = map_fields.PointField(
        verbose_name=_('Where can your idea be located on a map?'),
        help_text=_('Click inside the marked area '
                    'or type in an address to set the marker. A set '
                    'marker can be dragged when pressed.'))

    point_label = models.CharField(
        blank=True,
        default='',
        max_length=255,
        verbose_name=_('Label of the ideas location'),
        help_text=_('This could be an address or the name of a landmark.'),
    )

    class Meta:
        abstract = True
Exemple #4
0
class MapIdea(module_models.Item):
    slug = AutoSlugField(populate_from='name', unique=True)
    name = models.CharField(max_length=120)
    description = RichTextField()
    image = fields.ConfiguredImageField(
        'idea_image',
        upload_to='ideas/images',
        blank=True,
    )
    ratings = GenericRelation(rating_models.Rating,
                              related_query_name='idea',
                              object_id_field='object_pk')
    comments = GenericRelation(comment_models.Comment,
                               related_query_name='idea',
                               object_id_field='object_pk')
    category = CategoryField()

    point = map_fields.PointField(
        verbose_name=_('Where can your idea be located on a map?'),
        help_text=_('Click inside the marked area '
                    'or type in an address to set the marker. A set '
                    'marker can be dragged when pressed.'))

    point_label = models.CharField(
        blank=True,
        default='',
        max_length=255,
        verbose_name=_('Label of the ideas location'),
        help_text=_('This could be an address or the name of a landmark.'),
    )

    objects = IdeaQuerySet.as_manager()

    def __str__(self):
        return self.name

    def save(self, *args, **kwargs):
        self.description = transforms.clean_html_field(self.description)
        super().save(*args, **kwargs)

    def get_absolute_url(self):
        return reverse('mapidea-detail', args=[str(self.slug)])
Exemple #5
0
class MapTopic(module_models.Item):
    item_ptr = models.OneToOneField(to=module_models.Item,
                                    parent_link=True,
                                    related_name='%(app_label)s_%(class)s',
                                    on_delete=models.CASCADE)
    slug = AutoSlugField(populate_from='name', unique=True)
    name = models.CharField(max_length=120, verbose_name=_('Title'))
    description = RichTextUploadingField(config_name='image-editor',
                                         verbose_name=_('Description'))
    image = ConfiguredImageField(
        'idea_image',
        upload_to='ideas/images',
        blank=True,
    )
    ratings = GenericRelation(rating_models.Rating,
                              related_query_name='maptopic',
                              object_id_field='object_pk')
    comments = GenericRelation(comment_models.Comment,
                               related_query_name='maptopic',
                               object_id_field='object_pk')
    category = CategoryField()
    labels = models.ManyToManyField(labels_models.Label,
                                    verbose_name=_('Labels'),
                                    related_name=('%(app_label)s_'
                                                  '%(class)s_label'))
    point = map_fields.PointField(
        verbose_name=_('Where can your idea be located on a map?'),
        help_text=_('Click inside the marked area '
                    'or type in an address to set the marker. A set '
                    'marker can be dragged when pressed.'))

    point_label = models.CharField(
        blank=True,
        default='',
        max_length=255,
        verbose_name=_('Label of the ideas location'),
        help_text=_('This could be an address or the name of a landmark.'),
    )

    objects = MapTopicQuerySet.as_manager()

    class Meta:
        ordering = ['-created']
        verbose_name = 'maptopic'

    @property
    def reference_number(self):
        return '{:d}-{:05d}'.format(self.created.year, self.pk)

    def __str__(self):
        return self.name

    def save(self, *args, **kwargs):
        self.description = transforms.clean_html_field(self.description,
                                                       'image-editor')
        super().save(*args, **kwargs)

    def get_absolute_url(self):
        return reverse('meinberlin_maptopicprio:maptopic-detail',
                       kwargs=dict(pk='{:05d}'.format(self.pk),
                                   year=self.created.year))
Exemple #6
0
class Plan(UserGeneratedContentModel):

    PARTICIPATION_YES = 0
    PARTICIPATION_NO = 1
    PARTICIPATION_UNDECIDED = 2
    PARTICIPATION_CHOICES = (
        (PARTICIPATION_YES, _('with')),
        (PARTICIPATION_NO, _('without')),
        (PARTICIPATION_UNDECIDED, _('undecided')),
    )

    STATUS_ONGOING = 0
    STATUS_DONE = 1

    STATUS_CHOICES = ((STATUS_ONGOING, _('running')), (STATUS_DONE, _('done')))

    title = models.CharField(max_length=120, verbose_name=_('Title'))
    organisation = models.ForeignKey(settings.A4_ORGANISATIONS_MODEL,
                                     on_delete=models.CASCADE,
                                     verbose_name=_('Organisation'))
    projects = models.ManyToManyField(project_models.Project,
                                      related_name='plans',
                                      blank=True)
    group = models.ForeignKey(Group,
                              on_delete=models.SET_NULL,
                              blank=True,
                              null=True)
    point = map_fields.PointField(
        blank=True,
        verbose_name=_('Where can the plan be located on a map?'),
        help_text=_('Click inside the marked area '
                    'or type in an address to set the marker. A set '
                    'marker can be dragged when pressed.'))
    point_label = models.CharField(
        blank=True,
        default='',
        max_length=255,
        verbose_name=_('Label of the location'),
        help_text=_('The label of the location is '
                    'displayed in the detail view of the plan'),
    )
    district = models.ForeignKey(
        AdministrativeDistrict,
        verbose_name=_('District'),
        help_text=_('Please enter the district, in which your project is '
                    'located, or whether your project is citywide.'),
        null=True,
        blank=True,
        on_delete=models.CASCADE)
    contact = models.TextField(max_length=1000, verbose_name=_('Contact'))
    cost = models.CharField(blank=True,
                            null=True,
                            max_length=255,
                            verbose_name=_('Cost'))
    description = RichTextField(verbose_name=_('Description'))
    description_image = ConfiguredImageField(
        'plan_image',
        verbose_name=_('Add image'),
        upload_to='plan/description_image',
        blank=True,
        help_prefix=_('Visualize your plan.'),
    )
    description_image_copyright = models.CharField(
        verbose_name=_('Image copyright'), blank=True, max_length=120)
    topics = TopicField(verbose_name=_('Topics'),
                        help_text=_('Add topics to your project.'))
    status = models.SmallIntegerField(choices=STATUS_CHOICES,
                                      verbose_name=_('Status'))
    participation = models.SmallIntegerField(choices=PARTICIPATION_CHOICES,
                                             verbose_name=_('Participation'))

    class Meta:
        ordering = ['-created']

    @property
    def reference_number(self):
        return '{:d}-{:05d}'.format(self.created.year, self.pk)

    @property
    def administrative_district(self):
        return self.district

    @property
    def topic_names(self):
        if hasattr(settings, 'A4_PROJECT_TOPICS'):
            choices = dict(settings.A4_PROJECT_TOPICS)
            return [choices[topic] for topic in self.topics]
        return []

    @cached_property
    def published_projects(self):
        return self.projects.filter(is_draft=False,
                                    is_public=True,
                                    is_archived=False)

    @cached_property
    def participation_string(self):
        project_list = self.published_projects.values_list('id', flat=True)
        phases_in_plan = Phase.objects\
            .select_related('module__project')\
            .filter(module__project_id__in=project_list)\
            .order_by('-start_date')

        if phases_in_plan.active_phases():
            return _('running')

        future_phases_with_start_date = phases_in_plan.future_phases()\
            .exclude(start_date__isnull=True)

        if future_phases_with_start_date:
            future_phase = future_phases_with_start_date.first()
            return _('starts at {}')\
                .format(future_phase.start_date.strftime('%d.%m.%Y'))

    def __str__(self):
        return self.title

    def get_absolute_url(self):
        return reverse('meinberlin_plans:plan-detail',
                       kwargs=dict(pk='{:05d}'.format(self.pk),
                                   year=self.created.year))

    def save(self, *args, **kwargs):
        self.description = transforms.clean_html_field(self.description)
        super().save(*args, **kwargs)

    def _get_group(self, user, organisation):
        user_groups = user.groups.all()
        org_groups = organisation.groups.all()
        shared_groups = user_groups & org_groups
        return shared_groups.distinct().first()

    def is_group_member(self, user):
        if self.group:
            return user.groups.filter(id=self.group.id).exists()
        return False