示例#1
0
class ActivationWizardForm(forms.Form):
    home_airport = JSONField()
    email = forms.EmailField()
    password = forms.CharField(widget=forms.PasswordInput)
    first_name = forms.CharField()
    last_name = forms.CharField()
    activation_code = forms.CharField()
示例#2
0
class InviteWizardForm(forms.Form):
    home_airport = JSONField()
    password = forms.CharField(widget=forms.PasswordInput)
    first_name = forms.CharField()
    last_name = forms.CharField()
    code = forms.ModelChoiceField(
        CompanionInvite.objects.exclude(status=CompanionInviteStatus.active),
        to_field_name="invite_code",
    )
示例#3
0
文件: models.py 项目: mimo00/thesis
class AggregatorGroupDecision(models.Model):
    decision = models.ForeignKey(AggregatorDecision,
                                 on_delete=models.CASCADE,
                                 related_name="aggregator_group_decisions")
    group_params = JSONField()
    is_success = models.BooleanField()
    energy_coverage = models.DecimalField(max_digits=5, decimal_places=2)
    hour_coverage = models.DecimalField(max_digits=5, decimal_places=2)
    energy_loss = models.DecimalField(max_digits=5, decimal_places=2)
    group_id = models.IntegerField()
示例#4
0
class UploadForm(forms.Form):
    filename = forms.CharField()
    project = forms.ModelChoiceField(queryset=Project.objects.all())

    articleset = forms.ModelChoiceField(
        queryset=ArticleSet.objects.all(),
        required=False,
        help_text="If you choose an existing articleset, the articles will be "
        "appended to that set. If you leave this empty, a new articleset will be "
        "created using either the name given below, or using the file name")

    articleset_name = forms.CharField(
        max_length=ArticleSet._meta.get_field('name').max_length,
        required=False)

    encoding = forms.ChoiceField(
        choices=[(x, x)
                 for x in ["Autodetect", "ISO-8859-15", "UTF-8", "Latin-1"]])
    field_map = JSONField(
        validators=[validate_field_map],
        help_text=
        'json dict with property names (title, date, etc.) as keys, and field settings as values. '
        'Field settings should have the form {"type": "field"/"literal", "value": "field_name_or_literal"}'
    )

    def clean_articleset_name(self):
        """If articleset name not specified, use file base name instead"""
        if 'articleset' in self.errors:
            # skip check if error in articlesets: cleaned_data['articlesets'] does not exist
            return
        if not (self.cleaned_data.get('articleset_name')
                or self.cleaned_data.get('articleset')):
            fn = self.cleaned_data.get('filename')
            if (not fn) and self.cleaned_data.get('file'):
                fn = self.cleaned_data.get('file').name
            if fn:
                return os.path.basename(fn)
        name = self.cleaned_data['articleset_name']
        if not bool(name) ^ bool(self.cleaned_data['articleset']):
            raise forms.ValidationError(
                "Please specify either articleset or articleset_name")
        return name

    @classmethod
    def get_empty(cls, project=None, post=None, files=None, **_options):
        f = cls(post, files) if post is not None else cls()
        if project:
            f.fields['project'].initial = project.id
            f.fields['project'].widget = HiddenInput()
            f.fields['articlesets'].queryset = ArticleSet.objects.filter(
                project=project)
        return f

    def validate(self):
        return self.is_valid()
示例#5
0
class WizardForm(forms.Form):
    home_airport = JSONField()
    email = forms.EmailField()
    password = forms.CharField(widget=forms.PasswordInput)
    first_name = forms.CharField()
    last_name = forms.CharField()
    promo_code = forms.CharField(required=False)
    zip = forms.CharField(required=False)
    card_number = CardNumberField(required=False)
    expiry = CardExpiryField(required=False)
    cvc = SecurityCodeField(required=False)
    plan = forms.ChoiceField(choices=tuple(
        (o, o) for o in settings.PLAN_DEFINITIONS.keys()))
示例#6
0
class FeatureTypeModelForm(forms.ModelForm):

    title = forms.CharField(label='Titre', required=True)

    colors_style = JSONField(
        label='Style Couleur', required=False,
        # TODO voir si nécessaire au front
        initial={'custom_field_name': '', 'colors': {}}
    )

    class Meta:
        model = FeatureType
        fields = ('title', 'geom_type', 'color', 'colors_style')
示例#7
0
class PhraseForm(forms.ModelForm):
    pattern = JSONField(required=False)

    class Meta:
        model = Phrase
        fields = '__all__'

    def clean_pattern(self):
        pattern = self.cleaned_data['pattern']
        spacy_token_list = [key.value for key in SpacyPatternKeys]
        invalid_tokens = [next(iter(word)) for word in pattern if
                          next(iter(word)) not in spacy_token_list]
        if invalid_tokens:
            error_message = (f'Invalid word token(s) {invalid_tokens} in pattern, '
                             f'please consult spacy documentation for rule matcher')
            raise forms.ValidationError(error_message)
        return pattern
示例#8
0
class ProductAttributeSpecs(models.Model):
    product_picture_product_number = models.ForeignKey(
        Products, on_delete=models.CASCADE, default="", verbose_name='产品编号')
    product_attrinute = JSONField(db_index=True, verbose_name='产品属性规格')
    product_add_personnel = models.ForeignKey(UserProfile,
                                              on_delete=models.CASCADE,
                                              default="",
                                              verbose_name='产品添加人员')
    product_add_time = models.DateTimeField(auto_now_add=True,
                                            verbose_name='产品添加时间')
    product_change_time = models.DateTimeField(auto_now=True,
                                               verbose_name='产品更改时间')
    remarks = models.CharField(max_length=5000, null=False, verbose_name='备注')

    def __str__(self):
        return self.product_picture_product_number.product_name

    class Meta:
        # ordering 用来指定文章排序,
        ordering = ['-product_add_time']
示例#9
0
class WizardForm(forms.Form):
    home_airport = JSONField()
    email = forms.EmailField()
    password = forms.CharField(widget=forms.PasswordInput)
    first_name = forms.CharField()
    last_name = forms.CharField()
    promo_code = forms.CharField(required=False)
    zip = forms.CharField(required=False)
    card_number = CardNumberField(required=False)
    expiry = MyCardExpiryField(required=False)
    cvc = SecurityCodeField(required=False)
    plan = forms.ChoiceField(choices=tuple(
        (o, o) for o in settings.PLAN_DEFINITIONS.keys()),
                             required=False)

    def clean(self):
        cd = self.cleaned_data
        if cd.get("plan"):
            if not (cd.get("card_number") and cd.get("expiry")
                    and cd.get("cvc")):
                raise ValidationError(
                    "Paid account requires payment credentials")
示例#10
0
class DashboardExerciseForm(ExerciseForm):
    id = forms.CharField(
        widget=forms.TextInput(attrs={'readonly': 'readonly'}),
        required=False,
        label='ID')

    # analysis_enabled = forms.BooleanField(label='Enable Analysis', required=False)
    # analysis_modes = forms.MultipleChoiceField(
    #     widget=forms.CheckboxSelectMultiple(),
    #     choices=Exercise.ANALYSIS_MODE_CHOICES
    # )

    # highlight_enabled = forms.BooleanField(label='Enable Highlight', required=False)
    # highlight_modes = forms.MultipleChoiceField(
    #     widget=forms.CheckboxSelectMultiple,
    #     choices=Exercise.HIGHLIGHT_MODE_CHOICES
    # )

    # data_fields = ['analysis', 'highlight']

    data = JSONField(widget=forms.HiddenInput)

    editable_fields = ['description', 'is_public']

    class Meta:
        model = Exercise
        exclude = ['authored_by']
        widgets = {
            'data': PrettyJSONWidget(attrs={'initial': 'parsed'}),
            'id': forms.TextInput(attrs={'readonly': 'readonly'}),
        }

    def __init__(self, disable_fields=False, *args, **kwargs):
        super(DashboardExerciseForm, self).__init__(*args, **kwargs)
        if disable_fields:
            for field in self.fields:
                if field not in self.editable_fields:
                    self.fields.get(field).disabled = True
