Exemplo n.º 1
0
    def ready(self):
        # Register signals.
        from . import signals

        # When registering by decorator, the last app in INSTALLED_APPS gets
        # called first. But in order to override cartridge templates, we need to
        # be before cartridge in INSTALLED_APPS. Therefore we register here
        # after all apps have been init'd.
        from mezzanine.forms.models import Form
        from mezzanine.pages.page_processors import processor_for
        from .page_processors import override_mezzanine_form_processor
        processor_for(Form)(override_mezzanine_form_processor)

        if not settings.SESSION_COOKIE_SECURE:
            logger = logging.getLogger(__name__)
            logger.warning(
                'SESSION_COOKIE_SECURE is not set! Cartridge-Downloads stores '
                'client credentials in session cookies.')
Exemplo n.º 2
0
    def can_change(self, request):
        return AbstractResource.can_change(self, request)

    def can_delete(self, request):
        return AbstractResource.can_delete(self, request)

    def can_view(self, request):
        return AbstractResource.can_view(self, request)

    @classmethod
    def get_supported_upload_file_types(cls):
        # all file types are supported
        return ('.*')

processor_for(ModelInstanceResource)(resource_processor)

# metadata container class
class ModelInstanceMetaData(CoreMetaData):
    _model_output = generic.GenericRelation(ModelOutput)
    _executed_by = generic.GenericRelation(ExecutedBy)

    @property
    def model_output(self):
        return self._model_output.all().first()

    @property
    def executed_by(self):
        return self._executed_by.all().first()

    @classmethod
Exemplo n.º 3
0
            return

        nc_res_file = get_resource_files_by_extension(self, ".nc")
        txt_res_file = get_resource_files_by_extension(self, ".txt")

        from hs_file_types.models.netcdf import netcdf_file_update  # avoid recursive import
        if nc_res_file and txt_res_file:
            netcdf_file_update(self, nc_res_file[0], txt_res_file[0], user)

    discovery_content_type = 'Multidimensional (NetCDF)'  # used during discovery

    class Meta:
        verbose_name = 'Multidimensional (NetCDF)'
        proxy = True

processor_for(NetcdfResource)(resource_processor)


class NetCDFMetaDataMixin(models.Model):
    """This class must be the first class in the multi-inheritance list of classes"""
    variables = GenericRelation(Variable)
    ori_coverage = GenericRelation(OriginalCoverage)

    class Meta:
        abstract = True

    @property
    def originalCoverage(self):
        return self.ori_coverage.all().first()

    def has_all_required_elements(self):
Exemplo n.º 4
0
    @classmethod
    def can_have_multiple_files(cls):
        # resource can't have any files
        return False

    @classmethod
    def get_metadata_class(cls):
        return ToolMetaData

    @property
    def can_be_published(self):
        return False


processor_for(ToolResource)(resource_processor)


class SupportedFileExtensions(AbstractMetaDataElement):
    term = 'SupportedFileExtensions'
    value = models.CharField(max_length=1024, blank=True, default="")

    class Meta:
        # SupportedFileExtensions element is not repeatable
        unique_together = ("content_type", "object_id")


class AppHomePageUrl(AbstractMetaDataElement):
    term = 'AppHomePageUrl'
    value = models.CharField(max_length=1024, blank=True, default="")
Exemplo n.º 5
0
    def has_resources(self):
        return self.resources.count() > 0

    @property
    def are_all_contained_resources_published(self):
        if not self.has_resources:
            return False
        return not self.resources.all().filter(raccess__published=False).exists()

    @property
    def can_be_published(self):
        return self.can_be_public_or_discoverable and \
               self.are_all_contained_resources_published

    @property
    def update_text_file(self):
        return self.extra_data.get('update_text_file', 'True')


processor_for(CollectionResource)(resource_processor)


class CollectionDeletedResource(models.Model):
    resource_title = models.TextField(null=False, blank=False)
    deleted_by = models.ForeignKey(User)
    date_deleted = models.DateTimeField(auto_now_add=True)
    collection = models.ForeignKey(BaseResource)
    resource_id = models.CharField(max_length=32)
    resource_type = models.CharField(max_length=50)
    resource_owners = models.ManyToManyField(User, related_name='collectionDeleted')
Exemplo n.º 6
0
        return AbstractResource.can_add(self, request)

    def can_change(self, request):
        return AbstractResource.can_change(self, request)

    def can_delete(self, request):
        return AbstractResource.can_delete(self, request)

    def can_view(self, request):
        return AbstractResource.can_view(self, request)

    class Meta:
        verbose_name = 'Multidimensional (NetCDF)'


