class Device(Document):
    serialNumberInserv = fields.StringField()
    system = fields.EmbeddedDocumentField(System)
    capacity = fields.EmbeddedDocumentField(Capacity)
    performance = fields.EmbeddedDocumentField(Performance)
    disks = fields.EmbeddedDocumentField(Disks)
    nodes = fields.DictField()
    authorized = fields.EmbeddedDocumentField(Authorized)
    updated = fields.DateTimeField()
    date = fields.DateTimeField()

    def __str__(self):
        if self.system and self.system.fullModel:
            return "{} ({})".format(self.system.fullModel,
                                    self.serialNumberInserv)
        return "{}".format(self.serialNumberInserv)

    @staticmethod
    def for_user(user_id):
        tenant = Tenant.id_for_user(user_id)
        d = Device.objects.filter(authorized__tenants=tenant)
        d._user_id = user_id
        return d

    def has_triggered(self):
        user_ids = Tenant.objects.filter(
            tenant_id__in=self.authorized.tenants).values_list('user_id')
        statuses = Status.objects.filter(device_id=str(self.id),
                                         user_id__in=user_ids)
        for s in statuses:
            if s.current_check():
                return True
        return False
Exemple #2
0
class StorageGroup(DynamicDocument):  # storage 分组
    group = fields.ReferenceField('self', blank=True, null=True)
    name = fields.StringField(max_length=200, required=True)
    ctime = fields.DateTimeField(default=datetime.datetime.now())
    utime = fields.DateTimeField(default=datetime.datetime.now())

    meta = {
        "collection": "storagegroup",
        "indexes": [
            "name",
            "ctime",
        ],
    }
Exemple #3
0
class Layer(Document):  # CI 层
    name = fields.StringField(max_length=200, unique=True, required=True)
    ctime = fields.DateTimeField(default=datetime.datetime.now())
    utime = fields.DateTimeField(default=datetime.datetime.now())

    meta = {
        "collection": "layer",
        "indexes": [
            "name",
            # "$name",
            "ctime",
        ],
    }
Exemple #4
0
class Item(DynamicDocument):  # CI 模型实例
    name = fields.StringField(max_length=200, required=True)
    group = fields.ReferenceField('Group', required=True)
    category = fields.ReferenceField(ItemCategory, required=True)
    ctime = fields.DateTimeField(default=datetime.datetime.now())
    utime = fields.DateTimeField(default=datetime.datetime.now())

    meta = {
        "collection": "item",
        "indexes": [
            "category",
            "ctime",
        ],
    }
Exemple #5
0
class Channel(Document):
    title = fields.StringField(max_lenght=100, blank=False)
    slug = fields.StringField(max_lenght=150, blank=False)
    platform = fields.StringField(default="Swachhata",
                                  choices=['Swachhata', 'ICMYC'])
    app_name = fields.StringField(blank=False)
    type = fields.StringField(blank=False)
    archived = fields.BooleanField(default=False)
    created_at = fields.DateTimeField(default=datetime.datetime.now)
    updated_at = fields.DateTimeField()

    meta = {'collection': 'channels'}

    def __str__(self):
        return self.title
Exemple #6
0
class User(Document):
    email = fields.EmailField(
        verbose_name='email address',
        max_length=255,
        unique=True,
    )
    username = fields.StringField(max_length=50, unique=True)
    password = fields.StringField(max_length=128, verbose_name=('password'))

    is_active = fields.BooleanField(default=True)
    is_staff = fields.BooleanField(default=False)
    is_admin = fields.BooleanField(default=False)
    is_superuser = fields.BooleanField(default=False)
    last_login = fields.DateTimeField(default=datetime.now,
                                      verbose_name=('last login'))
    date_joined = fields.DateTimeField(default=datetime.now,
                                       verbose_name=('date joined'))

    USERNAME_FIELD = 'username'
    REQUIRED_FIELDS = ["email"]

    #objects= UserManager()

    def __str__(self):
        return self.username

    def set_password(self, raw_password):
        self.password = make_password(raw_password)
        self.save()
        return self

    @classmethod
    def create_user(cls, username, password, email):

        now = datetime.datetime.now()

        if email is not None:
            try:
                email_name, domain_part = email.strip().split('@', 1)
            except ValueError:
                pass
            else:
                email = '@'.join([email_name, domain_part.lower()])

        user = cls(username=username, email=email, date_joined=now)
        user.set_password(password)
        user.save()
        return user
