class StockPrice(models.Model):
    code = models.CharField(max_length=6)
    data = models.ArrayField(model_container=StockRow)
    name = models.CharField(max_length=100)
    market_price = models.IntegerField()
Ejemplo n.º 2
0
class MesiboUser(models.Model):
    uid = models.CharField(blank=True, max_length=100)
    access_token = models.CharField(blank=True, max_length=100)
    groups = models.ArrayField(model_container=MesiboGroup, blank=True)
Ejemplo n.º 3
0
class LastSeen(models.Model):
    mid = models.IntegerField(blank=True)
    flag = models.CharField(max_length=10, blank=True)
    uni_ids = models.ArrayField(model_container=Mail, blank=True)
Ejemplo n.º 4
0
class UserData(models.Model):
    user = models.OneToOneField(User, on_delete=models.PROTECT)
    pages = models.ArrayField(model_container=Page)

    objects = models.DjongoManager()
Ejemplo n.º 5
0
class MesiboGroup(models.Model):
    gid = models.IntegerField(blank=True)
    status = models.BooleanField(blank=True)
    last_seen_msgs = models.ArrayField(model_container=LastSeen, blank=True)
Ejemplo n.º 6
0
class Item(models.Model):
    otssCategoriesChoice = [
        ('1', '1'),
        ('2', '2'),
        ('3', '3'),
        ('Не секретно', 'Не секретно')
    ]

    conditionsChoice = [
        ('Исправно', 'Исправно'),
        ('Неисправно', 'Неисправно')
    ]

    inOperationChoice = [
        ('Используется', 'Используется'),
        ('Не используется', 'Не используется')
    ]
    user = models.CharField('сотрудник, которому передали мат. ценность в пользование',
                            max_length=100, default='',
                            blank=True)
    responsible = models.CharField('сотрудник, ответственный за мат. ценность',
                                   max_length=100, default='')
    components = models.ArrayField(model_container=Component, null=True)
    name = models.CharField('наименование', max_length=100, default='')
    inventory_n = models.CharField('инвентарный номер', max_length=100,
                                   default='', unique=True)
    otss_category = models.CharField('категория ОТСС', max_length=100,
                                     choices=otssCategoriesChoice, default='Не секретно')
    condition = models.CharField('состояние', max_length=20,
                                 default='Исправно', choices=conditionsChoice)
    unit_from = models.CharField('подразделение, откуда поступила мат. ценность',
                                 max_length=50, default='')
    in_operation = models.CharField('ипользуется', choices=inOperationChoice,
                                    max_length=20, default='да')
    fault_document_requisites = models.CharField('документы о неисправности',
                                                 max_length=100, null=True, blank=True)
    date_of_receipt = models.DateField('дата поступления на учет',
                                       default=datetime.date.today)
    number_of_receipt = models.CharField('номер требования о поступлении на учет',
                                         max_length=100, default='')
    requisites = models.TextField('реквизиты книги учета мат. ценностей',
                                  default='', max_length=4000)
    transfer_date = models.DateField('дата передачи во временное пользование',
                                     null=True, blank=True)
    otss_requisites = models.TextField('реквизиты документа о категории ОТСС',
                                       max_length=4000, blank=True)
    spsi_requisites = models.TextField('реквизиты документа о прохождении СПСИ',
                                       max_length=4000, blank=True)
    transfer_requisites = models.TextField('реквизиты о передаче во временное пользование',
                                           max_length=4000, blank=True)
    comment = models.TextField('примечание', max_length=4000, blank=True)
    last_check = models.DateField('дата последней проверки', null=True, blank=True)

    objects = models.DjongoManager()

    def __str__(self):
        return self.name.__str__()

    class Meta:
        verbose_name = 'материальная ценность'
        verbose_name_plural = 'материальные ценности'
