Exemplo n.º 1
0
 def restore_object(self, attrs, instance=None):
     collection = instance if instance else Collection()
     collection.mnemonic = attrs.get(self.Meta.lookup_field,
                                     collection.mnemonic)
     collection.name = attrs.get('name', collection.name)
     collection.full_name = attrs.get('full_name', collection.full_name)
     collection.preferred_source = attrs.get('preferred_source',
                                             collection.preferred_source)
     collection.repository_type = attrs.get('repository_type',
                                            collection.repository_type)
     collection.custom_resources_linked_source = attrs.get(
         'custom_resources_linked_source',
         collection.custom_resources_linked_source)
     collection.description = attrs.get('description',
                                        collection.description)
     collection.custom_validation_schema = attrs.get(
         'custom_validation_schema', collection.custom_validation_schema)
     collection.collection_type = attrs.get('collection_type',
                                            collection.collection_type)
     collection.public_access = attrs.get(
         'public_access', collection.public_access or DEFAULT_ACCESS_TYPE)
     collection.default_locale = attrs.get(
         'default_locale', collection.default_locale
         or Common.DEFAULT_LOCALE)
     collection.website = attrs.get('website', collection.website)
     collection.supported_locales = attrs.get('supported_locales').split(
         ',') if attrs.get(
             'supported_locales') else collection.supported_locales
     collection.extras = attrs.get('extras', collection.extras)
     collection.external_id = attrs.get('external_id',
                                        collection.external_id)
     return collection
Exemplo n.º 2
0
def vue_collection_save(request):
    if request.user.is_authenticated:
        image = request.FILES.get('image')

        data = request.POST.get('data')
        data = json.loads(data)

        id = data.get('id', None)
        title = data.get('title')
        text = data.get('text')
        books = data.get('books', None)

        key = make_template_fragment_key('libs__collection')
        cache.delete(key)

        if id:
            # Сохраняет изменения
            collection = Collection.objects.get(pk=id, user=request.user)
            collection.title = title
            collection.text = text
            collection.user = request.user
            collection.book.set(books)
            collection.save()
        else:
            # Создает новую коллекцию
            collection = Collection(title=title, text=text, user=request.user)
            collection.save()

            if books:
                collection.book.set(books)

        if image:
            collection.image.save(image.name, image)

    return JsonResponse({'id': collection.id})
Exemplo n.º 3
0
def create_collection(request):
    title = request.POST.get('title')
    discription = request.POST.get('discription')
    user = request.user
    boutique = Boutique.objects.get(user=user)
    collection = Collection(title=title, discription=discription, owner=user)
    form = CollectionForm(request.POST, request.FILES, instance=collection)

    if form.is_valid():
        obj = form.save(commit=False)
        obj.title = title
        obj.discription = discription
        obj.owner = user
        obj.save()
        collection = obj
    if request.POST.getlist("produit", None):
        checked = request.POST.getlist('produit', None)
        for k in checked:
            produits = Produit.objects.get(pk=int(k))
            collection.produit.add(produits)
            collection.save()
    collections = Collection.objects.filter(owner=user)
    return render(request, 'collection/collections.html', {
        'collection': collection,
        'boutique': boutique,
        'collections': collections
    })
Exemplo n.º 4
0
def initiailize_collection(sender, instance=None, created=False, **kwargs):
    if created:
        collection = Collection(user=instance)
        collection.save()
        collection.initialize_comic_boxes(collection=collection)
        pull_list = PullList(collection=collection)
        pull_list.save()
Exemplo n.º 5
0
 def test_collection_override_save_with_slug(self):
     # Collection class comes with a blank slug upon instantiation.
     new_collection = Collection(name='Test\'s collection',
                                 id=3,
                                 owner=User.objects.create_user(
                                     username='******',
                                     password='******'))
     # Assert SlugField contains default blank value.
     self.assertEqual(new_collection.slug, '')
     # .save() is overriden to call slugify(f'{new_collection.name}')
     new_collection.save()
     self.assertEqual(new_collection.slug, 'tests-collection')