class Profile(Document):

    #user = fields.ReferenceField('User')
    user_id = fields.IntField()
    full_name = fields.StringField(max_length=191, blank=True)
    location = fields.DictField({}, blank=True)
    settings = fields.DictField({}, blank=True)
    has_at_least_one_social_account = fields.BooleanField(default=False)
    social_accounts = fields.ListField(fields.DictField({}, blank=True),
                                       blank=True)
    associated_platforms = fields.ListField(fields.DictField(), blank=True)
    channels = fields.ListField(fields.DictField(blank=True), blank=True)
    authorized_devices = fields.ListField(fields.DictField(blank=True),
                                          blank=True)
    birth_date = fields.DateTimeField(blank=True)
    roles = fields.ListField(fields.DictField({}, blank=True), blank=True)
    permissions = fields.ListField(fields.DictField({}, blank=True),
                                   blank=True)
    signed_up_with = fields.StringField(defalut="email")
    signed_up_ip_address = fields.StringField(blank=True)
    singed_up_user_agent = fields.StringField(blank=True)
    logged_in_ip_address = fields.StringField(blank=True)
    logged_in_user_agent = fields.StringField(blank=True)

    meta = {"collection": "auth_profile"}

    def __str__(self):
        return self.mobile_number

    def check_otp(self, otp):
        return check_password(otp, self.otp)
class Post(Document):
    created_at = fields.DateTimeField(
        default=datetime.datetime.now,
        required=True,
        editable=False,
    )
    title = fields.StringField(max_length=255, required=True)
    slug = fields.StringField(max_length=255, required=True, primary_key=True)
    comments = fields.ListField(fields.EmbeddedDocumentField('Comment'))

    def get_absolute_url(self):
        return reverse('post', kwargs={"slug": self.slug})

    def __unicode__(self):
        return self.title

    @property
    def post_type(self):
        return self.__class__.__name__

    meta = {
        'indexes': ['-created_at', 'slug'],
        'ordering': ['-created_at'],
        'allow_inheritance': True
    }
class AccountRequest(Document):
    """ Represents a request sent by an user to get an account
    """
    username = fields.StringField(
        blank=False)  #: Username associated with the request
    first_name = fields.StringField(blank=False)
    last_name = fields.StringField(blank=False)
    email = fields.StringField(blank=False)
    date = fields.DateTimeField(default=datetime.datetime.now, blank=False)

    @staticmethod
    def get_by_id(request_id):
        """ Get a request given its primary key

            Parameters:
                request_id (str): Primary key of the request

            Returns:
                Request object corresponding to the given id
        """
        try:
            return AccountRequest.objects().get(pk=str(request_id))
        except mongoengine_errors.DoesNotExist as e:
            raise exceptions.DoesNotExist(e.message)
        except Exception as ex:
            raise exceptions.ModelError(ex.message)
Exemple #10
0
class User(Document):
    name = fields.StringField()
    username = fields.StringField(unique=True)
    email = fields.EmailField(unique=True)

    # these 2 fields are NOT TO BE FILLED
    ratings = fields.IntField(default=0)
    date_joined = fields.DateTimeField(default=timezone.now, editable=False)

    gears = fields.ListField(fields.ReferenceField('Gear'),
                             default=[],
                             blank=True)
    password = fields.StringField(min_length=8, max_length=128)

    USERNAME_FIELD = 'username'
    REQUIRED_FIELDS = ['name', 'email', 'password']

    def __str__(self):
        return self.username

    def get_username(self):
        return self.username

    def get_name(self):
        return self.name

    def get_ratings(self):
        return self.ratings

    def is_active(self):
        return True

    def check_password(self, raw_password):
        """ Checks the password if it matches the stored password """
        return check_password(raw_password, self.password)
Exemple #11
0
class Comment(EmbeddedDocument):
    created_at = fields.DateTimeField(
        default=datetime.datetime.now, editable=False,
    )
    author = fields.StringField(verbose_name="Name", max_length=255)
    email  = fields.EmailField(verbose_name="Email", blank=True)
    body = fields.StringField(verbose_name="Comment")
Exemple #12
0
class ExchangeData(Document):
    open_time= fields.IntField()
    close_time = fields.IntField()
    price = fields.IntField()
    value = fields.IntField()
    exchnage = fields.StringField(max_length=255)
    updated = fields.DateTimeField(default=datetime.datetime.utcnow)
Exemple #13
0
class Users(Document):
	created_at = fields.DateTimeField(
		default=datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"), 
		required=True, editable=False,unique=False
	)
	user_id = fields.StringField(max_length=36,required=True,unique=True)
	username = fields.StringField(unique=True, max_length=30)
	email_id = fields.EmailField(unique=True, max_length=254)
	first_name = fields.StringField(max_length=30, required=False, allow_null=True,unique=False)
	last_name = fields.StringField(max_length=30, required=False, null=True,unique=False)
	profile_url = fields.StringField(
		default = "http://profile.ak.fbcdn.net/static-ak/rsrc.php/v2/yo/r/UlIqmHJn-SK.gif",unique=False
	)
	followed_users_list = fields.EmbeddedDocumentListField(FollowingList, required=False, 
		default= [], blank=True,unique=False)
	follower_users_list = fields.EmbeddedDocumentListField(FollowerList, required=False, 
		default= [], blank=True,unique=False)
	gender = fields.StringField(default=None,unique=False, blank=True, required=False)
	push_notifications = fields.BooleanField(default=True, unique=False)
	token = fields.StringField(default=None, blank=True)
	# phone_number = fields.StringField(min_length=10, max_length=10,blank=True, default=None, required=False)
	notifications = fields.EmbeddedDocumentListField(Notifications, required=False, 
		default= [], blank=True,unique=False)
	is_unread_notification = fields.BooleanField(default=False)
	user_bio = fields.StringField(default=None,unique=False, blank=True, required=False)
	favorite_genre = fields.StringField(default=None,unique=False, blank=True, required=False)
	favorite_artist = fields.StringField(default=None,unique=False, blank=True, required=False)
	favorite_instrument = fields.StringField(default=None,unique=False, blank=True, required=False)
	farorite_album = fields.StringField(default=None,unique=False, blank=True, required=False)
	date_of_birth = fields.StringField(default=None,blank=True, required=False)
	gender = fields.StringField(default=None,blank=True, required=False)
	pending_requests = fields.EmbeddedDocumentListField(PendingRequests, required=False, 
		default= [], blank=True,unique=False)
	requested_users = fields.EmbeddedDocumentListField(RequestedUsers, required=False, 
		default= [], blank=True,unique=False)
Exemple #14
0
class ItemCategory(Document):  #CI 模型定义
    name = fields.StringField(max_length=200, required=True)
    # name = fields.StringField(max_length=200, required=True, unique_with='group')
    group = fields.ReferenceField('Group')
    structure = fields.DictField()
    ctime = fields.DateTimeField(default=datetime.datetime.now())
    utime = fields.DateTimeField(default=datetime.datetime.now())

    meta = {
        "collection": "item_category",
        "indexes": [
            "name",
            # "$name",
            "ctime",
        ],
    }
Exemple #15
0
class Group(Document):  # CI 分组
    name = fields.StringField(max_length=200,
                              required=True,
                              unique_with="layer")
    layer = fields.ReferenceField(Layer, required=True)
    ctime = fields.DateTimeField(default=datetime.datetime.now())
    utime = fields.DateTimeField(default=datetime.datetime.now())

    meta = {
        "collection": "group",
        "indexes": [
            "name",
            # "$name",
            "ctime",
        ],
    }
Exemple #16
0
class Comment(fields.EmbeddedDocument):
    created_at = fields.DateTimeField(default=datetime.datetime.now,
                                      required=True)
    author = fields.StringField(verbose_name="Name",
                                max_length=255,
                                required=True)
    body = fields.StringField(verbose_name="Comment", required=True)
Exemple #17
0
class Notifications(EmbeddedDocument):
	user_id = fields.StringField(unique=False)
	notification_id = fields.StringField(unique=False)
	notification_received_at = fields.DateTimeField(default=datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"), 
		unique=False)
	notification_type = fields.IntField()
	notification_details = fields.EmbeddedDocumentField(NotificationDetails, required=False, 
		default= None, blank=True,unique=False)
Exemple #18
0
class post_transaction(Document):
	title = fields.StringField(max_length=100, unique=False)
	body = fields.StringField(max_length=1000, unique=False)
	category = fields.StringField(max_length=100, unique=True)
	slug= fields.StringField(max_length=100, unique=True)
	image=fields.StringField(max_length=100, unique=True)
	posted_by=fields.StringField(max_length=100, unique=False)
	posted_on= fields.DateTimeField(default=datetime.now)
Exemple #19
0
class CommentDetails(EmbeddedDocument):
	comment_id = fields.StringField(unique=False)
	notification_id = fields.StringField(unique=False)
	user_id = fields.StringField(unique=False)
	comment = fields.StringField(unique=False)
	created_at = fields.DateTimeField(
		default=datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
		, required=True, unique=False
	)
Exemple #20
0
class ReportPosts(Document):
	post_id = fields.StringField(max_length=36,required=True)
	user_id = fields.StringField(required=True, max_length=36)
	report_id = fields.StringField(max_length=36,required=True)
	report_type = fields.IntField(default=0)
	created_at = fields.DateTimeField(
		default=datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
		, required=True, unique=False
	)