示例#11
0
class Checklist(models.Model):
    """
    The Checklist class defines the master data model for Checklist
    ## Fields
    **Basic**
    - created: DateTime
    - updated: DateTime

    **Identifiers**
    - name: Char(120)
    - slug: auto from name

    **Properties**

    **State**
    - active:bool
    - meta: JSON

    **Relationship Fields**
    - created_by: Account defined <em>defined in accounts.models</em>
    - last_updated_by: Account defined <em>defined in accounts.models</em>

    ## **Builtin methods**
    - __str__: returns a string representation of the object

    **Model overrides**
    - clean: exposed for placeholder of custom validation
    - save: auto-call full_clean() parent method

    **Model-specific methods**

    **Signals**
    - scaffold_post_save: post-save trigger
    - scaffold_pre_save: pre-save trigger

    """

    # === Basic ===
    created = models.DateTimeField(null=False, auto_now_add=True)
    updated = models.DateTimeField(null=False, auto_now=True)

    # === Identifiers ===

    # === Properties ===
    building_permit = models.BooleanField()
    occupancy_permit = models.BooleanField()
    fsic_control_no = models.CharField(max_length=18, blank=True, null=True)
    fsic_fee = models.DecimalField(max_digits=8,
                                   decimal_places=2,
                                   blank=True,
                                   null=True)
    fire_drill_certificate = models.BooleanField()
    violation_control_no = models.CharField(max_length=24,
                                            blank=True,
                                            null=True)
    electrical_inspection_no = models.CharField(max_length=24,
                                                blank=True,
                                                null=True)
    sectional_occupancy = models.PositiveSmallIntegerField(blank=True,
                                                           null=True)
    occupant_load = models.PositiveSmallIntegerField(blank=True, null=True)
    egress_capacity = models.PositiveSmallIntegerField(blank=True, null=True)
    first_name = models.CharField(max_length=24, blank=True, null=True)
    middle_name = models.CharField(max_length=24, blank=True, null=True)
    last_name = models.CharField(max_length=24, blank=True, null=True)
    policy_no = models.CharField(max_length=24, blank=True, null=True)
    any_renovation = models.BooleanField()
    renovation_specification = models.CharField(max_length=254,
                                                blank=True,
                                                null=True)
    horizontal_exit_capacity = models.PositiveSmallIntegerField(blank=True,
                                                                null=True)
    exit_stair_capacity = models.PositiveSmallIntegerField(blank=True,
                                                           null=True)
    no_of_exits = models.PositiveSmallIntegerField(blank=True, null=True)
    is_exits_remote = models.BooleanField()
    exit_location = models.CharField(max_length=254, blank=True, null=True)
    any_enclosure = models.BooleanField()
    is_exit_accessible = models.BooleanField()
    is_fire_doors_provided = models.BooleanField()
    self_closing_mechanism = models.BooleanField()
    panic_hardware = models.BooleanField()
    readily_accessible = models.BooleanField()
    travel_distance_within_limit = models.BooleanField()
    adequate_illumination = models.BooleanField()
    panic_hardware_operational = models.BooleanField()
    doors_open_easily = models.BooleanField()
    bldg_with_mezzanine = models.BooleanField()
    is_obstructed = models.BooleanField()
    dead_ends_within_limits = models.BooleanField()
    proper_rating_illumination = models.BooleanField()
    door_swing_in_the_direction_of_exit = models.BooleanField()
    self_closure_operational = models.BooleanField()
    mezzanine_with_proper_exits = models.BooleanField()
    corridors_of_sufficient_size = models.BooleanField()
    main_stair_width = models.FloatField(blank=True, null=True)
    construction = models.CharField(max_length=254, blank=True,
                                    null=True)  # not_sure
    main_stair_railings = models.BooleanField()
    main_stair_railings_built = models.CharField(max_length=254,
                                                 blank=True,
                                                 null=True)
    main_stair_any_enclosure_provided = models.BooleanField()
    enclosure_built = models.CharField(max_length=254, blank=True, null=True)
    any_openings = models.BooleanField()
    main_stair_door_proper_rating = models.BooleanField()
    main_stair_door_provided_with_vision_panel = models.BooleanField()
    main_stair_door_vision_panel_built = models.CharField(max_length=254,
                                                          blank=True,
                                                          null=True)
    main_stair_pressurized_stairway = models.BooleanField()
    main_stair_type_of_pressurized_stairway = models.CharField(max_length=254,
                                                               blank=True,
                                                               null=True)
    fire_escape_count = models.PositiveSmallIntegerField(blank=True, null=True)
    fire_escape_width = models.FloatField(blank=True, null=True)
    fire_escape_construction = models.CharField(max_length=254,
                                                blank=True,
                                                null=True)
    fire_escape_railings = models.BooleanField()
    fire_escape_built = models.CharField(max_length=254, blank=True, null=True)
    fire_escape_location = models.CharField(choices=LOCATION_CHOICES,
                                            blank=True,
                                            null=True,
                                            max_length=64)
    fire_escape_obstruction = models.BooleanField()
    discharge_of_exits = models.BooleanField()  # not_sure
    fire_escape_any_enclosure_provided = models.BooleanField()
    fire_escape_enclosure = models.BooleanField()
    fire_escape_opening = models.BooleanField()
    fire_escape_opening_protected = models.BooleanField()
    fire_door_provided = models.BooleanField()
    fire_door_width = models.FloatField(blank=True, null=True)
    fire_door_construction = models.CharField(max_length=254,
                                              blank=True,
                                              null=True)
    fire_door_door_proper_rating = models.BooleanField()
    fire_door_door_provided_with_vision_panel = models.BooleanField()
    fire_door_door_vision_panel_built = models.CharField(max_length=254,
                                                         blank=True,
                                                         null=True)
    fire_door_pressurized_stairway = models.BooleanField()
    fire_door_type_of_pressurized_stairway = models.CharField(max_length=254,
                                                              blank=True,
                                                              null=True)
    horizontal_exit_width = models.FloatField(blank=True, null=True)
    horizontal_exit_construction = models.CharField(max_length=254,
                                                    blank=True,
                                                    null=True)
    horizontal_exit_vision_panel = models.BooleanField()
    horizontal_exit_door_swing_in_direction_of_egress = models.BooleanField()
    horizontal_exit_with_self_closing_device = models.BooleanField()
    horizontal_exit_corridor_width = models.FloatField(blank=True, null=True)
    horizontal_exit_corridor_construction = models.CharField(max_length=254,
                                                             blank=True,
                                                             null=True)
    horizontal_exit_corridor_walls_extended = models.BooleanField()
    horizontal_exit_properly_illuminated = models.BooleanField()
    horizontal_exit_readily_visible = models.BooleanField()
    horizontal_exit_properly_marked = models.BooleanField()
    horizontal_exit_with_illuminated_directional_sign = models.BooleanField()
    horizontal_exit_properly_located = models.BooleanField()
    ramps_provided = models.BooleanField()
    ramps_type = models.CharField(choices=LOCATION_CHOICES,
                                  blank=True,
                                  null=True,
                                  max_length=64)
    ramps_width = models.FloatField(blank=True, null=True)
    ramps_class = models.CharField(max_length=254, blank=True, null=True)
    ramps_railing_provided = models.BooleanField()
    ramps_height = models.FloatField(blank=True, null=True)
    ramps_enclosure = models.BooleanField()
    ramps_construction = models.CharField(max_length=254,
                                          blank=True,
                                          null=True)
    ramps_fire_doors = models.BooleanField()
    ramps_fire_doors_width = models.FloatField(blank=True, null=True)
    ramps_fire_doors_construction = models.CharField(max_length=254,
                                                     blank=True,
                                                     null=True)
    ramps_with_self_closing_device = models.BooleanField()
    ramps_door_with_proper_rating = models.BooleanField()
    ramps_door_with_vision_panel = models.BooleanField()
    ramps_door_vision_panel_built = models.CharField(max_length=254,
                                                     blank=True,
                                                     null=True)
    ramps_door_swing_in_direction_of_egress = models.BooleanField()
    ramps_obstruction = models.BooleanField()
    ramps_discharge_of_exit = models.BooleanField()
    safe_refuge_provided = models.BooleanField()
    safe_refuge_type = models.CharField(choices=LOCATION_CHOICES,
                                        blank=True,
                                        null=True,
                                        max_length=64)
    safe_refuge_enclosure = models.BooleanField()
    safe_refuge_construction = models.CharField(max_length=254,
                                                blank=True,
                                                null=True)
    safe_refuge_fire_door = models.BooleanField()
    safe_refuge_fire_door_width = models.FloatField(blank=True, null=True)
    safe_refuge_fire_door_construction = models.CharField(max_length=254,
                                                          blank=True,
                                                          null=True)
    safe_refuge_with_self_closing_device = models.BooleanField()
    safe_refuge_door_proper_rating = models.BooleanField()
    safe_refuge_with_vision_panel = models.BooleanField()
    safe_refuge_vision_panel_built = models.BooleanField()
    safe_refuge_swing_in_direction_of_egress = models.BooleanField()
    emergency_light = models.BooleanField()
    emergency_light_source = models.CharField(choices=CURRENT_CHOICES,
                                              blank=True,
                                              null=True,
                                              max_length=64)
    emergency_light_per_floor_count = models.PositiveSmallIntegerField(
        blank=True, null=True)
    emergency_light_hallway_count = models.PositiveSmallIntegerField(
        blank=True, null=True)
    emergency_light_stairway_count = models.PositiveSmallIntegerField(
        blank=True, null=True)
    emergency_light_operational = models.BooleanField()
    emergency_light_exit_path_properly_illuminated = models.BooleanField()
    emergency_light_tested_monthly = models.BooleanField()
    exit_signs_illuminated = models.BooleanField()
    exit_signs_location = models.CharField(max_length=254,
                                           blank=True,
                                           null=True)
    exit_signs_source = models.CharField(choices=CURRENT_CHOICES,
                                         blank=True,
                                         null=True,
                                         max_length=64)
    exit_signs_visible = models.BooleanField()
    exit_signs_min_letter_size = models.FloatField(blank=True, null=True)
    exit_route_posted_on_lobby = models.BooleanField()
    exit_route_posted_on_rooms = models.BooleanField()
    directional_exit_signs = models.BooleanField()
    directional_exit_signs_location = models.CharField(max_length=254,
                                                       blank=True,
                                                       null=True)
    no_smoking_sign = models.BooleanField()
    dead_end_sign = models.BooleanField()
    elevator_sign = models.BooleanField()
    keep_door_closed_sign = models.BooleanField()
    others = models.CharField(max_length=254, blank=True, null=True)
    vertical_openings_properly_protected = models.BooleanField()
    vertical_openings_atrium = models.BooleanField()
    fire_doors_good_condition = models.BooleanField()
    elevator_opening_protected = models.BooleanField()
    pipe_chase_opening_protected = models.BooleanField()
    aircon_ducts_with_dumper = models.BooleanField()
    garbage_chute_protected = models.BooleanField()
    between_floor_protected = models.BooleanField()
    standpipe_type = models.CharField(choices=STANDPIPE_CHOICES,
                                      blank=True,
                                      null=True,
                                      max_length=64)
    standpipe_tank_capacity = models.FloatField(blank=True, null=True)
    standpipe_location = models.CharField(max_length=254,
                                          blank=True,
                                          null=True)
    siamese_intake_provided = models.BooleanField()
    siamese_intake_location = models.CharField(max_length=254,
                                               blank=True,
                                               null=True)
    siamese_intake_size = models.FloatField(blank=True, null=True)
    siamese_intake_count = models.PositiveSmallIntegerField(blank=True,
                                                            null=True)
    siamese_intake_accessible = models.BooleanField()
    fire_hose_cabinet = models.BooleanField()
    fire_hose_cabinet_accessories = models.BooleanField()
    fire_hose_cabinet_location = models.CharField(max_length=254,
                                                  blank=True,
                                                  null=True)
    fire_hose_per_floor_count = models.PositiveSmallIntegerField(blank=True,
                                                                 null=True)
    fire_hose_size = models.FloatField(blank=True, null=True)
    fire_hose_length = models.FloatField(blank=True, null=True)
    fire_hose_nozzle = models.CharField(max_length=254, blank=True,
                                        null=True)  # not_user
    fire_lane = models.BooleanField()
    fire_hydrant_location = models.CharField(max_length=254,
                                             blank=True,
                                             null=True)
    portable_fire_extinguisher_type = models.CharField(max_length=254,
                                                       blank=True,
                                                       null=True)  # not_sure
    portable_fire_extinguisher_capacity = models.FloatField(blank=True,
                                                            null=True)
    portable_fire_extinguisher_count = models.PositiveSmallIntegerField(
        blank=True, null=True)
    portable_fire_extinguisher_with_ps_mark = models.BooleanField()
    portable_fire_extinguisher_with_iso_mark = models.BooleanField()
    portable_fire_extinguisher_maintained = models.BooleanField()
    portable_fire_extinguisher_conspicuously_located = models.CharField(
        max_length=254, blank=True, null=True)
    portable_fire_extinguisher_accessible = models.BooleanField()
    portable_fire_extinguisher_other_type = models.CharField(
        max_length=254, blank=True, null=True)  # not_sure
    sprinkler_system_agent_used = models.BooleanField()
    jockey_pump_capacity = models.FloatField(blank=True, null=True)
    fire_pump_capacity = models.FloatField(blank=True, null=True)
    gpm_tank_capacity = models.FloatField(blank=True, null=True)
    maintaining_line_pressure = models.BooleanField()  # not_sure
    farthest_sprinkler_head_pressure = models.CharField(max_length=254,
                                                        blank=True,
                                                        null=True)
    riser_size = models.FloatField(blank=True, null=True)
    type_of_heads_installed = models.CharField(max_length=254,
                                               blank=True,
                                               null=True)
    heads_per_floor_count = models.PositiveSmallIntegerField(blank=True,
                                                             null=True)
    heads_total_count = models.PositiveSmallIntegerField(blank=True, null=True)
    spacing_of_heads = models.CharField(max_length=254, blank=True, null=True)
    location_of_fire_dept_connection = models.CharField(max_length=254,
                                                        blank=True,
                                                        null=True)
    plan_submitted = models.BooleanField()
    firewall_required = models.BooleanField()
    firewall_provided = models.BooleanField()
    firewall_opening = models.BooleanField()
    boiler_provided = models.BooleanField()
    boiler_unit_count = models.PositiveSmallIntegerField(blank=True, null=True)
    boiler_fuel = models.CharField(choices=FUEL_CHOICES,
                                   blank=True,
                                   null=True,
                                   max_length=64)
    boiler_capacity = models.FloatField(blank=True, null=True)
    boiler_container = models.CharField(choices=CONTAINER_LOCATION_CHOICES,
                                        blank=True,
                                        null=True,
                                        max_length=64)
    boiler_location = models.CharField(max_length=254, blank=True, null=True)
    lpg_installation_with_permit = models.BooleanField()
    fuel_with_storage_permit = models.BooleanField()
    generator_set = models.CharField(max_length=254, blank=True, null=True)
    generator_set_type = models.CharField(choices=GENERATOR_TYPE_CHOICES,
                                          blank=True,
                                          null=True,
                                          max_length=64)
    generator_fuel = models.CharField(choices=GENERATOR_FUEL_CHOICES,
                                      blank=True,
                                      null=True,
                                      max_length=64)
    generator_capacity = models.FloatField(blank=True, null=True)
    generator_location = models.CharField(max_length=254,
                                          blank=True,
                                          null=True)
    generator_bound_on_wall = models.BooleanField()
    generator_container = models.CharField(choices=CONTAINER_LOCATION_CHOICES,
                                           blank=True,
                                           null=True,
                                           max_length=64)
    generator_dispensing_system = models.CharField(
        choices=GENERATOR_DISPENSING_CHOICES,
        blank=True,
        null=True,
        max_length=64)
    generator_output_capacity = models.FloatField(blank=True, null=True)
    generator_mechanical_permit = models.BooleanField()
    generator_fuel_storage_permit = models.BooleanField()
    generator_others = models.CharField(max_length=254, blank=True, null=True)
    generator_automatic_transfer_switch = models.BooleanField()
    generator_time_interval = models.TimeField(
        verbose_name='Generator time interval', blank=True, null=True)
    refuse_handling = models.BooleanField()
    refuse_handling_enclosure = models.BooleanField()
    refuse_handling_fire_resistive = models.BooleanField()
    refuse_handling_fire_protection = models.BooleanField()
    refuse_handling_fire_protection_type = models.CharField(max_length=254,
                                                            blank=True,
                                                            null=True)
    refuse_handling_disposal = models.BooleanField()
    refuse_handling_collection_method = models.CharField(max_length=254,
                                                         blank=True,
                                                         null=True)
    electrical_hazard = models.BooleanField()
    electrical_hazard_location = models.CharField(max_length=254,
                                                  blank=True,
                                                  null=True)
    mechanical_hazard = models.BooleanField()
    mechanical_hazard_location = models.CharField(max_length=254,
                                                  blank=True,
                                                  null=True)
    elevator_count = models.PositiveSmallIntegerField(blank=True, null=True)
    fireman_elevator = models.BooleanField()
    fireman_elevator_key = models.BooleanField()
    other_service_system = models.CharField(choices=SERVICE_SYSTEM_CHOICES,
                                            blank=True,
                                            null=True,
                                            max_length=64)
    hazardous_area = models.CharField(choices=HAZARDOUS_AREA_CHOICES,
                                      blank=True,
                                      null=True,
                                      max_length=64)
    hazardous_area_other = models.CharField(max_length=254,
                                            blank=True,
                                            null=True)
    separation_fire_rated = models.BooleanField()
    type_of_protection = models.CharField(max_length=254,
                                          blank=True,
                                          null=True)
    separation_fire_rated_count = models.PositiveSmallIntegerField(blank=True,
                                                                   null=True)
    separation_fire_rated_capacity = models.FloatField(blank=True, null=True)
    separation_fire_rated_accessible = models.BooleanField()
    separation_fire_rated_fuel = models.BooleanField()
    separation_fire_rated_location = models.CharField(max_length=254,
                                                      blank=True,
                                                      null=True)
    separation_fire_rated_permit = models.BooleanField()
    chimney_built = models.CharField(max_length=254, blank=True, null=True)
    chimney_spark_arrestor = models.BooleanField()
    chimney_smoke_hood = models.BooleanField()
    hazardous_material = models.BooleanField()
    hazardous_material_stored = models.BooleanField()
    fire_brigade_organization = models.BooleanField()
    fire_safety_seminar = models.BooleanField()
    employee_trained_in_emergency_procedures = models.BooleanField()
    evacuation_drill_first = models.BooleanField()
    evacuation_drill_second = models.BooleanField()
    defects = models.CharField(max_length=254, blank=True, null=True)
    defects_photo = models.FileField(verbose_name='Defects supporting image',
                                     upload_to=defect_upload_path,
                                     max_length=254,
                                     blank=True,
                                     null=True)
    recommendations = models.CharField(max_length=254, blank=True, null=True)

    # === State ===
    active = models.BooleanField(default=True)
    meta = JSONField()

    # === Relationship Fields ===
    building = models.ForeignKey('buildings.Building',
                                 on_delete=models.CASCADE,
                                 null=False,
                                 db_index=False,
                                 related_name='building_checklist',
                                 blank=False)
    business = models.ForeignKey('business.Business',
                                 on_delete=models.CASCADE,
                                 null=True,
                                 db_index=False,
                                 related_name='business_checklists',
                                 blank=True)
    building_permit_date_issued = models.ForeignKey(
        'datesdim.DateDim',
        blank=True,
        null=True,
        on_delete=models.SET_NULL,
        related_name='building_issued_datetime')
    occupancy_permit_date_issued = models.ForeignKey(
        'datesdim.DateDim',
        blank=True,
        null=True,
        on_delete=models.SET_NULL,
        related_name='occupancy_issued_datetime')
    fsic_date_issued = models.ForeignKey('datesdim.DateDim',
                                         blank=True,
                                         null=True,
                                         on_delete=models.SET_NULL,
                                         related_name='fsic_issued_datetime')
    fire_drill_certificate_date_issued = models.ForeignKey(
        'datesdim.DateDim',
        blank=True,
        null=True,
        on_delete=models.SET_NULL,
        related_name='fire_drill_datetime')
    violation_control_no_date_issued = models.ForeignKey(
        'datesdim.DateDim',
        blank=True,
        null=True,
        on_delete=models.SET_NULL,
        related_name='violation_control_no_datetime')
    electrical_inspection_date_issued = models.ForeignKey(
        'datesdim.DateDim',
        blank=True,
        null=True,
        on_delete=models.SET_NULL,
        related_name='electrical_inspection_datetime')
    insurance_date_issued = models.ForeignKey(
        'datesdim.DateDim',
        blank=True,
        null=True,
        on_delete=models.SET_NULL,
        related_name='issurance_datetime')
    main_stair_pressurized_stairway_last_tested = models.ForeignKey(
        'datesdim.DateDim',
        blank=True,
        null=True,
        on_delete=models.SET_NULL,
        related_name='main_stair_pressurized_stairway_datetime')
    fire_door_pressurized_stairway_last_tested = models.ForeignKey(
        'datesdim.DateDim',
        blank=True,
        null=True,
        on_delete=models.SET_NULL,
        related_name='fire_door_pressurized_stairway_datetime')
    vertical_opening_last_tested = models.ForeignKey(
        'datesdim.DateDim',
        blank=True,
        null=True,
        on_delete=models.SET_NULL,
        related_name='vertical_opening_datetime')
    fire_hose_last_tested = models.ForeignKey(
        'datesdim.DateDim',
        blank=True,
        null=True,
        on_delete=models.SET_NULL,
        related_name='fire_hose_datetime')
    sprinkler_system_last_tested = models.ForeignKey(
        'datesdim.DateDim',
        blank=True,
        null=True,
        on_delete=models.SET_NULL,
        related_name='sprinkler_system_datetime')
    sprinkler_system_last_conducted = models.ForeignKey(
        'datesdim.DateDim',
        blank=True,
        null=True,
        on_delete=models.SET_NULL,
        related_name='sprinkler_system_conducted_datetime')
    certificate_of_installation_date = models.ForeignKey(
        'datesdim.DateDim',
        blank=True,
        null=True,
        on_delete=models.SET_NULL,
        related_name='certificate_of_installation_datetime')
    generator_mechanical_permit_date_issued = models.ForeignKey(
        'datesdim.DateDim',
        blank=True,
        null=True,
        on_delete=models.SET_NULL,
        related_name='generator_permit_datetime')
    date_checked = models.ForeignKey('datesdim.DateDim',
                                     blank=True,
                                     null=True,
                                     on_delete=models.CASCADE,
                                     related_name='checked_datetime')
    created_by = models.ForeignKey('accounts.Account',
                                   on_delete=models.SET_NULL,
                                   null=True,
                                   db_index=False,
                                   related_name='created_checklists',
                                   blank=True)
    last_updated_by = models.ForeignKey('accounts.Account',
                                        on_delete=models.SET_NULL,
                                        null=True,
                                        db_index=False,
                                        related_name='updated_checklists',
                                        blank=True)

    # Manager
    objects = ChecklistManager()

    class Meta:
        ordering = ('building', )
        verbose_name = "Checklist"
        verbose_name_plural = "Checklists"

    ################################################################################
    # === Builtin methods ===
    ################################################################################
    def __str__(self):
        return f'{self.business.name}'

    ################################################################################
    # === Model overrides ===
    ################################################################################
    def clean(self, *args, **kwargs):
        # add custom validation here
        super().clean(*args, **kwargs)

    def save(self, *args, **kwargs):
        # self.full_clean()
        super().save(*args, **kwargs)

    ################################################################################
    # === Model-specific methods ===
    ################################################################################
    def count_score(self):
        score = 0
        fields = []

        for field in Checklist._meta.fields:
            if isinstance(field, BooleanField):
                if field.name not in EXCLUDE_FIELDS:
                    fields.append(field.name)
                    score += getattr(self, field.name)

        return score