Exemplo n.º 6
0
def create_collection(user, validation_schema=None, name=None):
    suffix = generate_random_string()

    collection = Collection(
        name=name if name else "collection{0}".format(suffix),
        mnemonic=name if name else "collection{0}".format(suffix),
        full_name=name if name else "Collection {0}".format(suffix),
        collection_type='Dictionary',
        public_access=ACCESS_TYPE_EDIT,
        default_locale='en',
        supported_locales=['en'],
        website='www.collection2.com',
        description='This is the second test collection',
        custom_validation_schema=validation_schema)

    kwargs = {'parent_resource': UserProfile.objects.get(user=user)}

    Collection.persist_new(collection, user, **kwargs)

    return Collection.objects.get(id=collection.id)
Exemplo n.º 7
0
    def test_collections_version_ids(self):
        kwargs = {
            'parent_resource': self.userprofile1
        }

        collection = Collection(
            name='collection2',
            mnemonic='collection2',
            full_name='Collection Two',
            collection_type='Dictionary',
            public_access=ACCESS_TYPE_EDIT,
            default_locale='en',
            supported_locales=['en'],
            website='www.collection2.com',
            description='This is the second test collection'
        )
        Collection.persist_new(collection, self.user1, **kwargs)

        source = Source(
            name='source',
            mnemonic='source',
            full_name='Source One',
            source_type='Dictionary',
            public_access=ACCESS_TYPE_EDIT,
            default_locale='en',
            supported_locales=['en'],
            website='www.source1.com',
            description='This is the first test source'
        )
        kwargs = {
            'parent_resource': self.org1
        }
        Source.persist_new(source, self.user1, **kwargs)

        (concept1, errors) = create_concept(mnemonic='concept12', user=self.user1, source=source)
        (from_concept, errors) = create_concept(mnemonic='fromConcept', user=self.user1, source=source)
        (to_concept, errors) = create_concept(mnemonic='toConcept', user=self.user1, source=source)

        mapping = Mapping(
            map_type='Same As',
            from_concept=from_concept,
            to_concept=to_concept,
            external_id='mapping',
        )
        kwargs = {
            'parent_resource': source,
        }

        Mapping.persist_new(mapping, self.user1, **kwargs)

        mapping = Mapping.objects.filter()[1]
        mapping_reference = '/orgs/org1/sources/source/mappings/' + mapping.id + '/'

        references = [mapping_reference]

        collection.expressions = references
        collection.full_clean()
        collection.save()

        mapping_version = MappingVersion.objects.filter()[0]
        collection_version = CollectionVersion(
            name='version1',
            mnemonic='version1',
            versioned_object=collection,
            released=True,
            created_by=self.user1,
            updated_by=self.user1,
            mappings=[mapping_version.id]
        )
        collection_version.full_clean()
        collection_version.save()

        self.assertEquals(mapping_version.collection_version_ids, [collection_version.id])
Exemplo n.º 8
0
    def test_collections_ids(self):
        kwargs = {
            'parent_resource': self.userprofile1
        }

        collection = Collection(
            name='collection2',
            mnemonic='collection2',
            full_name='Collection Two',
            collection_type='Dictionary',
            public_access=ACCESS_TYPE_EDIT,
            default_locale='en',
            supported_locales=['en'],
            website='www.collection2.com',
            description='This is the second test collection'
        )
        Collection.persist_new(collection, self.user1, **kwargs)

        source = Source(
            name='source',
            mnemonic='source',
            full_name='Source One',
            source_type='Dictionary',
            public_access=ACCESS_TYPE_EDIT,
            default_locale='en',
            supported_locales=['en'],
            website='www.source1.com',
            description='This is the first test source'
        )
        kwargs = {
            'parent_resource': self.org1
        }
        Source.persist_new(source, self.user1, **kwargs)

        (concept1, errors) = create_concept(mnemonic='concept12', user=self.user1, source=source)
        (from_concept, errors) = create_concept(mnemonic='fromConcept', user=self.user1, source=source)
        (to_concept, errors) = create_concept(mnemonic='toConcept', user=self.user1, source=source)

        mapping = Mapping(
            map_type='Same As',
            from_concept=from_concept,
            to_concept=to_concept,
            external_id='mapping',
        )
        kwargs = {
            'parent_resource': source,
        }

        Mapping.persist_new(mapping, self.user1, **kwargs)
        initial_mapping_version = MappingVersion.objects.get(versioned_object_id=mapping.id)
        new_mapping_version = MappingVersion.for_mapping(mapping)
        new_mapping_version.mnemonic = 98
        new_mapping_version.save()

        from_concept_reference = '/orgs/org1/sources/source/concepts/' + Concept.objects.get(mnemonic=from_concept.mnemonic).mnemonic + '/'
        concept1_reference = '/orgs/org1/sources/source/concepts/' + Concept.objects.get(mnemonic=concept1.mnemonic).mnemonic + '/'
        mapping = Mapping.objects.filter()[1]
        references = [concept1_reference, from_concept_reference, mapping.uri, initial_mapping_version.uri]

        collection.expressions = references
        collection.full_clean()
        collection.save()
        self.assertEquals(initial_mapping_version.collection_ids, [collection.id])
        self.assertEquals(new_mapping_version.collection_ids, [collection.id])
