Beispiel #1
0
 def refresh(self, event=None, group=None):
     log_line = 'Re-caching tag counts'
     if event is not None:
         log_line += ' for event:' + str(event.id)
     elif group is not None:
         log_line += ' for group:' + str(group.id)
     print(log_line)
     value = self._projects_tag_counts(event, group)
     Cache.refresh(self._get_key(event), value)
     return value
Beispiel #2
0
    def create_or_edit_project(request, project_id):
        form = ProjectCreationForm(request.POST)
        if project_id is not None:
            project = Project.objects.get(id=project_id)
        else:
            project = Project.objects.create(
                project_creator=get_request_contributor(request),
                project_name=form.data.get('project_name'),
                project_date_created=timezone.now(),
                is_created=False)

        if not is_co_owner_or_staff(request.user, project):
            raise PermissionDenied()

        is_created_original = project.is_created
        read_form_field_boolean(project, form, 'is_created')

        read_form_field_string(project, form, 'project_description')
        read_form_field_string(project, form, 'project_description_solution')
        read_form_field_string(project, form, 'project_description_actions')
        read_form_field_string(project, form, 'project_short_description')
        read_form_field_string(project, form, 'project_location')
        read_form_field_string(project, form, 'project_country')
        read_form_field_string(project, form, 'project_state')
        read_form_field_string(project, form, 'project_city')
        read_form_field_string(project, form, 'project_name')
        read_form_field_string(project, form, 'project_url')

        read_form_fields_point(project, form, 'project_location_coords',
                               'project_latitude', 'project_longitude')

        tags_changed = False
        tags_changed |= read_form_field_tags(project, form,
                                             'project_issue_area')
        tags_changed |= read_form_field_tags(project, form, 'project_stage')
        tags_changed |= read_form_field_tags(project, form,
                                             'project_technologies')
        tags_changed |= read_form_field_tags(project, form,
                                             'project_organization')
        tags_changed |= read_form_field_tags(project, form,
                                             'project_organization_type')

        if not request.user.is_staff:
            project.project_date_modified = timezone.now()

        project.save()

        merge_json_changes(ProjectLink, project, form, 'project_links')
        merge_json_changes(ProjectFile, project, form, 'project_files')
        tags_changed |= merge_json_changes(ProjectPosition, project, form,
                                           'project_positions')

        merge_single_file(project, form, FileCategory.THUMBNAIL,
                          'project_thumbnail_location')

        if is_created_original != project.is_created:
            print('notifying project creation')
            send_project_creation_notification(project)

        if project.is_searchable and tags_changed:
            Cache.refresh(CacheKeys.ProjectTagCounts.value)

        # TODO: Don't recache when nothing has changed
        project.recache()

        return project
def projects_tag_counts():
    return Cache.get(CacheKeys.ProjectTagCounts.value, generator_func=_projects_tag_counts)
Beispiel #4
0
 def get(self, project):
     return Cache.get(self._get_key(project))
Beispiel #5
0
 def get(self, event=None, group=None):
     key = self._get_key(event=event, group=group)
     return Cache.get(key) or self.refresh(event=event, group=group)
Beispiel #6
0
 def refresh(self, group, value):
     print('Re-caching group ' + str(group))
     Cache.refresh(self._get_key(group), value)
     return value
Beispiel #7
0
 def get(self, group):
     return Cache.get(self._get_key(group))
Beispiel #8
0
 def refresh(self, event, value):
     print('Re-caching event ' + str(event))
     Cache.refresh(self._get_key(event), value)
     return value
Beispiel #9
0
 def refresh(self, project, value):
     print('Re-caching project ' + str(project))
     Cache.refresh(self._get_key(project), value)
     return value