class Checklist(models.Model):
    """
    The Checklist class defines the master data model for Checklist
    ## Fields
    **Basic**
    - created: DateTime
    - updated: DateTime

    **Identifiers**
    - name: Char(120)
    - slug: auto from name

    **Properties**

    **State**
    - active:bool
    - meta: JSON

    **Relationship Fields**
    - created_by: Account defined <em>defined in accounts.models</em>
    - last_updated_by: Account defined <em>defined in accounts.models</em>

    ## **Builtin methods**
    - __str__: returns a string representation of the object

    **Model overrides**
    - clean: exposed for placeholder of custom validation
    - save: auto-call full_clean() parent method

    **Model-specific methods**

    **Signals**
    - scaffold_post_save: post-save trigger
    - scaffold_pre_save: pre-save trigger

    """

    # === Basic ===
    created = models.DateTimeField(null=False, auto_now_add=True)
    updated = models.DateTimeField(null=False, auto_now=True)

    # === Identifiers ===

    # === Properties ===
    first_name = models.CharField(max_length=42, blank=True, null=True)
    middle_name = models.CharField(max_length=42, blank=True, null=True)
    last_name = models.CharField(max_length=42, blank=True, null=True)
    policy_no = models.CharField(max_length=24, blank=True, null=True)
    building_permit = models.BooleanField(default=False)
    occupancy_permit = models.BooleanField(default=False)
    fsic_control_no = models.CharField(max_length=18, blank=True, null=True)
    fsic_fee = models.DecimalField(max_digits=8,
                                   decimal_places=2,
                                   blank=True,
                                   null=True,
                                   default=0)
    fire_drill_certificate = models.BooleanField(default=False)
    violation_control_no = models.CharField(max_length=24,
                                            blank=True,
                                            null=True)
    electrical_inspection_no = models.CharField(max_length=24,
                                                blank=True,
                                                null=True)
    sectional_occupancy = models.CharField(max_length=1024,
                                           blank=True,
                                           null=True)

    # Means of egress
    exits_count = models.PositiveSmallIntegerField(blank=True,
                                                   null=True,
                                                   default=0)
    exits_width = models.PositiveSmallIntegerField(blank=True,
                                                   null=True,
                                                   default=0)
    exits_accessible = models.BooleanField(default=False)
    termination_of_exit = models.CharField(max_length=254,
                                           blank=True,
                                           null=True)
    exits_enclosure_provided = models.BooleanField(default=False)
    exits_enclosure_construction = models.CharField(max_length=254,
                                                    blank=True,
                                                    null=True)
    exits_fire_doors_provided = models.BooleanField(default=False)
    exits_fire_door_construction = models.CharField(max_length=254,
                                                    blank=True,
                                                    null=True)
    stairs_count = models.PositiveSmallIntegerField(blank=True,
                                                    null=True,
                                                    default=0)
    stairs_enclosure_provided = models.BooleanField(default=False)
    stairs_enclosure_construction = models.CharField(max_length=254,
                                                     blank=True,
                                                     null=True)
    stairs_fire_doors_provided = models.BooleanField(default=False)
    stairs_fire_door_construction = models.CharField(max_length=254,
                                                     blank=True,
                                                     null=True)
    other_details = models.CharField(max_length=1024, blank=True, null=True)

    # Emergency equipment
    emergency_light = models.BooleanField(default=False)
    exit_signs_illuminated = models.BooleanField(default=False)
    fire_extinguisher_count = models.PositiveSmallIntegerField(blank=True,
                                                               null=True,
                                                               default=0)
    fire_extinguisher_accessible = models.BooleanField(default=False)
    fire_extinguisher_conspicuous_location = models.BooleanField(default=False)
    fire_alarm = models.BooleanField(default=False)
    detectors = models.BooleanField(default=False)
    control_panel_location = models.CharField(max_length=254,
                                              blank=True,
                                              null=True)
    control_panel_functional = models.BooleanField(default=False)

    # Flammables
    hazardous_materials = models.BooleanField(default=False)
    hazardous_materials_properly_stored = models.BooleanField(default=False)
    no_smoking_sign = models.BooleanField(default=False)
    smoking_permitted = models.BooleanField(default=False)
    smoking_area_location = models.CharField(max_length=254,
                                             blank=True,
                                             null=True)
    storage_location = models.CharField(max_length=254, blank=True, null=True)
    safety_device_for_lpg = models.BooleanField(default=False)
    oven_used = models.CharField(max_length=254, blank=True, null=True)
    kind_of_fuel = models.CharField(max_length=254, blank=True, null=True)
    smoke_hood = models.CharField(max_length=254, blank=True, null=True)
    spark_arrester = models.CharField(max_length=254, blank=True, null=True)
    partition_construction = models.CharField(max_length=254,
                                              blank=True,
                                              null=True)

    defects = models.PositiveSmallIntegerField(blank=True,
                                               null=True,
                                               default=0)
    building_permit_date_issued = models.DateField(null=True, blank=True)
    occupancy_permit_date_issued = models.DateField(null=True, blank=True)
    fsic_date_issued = models.DateField(null=True, blank=True)
    fire_drill_certificate_date_issued = models.DateField(null=True,
                                                          blank=True)
    violation_control_no_date_issued = models.DateField(null=True, blank=True)
    electrical_inspection_date_issued = models.DateField(null=True, blank=True)
    insurance_date_issued = models.DateField(null=True, blank=True)
    notes = models.CharField(max_length=1024, blank=True, null=True)
    recommendations = models.CharField(max_length=1024, blank=True, null=True)

    # === State ===
    active = models.BooleanField(default=True)
    status = models.PositiveSmallIntegerField(choices=STATUS_CHOICES,
                                              blank=True,
                                              null=True,
                                              default=0)
    remarks = models.PositiveIntegerField(choices=REMARKS_CHOICES,
                                          blank=True,
                                          null=True,
                                          default=1)
    meta = JSONField()

    # === Relationship Fields ===
    building = models.ForeignKey('buildings.Building',
                                 on_delete=models.CASCADE,
                                 null=False,
                                 db_index=False,
                                 related_name='building_checklist',
                                 blank=False)
    business = models.ForeignKey('business.Business',
                                 on_delete=models.CASCADE,
                                 null=True,
                                 db_index=False,
                                 related_name='business_checklists',
                                 blank=True)
    inspection = models.ForeignKey('inspections.InspectionSchedule',
                                   on_delete=models.CASCADE,
                                   null=True,
                                   db_index=False,
                                   related_name='inspection_checklist',
                                   blank=True)
    date_checked = models.ForeignKey('datesdim.DateDim',
                                     blank=True,
                                     null=True,
                                     on_delete=models.SET_NULL,
                                     related_name='date_checked_checklist')
    created_by = models.ForeignKey('accounts.Account',
                                   on_delete=models.SET_NULL,
                                   null=True,
                                   db_index=False,
                                   related_name='created_checklists',
                                   blank=True)
    last_updated_by = models.ForeignKey('accounts.Account',
                                        on_delete=models.SET_NULL,
                                        null=True,
                                        db_index=False,
                                        related_name='updated_checklists',
                                        blank=True)

    # Manager
    objects = ChecklistManager()

    analytics_features = [
        'defects',
    ]

    class Meta:
        ordering = ('date_checked', )
        verbose_name = "Checklist"
        verbose_name_plural = "Checklists"

    ################################################################################
    # === Builtin methods ===
    ################################################################################
    def __str__(self):
        return f'{self.business.name}'

    ################################################################################
    # === Model overrides ===
    ################################################################################
    def clean(self, *args, **kwargs):
        # add custom validation here
        super().clean(*args, **kwargs)

    def save(self, *args, **kwargs):
        # self.full_clean()
        super().save(*args, **kwargs)

    ################################################################################
    # === Model-specific methods ===
    ################################################################################
    def get_full_name(self):
        if self.middle_name:
            return f'{self.first_name} {self.middle_name[0]}. {self.last_name}'
        return f'{self.first_name} {self.last_name}'

    def get_boolean_fields(self):
        field_count = 0

        for field in Checklist._meta.fields:
            if isinstance(field, BooleanField):
                if field.name not in EXCLUDE_FIELDS:
                    field_count += 1

        return field_count

    def count_score(self):
        score = 0
        fields = []

        for field in Checklist._meta.fields:
            if isinstance(field, BooleanField):
                if field.name not in EXCLUDE_FIELDS:
                    fields.append(field.name)
                    score += getattr(self, field.name)

        return score

    def avg_checklist_rating(self):
        field_count = self.get_boolean_fields()

        total = self.count_score()
        if total != 0:
            avg = total / field_count

            return avg
        return 0

    def percentage_checklist_rating(self):
        field_count = self.get_boolean_fields()
        score_percentage = self.count_score() / field_count * 100

        return score_percentage

    def result(self):
        rating = self.percentage_checklist_rating()
        if rating >= 85:
            return True
        else:
            return False

    def risk(self):
        chance_of_fire = 0.001

        if self.hazardous_materials:
            chance_of_fire += 0.20

        if self.smoking_permitted:
            chance_of_fire += 0.01

        if not self.hazardous_materials_properly_stored:
            chance_of_fire += 0.15

        if not self.safety_device_for_lpg:
            chance_of_fire += 0.15

        if not self.defects:
            self.defects = 0

        if 0 < self.defects <= 100:
            chance_of_fire += self.defects * 0.01

        if self.defects > 100:
            chance_of_fire += .22

        return chance_of_fire