processor_for(NetcdfResource)(resource_processor)


# define the netcdf metadata
class NetcdfMetaData(CoreMetaData):
    variables = generic.GenericRelation(Variable)
    ori_coverage = generic.GenericRelation(OriginalCoverage)

    @classmethod
    def get_supported_element_names(cls):
        # get the names of all core metadata elements
        elements = super(NetcdfMetaData, cls).get_supported_element_names()
        # add the name of any additional element to the list
        elements.append('Variable')
        elements.append('OriginalCoverage')
        return elements
Exemplo n.º 7
0
# Model Instance Resource type
class ModelInstanceResource(BaseResource):
    objects = ResourceManager("ModelInstanceResource")

    discovery_content_type = 'Model Instance'  # used during discovery

    class Meta:
        verbose_name = 'Model Instance Resource'
        proxy = True

    @classmethod
    def get_metadata_class(cls):
        return ModelInstanceMetaData


processor_for(ModelInstanceResource)(resource_processor)


# metadata container class
class ModelInstanceMetaData(CoreMetaData):
    _model_output = GenericRelation(ModelOutput)
    _executed_by = GenericRelation(ExecutedBy)

    @property
    def resource(self):
        return ModelInstanceResource.objects.filter(object_id=self.id).first()

    @property
    def model_output(self):
        return self._model_output.all().first()
Exemplo n.º 8
0
        geometryinformation = self.metadata.geometryinformation
        if geometryinformation is not None:
            hs_term_dict[
                "HS_GFR_FEATURE_COUNT"] = geometryinformation.featureCount
        else:
            hs_term_dict["HS_GFR_FEATURE_COUNT"] = 0
        return hs_term_dict

    discovery_content_type = 'Geographic Feature (ESRI Shapefiles)'  # used during discovery

    class Meta:
        verbose_name = 'Geographic Feature (ESRI Shapefiles)'
        proxy = True


processor_for(GeographicFeatureResource)(resource_processor)


class GeographicFeatureMetaDataMixin(models.Model):
    """This class must be the first class in the multi-inheritance list of classes"""
    geometryinformations = GenericRelation(GeometryInformation)
    fieldinformations = GenericRelation(FieldInformation)
    originalcoverages = GenericRelation(OriginalCoverage)

    class Meta:
        abstract = True

    @property
    def geometryinformation(self):
        return self.geometryinformations.all().first()
Exemplo n.º 9
0
    discovery_content_type = 'Model Program'  # used during discovery

    class Meta:
        verbose_name = 'Model Program Resource'
        proxy = True

    @classmethod
    def get_metadata_class(cls):
        return ModelProgramMetaData

    @classmethod
    def get_supported_upload_file_types(cls):
        # all file types are supported
        return ('.*')

processor_for(ModelProgramResource)(resource_processor)


class ModelProgramMetaData(CoreMetaData):
    _mpmetadata = GenericRelation(MpMetadata)

    @property
    def resource(self):
        return ModelProgramResource.objects.filter(object_id=self.id).first()

    @property
    def serializer(self):
        """Return an instance of rest_framework Serializer for self """
        from serializers import ModelProgramMetaDataSerializer
        return ModelProgramMetaDataSerializer(self)
Exemplo n.º 10
0
            if date_data[key] is None:
                date_data[key] = coverage_element.value[key]
            else:
                if comparison_operator(
                        parser.parse(date_data[key]),
                        parser.parse(coverage_element.value[key])):
                    date_data[key] = coverage_element.value[key]

        for temp_cov in temporal_coverages:
            start_date = parser.parse(temp_cov.value['start'])
            end_date = parser.parse(temp_cov.value['end'])
            temp_cov.value['start'] = start_date.strftime('%m/%d/%Y')
            temp_cov.value['end'] = end_date.strftime('%m/%d/%Y')
            set_date_value(date_data, temp_cov, 'start')
            set_date_value(date_data, temp_cov, 'end')

        temp_cov = self.metadata.temporal_coverage
        if date_data['start'] is not None and date_data['end'] is not None:
            if temp_cov:
                temp_cov._value = json.dumps(date_data)
                temp_cov.save()
            else:
                self.metadata.create_element("coverage",
                                             type='period',
                                             value=date_data)


