コード例 #1
0
class SocialMediaExtension(AdExtension):
    """
    This extension adds social media links to the
    advertisement impression.
    """
    facebook_handle = URLField(default="", required=False)
    twitter_handle = URLField(default="", required=False)
コード例 #2
0
class Episode(Document):
    """
    The database schema for an episode entry. Episodes are identified by their
    unique page url, which prevents an episode being added multiple times.
    An episode is guaranteed to have a page url and a title.
    """

    page_url = URLField(unique=True, required=True)
    date = DateField()
    title = StringField(required=True, default="Untitled")
    description = StringField()
    mp3_url = URLField()

    def __repr__(self):
        return f"Episode ({self.date}): \n{self.title}"

    @queryset_manager
    def missing_audio(doc_cls, queryset):
        """
        Return all episodes that don't have an MP3 url set yet.
        """
        return queryset.filter(mp3_url__exists=False)

    @queryset_manager
    def playable(doc_cls, queryset):
        """
        The opposite of `missing_audio`. Return all episodes that DO have an MP3
        url set.
        """
        return queryset.filter(mp3_url__exists=True)
コード例 #3
0
def RevalidURL(url):
    try:
        if url != None:
            mongo_validator = URLField()
            mongo_validator.validate(url)
            return True
    except:
        return False
コード例 #4
0
class Brand(EmbeddedDocument):
    banner_url = URLField()
    banner_title = StringField()
    brand_logo = URLField()
    nearest_store = StringField()
    is_following = BooleanField()
    product_count = IntField()
    followers_count = IntField()
    products = ListField(GenericEmbeddedDocumentField(ProductThumbnails))
コード例 #5
0
class Collection(EmbeddedDocument):
    banner_url = URLField()
    banner_title = StringField()
    collection_logo = URLField()
    last_updated = StringField()
    is_following = BooleanField()
    product_count = IntField()
    followers_count = IntField()
    products = ListField(GenericEmbeddedDocumentField(ProductThumbnails))
コード例 #6
0
class Vulnerability(Document):
    meta = {"collection": "vulnerabilities"}
    ID = ObjectIdField(primary_key=True)
    value = StringField()
    label = StringField()
    type = StringField()
    exploitDbUrl = URLField()
コード例 #7
0
ファイル: models.py プロジェクト: DahaWong/castpod
class Logo(EmbeddedDocument):
    _path = StringField(required=True)
    is_local = BooleanField(default=False)
    url = URLField()
    file_id = StringField()

    @property
    def path(self):
        if not self.is_local:
            data = io.BytesIO(requests.get(self.url).content)
            with Image.open(data) as im:
                # then process image to fit restriction:
                # 1. jpeg format
                im = im.convert('RGB')
                # 2. < 320*320
                size = (80, 80)
                im = im.resize(size, Image.ANTIALIAS)
                # 3. less than 200 kB !!
                im.save(self._path, "JPEG")
                # print(os.stat(path).st_size)
            # with open(path, 'rb') as fr:
            # self._logo.put(fr, content_type='image/jpeg')
            # self.save()
        # return self._logo
        self.is_local = True
        return self._path

    @path.setter
    def path(self, value):
        self._path = value
        self.save()
コード例 #8
0
ファイル: vendor.py プロジェクト: fossabot/noc
class Vendor(Document):
    """
    Equipment vendor
    """
    meta = {
        "collection": "noc.vendors",
        "allow_inheritance": False,
        "json_collection": "inv.vendors"
    }

    name = StringField(unique=True)
    code = StringField()
    site = URLField(required=False)
    uuid = UUIDField(binary=True)

    def __unicode__(self):
        return self.name

    def to_json(self):
        return to_json(
            {
                "name": self.name,
                "$collection": self._meta["json_collection"],
                "code": self.code,
                "site": self.site,
                "uuid": self.uuid
            },
            order=["name", "uuid", "code", "site"])

    def get_json_path(self):
        return "%s.json" % self.code
