This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Drupal\nypl_ip_checker\Form; | |
/** | |
* @file | |
* Contains \Drupal\contact_info\Form\NyplIpCheckerAdminForm. | |
*/ | |
use Drupal\Core\Config\ConfigFactoryInterface; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.a11y--skip-hide { | |
background: #444; | |
color: #fff; | |
position: relative; | |
text-align: center; | |
} | |
.a11y--skip-hide a { | |
color: #fff; | |
display: block; | |
height: 1px; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@dataclass | |
class AttributeCriteria: | |
attribute_type: LocationAttributeType | |
display_value: str | |
operators: List[CriteriaOperator] | |
choices: List[AttributeCriteriaChoice] | |
def __post_init__(self): | |
for idx, operator in enumerate(self.operators): | |
if isinstance(operator, str): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
init_dict = dict( | |
attribute_key=REGION_KEY, | |
display_value="Regions", | |
operators=[EQ_OPERATOR, IN_OPERATOR], | |
choices=[dict(value=42, display_value="West Coast"), ...] | |
) | |
attribute_criteria_example = AttributeCriteria(**init_dict) | |
# attribute_criteria.choices[0] is a dict not a AttributeCriteriaChoice as we would hope! | |
# This is true for a dataclass as well as this example of a list of dataclasses |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ExampleModel(models.Model): | |
... | |
json_attributes = DataclassJSONField( | |
default=None, blank=True, null=True, dataclass_cls=AttributeCriteriaFilters | |
) | |
model = ExampleModel.objects.first() | |
assert dataclasses.is_dataclass(model.json_attributes)) is True |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class DataclassJSONEncoder(JSONEncoder): | |
""" JSON encoder for JSON mysql fields to handle encoding dataclasses and enum classes """ | |
def default(self, o): | |
if is_dataclass(o): | |
return dataclasses.asdict(o) | |
elif isinstance(o, Enum): | |
return o.value | |
return super().default(o) | |
class DataclassJSONField(JSONField): | |
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@dataclass | |
class AttributeCriteriaChoice: | |
value: Type[Any] | |
display_value: str | |
@dataclass | |
class AttributeCriteria: | |
attribute_key: str | |
display_value: str | |
operators: List[str] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
attribute_criteria = dict( | |
attribute_key=REGION_KEY, | |
display_value="Regions", | |
operators=[EQ_OPERATOR, IN_OPERATOR], | |
choices=[dict(value=42, display_value="West Coast"), ...] | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: petrol | |
recipe: drupal7 | |
config: | |
php: '5.6' | |
via: nginx:1.17 | |
webroot: . | |
database: mysql:5.7 | |
drush: '^7' | |
xdebug: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$view = new view(); | |
$view->name = 'd8_migrations'; | |
$view->description = 'Views Data Exports for migrating to Drupal 8'; | |
$view->tag = 'default'; | |
$view->base_table = 'node'; | |
$view->human_name = 'D8 Migrate'; | |
$view->core = 7; | |
$view->api_version = '3.0'; | |
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */ |