Esempio n. 1
0
class InventoryItem(db.Document):
    # constants
    CHECKED_IN = 1
    CHECKED_OUT = 2
    # fields
    group = db.ReferenceField(InventoryGroup, dbref=True)
    name = db.StringField(max_length=255)
    identifier = db.StringField(max_length=500)
    comment = db.StringField(max_length=200)
    date_added = db.DateTimeField()
    date_updated = db.DateTimeField()
    status = db.IntField(default=1, choices=INVENTORY_STATUS)
    meta = {'ordering': ['name']}

    def __unicode__(self):
        return self.name

    def get_latest_log(self):
        """Return the latest log for this item"""
        try:
            log = InventoryLog.objects(
                item=self).order_by('-date_added').first()
            if not log:
                return None
        except InventoryLog.DoesNotExist:
            return None
        return log

    def get_latest_person(self):
        """Return the latest person for this item"""
        log = self.get_latest_log()
        if not log:
            return None
        return log.person
Esempio n. 2
0
class UserLocation(db.EmbeddedDocument):
    date = db.DateTimeField(default=datetime.datetime.utcnow)
    position = db.GeoPointField()
    duration = db.IntField(default=0)

    def __str__(self):
        return str(self.position.join(','))
Esempio n. 3
0
class Spot(db.Document):
    name = db.StringField(required=True)
    user = db.ReferenceField(User)
    location = GeoPointField(required=True)
    wifi = db.IntField(min_value=0, max_value=5)
    power = db.BooleanField()
    category = db.StringField()
    comments = db.ListField(db.StringField())
    creation_date = db.DateTimeField(default=datetime.datetime.utcnow)
    user_url = db.StringField()

    meta = {
        'ordering': ['-creation_date']
    }

    def __str__(self):
        return self.name

    def to_dict(self):
        data = self.to_mongo()
        data['creation_date'] = str(self.creation_date.timestamp())
        data['id'] = str(self.id)
        del data['_id']
        data['user'] = str(data['user'])
        return data

    def to_json(self):
        return json.dumps(self.to_dict())
Esempio n. 4
0
class CheckoutMeta(db.EmbeddedDocument):
    # constants
    DURATION_TYPE_UNKNOWN = 0
    DURATION_TYPE_MINS = 1
    DURATION_TYPE_HOURS = 2
    DURATION_TYPE_DAYS = 3
    # fields
    duration = db.FloatField(default=0)
    duration_type = db.IntField(default=DURATION_TYPE_UNKNOWN,
                                choices=DURATION_TYPES)
    is_ooo = db.BooleanField(default=False)  # out of office
Esempio n. 5
0
class Repository(db.Document):
    """
    Main repository document to store data in MongoDB.
    """

    full_name = db.StringField()
    html_url = db.URLField()
    description = db.StringField()
    stargazers_count = db.IntField()
    language = db.StringField()

    meta = {'collection': 'repository'}
Esempio n. 6
0
class Spot(db.Document):
    name = db.StringField(required=True)
    user = db.ReferenceField(User)
    location = db.GeoPointField(required=True)
    wifi = db.IntField(min_value=0, max_value=5)
    power = db.BooleanField()
    category = db.StringField()
    comments = db.ListField(db.StringField())
    creation_date = db.DateTimeField(default=datetime.datetime.utcnow)

    meta = {'ordering': ['-creation_date']}

    def __str__(self):
        return self.name
Esempio n. 7
0
class User(db.Document):
    name = db.StringField(
        required=True,
        max_length=20,
        unique=True,
    )
    password = db.StringField(required=True)
    actions_performed = db.IntField()
    cooldown_started = db.DateTimeField()

    @staticmethod
    def generate_hash(password):
        return sha256.hash(password)

    @staticmethod
    def verify_hash(password, hash):
        return sha256.verify(password, hash)
Esempio n. 8
0
class User(db.Document, UserMixin):
    """A user account object."""

    name = db.StringField(max_length=255)
    email = db.EmailField(max_length=255, unique=True)
    password = db.StringField(max_length=255)

    phone_number = db.StringField(max_length=255)

    parent_name = db.StringField(max_length=255)
    parent_phone_number = db.StringField(max_length=255)
    parent_email = db.StringField(max_length=255)

    entering_grade = db.IntField()
    is_first_year_at_wshs = db.BooleanField(default=False)

    roles = db.SortedListField(db.ReferenceField(Role), default=[])

    active = db.BooleanField(default=True)
Esempio n. 9
0
class InventoryLog(db.Document):
    person = db.ReferenceField(Person, dbref=True)
    item = db.ReferenceField(InventoryItem, dbref=True)
    status = db.IntField(default=2, choices=INVENTORY_STATUS)
    date_added = db.DateTimeField(default=datetime.now)
    checkout_meta = db.EmbeddedDocumentField(CheckoutMeta)
    meta = {'ordering': ['-date_added']}
    person_name = db.StringField(max_length=250)

    def __unicode__(self):
        return u'%s - %s' % (self.status, self.date_added)

    @classmethod
    def add_log(cls, person, item, status, checkout_meta, **kwargs):
        log = InventoryLog(person=person,
                           item=item,
                           status=int(status),
                           date_added=datetime.now(),
                           checkout_meta=checkout_meta)
        if person.name:
            log.person_name = kwargs.get('person_name', person.name)
        log.save()
        return log

    def get_person_name(self):
        """Returns the name of the person assigned to this log"""
        if isinstance(self.person, Person):
            return self.person.name
        # return known/alt person name
        return self.person_name

    def get_checkout_description(self):
        """Returns a human-readable description for the checkout"""
        name = u''
        if not self.checkout_meta:
            return name
        # no duration, then assume default
        duration = self.checkout_meta.duration
        if not duration:
            return u'soon'
        # determine name of duration
        dtype = self.checkout_meta.duration_type
        if dtype == CheckoutMeta.DURATION_TYPE_UNKNOWN:
            return u'soon'
        elif dtype == CheckoutMeta.DURATION_TYPE_MINS:
            name = u'min'
        elif dtype == CheckoutMeta.DURATION_TYPE_HOURS:
            name = u'hr'
        elif dtype == CheckoutMeta.DURATION_TYPE_DAYS:
            name = u'day'
        # format OOO
        ooo_str = ''
        if self.checkout_meta.is_ooo:
            ooo_str = ' OOO'
        # pluralize name
        if duration > 1:
            name += u's'
        description = u'{duration:.0f} {dname}{ooo}'.format(duration=duration,
                                                            dname=name,
                                                            ooo=ooo_str)
        return description

    def get_date_added(self):
        """Returns a formatted date added value"""
        # ref: http://docs.python.org/2/library/time.html#time.strftime
        return self.date_added.strftime(
            settings.INVENTORY_CHECKOUT_DATE_FORMAT)