コード例 #9
0
class NodeConfig(Document):
    version = IntField()
    node_name = StringField(max_length=1000)
    icon_link = URLField()
    connection_method = DictField()
    configures = EmbeddedDocumentListField(OperateFactor)
    device_icons = DictField()  # key:hid, value:URL
コード例 #10
0
class Post(Document):
    """
    Defines structure of reddit_top_posts collection.
    """
    comments_url = URLField(required=True)
    date = DateTimeField(required=True)
    date_str = StringField(max_length=10, required=True)
    score = IntField(required=True)
    sub = StringField(max_length=20, required=True)
    title = StringField(max_lenght=300, required=True)
    url = URLField(required=True)

    meta = {
        'collection': 'top_reddit_posts',
        'ordering': ['-score'],
        'auto_create_index': False
    }
コード例 #11
0
class Post(Document):
    company = StringField(required=True)
    date = StringField(required=True)
    link = URLField(required=True)
    job_id = StringField(required=True)
    title = StringField(required=True)
    description = StringField(required=True)
    teaser_text = StringField(required=True)
コード例 #12
0
class Post(Document):
    ''' Class for defining structure of reddit-top-posts collection
    '''
    url = URLField(required=True)
    date = DateTimeField(required=True)
    date_str = StringField(max_length=10, required=True)
    commentsUrl = URLField(required=True)
    sub = StringField(max_length=20, required=True)  # subredit can be 20 chars
    title = StringField(max_length=300,
                        required=True)  # title can be 300 chars
    score = IntField(required=True)

    meta = {
        'collection': 'top_reddit_posts',  # collection name
        'ordering': ['-score'],  # default ordering
        'auto_create_index': False,  # MongoEngine will not create index
    }
コード例 #13
0
ファイル: document.py プロジェクト: rossbutler2000/MPContribs
class Reference(EmbeddedDocument):
    label = StringField(
        required=True,
        min_length=3,
        max_length=8,
        help_text="label",
        validation=valid_key,
    )
    url = URLField(required=True, help_text="URL")
コード例 #14
0
class Product(EmbeddedDocument):
    product_name = StringField
    product_image = URLField
    is_bookmarked = BooleanField
    price_marked = IntField()
    price_effective = IntField()
    brand_name = StringField()
    badge_url = URLField()
    action = EmbeddedDocumentField(Action)
コード例 #15
0
ファイル: models.py プロジェクト: olga-f/jsprep.org
class Unit(Document):
    ID = ObjectIdField()
    title = StringField(unique=True, required=True)
    about = ListField(StringField())
    description = StringField()
    image_url = URLField()
    date_created = DateTimeField(default=datetime.utcnow)
    position = IntField(default=0, required=True)
    slug = StringField(unique=True, required=True)
コード例 #16
0
class Job(Document):
    meta = {"collection": "jobs"}
    ID = ObjectIdField()
    description = StringField()
    minimumRank = IntField()
    responsibilities = StringField()
    qualifications = StringField()
    applyLink = URLField()
    applyEmail = EmailField()
    payRange = StringField()
    qualified = ListField(ReferenceField(User))
コード例 #17
0
class Audio(EmbeddedDocument):
    """Audio information.

    url: audio url
    duration: audio duration in seconds
    """
    url = URLField(max_length=256, required=True)
    duration = IntField(min_value=1, required=True)

    def to_vo(self, **kwargs):
        return {'url': self.url, 'duration': self.duration}