Exemplo n.º 9
0
    def test_collections_version_ids(self):
        kwargs = {'parent_resource': self.userprofile1}

        collection = Collection(
            name='collection2',
            mnemonic='collection2',
            full_name='Collection Two',
            collection_type='Dictionary',
            public_access=ACCESS_TYPE_EDIT,
            default_locale='en',
            supported_locales=['en'],
            website='www.collection2.com',
            description='This is the second test collection')
        Collection.persist_new(collection, self.user1, **kwargs)

        source = Source(name='source',
                        mnemonic='source',
                        full_name='Source One',
                        source_type='Dictionary',
                        public_access=ACCESS_TYPE_EDIT,
                        default_locale='en',
                        supported_locales=['en'],
                        website='www.source1.com',
                        description='This is the first test source')
        kwargs = {'parent_resource': self.org1}
        Source.persist_new(source, self.user1, **kwargs)

        concept1 = Concept(
            mnemonic='concept12',
            created_by=self.user1,
            updated_by=self.user1,
            parent=source,
            concept_class='First',
            names=[LocalizedText.objects.create(name='User', locale='es')],
        )
        kwargs = {
            'parent_resource': source,
        }
        Concept.persist_new(concept1, self.user1, **kwargs)

        another_concept = Concept(
            mnemonic='anotherConcept',
            created_by=self.user1,
            updated_by=self.user1,
            parent=source,
            concept_class='First',
            names=[LocalizedText.objects.create(name='User', locale='es')],
        )
        kwargs = {
            'parent_resource': source,
        }
        Concept.persist_new(another_concept, self.user1, **kwargs)

        another_concept_reference = '/orgs/org1/sources/source/concepts/' + Concept.objects.get(
            mnemonic=another_concept.mnemonic).mnemonic + '/'
        concept1_reference = '/orgs/org1/sources/source/concepts/' + Concept.objects.get(
            mnemonic=concept1.mnemonic).mnemonic + '/'

        references = [concept1_reference, another_concept_reference]

        collection.expressions = references
        collection.full_clean()
        collection.save()

        concept_version = ConceptVersion.objects.get(
            versioned_object_id=Concept.objects.get(
                mnemonic=another_concept.mnemonic).id)

        version = CollectionVersion.for_base_object(collection, 'version1')
        kwargs = {}
        CollectionVersion.persist_new(version, **kwargs)
        self.assertEquals(
            concept_version.collection_version_ids,
            [CollectionVersion.objects.get(mnemonic='version1').id])