Exemple #21
0
class cart(DynamicDocument):
    cart_item_name = fields.StringField(max_length=100, unique=False)
    cart_item_description = fields.StringField(max_length=500)
    cart_item_price = fields.StringField(max_length=100, blank=True)
    cart_session_id = fields.StringField(max_length=100)
    cart_slug = fields.StringField(db_field='slug', max_length=100)
    quantity = fields.StringField(max_length=100)
    total_price = fields.StringField(max_length=100)
    date = fields.DateTimeField(default=datetime.now)
class Result(Document):
    """Result class"""

    title = fields.StringField(blank=False)
    xml_content = fields.StringField(blank=False)
    template_info = fields.EmbeddedDocumentField(TemplateInfo)
    permission_url = fields.StringField(blank=True, null=True)
    detail_url = fields.StringField(blank=True)
    access_data_url = fields.StringField(blank=True)
    last_modification_date = fields.DateTimeField(blank=True, default=None)
Exemple #23
0
class OaiHarvesterMetadataFormatSet(Document):
    """Association table between OaiHarvesterMetadataFormat and OaiHarvesterSet"""

    harvester_set = fields.ReferenceField(OaiHarvesterSet,
                                          reverse_delete_rule=CASCADE)
    harvester_metadata_format = fields.ReferenceField(
        OaiHarvesterMetadataFormat,
        reverse_delete_rule=CASCADE,
        unique_with="harvester_set",
    )
    last_update = fields.DateTimeField(blank=True)

    @staticmethod
    def get_by_metadata_format_and_set(oai_harvester_metadata_format,
                                       oai_harvester_set):
        """Get an OaiHarvesterMetadataFormatSet by its OaiHarvesterMetadataFormat and OaiHarvesterSet.

        Args:
            oai_harvester_metadata_format:
            oai_harvester_set:

        Returns:
            OaiHarvesterMetadataFormatSet instance.

        """
        try:
            return OaiHarvesterMetadataFormatSet.objects.get(
                harvester_metadata_format=oai_harvester_metadata_format,
                harvester_set=oai_harvester_set,
            )
        except mongoengine_errors.DoesNotExist as e:
            raise exceptions.DoesNotExist(str(e))
        except Exception as e:
            raise exceptions.ModelError(str(e))

    @staticmethod
    def upsert_last_update_by_metadata_format_and_set(
            harvester_metadata_format, harvester_set, last_update):
        """Update the last_update date for a given metadata_format and set. Create an
        OaiHarvesterMetadataFormatSet if doesn't exist.

            Args:
                harvester_metadata_format: Metadata format.
                harvester_set: Set.
                last_update: Last update date.

        """
        try:
            OaiHarvesterMetadataFormatSet.objects(
                harvester_metadata_format=harvester_metadata_format,
                harvester_set=harvester_set,
            ).update_one(last_update=last_update, upsert=True)
        except Exception as e:
            raise exceptions.ModelError(str(e))
Exemple #24
0
class Image(Document):
    uuid = fields.StringField(max_length=255, primary_key=True)
    content = fields.DictField(verbose_name="Imagens")
    created_at = fields.DateTimeField(default=datetime.datetime.now,
                                      editable=False)

    @property
    def url_images(self):
        for im in self.content['images']:
            url = list(im.values())[0]
            yield os.path.join(settings.MEDIA_URL, url)
Exemple #25
0
class Event(Document):
    title = fields.StringField(max_length=255)
    description = fields.StringField(max_length=255)
    location = fields.StringField(max_length=255)
    landmark = fields.StringField(max_length=255)
    city = fields.StringField(max_length=255)
    coordinates = fields.ListField(fields.FloatField())
    start_timestamp = fields.DateTimeField()
    end_timestamp = fields.DateTimeField()
    banner = fields.StringField()
    #banner = fields.ImageField(upload_to='banners', default="images/None/no-img.jpeg")
    #banner = fields.ImageField(upload_to=fs, default="images/None/no-img.jpeg")
    tags = fields.ListField(fields.StringField())
    recurring = fields.BooleanField(default=False)
    open_event = fields.BooleanField(default=True)
    full_day_event = fields.BooleanField(default=False)
    created_by = fields.IntField()
    user_agent = fields.StringField(blank=True)
    timestamp = fields.DateTimeField(default=datetime.datetime.now)
    updated_at = fields.DateTimeField(default=datetime.datetime.now)
    slug = fields.StringField(blank=True)
    ip_address = fields.StringField(blank=True)
    channel = fields.ObjectIdField()
    deleted = fields.BooleanField(default=False)
    deleted_at = fields.DateTimeField(blank=True)

    meta = {'collection': 'events'}

    def __str__(self):
        return self.title

    @classmethod
    def pre_save(cls, sender, document, **kwargs):
        document.title = document.title.capitalize()
        document.description = document.description.capitalize()
        document.location = document.location.title()
        document.landmark = document.landmark.title()
        document.city = document.city.title()

        if not document.slug:
            document.slug = slugify(document.title)