示例#13
0
文件: forms.py 项目: z-station/cappa
class TaskAdminForm(forms.ModelForm):
    class Meta:
        model = Task
        fields = '__all__'

    tests = JSONField(label='Тесты', widget=JsonWidget, required=False)
示例#14
0
class JSONFilter(Filter):
    field_class = JSONField()
示例#15
0
class ApplicationForm(forms.Form):
    def get_grad_years():
        year = date.today().year
        grad_years = [(year, str(year))]
        for i in range(4):
            year += 1
            grad_years.append((year, str(year)))
        return grad_years

    def get_course_choices():
        course_choices = [('', 'No preference')]
        sem = get_year_and_semester_code(get_current_semester())
        current_semester = Semester.objects.filter(year=sem[0],
                                                   semester_code=sem[1])[0]
        current_courses = list(
            Course.objects.filter(semester=current_semester).values_list(
                'name', flat=True).distinct())
        for course in current_courses:
            if (course, course) in course_choices:
                continue
            course_choices.append((course, course))
        return course_choices

    def get_prof_choices():
        prof_choices = [('', 'No preference')]
        sem = get_year_and_semester_code(get_current_semester())
        current_semester = Semester.objects.filter(year=sem[0],
                                                   semester_code=sem[1])[0]
        prof_ids = list(
            Course.objects.filter(semester=current_semester).values_list(
                'instructor', flat=True).distinct())
        profs = []
        for prof in prof_ids:
            profs.append(Instructor.objects.get(id=prof))
        for prof in profs:
            if (prof, prof) in prof_choices:
                continue
            prof_choices.append((prof, prof))
        return prof_choices

    course1 = forms.ChoiceField(choices=get_course_choices,
                                required=False,
                                label='Course Preference 1')
    course2 = forms.ChoiceField(choices=get_course_choices,
                                required=False,
                                label='Course Preference 2')
    course3 = forms.ChoiceField(choices=get_course_choices,
                                required=False,
                                label='Course Preference 3')
    prof1 = forms.ChoiceField(choices=get_prof_choices,
                              required=False,
                              label='Professor Preference 1')
    prof2 = forms.ChoiceField(choices=get_prof_choices,
                              required=False,
                              label='Professor Preference 2')
    prof3 = forms.ChoiceField(choices=get_prof_choices,
                              required=False,
                              label='Professor Preference 3')
    major = forms.CharField(max_length=200, label='Major(s)')
    grad_year = forms.ChoiceField(choices=get_grad_years,
                                  label='Graduation Year')
    lab_hour_data = JSONField(widget=forms.HiddenInput(), required=False)