# this would allow us to pick up additional form elements for the template before the template
# is displayed
processor_for(CompositeResource)(resource_processor)
Exemplo n.º 11
0
        md = ConfigParser.ConfigParser()
        md.readfp(StringIO.StringIO(metadata))

        resource.project_name = root

        resource.model_desc = md.get('rhessys', 'model_description')

        resource.git_repo = md.get('rhessys', 'rhessys_src')

        resource.commit_id = md.get('rhessys', 'rhessys_sha')

        resource.study_area_bbox = md.get('study_area', 'bbox_wgs84')
        resource.save()
        zfile.close()

processor_for(InstResource)(resource_processor)

@processor_for(InstResource)
def main_page(request, page):
    if(request.method == 'POST'):
        form = InputForm(request.POST)
        if(form.is_valid()):
            content_model = page.get_content_model()
            content_model.name=form.cleaned_data['name']
            content_model.git_username = form.cleaned_data['git_username']
            content_model.git_password = form.cleaned_data['git_password']
            content_model.git_branch = form.cleaned_data['git_branch']
            content_model.model_command_line_parameters = form.cleaned_data['model_command_line_parameters']
            #content_model.project_name = form.cleaned_data['project_name']
            #content_model.model_desc = form.cleaned_data['model_desc']
            #content_model.study_area_bbox = form.cleaned_data['study_area_bbox']
Exemplo n.º 12
0
    # modified










    # #######################
    # # TEMPORAL DEFINITION #
    # #######################
    # # Only for Instance Types
    # hm_begin = models.DateTimeField(verbose_name='Simulation Begin',
    #                              help_text='The start date of the model simulation (mm/dd/yyyy hh:mm)')
    # hm_end  = models.DateTimeField(verbose_name='Simulation End',
    #                             help_text='The end date of the model simulation (mm/dd/yyyy hh:mm)')
    # hm_timestep = models.FloatField(verbose_name='Simulation Time Interval',
    #                              help_text='The timestep interval that is used for calculations (in seconds)')





    class Meta:
        verbose_name = 'HydroProgram'

processor_for(HydroProgramResource)(resource_processor)
Exemplo n.º 13
0
from django.contrib.contenttypes import generic
from django.contrib.auth.models import User, Group
from django.db import models
from mezzanine.pages.models import Page, RichText
from mezzanine.core.models import Ownable
from hs_core.models import AbstractResource
from hs_core.models import resource_processor
from mezzanine.pages.page_processors import processor_for

class TimeSeries(Page, RichText, AbstractResource):
    resource_description = models.TextField(null=False, blank=True, default='',
        help_text='I.E. Upper Provo River Flow',
    )
    resource_url=models.TextField(max_length=100,null=False, blank=True, default='',
        help_text="The WSDL Url for your web services- I.E. 'http://worldwater.byu.edu/interactive/dr/services/index.php/services/cuahsi_1_1.asmx?WSDL'"
    )
    resource_namespace=models.TextField(max_length=100,null=False, blank=True, default='',
        help_text='The namespace is probably {http://www.cuahsi.org/waterML/1.1/}'
    )
    resource_file=models.FileField(upload_to="timeseries",null=True,blank=True)
    class Meta:
        verbose_name = "Time Series"

processor_for(TimeSeries)(resource_processor)


Exemplo n.º 14
0
    class Meta:
        proxy = True
        verbose_name = 'Script Resource'

    @classmethod
    def get_supported_upload_file_types(cls):
        # one file type is supported
        return ".r", ".py", ".m"

    @classmethod
    def get_metadata_class(cls):
        return ScriptMetaData


processor_for(ScriptResource)(resource_processor)