class UserData(mongo.Model):
    id = mongo.CharField(max_length=36, db_column='_id', primary_key=True)
    created_on = mongo.DateTimeField(auto_now_add=True)
    updated_on = mongo.DateTimeField(auto_now=True)
    email = mongo.EmailField(max_length=36, db_index=True, unique=True, null=False)
    username = mongo.CharField(max_length=256, db_index=True, unique=True, null=False)

    avatar_url = mongo.CharField(max_length=36)
    given_name = mongo.CharField(max_length=256, null=False)
    family_name = mongo.CharField(max_length=256, null=False)
    name = mongo.CharField(max_length=256, null=False)

    # Social Auth fields
    social_auth = mongo.ArrayField(
        model_container=SocialAuth,
        model_form_class=SocialAuthForm,
        default=[]
    )

    objects = mongo.DjongoManager()

    AUTH_FIELD_MAPPING = {
        'google': {
            'sub': 'uid',
            'access_token': 'access_token',
            'provider': 'provider',
        }
    }

    def get_absolute_url(self):
        return reverse_lazy('profile:profile', kwargs={'username': self.username})

    def get_access_token(self, provider='google'):
        for auth in self.social_auth:
            if auth['provider'] == provider:
                return auth['access_token']

        raise Exception('This provider is not active for this user!')

    def add_or_update_social_auth(self, new_data):
        for provider, data in new_data.items():
            now = timezone.now()
            new_social_auth = {
                'provider': provider,
                'access_token': data.pop('access_token'),
                'uid': data.pop('sub'),
                'extra_data': data,
                'updated_on': now
            }

            updated = False
            for index, social_auth in enumerate(self.social_auth):
                if social_auth['provider'] == provider:
                    new_social_auth['created_on'] = social_auth.get('created_on', now)
                    self.social_auth[index] = new_social_auth
                    updated = True
                    break

            if updated:
                continue

            new_social_auth['created_on'] = now
            # if Auth method doesn't exist add it
            self.social_auth += [new_social_auth]

    class Meta:
        db_table = 'user_data'
        db = settings.MONGO_DATABASE
Ejemplo n.º 8
0
class Livro(models.Model):
    receitas = models.ArrayField(model_container=Receita)
Ejemplo n.º 9
0
class UserFavorite(models.Model):
    user_id = models.CharField(max_length=20, primary_key=True)
    standard = models.CharField(max_length=30)
    targets = models.ArrayField(model_container=Market)
    objects = models.DjongoManager()
Ejemplo n.º 10
0
class MsgRefer(models.Model):
    refer_to = models.IntegerField(blank=True)
    refer_by = models.ArrayField(model_container=MsgReferBy, blank=True)
Ejemplo n.º 11
0
class Group(models.Model):
    gid = models.IntegerField(blank=False)
    uni_ids = models.ArrayField(model_container=Mail, blank=True)
    name = models.CharField(max_length=200, blank=True)
    msg_refers = models.ArrayField(model_container=MsgRefer, blank=True)
Ejemplo n.º 12
0
class Profile(models.Model):
    location = models.CharField(max_length=200, blank=True)
    bio = models.CharField(max_length=500, blank=True)
    about = models.CharField(max_length=500, blank=True)
    school = models.EmbeddedField(model_container=SchoolEdu, blank=True)
    twelth = models.EmbeddedField(model_container=TwelthEdu, blank=True)
    colleges = models.ArrayField(model_container=College, blank=True)
    self_projects = models.ArrayField(model_container=SelfProject, blank=True)
    academic_projects = models.ArrayField(model_container=AcademicProject, blank=True)
    self_research_papers = models.ArrayField(model_container=SelfResearchPaper, blank=True)
    academic_research_papers = models.ArrayField(model_container=AcademicResearchPaper, blank=True)
    patents = models.ArrayField(model_container=Patent, blank=True)
    prev_interns = models.ArrayField(model_container=PrevIntern, blank=True)
    work_experience = models.ArrayField(model_container=WorkExperience, blank=True)
    por = models.ArrayField(model_container=PoR, blank=True)
    online_courses = models.ArrayField(model_container=OnlineCourse, blank=True)
    competitions = models.ArrayField(model_container=Competition, blank=True)
    certifications = models.ArrayField(model_container=Certification, blank=True)
    skills = models.ArrayField(model_container=Skill, blank=True)
    preferences = models.ArrayField(model_container=Preferences, blank=True, default=None)
    pro_pic = models.ImageField(blank=True, null=True, upload_to=upload_path)