示例#16
0
class Profile(models.Model):
    # Fields
    first_name = models.CharField(max_length=32, blank=True, null=True, default='')
    middle_name = models.CharField(max_length=32, blank=True, null=True, default='')
    last_name = models.CharField(max_length=32, blank=True, null=True, default='')
    date_of_birth = models.DateField(default=None, blank=True, null=True)

    created = models.DateTimeField(null=False, auto_now_add=True)
    updated = models.DateTimeField(null=False, auto_now=True)

    # Relationship Fields
    gender = models.ForeignKey(Gender, related_name='gender_profiles', on_delete=models.SET_NULL, null=True, blank=True)
    account = models.OneToOneField(
        'accounts.Account',
        on_delete=models.SET_NULL,
        null=True,
        blank=True
    )

    meta = JSONField()

    objects = ProfileManager()

    class Meta:
        ordering = ('account', '-created')

    def __str__(self):
        return self.get_full_name()

    def as_html(self):
        html = f"<p class='kv-pair kv-pair-center'><span class='kv-key'>Full Name</span><span class='kv-value'>{self.get_full_name()}</p>" \
            f"<p class='kv-pair kv-pair-center'><span class='kv-key'>Sex</span><span class='kv-value'>{self.gender}</p>" \
            f"<p class='kv-pair kv-pair-center'><span class='kv-key'>Date of Birth</span><span class='kv-value'>{self.date_of_birth}</p>"
        return html

    def get_casual_name(self):
        if self.first_name != '':
            return self.first_name
        return 'Unnamed'

    def get_name(self):
        if self.first_name != '' and self.last_name != '':
            return '{} {}'.format(
                self.first_name, self.last_name
            )
        else:
            if self.account.username is not None:
                return self.account.username
            return self.account.email

    def get_full_name(self):
        if self.first_name != '' and self.last_name != '':
            return '{}, {}'.format(
                self.last_name, self.first_name
            )
        else:
            try:
                if self.account.username is not None:
                    return self.account.username
            except AttributeError:
                return 'Unnamed'
            return 'Unnamed'