class ScriptSpecificMetadata(AbstractMetaDataElement):
    term = "ScriptSpecificMetadata"

    # program language
    scriptLanguage = models.CharField(verbose_name='Programming Language', blank=True, max_length=100, default='R',
                                      help_text='The programming language that the script is written in')

    # language version
    languageVersion = models.CharField(verbose_name='Programming Language Version', blank=True, max_length=255,
                                       help_text='The software version of the script')

    # script version
    scriptVersion = models.CharField(verbose_name='Script Version', max_length=255, blank=True, default='1.0',
Exemplo n.º 15
0
    @property
    def are_all_contained_resources_published(self):
        if not self.has_resources:
            return False
        return not self.resources.all().filter(
            raccess__published=False).exists()

    @property
    def can_be_published(self):
        return self.can_be_public_or_discoverable and \
               self.are_all_contained_resources_published

    @property
    def update_text_file(self):
        return self.extra_data.get('update_text_file', 'True')


processor_for(CollectionResource)(resource_processor)


class CollectionDeletedResource(models.Model):
    resource_title = models.TextField(null=False, blank=False)
    deleted_by = models.ForeignKey(User)
    date_deleted = models.DateTimeField(auto_now_add=True)
    collection = models.ForeignKey(BaseResource)
    resource_id = models.CharField(max_length=32)
    resource_type = models.CharField(max_length=50)
    resource_owners = models.ManyToManyField(User,
                                             related_name='collectionDeleted')
Exemplo n.º 16
0
    @classmethod
    def can_have_multiple_files(cls):
        # resource can't have any files
        return False

    @classmethod
    def get_metadata_class(cls):
        return ToolMetaData

    @property
    def can_be_published(self):
        return False


processor_for(ToolResource)(resource_processor)


class SupportedFileExtensions(AbstractMetaDataElement):
    term = 'SupportedFileExtensions'
    value = models.CharField(max_length=1024, blank=True, default="")

    class Meta:
        # SupportedFileExtensions element is not repeatable
        unique_together = ("content_type", "object_id")


class AppHomePageUrl(AbstractMetaDataElement):
    term = 'AppHomePageUrl'
    value = models.CharField(max_length=1024, blank=True, default="")
Exemplo n.º 17
0
        # get existing hs_term_dict from base class
        hs_term_dict = super(RasterResource, self).get_hs_term_dict()
        # add new terms for Raster res
        hs_term_dict["HS_FILE_NAME"] = ""
        for res_file in self.files.all():
            _, f_fullname, f_ext = get_resource_file_name_and_extension(
                res_file)
            if f_ext.lower() == '.vrt':
                hs_term_dict["HS_FILE_NAME"] = f_fullname
                break
        return hs_term_dict


# this would allow us to pick up additional form elements for the template
# before the template is displayed via Mezzanine page processor
processor_for(RasterResource)(resource_processor)


class GeoRasterMetaDataMixin(models.Model):
    """This class must be the first class in the multi-inheritance list of classes"""

    # required non-repeatable cell information metadata elements
    _cell_information = GenericRelation(CellInformation)
    _band_information = GenericRelation(BandInformation)
    _ori_coverage = GenericRelation(OriginalCoverage)

    class Meta:
        abstract = True

    @property
    def cellInformation(self):
Exemplo n.º 18
0
    class Meta:
        verbose_name = 'Generic Hydroshare Resource'

    def can_add(self, request):
        return AbstractResource.can_add(self, request)

    def can_change(self, request):
        return AbstractResource.can_change(self, request)

    def can_delete(self, request):
        return AbstractResource.can_delete(self, request)

    def can_view(self, request):
        return AbstractResource.can_view(self, request)

def resource_processor(request, page):
    extra = page_permissions_page_processor(request, page)
    extra['res'] = page.get_content_model()
    extra['dc'] = { m.term_name : m.content for m in extra['res'].dublin_metadata.all() }
    return extra

processor_for(GenericResource)(resource_processor)

@processor_for('resources')
def resource_listing_processor(request, page):
    owned_resources = list(GenericResource.objects.filter(owners__pk=request.user.pk))
    editable_resources = list(GenericResource.objects.filter(owners__pk=request.user.pk))
    viewable_resources = list(GenericResource.objects.filter(public=True))

    return locals()
Exemplo n.º 19
0
        verbose_name = 'Model Program Resource'
        proxy = True

    @property
    def metadata(self):
        md = ModelProgramMetaData()
        meta = self._get_metadata(md)
        return meta

    @classmethod
    def get_supported_upload_file_types(cls):
        # all file types are supported
        return ('.*')


processor_for(ModelProgramResource)(resource_processor)


class ModelProgramMetaData(CoreMetaData):
    _mpmetadata = GenericRelation(MpMetadata)

    @property
    def resource(self):
        return ModelProgramResource.objects.filter(object_id=self.id).first()

    @property
    def program(self):
        return self._mpmetadata.all().first()

    @classmethod
    def get_supported_element_names(cls):
Exemplo n.º 20
0
from mezzanine.pages.page_processors import processor_for
from django.db import models
from django.contrib.contenttypes.models import ContentType


class ResourceAggregation(Page, AbstractResource, RichText):

        resources = generic.GenericRelation('resource_aggregation.Resource')

        def can_add(self, request):
                return AbstractResource.can_add(self, request)

        def can_change(self, request):
                return AbstractResource.can_change(self, request)

        def can_delete(self, request):
                return AbstractResource.can_delete(self, request)

        def can_view(self, request):
                return AbstractResource.can_view(self, request)

processor_for(ResourceAggregation)(resource_processor)

class Resource(models.Model):
    object_id = models.PositiveIntegerField()
    content_type = models.ForeignKey(ContentType)
    content_object = generic.GenericForeignKey('content_type', 'object_id')

    resource_short_id = models.CharField(max_length=32, db_index=True)  # the short_id of the resource
    resource_description = models.CharField(max_length=5000, blank=True, default='')
Exemplo n.º 21
0
    def get_supported_upload_file_types(cls):
        # no file types are supported
        return ()

    @classmethod
    def allow_multiple_file_upload(cls):
        # no file can be uploaded
        return False

    @classmethod
    def can_have_multiple_files(cls):
        # resource can't have any files
        return False


processor_for(RefTimeSeriesResource)(resource_processor)

class ReferenceURL(AbstractMetaDataElement):
    term = 'ReferenceURL'
    value = models.CharField(max_length=500)
    type = models.CharField(max_length=4)

class Method(AbstractMetaDataElement):
    term = 'Method'
    code = models.CharField(max_length=500, default="", blank=True)
    description = models.TextField(default="", blank=True)

class QualityControlLevel(AbstractMetaDataElement):
    term = 'QualityControlLevel'
    code = models.CharField(max_length=500, default="", blank=True)
    definition = models.CharField(max_length=500, default="", blank=True)
Exemplo n.º 22
0
        return False

    def can_add(self, request):
        return AbstractResource.can_add(self, request)

    def can_change(self, request):
        return AbstractResource.can_change(self, request)

    def can_delete(self, request):
        return AbstractResource.can_delete(self, request)

    def can_view(self, request):
        return AbstractResource.can_view(self, request)

# this would allow us to pick up additional form elements for the template before the template is displayed via Mezzanine page processor
processor_for(RasterResource)(resource_processor)


class RasterMetaData(CoreMetaData):
    # required non-repeatable cell information metadata elements
    _cell_information = generic.GenericRelation(CellInformation)
    _band_information = generic.GenericRelation(BandInformation)
    _ori_coverage = generic.GenericRelation(OriginalCoverage)

    @property
    def cellInformation(self):
        return self._cell_information.all().first()

    @property
    def bandInformation(self):
        return self._band_information.all()
Exemplo n.º 23
0
    class Meta:
        proxy = True
        verbose_name = 'Script Resource'

    @classmethod
    def get_supported_upload_file_types(cls):
        # one file type is supported
        return ".r", ".py", ".m"

    @property
    def metadata(self):
        md = ScriptMetaData()
        return self._get_metadata(md)


processor_for(ScriptResource)(resource_processor)


class ScriptSpecificMetadata(AbstractMetaDataElement):
    term = "ScriptSpecificMetadata"

    # program language
    scriptLanguage = models.CharField(
        verbose_name='Programming Language',
        blank=True,
        max_length=100,
        default='R',
        help_text='The programming language that the script is written in')

    # language version
    languageVersion = models.CharField(
Exemplo n.º 24
0
        hs_term_dict = super(GeographicFeatureResource, self).get_hs_term_dict()
        geometryinformation = self.metadata.geometryinformation
        if geometryinformation is not None:
            hs_term_dict["HS_GFR_FEATURE_COUNT"] = geometryinformation.featureCount
        else:
            hs_term_dict["HS_GFR_FEATURE_COUNT"] = 0
        return hs_term_dict

    discovery_content_type = 'Geographic Feature (ESRI Shapefiles)'  # used during discovery

    class Meta:
        verbose_name = 'Geographic Feature (ESRI Shapefiles)'
        proxy = True


processor_for(GeographicFeatureResource)(resource_processor)


class GeographicFeatureMetaDataMixin(models.Model):
    """This class must be the first class in the multi-inheritance list of classes"""
    geometryinformations = GenericRelation(GeometryInformation)
    fieldinformations = GenericRelation(FieldInformation)
    originalcoverages = GenericRelation(OriginalCoverage)

    class Meta:
        abstract = True

    @property
    def geometryinformation(self):
        return self.geometryinformations.all().first()