コード例 #18
0
class Replay(Document):
    id = IntField(required=True, primary_key=True)
    date = DateTimeField(required=True)
    heroes_winning = ListField(ReferenceField(PlayerHero))
    heroes_losing = ListField(ReferenceField(PlayerHero))
    length = IntField(required=True)
    map = StringField(required=True, max_length=50)
    mode = StringField(required=True, max_length=25)
    players_losing = ListField(ReferenceField(Player))
    players_winning = ListField(ReferenceField(Player))
    region = IntField(required=True)
    url = URLField(required=True)
    version = StringField(required=True, max_length=25)
    bans = ListField(ReferenceField(Hero))
    meta = {
        'indexes': [
            '-date',
            ('-date', 'mode')
        ]
    }

    @classmethod
    def get_replays_by_result_for_hero_mode_and_date_range(cls, hero, start_date, end_date=None, mode=None,
                                                           min_level=None):
        response = {'wins': [], 'losses': [], 'bans': []}

        if end_date and mode:
            replays = cls.objects(date__gte=start_date, date__lte=end_date, mode=mode)
        elif end_date:
            replays = cls.objects(date__gte=start_date, date__lte=end_date)
        elif mode:
            replays = cls.objects(date__gte=start_date, mode=mode)
        else:
            replays = cls.objects(date__gte=start_date)

        for replay in replays:
            if hero in replay.bans:
                response['bans'].append(replay)
                continue
            player_heroes_winning = [ph for ph in replay.heroes_winning if ph.hero == hero]
            player_heroes_losing = [ph for ph in replay.heroes_losing if ph.hero == hero]
            if len(player_heroes_winning) > 0 and len(player_heroes_losing) > 0:
                continue  # ignore mirror matches
            if len(player_heroes_winning) > 0:
                if not min_level or (min_level and PlayerReplay.objects(player_hero=player_heroes_winning[0],
                                                                        replay=replay).get().hero_level >= min_level):
                    response['wins'].append(replay)
            if len(player_heroes_losing) > 0:
                if not min_level or (min_level and PlayerReplay.objects(player_hero=player_heroes_losing[0],
                                                                        replay=replay).get().hero_level >= min_level):
                    response['losses'].append(replay)
        return response
コード例 #19
0
class Image(EmbeddedDocument):
    """Image information.

    url: image url
    width: image width
    height: image height
    """
    url = URLField(max_length=256, required=True)
    width = IntField(min_value=1, required=True)
    height = IntField(min_value=1, required=True)

    def to_vo(self, **kwargs):
        return {'url': self.url, 'width': self.width, 'height': self.height}
コード例 #20
0
class AspectQ(Document):
	base_url  = URLField(required=True)
	survey_id = StringField(required=True)
	unique_identifier=StringField(required=True,unique=True)
	parent= StringField() #Value , 'true'
	parent_id=StringField()
	status=StringField(default="false")
	last_update=DateTimeField()
	meta = {'allow_inheritance': True}

	@property
	def repr(self):
		return {
			'id': str(self.pk),
			'access_url': self.base_url,
			'survey_id': self.survey_id,
			# 'children': self.children
		}

	def execute(self):
		# Get minute difference
		# fmt = '%Y-%m-%d %H:%M:%S'
		# now= datetime.now()
		# d1 = str(datetime.strptime(now, fmt))
		# d2 = str(datetime.strptime(self.last_update, fmt))

		# # convert to unix timestamp
		# d1_ts = time.mktime(d1.timetuple())
		# d2_ts = time.mktime(d2.timetuple())
		# minutes=int(d2_ts-d1_ts) / 60
		minutes=61
		if self.status=="true" and minutes < MINUTES:
			print("Already Done",self.survey_id)
		else:
			if minutes>MINUTES:
				print ("Re-working")
			if self.parent=="true":
				survey_id=[self.survey_id]
				for obj in AspectQ.objects(parent_id=self.survey_id):
					survey_id.append(obj.survey_id)
			else:
				survey_id=self.survey_id
			try:
				print("provider",self.provider)
				Sentient(self.base_url,survey_id,self.provider).run()
				pass
			except Exception as e:

				print("EXECUTE Exception", e)
				raise e
			print("survey_id",survey_id)