Exemplo n.º 10
0
    def test_collections_version_ids(self):
        kwargs = {'parent_resource': self.userprofile1}

        collection = Collection(
            name='collection2',
            mnemonic='collection2',
            full_name='Collection Two',
            collection_type='Dictionary',
            public_access=ACCESS_TYPE_EDIT,
            default_locale='en',
            supported_locales=['en'],
            website='www.collection2.com',
            description='This is the second test collection')
        Collection.persist_new(collection, self.user1, **kwargs)

        source = Source(name='source',
                        mnemonic='source',
                        full_name='Source One',
                        source_type='Dictionary',
                        public_access=ACCESS_TYPE_EDIT,
                        default_locale='en',
                        supported_locales=['en'],
                        website='www.source1.com',
                        description='This is the first test source')
        kwargs = {'parent_resource': self.org1}
        Source.persist_new(source, self.user1, **kwargs)

        concept1 = Concept(
            mnemonic='concept12',
            created_by=self.user1,
            updated_by=self.user1,
            parent=source,
            concept_class='First',
            names=[LocalizedText.objects.create(name='User', locale='es')],
        )
        kwargs = {
            'parent_resource': source,
        }
        Concept.persist_new(concept1, self.user1, **kwargs)

        fromConcept = Concept(
            mnemonic='fromConcept',
            created_by=self.user1,
            updated_by=self.user1,
            parent=source,
            concept_class='First',
            names=[LocalizedText.objects.create(name='User', locale='es')],
        )
        kwargs = {
            'parent_resource': source,
        }
        Concept.persist_new(fromConcept, self.user1, **kwargs)

        toConcept = Concept(
            mnemonic='toConcept',
            created_by=self.user1,
            updated_by=self.user1,
            parent=source,
            concept_class='First',
            names=[LocalizedText.objects.create(name='User', locale='es')],
        )
        kwargs = {
            'parent_resource': source,
        }
        Concept.persist_new(toConcept, self.user1, **kwargs)

        mapping = Mapping(
            map_type='Same As',
            from_concept=fromConcept,
            to_concept=toConcept,
            external_id='mapping',
        )
        kwargs = {
            'parent_resource': source,
        }

        Mapping.persist_new(mapping, self.user1, **kwargs)

        from_concept_reference = '/orgs/org1/sources/source/concepts/' + Concept.objects.get(
            mnemonic=fromConcept.mnemonic).mnemonic + '/'
        concept1_reference = '/orgs/org1/sources/source/concepts/' + Concept.objects.get(
            mnemonic=concept1.mnemonic).mnemonic + '/'
        mapping = Mapping.objects.filter()[1]
        mapping_reference = '/orgs/org1/sources/source/mappings/' + mapping.id + '/'

        references = [
            concept1_reference, from_concept_reference, mapping_reference
        ]

        collection.expressions = references
        collection.full_clean()
        collection.save()

        self.assertEquals(mapping.collection_version_ids, [
            Collection.objects.get(mnemonic=collection.mnemonic).get_head().id
        ])
Exemplo n.º 11
0
def data_to_table():
    lines = DataFromAvtomat.objects.filter(flag=False)
    for line in lines:
        string_from_avtomat = line.line
        time = line.time
        if len(string_from_avtomat) == 38:
            data = parsing_line38(string_from_avtomat)
            if data == 'error':
                continue
        elif len(string_from_avtomat) == 48:
            data = parsing_line48(string_from_avtomat)
            if data == 'error':
                continue
        try:
            avtomat = Avtomat.objects.get(number=data['number'])
        except Avtomat.DoesNotExist:
            avtomat = Avtomat(number=data['number'])
            avtomat.save()
        try:
            status = Status.objects.get(avtomat=avtomat)
        except Status.DoesNotExist:
            status = Status(avtomat=avtomat, time=time)
        if len(string_from_avtomat) == 48 and status.grn == data['grn']:
            status.ev_bill_time += int(
                (time - status.time).total_seconds() / 60)
        else:
            status.ev_bill_time = 0
        if len(string_from_avtomat) == 48 and status.kop == data['kop']:
            status.ev_coin_time += int(
                (time - status.time).total_seconds() / 60)
        else:
            status.ev_coin_time = 0
        status.time = time
        status.how_money = data['how_money']
        status.water_balance = data['water_balance']
        status.water_price = data['water_price']
        status.ev_water = data['ev_water']
        status.ev_bill = data['ev_bill']
        status.ev_volt = data['ev_volt']
        status.ev_counter_water = data['ev_counter_water']
        status.event = data['event']
        status.ev_register = data['ev_register']
        status.grn = data['grn']
        status.kop = data['kop']
        status.time_to_block = data['time_to_block']
        status.save()
        Statistic(avtomat=avtomat,
                  time=time,
                  water_balance=data['water_balance'],
                  how_money=data['how_money'],
                  water_price=data['water_price'],
                  ev_water=data['ev_water'],
                  ev_bill=data['ev_bill'],
                  ev_volt=data['ev_volt'],
                  ev_counter_water=data['ev_counter_water'],
                  ev_register=data['ev_register'],
                  grn=data['grn'],
                  kop=data['kop'],
                  event=data['event']).save(force_insert=True)
        if data['event'] == 3:
            Collection(avtomat=avtomat,
                       how_money=data['how_money'],
                       time=time,
                       time_in_message=data['time_in_message']).save(
                           force_insert=True)
        line.delete()
Exemplo n.º 12
0
 def save(self):
     logger.info("")
     collection = Collection(title=self.cleaned_data["title"],
                             author=self.cleaned_data["author"],
                             publisher=self.cleaned_data["publisher"])
     collection.save()