Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
table_name = 'test_complex_model_async'
host = settings.DYNAMODB_HOST
id = NumberAttribute(hash_key=True)
list_attr = ListAttribute(default=[])
name = UnicodeAttribute()
description = UnicodeAttribute()
class TestComplexModelSync(PynamoDBModel):
class Meta:
table_name = 'test_complex_model_sync'
host = settings.DYNAMODB_HOST
id = NumberAttribute(hash_key=True)
list_attr = ListAttribute(default=[])
name = UnicodeAttribute()
description = UnicodeAttribute()
tab.set_document_tab_page(tab_data['page'])
self.add_document_tab(tab)
class ProjectModel(BaseModel):
"""
Represents a project in the database.
"""
class Meta:
"""Meta class for Project."""
table_name = 'cla-{}-projects'.format(stage)
if stage == 'local':
host = 'http://localhost:8000'
project_id = UnicodeAttribute(hash_key=True)
project_external_id = UnicodeAttribute()
project_name = UnicodeAttribute()
project_individual_documents = ListAttribute(of=DocumentModel, default=[])
project_corporate_documents = ListAttribute(of=DocumentModel, default=[])
project_icla_enabled = BooleanAttribute(default=True)
project_ccla_enabled = BooleanAttribute(default=True)
project_ccla_requires_icla_signature = BooleanAttribute(default=False)
project_external_id_index = ExternalProjectIndex()
project_acl = UnicodeSetAttribute(default=set())
class Project(model_interfaces.Project): # pylint: disable=too-many-public-methods
"""
ORM-agnostic wrapper for the DynamoDB Project model.
"""
def __init__(self, project_id=None, project_external_id=None, project_name=None,
project_icla_enabled=True, project_ccla_enabled=True,
project_ccla_requires_icla_signature=False,
project_acl=None):
super(Project).__init__()
signature_project_external_id = UnicodeAttribute(null=True)
signature_company_signatory_id = UnicodeAttribute(null=True)
signature_company_signatory_name = UnicodeAttribute(null=True)
signature_company_signatory_email = UnicodeAttribute(null=True)
signature_company_initial_manager_id = UnicodeAttribute(null=True)
signature_company_initial_manager_name = UnicodeAttribute(null=True)
signature_company_initial_manager_email = UnicodeAttribute(null=True)
signature_company_secondary_manager_list = JSONAttribute(null=True)
signature_company_signatory_index = SignatureCompanySignatoryIndex()
signature_company_initial_manager_index = SignatureCompanyInitialManagerIndex()
project_signature_external_id_index = SignatureProjectExternalIndex()
# whitelists are only used by CCLAs
domain_whitelist = ListAttribute(null=True)
email_whitelist = ListAttribute(null=True)
github_whitelist = ListAttribute(null=True)
github_org_whitelist = ListAttribute(null=True)
class Signature(model_interfaces.Signature): # pylint: disable=too-many-public-methods
"""
ORM-agnostic wrapper for the DynamoDB Signature model.
"""
def __init__(
self, # pylint: disable=too-many-arguments
signature_id=None,
signature_external_id=None,
signature_project_id=None,
signature_document_minor_version=None,
signature_document_major_version=None,
signature_reference_id=None,
@convert_pynamo_attribute.register(attributes.ListAttribute)
def convert_list_to_list(type, attribute, registry=None):
if attribute.element_type:
try:
name = attribute.attr_name
except KeyError:
name = "MapAttribute"
required = not attribute.null if hasattr(attribute, 'null') else False
return ListOfMapToObject(description=name, required=required)
else:
return List(String, description=attribute.attr_name)
from bs4 import BeautifulSoup
from pynamodb.models import Model
from pynamodb.attributes import UnicodeAttribute, ListAttribute
class PortalKeyword(Model):
"""
A DynamoDB Keyword
"""
class Meta:
table_name = "PortalKeyword"
region = 'ap-northeast-2'
portal = UnicodeAttribute(hash_key=True)
createdAt = UnicodeAttribute(range_key=True)
keywords = ListAttribute()
def naver_keywords_crawler():
created_at = datetime.datetime.utcnow().isoformat()[:19]
naver_keywords = []
try:
naver_resp = requests.get('https://www.naver.com/')
naver_soup = BeautifulSoup(naver_resp.text, 'html.parser')
for i, tag in enumerate(naver_soup.find_all('span', {'class':'ah_k'})[:20]):
rank = i+1
keyword = tag.get_text()
naver_keywords.append({'rank': rank, 'keyword': keyword})
note = UnicodeAttribute(null=True)
signature_project_external_id = UnicodeAttribute(null=True)
signature_company_signatory_id = UnicodeAttribute(null=True)
signature_company_signatory_name = UnicodeAttribute(null=True)
signature_company_signatory_email = UnicodeAttribute(null=True)
signature_company_initial_manager_id = UnicodeAttribute(null=True)
signature_company_initial_manager_name = UnicodeAttribute(null=True)
signature_company_initial_manager_email = UnicodeAttribute(null=True)
signature_company_secondary_manager_list = JSONAttribute(null=True)
signature_company_signatory_index = SignatureCompanySignatoryIndex()
signature_company_initial_manager_index = SignatureCompanyInitialManagerIndex()
project_signature_external_id_index = SignatureProjectExternalIndex()
# whitelists are only used by CCLAs
domain_whitelist = ListAttribute(null=True)
email_whitelist = ListAttribute(null=True)
github_whitelist = ListAttribute(null=True)
github_org_whitelist = ListAttribute(null=True)
class Signature(model_interfaces.Signature): # pylint: disable=too-many-public-methods
"""
ORM-agnostic wrapper for the DynamoDB Signature model.
"""
def __init__(
self, # pylint: disable=too-many-arguments
signature_id=None,
signature_external_id=None,
signature_project_id=None,
signature_document_minor_version=None,
signature_document_major_version=None,
def has_map_or_list_attributes(cls):
for attr_value in cls._get_attributes().values():
if isinstance(attr_value, MapAttribute) or isinstance(attr_value, ListAttribute):
return True
return False
signature_reference_id = UnicodeAttribute()
signature_reference_type = UnicodeAttribute()
signature_type = UnicodeAttribute(default='cla')
signature_signed = BooleanAttribute(default=False)
signature_approved = BooleanAttribute(default=False)
signature_sign_url = UnicodeAttribute(null=True)
signature_return_url = UnicodeAttribute(null=True)
signature_callback_url = UnicodeAttribute(null=True)
signature_user_ccla_company_id = UnicodeAttribute(null=True)
signature_project_index = ProjectSignatureIndex()
signature_reference_index = ReferenceSignatureIndex()
# Callback type refers to either Gerrit or GitHub
signature_return_url_type = UnicodeAttribute(null=True)
# whitelists are only used by CCLAs
domain_whitelist = ListAttribute(null=True)
email_whitelist = ListAttribute(null=True)
class Signature(model_interfaces.Signature): # pylint: disable=too-many-public-methods
"""
ORM-agnostic wrapper for the DynamoDB Signature model.
"""
def __init__(self, # pylint: disable=too-many-arguments
signature_id=None,
signature_external_id=None,
signature_project_id=None,
signature_document_minor_version=None,
signature_document_major_version=None,
signature_reference_id=None,
signature_reference_type='user',
signature_type=None,
signature_signed=False,
Represents a project in the database.
"""
class Meta:
"""Meta class for Project."""
table_name = "cla-{}-projects".format(stage)
if stage == "local":
host = "http://localhost:8000"
project_id = UnicodeAttribute(hash_key=True)
project_external_id = UnicodeAttribute()
project_name = UnicodeAttribute()
project_name_lower = UnicodeAttribute(null=True)
project_individual_documents = ListAttribute(of=DocumentModel, default=[])
project_corporate_documents = ListAttribute(of=DocumentModel, default=[])
project_member_documents = ListAttribute(of=DocumentModel, default=[])
project_icla_enabled = BooleanAttribute(default=True)
project_ccla_enabled = BooleanAttribute(default=True)
project_ccla_requires_icla_signature = BooleanAttribute(default=False)
project_external_id_index = ExternalProjectIndex()
project_acl = UnicodeSetAttribute(default=set())
class Project(model_interfaces.Project): # pylint: disable=too-many-public-methods
"""
ORM-agnostic wrapper for the DynamoDB Project model.
"""
def __init__(
self,
project_id=None,
rval.append({attr_key: attr_class.serialize(v)})
return rval
def deserialize(self, values):
"""
Decode from list of AttributeValue types.
"""
deserialized_lst = []
for v in values:
class_for_deserialize = self.element_type() if self.element_type else _get_class_for_deserialize(v)
attr_value = _get_value_for_deserialize(v)
deserialized_lst.append(class_for_deserialize.deserialize(attr_value))
return deserialized_lst
DESERIALIZE_CLASS_MAP = {
LIST_SHORT: ListAttribute(),
NUMBER_SHORT: NumberAttribute(),
STRING_SHORT: UnicodeAttribute(),
BOOLEAN: BooleanAttribute(),
MAP_SHORT: MapAttribute(),
NULL: NullAttribute()
}
SERIALIZE_CLASS_MAP = {
dict: MapAttribute(),
list: ListAttribute(),
set: ListAttribute(),
bool: BooleanAttribute(),
float: NumberAttribute(),
int: NumberAttribute(),
str: UnicodeAttribute(),
}