Ejemplo n.º 13
0
class Preferences(models.Model): 
    prefered_sectors = models.ArrayField(model_container=Place, blank=True)
    prefered_interns = models.ArrayField(model_container=Place, blank=True)
    prefered_jobs = models.ArrayField(model_container=Place, blank=True)
Ejemplo n.º 14
0
class PoR(models.Model): 
    place = models.CharField(max_length=200, blank=True) 
    positions = models.ArrayField(model_container=Position, blank=True)
Ejemplo n.º 15
0
class DayProbability(models.Model):
    # day of week enumeration. see DayOfWeekEnum above for values
    day_of_week = models.CharField(max_length=10, choices=DAYS_OF_WEEK)
    # array/list of Probability. [0] = 00:00, [1] = 00:15, ..., [94] = 23:45
    probability = models.ArrayField(model_container=Probability)
Ejemplo n.º 16
0
class User(models.Model):
    username = models.CharField(max_length=50)
    email = models.EmailField()
    token = models.CharField(max_length=200, null=True)
    watchlist = models.ArrayField(model_container=Ticker)
Ejemplo n.º 17
0
class Attendance(models.Model):
    day = models.DateField(default=datetime.date.today)
    student_list = models.ArrayField(model_container=AttendanceEntry)
Ejemplo n.º 18
0
class User(models.Model):
    _id = models.ObjectIdField()
    email = models.CharField(max_length=200)
    password = models.CharField(max_length=200)
    role = models.IntegerField()
    courses = models.ArrayField(model_container=Course)
Ejemplo n.º 19
0
class UserScope(models.Model):
    """ Class used to represent a Portal instance used for authentication

    """
    """ Mandatory principal attributes """
    name = models.TextField(default="User scope",
                            unique=True,
                            verbose_name=_("Name"),
                            help_text=_("Custom object name"))
    repo_attributes = models.ArrayField(
        model_container=RepoAttribute,
        model_form_class=RepoAttributeForm,
        verbose_name=_('Create user scope'),
        null=True,
        default=None,
        help_text=_("Repo attributes whitelist, for re-use in SSO and ACLs"))

    objects = models.DjongoManager()

    def __str__(self):
        return "{} ({})".format(str(
            self.name), [r['action_var_name'] for r in self.repo_attributes])

    @staticmethod
    def str_attrs():
        """ List of attributes required by __str__ method """
        return ["name", "repo_attributes"]

    def to_template(self):
        """  returns the attributes of the class """
        data = model_to_dict(self)
        return data

    def get_repo_attributes(self):
        if not self.repo_attributes:
            return []
        else:
            return [RepoAttribute(**r) for r in self.repo_attributes]

    def to_dict(self):
        data = model_to_dict(self)
        data['id'] = str(self.pk)
        data['repo_attributes'] = []
        for repo_attr in self.repo_attributes:
            repo_attr.pop('_id', None)
            data['repo_attributes'].append(repo_attr)
        return data

    def to_html_template(self):
        """ Returns needed attributes for html rendering """
        result = {
            'id': str(self.id),
            'name': self.name,
            'scope_keys': [r['action_var_name'] for r in self.repo_attributes]
        }
        return result

    def get_user_scope(self, claims, repo_attrs):
        user_scope = {}
        for u in self.get_repo_attributes():
            user_scope = u.get_scope(user_scope, claims, repo_attrs)
        return user_scope
Ejemplo n.º 20
0
class Lecture(models.Model):
    _id = models.ObjectIdField()
    title = models.CharField(max_length=200)
    subject = models.CharField(max_length=200)
    attachment = models.CharField(max_length=200)
    courses = models.ArrayField(model_container=Course)
Ejemplo n.º 21
0
class Movies(models.Model):
    title = models.CharField(max_length=200)
    year = models.CharField(max_length=4)

    genres = models.ArrayField(model_container=Genre,
                               model_form_class=GenreForm)

    ratings = models.ArrayField(model_container=Rating,
                                model_form_class=RatingForm)

    posterURL = models.CharField(max_length=255)
    storyline = models.TextField()
    imdbRating = models.FloatField()

    actors = models.ArrayField(model_container=Actor,
                               model_form_class=ActorForm)

    comments = models.ArrayField(model_container=Comment,
                                 model_form_class=CommentForm)

    def __str__(self):
        return self.title