示例#17
0
class LabHourPreferencesForm(forms.Form):
    lab_hour_data = JSONField(widget=forms.HiddenInput(), required=False)
示例#18
0
class LabHourConstraintsForm(forms.Form):
    semester = forms.CharField(widget=forms.HiddenInput(), required=False)
    lab_hour_data = JSONField(widget=forms.HiddenInput(), required=False)
示例#19
0
class Incident(models.Model):
    """
    The Incident class defines the master data model for Incident
    ## Fields
    **Basic**
    - created: DateTime
    - updated: DateTime

    **Identifiers**
    - name: Char(120)
    - slug: auto from name

    **Properties**

    **State**
    - active:bool
    - meta: JSON

    **Relationship Fields**
    - created_by: Account defined <em>defined in accounts.models</em>
    - last_updated_by: Account defined <em>defined in accounts.models</em>

    ## **Builtin methods**
    - __str__: returns a string representation of the object

    **Model overrides**
    - clean: exposed for placeholder of custom validation
    - save: auto-call full_clean() parent method

    **Model-specific methods**

    **Signals**
    - scaffold_post_save: post-save trigger
    - scaffold_pre_save: pre-save trigger

    """

    # === Basic ===
    created = models.DateTimeField(null=False, auto_now_add=True)
    updated = models.DateTimeField(null=False, auto_now=True)

    # === Identifiers ===

    # === Properties ===
    first_name = models.CharField(max_length=60, blank=True, null=True)
    last_name = models.CharField(max_length=60, blank=True, null=True)
    middle_name = models.CharField(max_length=60, blank=True, null=True)
    phone = models.CharField(max_length=16, blank=True, null=True)
    address = models.CharField(max_length=1024)
    image = models.ImageField(upload_to=photo_upload_path, max_length=512, blank=True, null=True)
    incident_type = models.CharField(choices=INCIDENT_TYPE_CHOICES, max_length=50, blank=False, null=False)

    # === State ===
    active = models.BooleanField(default=True)
    meta = JSONField()

    # === Relationship Fields ===
    building = models.ForeignKey(
        'buildings.Building',
        blank=True,
        null=True,
        related_name='incident_building',
        on_delete=models.SET_NULL
    )
    business = models.ForeignKey(
        'business.Business',
        blank=True,
        null=True,
        on_delete=models.SET_NULL,
        related_name='incident_business'
    )
    region = models.ForeignKey(
        'locations.Region',
        blank=True,
        null=False,
        default=6,
        related_name='incident_region',
        on_delete=models.CASCADE
    )
    province = models.ForeignKey(
        'locations.Province',
        blank=True,
        null=False,
        default=4,
        related_name='incident_province',
        on_delete=models.CASCADE
    )
    city = models.ForeignKey(
        'locations.City',
        blank=True,
        null=False,
        related_name='incident_city',
        on_delete=models.CASCADE
    )

    occurrence = models.ForeignKey(
        'datesdim.DateDim',
        blank=True,
        null=True,
        on_delete=models.CASCADE,
        related_name='incident_datetime'
    )

    created_by = models.ForeignKey(
        'accounts.Account',
        on_delete=models.SET_NULL,
        null=True,
        db_index=False,
        related_name='created_incidents',
        blank=True
    )
    last_updated_by = models.ForeignKey(
        'accounts.Account',
        on_delete=models.SET_NULL,
        null=True,
        db_index=False,
        related_name='updated_incidents',
        blank=True
    )

    # Manager
    objects = IncidentManager()

    class Meta:
        ordering = ('first_name',)
        verbose_name = "Incident"
        verbose_name_plural = "Incidents"

    ################################################################################
    # === Builtin methods ===
    ################################################################################
    def __str__(self):
        return f'{self.first_name} {self.last_name}'

    ################################################################################
    # === Model overrides ===
    ################################################################################
    def clean(self, *args, **kwargs):
        # add custom validation here
        super().clean(*args, **kwargs)

    def save(self, *args, **kwargs):
        # self.full_clean()
        super().save(*args, **kwargs)