コード例 #21
0
class Articles(Document):
    article_id = StringField(primary_key=True)
    article_title = StringField(required=True)
    author = StringField()
    board = StringField()
    content = StringField(required=True)
    date = StringField()
    ip = StringField()
    message_count = DictField()
    messages = ListField(DictField())
    url = URLField()
    created_at = DateTimeField(default=datetime.now)
    updated_at = DateTimeField(default=datetime.now)
    meta = {"allow_inheritance": True}
コード例 #22
0
ファイル: source.py プロジェクト: dolanor-galaxy/1flow
class Source(Document, DocumentHelperMixin):
    """ The "original source" for similar articles: they have different authors,
        different contents, but all refer to the same information, which can
        come from the same article on the net (or radio, etc).

        Eg:
            - article1 on Le Figaro
            - article2 on Liberation
            - both refer to the same AFP news, but have different content.

    """
    type = StringField()
    uri = URLField(unique=True)
    name = StringField()
    authors = ListField(ReferenceField('User', reverse_delete_rule=PULL))
    slug = StringField()
コード例 #23
0
class Video(EmbeddedDocument):
    """Video information.

    url: video url
    duration: video duration in seconds
    cover: video cover image
    """
    url = URLField(max_length=256, required=True)
    duration = IntField(min_value=1, required=True)
    cover = EmbeddedDocumentField(Image, required=True)

    def to_vo(self, **kwargs):
        return {
            'url': self.url,
            'duration': self.duration,
            'cover': self.cover.to_vo(**kwargs)
        }
コード例 #24
0
class Hook(Document):
    callback = URLField(required=True, unique_with='scope')
    scope = StringField(required=True, choices=scope_values)
    payload = DictField()
    active = BooleanField(default=True)

    meta = {'allow_inheritance': True}

    @property
    def repr(self):
        return {
            'id': str(self.id),
            'callback': self.callback,
        }

    def execute(self):
        # Send the webhook request
        async_post(self.callback, data=self.payload)
コード例 #25
0
ファイル: documents.py プロジェクト: dgk/modnoemesto
class Profile(Document):
    user = ReferenceField('User')
    is_active = BooleanField(default=False)

    hometown = StringField(max_length=30)
    birthday = StringField(max_length=10)
    sex = StringField(max_length=1)
    icq = StringField(max_length=30)

    mobile = StringField(max_length=30)
    website = URLField()

    university = StringField(max_length=30)
    department = StringField(max_length=30)
    university_status = StringField(max_length=30)

    get_news = BooleanField()

    announce = StringField(max_length=512,
                           default=unicode(_('No upcoming events')))

    inviter = ReferenceField('User')

    theme = ReferenceField('Theme')

    meta = {
        'indexes': [
            'user',
            'inviter',
        ]
    }

    def for_html(self):
        from apps.social.forms import ChangeProfileForm
        self.sex = dict(ChangeProfileForm.SEX_CHOICES).get(
            self.sex, ChangeProfileForm.SEX_CHOICES[0][1])
        if self.mobile:
            self.mobile = "+7 (%s) %s %s %s" % (
                self.mobile[:3], self.mobile[3:6], self.mobile[6:8],
                self.mobile[8:])
            self.mobile_code = self.mobile[:3]
            self.mobile_number = self.mobile[3:]
        return self
コード例 #26
0
class CallOnlyAd(Ad):
    """
    An ad for a Click to Call Only Campaign.
    """
    # Call'able parameters
    countryCode = StringField()
    phone_number = StringField()
    business_name = StringField()
    # Enable call tracking by parameters
    callTracked = BooleanField()
    # Parameters measures, count, call length
    callTrackParameters = DictField()
    # Phone number verification
    phonenumberVerificationUrl = URLField()

    ad_type = StringField(default='CallOnlyAd')

    def get_absolute_url(self):
        return "/mediacontent/ads/callonlyads/%i/" % self.id
