Beispiel #1
0
 def test_non_ascii_charts_in_value_descrizione(self):
     props = {
         'Descrizione':
         u"Area dedicata ad attività atletiche a corpo libero con il supporto di sbarre, "
         u"parallele e anelli. Quest'area NON è oggetto di co-progettazione"
     }
     expected_title = u"Descrizione Area dedicata ad attività atletiche a corpo libero con il supporto di " \
                      u"sbarre, parallele e anelli. Quest'area NON è oggetto di co-progettazione"
     output = get_link_title(properties=props)
     self.assertEqual(expected_title, output)
Beispiel #2
0
def make_event(class_name, instance, action):
    """Make OnToMap event."""
    domain = Site.objects.get_current().domain
    uwum_account = SocialAccount.objects.get(provider='uwum',
                                             user=get_request().user)

    activity_objects = []
    visibility_details = []
    details = {}
    if action == 'removed' or instance.status != 'active':
        hidden = True
    else:
        hidden = False

    # ###########################
    # ADDITIONS FOR PROJECT
    # ###########################

    if class_name == 'Project':
        external_url = '%s/api/projects/%s/' % (domain, instance.id)
        if instance.isprivate:
            hidden = True

        activity_objects.append({
            'type': 'Feature',
            'geometry': None,
            'properties': {
                'hasType': 'Project',
                'name': instance.name,
                'external_url': make_cm_url(external_url),
                'additionalProperties': {
                    'description': instance.description
                }
            }
        })

        visibility_details.append({
            'external_url': make_cm_url(external_url),
            'hidden': hidden
        })

        details['project_id'] = instance.id

    # ###########################
    # ADDITIONS FOR CATEGORY
    # ###########################

    if class_name == 'Category':
        external_url = '%s/api/projects/%s/categories/%s/' % (
            domain, instance.project.id, instance.id)
        if instance.project.isprivate:
            hidden = True

        activity_objects.append({
            'type': 'Feature',
            'geometry': None,
            'properties': {
                'hasType': 'Category',
                'name': instance.name,
                'external_url': make_cm_url(external_url),
                'additionalProperties': {
                    'description': instance.description
                }
            }
        })

        visibility_details.append({
            'external_url': make_cm_url(external_url),
            'hidden': hidden
        })

        details['project_id'] = instance.project.id
        details['category_id'] = instance.id

    # ###########################
    # ADDITIONS FOR CONTRIBUTION
    # ###########################

    if class_name == 'Observation':
        external_url = '%s/api/projects/%s/contributions/%s/' % (
            domain, instance.project.id, instance.id)
        if instance.project.isprivate:
            hidden = True

        geometry = literal_eval(instance.location.geometry.geojson)
        additional_properties = literal_eval(json.dumps(instance.properties))
        properties = {
            'hasType': 'Contribution',
            'external_url': make_cm_url(external_url),
            'additionalProperties': additional_properties,
            'name': get_link_title(properties=instance.properties)
        }

        activity_objects.append({
            'type': 'Feature',
            'geometry': geometry,
            'properties': properties
        })

        visibility_details.append({
            'external_url': make_cm_url(external_url),
            'hidden': hidden
        })

        details['project_id'] = instance.project.id
        details['category_id'] = instance.category.id

    # ###########################
    # ADDITIONS FOR COMMENT
    # ###########################

    if class_name == 'Comment':
        contribution = instance.commentto
        parent_comment = instance.respondsto or None

        external_url = '%s/api/projects/%s/contributions/%s/comments' % (
            domain, contribution.project.id, contribution.id)
        if contribution.project.isprivate:
            hidden = True

        activity_objects.append({
            'type': 'Feature',
            'geometry': None,
            'properties': {
                'hasType': 'Comment',
                'external_url': make_cm_url(external_url),
                'additionalProperties': {
                    'text':
                    instance.text,
                    'responds_to':
                    (None if not parent_comment else parent_comment.id)
                }
            }
        })

        visibility_details.append({
            'external_url': make_cm_url(external_url),
            'hidden': hidden
        })

        details['project_id'] = contribution.project.id
        details['category_id'] = contribution.category.id
        details['contribution_id'] = contribution.id

    # ###########################
    # ADDITIONS FOR MEDIA FILE
    # ###########################

    if class_name == 'MediaFile':
        contribution = instance.contribution

        external_url = '%s/api/projects/%s/contributions/%s/media/%s' % (
            domain, contribution.project.id, contribution.id, instance.id)
        if contribution.project.isprivate:
            hidden = True

        if hasattr(instance, 'audio'):
            url = domain + instance.audio.url
        elif hasattr(instance, 'image'):
            url = domain + instance.image.url
        elif hasattr(instance, 'video'):
            url = instance.youtube_link
        else:
            url = domain

        activity_objects.append({
            'type': 'Feature',
            'geometry': None,
            'properties': {
                'hasType': 'MediaFile',
                'name': instance.name,
                'external_url': make_cm_url(external_url),
                'additionalProperties': {
                    'description': instance.description,
                    'url': url
                }
            }
        })

        visibility_details.append({
            'external_url': make_cm_url(external_url),
            'hidden': hidden
        })

        details['project_id'] = contribution.project.id
        details['category_id'] = contribution.category.id
        details['contribution_id'] = contribution.id

    # ###########################
    # FINAL EVENT OBJECT
    # ###########################

    event = {
        'actor': int(uwum_account.id),
        'timestamp': int(round(time.time() * 1000)),
        'activity_type': 'object_%s' % action,
        'activity_objects': activity_objects,
        'visibility_details': visibility_details,
        'details': details
    }

    return event
Beispiel #3
0
 def test_non_ascii_charts_in_value(self):
     props = {'Title': 'Ç-THàNG¡'}
     expected_title = u'Ç-THàNG¡'
     output = get_link_title(properties=props)
     self.assertEqual(expected_title, output)
Beispiel #4
0
 def test_ascii_chars(self):
     props = {'Some normal chars': 'THIS-THING'}
     expected_title = 'Some normal chars THIS-THING'
     output = get_link_title(properties=props)
     self.assertEqual(output, expected_title)
Beispiel #5
0
 def test_numeric_values(self):
     props = {'Two divided by': 0, 'With each other': 1}
     expected_title = 'Two divided by 0'
     output = get_link_title(properties=props)
     self.assertEqual(output, expected_title)
Beispiel #6
0
 def test_numeric_keys(self):
     props = {0: 'Two divided by', 1: 'With each other'}
     expected_title = '0 Two divided by'
     output = get_link_title(properties=props)
     self.assertEqual(output, expected_title)
Beispiel #7
0
 def test_default_to_first_item(self):
     props = {'Strawberries': 'Wandering'}
     expected_title = "Strawberries Wandering"
     output = get_link_title(properties=props)
     self.assertEquals(output, expected_title)
Beispiel #8
0
 def test_find_1cap_name_field(self):
     props = {'Name': 'It could be sweet'}
     expected_title = "It could be sweet"
     output = get_link_title(properties=props)
     self.assertEquals(output, expected_title)
Beispiel #9
0
 def test_blank_dict_unknown(self):
     props = {}
     expected_title = "Unknown title"
     output = get_link_title(properties=props)
     self.assertEquals(output, expected_title)
Beispiel #10
0
 def test_non_ascii_charts_in_key(self):
     props = {'Title Çà¡': 'Thing!'}
     expected_title = u'Thing!'
     output = get_link_title(properties=props)
     self.assertEqual(expected_title, output)