class Incident(models.Model):
    """
    The Incident class defines the master data model for Incident
    ## Fields
    **Basic**
    - created: DateTime
    - updated: DateTime

    **Identifiers**
    - name: Char(120)
    - slug: auto from name

    **Properties**

    **State**
    - active:bool
    - meta: JSON

    **Relationship Fields**
    - created_by: Account defined <em>defined in accounts.models</em>
    - last_updated_by: Account defined <em>defined in accounts.models</em>

    ## **Builtin methods**
    - __str__: returns a string representation of the object

    **Model overrides**
    - clean: exposed for placeholder of custom validation
    - save: auto-call full_clean() parent method

    **Model-specific methods**

    **Signals**
    - scaffold_post_save: post-save trigger
    - scaffold_pre_save: pre-save trigger

    """

    # === Basic ===
    created = models.DateTimeField(null=False, auto_now_add=True)
    updated = models.DateTimeField(null=False, auto_now=True)

    # === Identifiers ===

    # === Properties ===
    first_name = models.CharField(max_length=60, blank=True, null=True)
    last_name = models.CharField(max_length=60, blank=True, null=True)
    middle_name = models.CharField(max_length=60, blank=True, null=True)
    phone = models.CharField(max_length=16, blank=True, null=True)
    address = models.CharField(max_length=1024)
    image = models.ImageField(upload_to=photo_upload_path,
                              max_length=512,
                              blank=True,
                              null=True)
    incident_type = models.CharField(choices=INCIDENT_TYPE_CHOICES,
                                     max_length=50,
                                     blank=False,
                                     null=False)
    property_damage = models.DecimalField(
        help_text="Value of property damage in tens of thousands of pesos",
        default=1,
        decimal_places=2,
        max_digits=12,
        blank=True,
        null=True)
    casualties = models.PositiveSmallIntegerField(default=0,
                                                  blank=True,
                                                  null=True)
    major_injuries = models.PositiveSmallIntegerField(default=0,
                                                      blank=True,
                                                      null=True)
    minor_injuries = models.PositiveSmallIntegerField(default=0,
                                                      blank=True,
                                                      null=True)
    intensity = models.PositiveSmallIntegerField(default=1,
                                                 help_text="Scale of 1 to 10")
    severity = models.PositiveSmallIntegerField(default=1,
                                                help_text="Scale of 1 to 10")
    duration = models.PositiveSmallIntegerField(
        default=1, help_text="Duration in minutes")

    # === State ===
    active = models.BooleanField(default=True)
    meta = JSONField()

    # === Relationship Fields ===
    building = models.ForeignKey('buildings.Building',
                                 blank=True,
                                 null=True,
                                 related_name='incident_building',
                                 on_delete=models.SET_NULL)
    business = models.ForeignKey('business.Business',
                                 blank=True,
                                 null=True,
                                 on_delete=models.SET_NULL,
                                 related_name='incident_business')
    region = models.ForeignKey('locations.Region',
                               blank=True,
                               null=False,
                               default=6,
                               related_name='incident_region',
                               on_delete=models.CASCADE)
    province = models.ForeignKey('locations.Province',
                                 blank=True,
                                 null=False,
                                 default=4,
                                 related_name='incident_province',
                                 on_delete=models.CASCADE)
    city = models.ForeignKey('locations.City',
                             blank=True,
                             null=False,
                             related_name='incident_city',
                             on_delete=models.CASCADE)

    occurrence = models.ForeignKey('datesdim.DateDim',
                                   blank=True,
                                   null=True,
                                   on_delete=models.CASCADE,
                                   related_name='incident_datetime')

    created_by = models.ForeignKey('accounts.Account',
                                   on_delete=models.SET_NULL,
                                   null=True,
                                   db_index=False,
                                   related_name='created_incidents',
                                   blank=True)
    last_updated_by = models.ForeignKey('accounts.Account',
                                        on_delete=models.SET_NULL,
                                        null=True,
                                        db_index=False,
                                        related_name='updated_incidents',
                                        blank=True)

    # Manager
    objects = IncidentManager()

    analytics_features = [
        'property_damage',
        'casualties',
        'major_injuries',
        'minor_injuries',
        'intensity',
        'severity',
        'duration',
    ]

    class Meta:
        ordering = ('first_name', )
        verbose_name = "Incident"
        verbose_name_plural = "Incidents"

    ################################################################################
    # === Builtin methods ===
    ################################################################################
    def __str__(self):
        return f'{self.building} - {self.created.date()}'

    def get_full_name(self):
        if self.first_name != '' and self.last_name != '':
            return '{}, {}'.format(self.last_name, self.first_name)
        else:
            return 'Unnamed'

    ################################################################################
    # === Model overrides ===
    ################################################################################
    def clean(self, *args, **kwargs):
        # add custom validation here
        super().clean(*args, **kwargs)

    def save(self, *args, **kwargs):
        # self.full_clean()
        super().save(*args, **kwargs)
class BusinessEvaluation(models.Model):
  """
    The BusinessEvaluation class defines the master data model for BusinessEvaluation
    ## Fields
    **Basic**
    - created: DateTime
    - updated: DateTime

    **Identifiers**

    **Properties**

    **State**
    - active:bool
    - meta: JSON

    **Relationship Fields**
    - created_by: Account defined <em>defined in accounts.models</em>
    - last_updated_by: Account defined <em>defined in accounts.models</em>

    ## **Builtin methods**
    - __str__: returns a string representation of the object

    **Model overrides**
    - clean: exposed for placeholder of custom validation
    - save: auto-call full_clean() parent method

    **Model-specific methods**

    **Signals**
    - scaffold_post_save: post-save trigger
    - scaffold_pre_save: pre-save trigger

    """

  # === Basic ===
  created = models.DateTimeField(null=False, auto_now_add=True)
  updated = models.DateTimeField(null=False, auto_now=True)

  # === Identifiers ===

  # === Properties ===
  architectural = models.BooleanField(default=False)
  structural = models.BooleanField(default=False)
  electrical = models.BooleanField(default=False)
  mechanical = models.BooleanField(default=False)
  license_of_involved_professional = models.BooleanField(default=False)
  plumbing = models.BooleanField(default=False)
  electronics = models.BooleanField(default=False)
  sanitary = models.BooleanField(default=False)
  fire_protection_plan = models.BooleanField(default=False)
  estimated_cost = models.BooleanField(default=False)

  # === State ===
  approved = models.BooleanField(default=False)
  meta = JSONField()

  # === Relationship Fields ===
  business = models.ForeignKey('business.Business', on_delete=models.CASCADE, related_name='business_evaluation')
  date_evaluated = models.ForeignKey('datesdim.DateDim', blank=True, null=True, on_delete=models.CASCADE, related_name='datetime_evaluated')

  # Manager
  objects = BusinessEvaluationManager()

  class Meta:
    ordering = ('-created',)
    verbose_name = "Business Evaluation"
    verbose_name_plural = "Business Evaluations"

  ################################################################################
  # === Builtin methods ===
  ################################################################################
  def __str__(self):
    return self.business.name

  ################################################################################
  # === Model overrides ===
  ################################################################################
  def clean(self, *args, **kwargs):
    # add custom validation here
    super().clean(*args, **kwargs)

  def save(self, *args, **kwargs):
    # self.full_clean()
    super().save(*args, **kwargs)