コード例 #27
0
class LocationExtension(AdExtension):
    """
    This extension add locations to the advertisement
    impression.
    """
    locationName = StringField()
    locationCode = StringField()
    locationPrimaryPhone = StringField()
    locationPrimaryCategory = StringField()
    locationtWebsiteUrl = URLField()
    locationAddresslines = ListField()
    locationAddressLocality = StringField()
    locationAdministrativeArea = StringField()
    locationCountry = StringField()
    locationPostalCode = StringField()
    # optional
    locationcode = GeoPointField()

    def get_absolute_url(self):
        return "/mediacontent/ads/extension/location/%i/" % self.id
コード例 #28
0
class User(mongo.Document):
    __name__ = "user"
    username = StringField(validators=[
        DataRequired(),
    ],
                           verbose_name=_("Username"))
    password = StringField(validators=[
        DataRequired(),
    ])
    listTest = ListField(ReferenceField(Certificate), default=list)
    listCert = ListField(ReferenceField(Certificate), default=list)

    name = StringField(verbose_name='Name', validators=[DataRequired()])

    lastName = StringField(verbose_name='Last name',
                           validators=[DataRequired()])

    email = EmailField(verbose_name="Email", validators=[DataRequired()])

    profileImageUrl = URLField()

    # birthDate = DateTimeField(verbose_name='Birth Date', validators=[DataRequired()], )

    gender = StringField(verbose_name='Gender',
                         choices=[('Male', 'Male'), ('Female', 'Female')])

    university = StringField(verbose_name='University/Institution')

    location = StringField(verbose_name='location')

    remember_me = BooleanField()
    blocked = BooleanField(default=False)

    admin = ReferenceField(Admin)

    # submit = SubmitField('Sign Up')

    birthDate = DateTimeField()

    pass
コード例 #29
0
ファイル: models.py プロジェクト: rohitjose/paranuara-api
class Person(Document):
    """Model to hold the information of the people in Paranuara"""
    meta = {'collection': 'people'}
    index = IntField(required=True)
    guid = StringField()
    has_died = BooleanField(required=True)
    balance = StringField()
    picture = URLField()
    age = IntField()
    eyeColor = StringField(required=True)
    name = StringField(required=True)
    gender = StringField(choices=['male', 'female'])
    company_id = IntField(required=True)
    email = EmailField()
    phone = StringField()
    address = StringField()
    about = StringField()
    registered = StringField()
    tags = ListField(StringField())
    friends = EmbeddedDocumentListField(Friend)
    greeting = StringField()
    favouriteFood = ListField(StringField())
コード例 #30
0
class Certificate(mongo.Document):
    __name__ = "certificate"
    imgUrl = URLField()
    title = StringField(max_length=30,
                        verbose_name="Title",
                        validators=[DataRequired()])
    description = StringField(verbose_name="Description",
                              validators=[DataRequired()])
    scoreForTrueFalse = IntField(
        verbose_name="Score For True False",
        validators=[DataRequired(), NumberRange(min=0)])
    scoreForSimpleSelection = IntField(
        verbose_name="Score For Simple Selection",
        validators=[DataRequired(), NumberRange(min=0)])
    numQuestions = IntField(verbose_name="numQuestions",
                            validators=[DataRequired(),
                                        NumberRange(min=0)])
    timeForTest = IntField(verbose_name="timeForTest",
                           validators=[DataRequired(),
                                       NumberRange(min=0)])
    submit = SubmitField(verbose_name='Save Changes')
    dateCreated = DateTimeField(default=datetime.datetime.utcnow)
    listQuestion = ListField(ReferenceField(Question), default=list)
    listQuestionActive = ListField(ReferenceField(Question), default=list)
    approvalScore = IntField()

    def clean(self):
        print(self.scoreForSimpleSelection)
        # self.scoreForTrueFalse = int(self.scoreForTrueFalse.data)
        # self.scoreForSimpleSelection = int(self.scoreForSimpleSelection.data)
        # self.numQuestions = int(self.numQuestions.data)
        # self.timeForTest = int(self.timeForTest.data)

    # users = []
    # pdf url / firm
    pass