#
#
#
# from djongo import models
# from django import forms
#
# class Movies(models.Model):
#     title = models.CharField(max_length=200)
#     year = models.CharField(max_length=4)
#
#     genres = models.ListField()
#
#     ratings = models.ListField()
#
#     # ratings = models.ArrayField(
#
#     # )
#
#     posterURL = models.CharField(max_length=255)
#     storyline = models.TextField()
#     imdbRating = models.FloatField()
#
#     actors = models.ListField()
#
#     comments = models.ListField()
#
#     def __str__(self):
#         return self.title

# class Rating(models.Model):
#     ratingValue = models.IntegerField()
#
#     class Meta:
#         abstract = True
#
#     def __str__(self):
#         return self.ratingValue
#
# class Genre(models.Model):
#     genreType = models.CharField(max_length=200)
#
#     class Meta:
#         abstract = True
#
#     def __str__(self):
#         return self.genreType
#
# class Actor(models.Model):
#     name = models.CharField(max_length=200)
#
#     class Meta:
#         abstract = True
#
#     def __str__(self):
#         return self.name
#
# class Comment(models.Model):
#     commentT = models.TextField()
#
#     class Meta:
#         abstract = True
#
#     def __str__(self):
#         return self.commentT
#
# class Movies(models.Model):
#     title = models.CharField(max_length=200)
#     year = models.CharField(max_length=4)
#
#     genres = models.ArrayField(
#         model_container=Genre
#     )
#
#     ratings = models.ArrayField(
#         model_container=Rating
#     )
#
#     poster = models.CharField(max_length=255)
#     contentRating = models.CharField(max_length=255)
#     duration = models.CharField(max_length=255)
#     releaseDate = models.CharField(max_length=255)
#     averageRating = models.IntegerField(default=0)
#     originalTitle = models.CharField(max_length=255)
#
#     storyline = models.TextField()
#
#     actors = models.ArrayField(
#         model_container=Actor,
#     )
#
#     imdbRating = models.ListField()
#     posterURL = models.CharField(max_length=255)
#
#     comments = models.ArrayField(
#         model_container=Comment,
#     )
#
#     def __str__(self):
#         return self.title
Ejemplo n.º 22
0
class Issue(models.Model):
    _id = models.ObjectIdField()
    number = models.PositiveIntegerField(null=False)
    repo = models.ForeignKey("project.Repository", on_delete=models.CASCADE)
    project = models.ForeignKey("project.Project", on_delete=models.CASCADE)
    title = models.CharField(max_length=100)
    type = models.CharField(max_length=16, choices=ISSUE_TYPES, blank=True)
    labels = models.CharField(max_length=255, blank=True)
    invalid = models.BooleanField(default=False)
    # author = models.CharField(max_length=64, blank=True)
    service = models.CharField(max_length=16,
                               choices=CLASSES_OF_SERVICE,
                               blank=True)
    timeline = models.ArrayField(model_container=Event, blank=True)
    done = models.BooleanField(default=False, blank=True)
    created_at = models.DateTimeField(blank=True)
    updated_at = models.DateTimeField(blank=True)
    # Kanban stuff
    kanban_start_date = models.DateTimeField(blank=True)
    kanban_end_date = models.DateTimeField(blank=True)
    kanban_lead_time = models.PositiveIntegerField(blank=True)
    kanban_total_hold_time = models.PositiveIntegerField(blank=True)
    kanban_total_blocked_time = models.PositiveIntegerField(blank=True)
    kanban_metrics = models.DictField(default=dict)

    objects = models.DjongoManager()

    class Meta:
        # We can have the same issue on different projects
        unique_together = (("repo", "number", "project"), )

    @cached_property
    def github(self):
        return get_github_issue(self.repo.identifier, self.number)

    @property
    def github_url(self):
        return format_html(
            "<a href='https://github.com/{path}' target=_blank>{path}</a>",
            path=
            f"{self.repo.organization}/{self.repo.code}/issues/{self.number}",
        )

    @property
    def github_labels(self):
        return [l.name.lower() for l in self.github.labels]

    @cached_property
    def github_timeline(self):
        events = []
        project_id = self.project.github_id
        for event in get_github_issue_timeline(self.github):
            project_card = event.raw_data.get("project_card", {})
            label = event.raw_data.get("label", {})

            if event.event in EVENT_LABEL_MAPPING and label.get("name") in (
                    "hold",
                    "blocked",
            ):
                events.append(
                    Event(
                        type=EVENT_LABEL_MAPPING[event.event][label["name"]],
                        date=as_utc(event.created_at),
                    ))
            elif project_card and project_card["project_id"] == project_id:
                # Exclude "remove from project" for now
                if event.event not in TIMELINE_CARD_EVENT_TYPES:
                    continue
                events.append(
                    Event(
                        type="moved",
                        column=project_card["column_name"],
                        date=as_utc(event.created_at),
                    ))
        return events

    def get_service_type(self):
        if "critical" in self.github_labels:
            return "expedite"
        return "standard"

    def __str__(self):
        return f"{self.repo.code}/{self.number} - {self.title}"

    def _col(self, name):
        for column in self.project.columns:
            if column.code == name:
                return column
        # This might break something, but oh well
        return None

    @cached_property
    def _last_col_for_project(self):
        for column in self.project.columns[::-1]:
            if column.valid_wip:
                return column
        return None

    def process_timeline_data(self):
        # data = {column.code: {} for column in self.project.columns}
        # data["blocked"] = 0
        # data["on_hold"] = 0
        blocked_since = None
        on_hold_since = None
        start_date = None
        end_date = None
        lead_time = None
        blocked = 0
        on_hold = 0
        # current_column = None
        for event in self.github_timeline:
            if event.type == "on_hold":
                on_hold_since = event.date
            elif event.type == "blocked":
                blocked_since = event.date
            elif on_hold_since and event.type == "on_hold_removed":
                # Ignore on hold for less than 2 hours
                on_hold_time = on_hold_since - event.date
                on_hold_since = None
                if on_hold_time.seconds > 7200:
                    on_hold += max(on_hold_time.days, 1)
            elif blocked_since and event.type == "blocked_removed":
                # Ignore block if less than 2 hours
                blocked_time = blocked_since - event.date
                blocked_since = None
                if blocked_time.seconds > 7200:
                    blocked += max(blocked_time.days, 1)
            elif event.type == "moved":
                column = self._col(event.column)
                if start_date is None and column.valid_wip:
                    start_date = event.date
                if column.code == self._last_col_for_project.code:
                    end_date = event.date
                    lead_time = max((end_date - start_date).days, 1)
                # TODO: Handle time in each column

        return {
            "kanban_start_date": start_date,
            "kanban_end_date": end_date,
            "kanban_lead_time": lead_time,
            "on_hold": on_hold,
            "blocked": blocked,
        }

    def save(self, *args, **kwargs):
        self.title = self.github.title
        self.labels = " | ".join(self.github_labels)
        # Find the first valid issue type
        for label in self.github_labels:
            if label in ISSUE_TYPE_LABEL_MAPPING:
                self.type = ISSUE_TYPE_LABEL_MAPPING[label]
                break
        else:
            self.type = "feature"
        self.service = self.get_service_type()
        self.created_at = as_utc(self.github.created_at)
        self.updated_at = as_utc(self.github.updated_at)
        self.timeline = self.github_timeline
        self.invalid = bool(
            set(self.github_labels) & set(INVALID_ISSUE_LABELS))
        data = self.process_timeline_data()
        self.done = data["kanban_lead_time"] is not None
        self.kanban_start_date = data["kanban_start_date"]
        self.kanban_end_date = data["kanban_end_date"]
        self.kanban_lead_time = data["kanban_lead_time"]
        self.kanban_total_hold_time = data["on_hold"]
        self.kanban_total_blocked_time = data["blocked"]
        super().save(*args, **kwargs)