示例#22
0
class Building(models.Model):
    """
    The Building class defines the master data model for Building
    ## Fields
    **Basic**
    - created: DateTime
    - updated: DateTime

    **Identifiers**
    - name: Char(120)
    - slug: auto from name

    **Properties**

    **State**
    - active:bool
    - meta: JSON

    **Relationship Fields**
    - created_by: Account defined <em>defined in accounts.models</em>
    - last_updated_by: Account defined <em>defined in accounts.models</em>

    ## **Builtin methods**
    - __str__: returns a string representation of the object

    **Model overrides**
    - clean: exposed for placeholder of custom validation
    - save: auto-call full_clean() parent method

    **Model-specific methods**

    **Signals**
    - scaffold_post_save: post-save trigger
    - scaffold_pre_save: pre-save trigger

    """

    # === Basic ===
    created = models.DateTimeField(null=False, auto_now_add=True)
    updated = models.DateTimeField(null=False, auto_now=True)

    # === Identifiers ===
    name = models.CharField(max_length=120)
    slug = extension_fields.AutoSlugField(populate_from='name', blank=True)

    # === Properties ===
    address = models.CharField(max_length=120, blank=True, null=True)
    floor_number = models.PositiveSmallIntegerField(blank=True, null=True)
    height = models.FloatField(blank=True, null=True)
    floor_area = models.FloatField(blank=True, null=True)
    total_floor_area = models.FloatField(blank=True, null=True)
    beams = models.PositiveSmallIntegerField(blank=True, null=True)
    columns = models.PositiveSmallIntegerField(blank=True, null=True)
    flooring = models.FloatField(blank=True, null=True)
    exterior_walls = models.FloatField(blank=True, null=True)
    corridor_walls = models.FloatField(blank=True, null=True)
    room_partitions = models.PositiveSmallIntegerField(blank=True, null=True)
    main_stair = models.PositiveSmallIntegerField(blank=True, null=True)
    window = models.PositiveSmallIntegerField(blank=True, null=True)
    ceiling = models.PositiveSmallIntegerField(blank=True, null=True)
    main_door = models.PositiveSmallIntegerField(blank=True, null=True)
    trusses = models.PositiveSmallIntegerField(blank=True, null=True)
    roof = models.BooleanField()
    latitude = models.CharField(max_length=24, blank=True, null=True)
    longitude = models.CharField(max_length=24, blank=True, null=True)

    # === State ===
    active = models.BooleanField(default=True)
    meta = JSONField()

    # === Relationship Fields ===
    created_by = models.ForeignKey('accounts.Account',
                                   on_delete=models.SET_NULL,
                                   null=True,
                                   db_index=False,
                                   related_name='created_buildings',
                                   blank=True)
    last_updated_by = models.ForeignKey('accounts.Account',
                                        on_delete=models.SET_NULL,
                                        null=True,
                                        db_index=False,
                                        related_name='updated_buildings',
                                        blank=True)

    region = models.ForeignKey('locations.Region',
                               on_delete=models.SET_NULL,
                               null=True,
                               related_name='region_building',
                               blank=True)
    province = models.ForeignKey('locations.Province',
                                 on_delete=models.SET_NULL,
                                 null=True,
                                 related_name='province_building',
                                 blank=True)
    city = models.ForeignKey('locations.City',
                             on_delete=models.SET_NULL,
                             null=True,
                             related_name='city_building',
                             blank=True)

    # Manager
    objects = BuildingManager()

    class Meta:
        ordering = ('name', )
        verbose_name = "Building"
        verbose_name_plural = "Buildings"

    ################################################################################
    # === Builtin methods ===
    ################################################################################
    def __str__(self):
        return f'{self.name}'

    ################################################################################
    # === Model overrides ===
    ################################################################################
    def clean(self, *args, **kwargs):
        # add custom validation here
        super().clean(*args, **kwargs)

    def save(self, *args, **kwargs):
        # self.full_clean()
        super().save(*args, **kwargs)
示例#23
0
class Business(models.Model):
    """
      The Business class defines the master data model for Business
      ## Fields
      **Basic**
      - created: DateTime
      - updated: DateTime

      **Identifiers**

      **Properties**

      **State**
      - active:bool
      - meta: JSON

      **Relationship Fields**
      - created_by: Account defined <em>defined in accounts.models</em>
      - last_updated_by: Account defined <em>defined in accounts.models</em>

      ## **Builtin methods**
      - __str__: returns a string representation of the object

      **Model overrides**
      - clean: exposed for placeholder of custom validation
      - save: auto-call full_clean() parent method

      **Model-specific methods**

      **Signals**
      - scaffold_post_save: post-save trigger
      - scaffold_pre_save: pre-save trigger

      """

    # === Basic ===
    created = models.DateTimeField(null=False, auto_now_add=True)
    updated = models.DateTimeField(null=False, auto_now=True)

    # === Identifiers ===

    # === Properties ===
    name = models.CharField(blank=False,
                            max_length=254,
                            null=False,
                            unique=True)
    nature = models.CharField(blank=True, max_length=254, null=True)
    owner_first_name = models.CharField(blank=True, max_length=42, null=True)
    owner_middle_name = models.CharField(blank=True, max_length=42, null=True)
    owner_last_name = models.CharField(blank=True, max_length=42, null=True)
    address = models.CharField(max_length=254, blank=True, null=True)
    landline = models.CharField(max_length=16, blank=True, null=True)
    mobile_number = PhoneNumberField(blank=True, null=True)
    email = models.EmailField(max_length=254,
                              unique=True,
                              verbose_name='email address')

    # === State ===
    active = models.BooleanField(default=True)
    meta = JSONField()

    # === Relationship Fields ===
    building = models.ForeignKey('buildings.Building',
                                 blank=True,
                                 null=True,
                                 on_delete=models.SET_NULL,
                                 related_name='building_business')
    region = models.ForeignKey('locations.Region',
                               blank=True,
                               default=6,
                               null=False,
                               on_delete=models.CASCADE,
                               related_name='region_business')
    province = models.ForeignKey('locations.Province',
                                 blank=True,
                                 default=22,
                                 null=False,
                                 on_delete=models.CASCADE,
                                 related_name='province_business')
    city = models.ForeignKey('locations.City',
                             blank=True,
                             default=381,
                             null=False,
                             on_delete=models.CASCADE,
                             related_name='province_business')

    # Manager
    objects = BusinessManager()

    class Meta:
        ordering = ('-created', )
        verbose_name = "Business"
        verbose_name_plural = "Businesses"
        unique_together = ('email', )

    ################################################################################
    # === Builtin methods ===
    ################################################################################
    def __str__(self):
        return self.name

    ################################################################################
    # === Model overrides ===
    ################################################################################
    def clean(self, *args, **kwargs):
        # add custom validation here
        super().clean(*args, **kwargs)

    def save(self, *args, **kwargs):
        # self.full_clean()
        super().save(*args, **kwargs)