Exemple #26
0
class DataItem(Document):
    """ Data Item object
    """
    # When data is deleted, all relative data item is deleted as well
    data = fields.ReferenceField(Data,
                                 blank=False,
                                 reverse_delete_rule=CASCADE)
    template = fields.ReferenceField(Template, blank=False)
    list_content = fields.ListField(fields.EmbeddedDocumentField(Item),
                                    default=[],
                                    blank=False)
    last_modification_date = fields.DateTimeField(blank=True, default=None)

    @staticmethod
    def get_by_data(data):
        """ Return a Data Item with the data given.

        Args:
            data:

        Returns:

        """
        try:
            return DataItem.objects(data=data).get()
        except mongoengine_errors.DoesNotExist as e:
            raise exceptions.DoesNotExist(e.message)
        except Exception as ex:
            raise exceptions.ModelError(ex.message)

    @staticmethod
    def delete_from_data(data):
        """ Delete data items relative to the given data

        Args:
            data:

        Returns:

        """
        DataItem.objects(data=data).delete()

    @staticmethod
    def execute_query_distinct_by_data(query):
        """Execute a query on the DataItem collection distinct by data.

        Args:
            query:

        Returns:

        """
        return DataItem.objects(__raw__=query).distinct("data")
Exemple #27
0
class Book(Document):
    id = fields.StringField(primary_key=True, default=ObjectId)
    name = fields.StringField(max_length=300)
    slug = fields.StringField()
    pages = fields.IntField()
    authors = fields.ListField(fields.ReferenceField(Author))
    pubdate = fields.DateTimeField()

    _meta = {"ordering": ["-pubdate"]}

    def __unicode__(self):
        return self.name or ""
Exemple #28
0
class OaiMetadataFormat(dme_Document):
    """
        A OaiMetadataFormat object
    """
    metadataPrefix = dme_fields.StringField()
    schema = dme_fields.StringField()
    xmlSchema = dme_fields.StringField(blank=True)
    metadataNamespace = dme_fields.StringField()
    raw = dme_fields.DictField()
    template = dme_fields.ReferenceField(Template, reverse_delete_rule=PULL, blank=True)
    registry = dme_fields.StringField(blank=True)
    hash = dme_fields.StringField(blank=True)
    harvest = dme_fields.BooleanField(blank=True)
    lastUpdate = dme_fields.DateTimeField(blank=True)
class OaiRequestPage(Document):
    """Informations about a request sent by a harvester needed a paginated
    response.
    """

    resumption_token = fields.StringField(blank=False, unique=True)
    template_id_list = fields.ListField(blank=False)
    metadata_format = fields.StringField(blank=False)
    oai_set = fields.StringField(blank=True, default=None)
    from_date = fields.DateTimeField(blank=True, default=None)
    until_date = fields.DateTimeField(blank=True, default=None)
    expiration_date = fields.DateTimeField(blank=False, default=None)
    page_number = fields.IntField(blank=False)

    @staticmethod
    def get_by_resumption_token(resumption_token):
        try:
            return OaiRequestPage.objects.get(
                resumption_token=resumption_token)
        except mongoengine_errors.DoesNotExist as e:
            raise exceptions.DoesNotExist(str(e))
        except Exception as ex:
            raise exceptions.ModelError(str(ex))
Exemple #30
0
class BioSubject(Feature):
    species = fields.ReferenceField(Species)
    subjectname = fields.StringField(max_length=255)
    subjectspeciesname = fields.StringField(max_length=1024)
    subjecttaxon = fields.IntField(default=None, null=True)
    strain = fields.StringField(max_length=1024, default=None, null=True)
    subjectdescription = fields.StringField(default="")
    dob = fields.DateTimeField(default=None, null=True)
    sex = fields.StringField(max_length=1, default=None, null=True)
    cohort = fields.StringField(max_length=10, default=None, null=True)
    changed = fields.BooleanField(default=False)
    comment = fields.StringField(max_length=1024, default=None, null=True)
    do_ignore = fields.BooleanField(default=False)
    centre = fields.StringField(max_length=255, default=None, null=True)

    def GetName(self):
        return self.subjectname