Added API for Ralph #44

Merged
merged 6 commits into from Aug 23, 2013

Conversation

Projects
None yet
3 participants
@andrzej-jankowski
Member

andrzej-jankowski commented Aug 21, 2013

No description provided.

@andrzej-jankowski andrzej-jankowski referenced this pull request in allegro/ralph Aug 21, 2013

Merged

Assets integration #621

src/ralph_assets/api_ralph.py
+ 'support_type': asset.support_type,
+ 'support_void_reporting': asset.support_void_reporting,
+ 'provider': asset.provider,
+ 'status': str(AssetStatus.from_id(asset.status)),

This comment has been minimized.

Show comment Hide comment
@vi4m

vi4m Aug 21, 2013

Member

unicode()

@vi4m

vi4m Aug 21, 2013

Member

unicode()

This comment has been minimized.

Show comment Hide comment
@andrzej-jankowski

andrzej-jankowski Aug 21, 2013

Member

done

src/ralph_assets/api_ralph.py
+ 'asset_id': asset.id,
+ 'model': asset.model.name,
+ 'manufacturer': asset.model.manufacturer.name,
+ 'source': str(AssetSource.from_id(asset.source)),

This comment has been minimized.

Show comment Hide comment
@vi4m

vi4m Aug 21, 2013

Member

unicode()

@vi4m

vi4m Aug 21, 2013

Member

unicode()

This comment has been minimized.

Show comment Hide comment
@andrzej-jankowski

andrzej-jankowski Aug 21, 2013

Member

done

src/ralph_assets/api_ralph.py
+from __future__ import print_function
+from __future__ import unicode_literals
+
+

This comment has been minimized.

Show comment Hide comment
@vi4m

vi4m Aug 21, 2013

Member

unneded line

@vi4m

vi4m Aug 21, 2013

Member

unneded line

This comment has been minimized.

Show comment Hide comment
@andrzej-jankowski

andrzej-jankowski Aug 21, 2013

Member

done

src/ralph_assets/api_ralph.py
+ return Asset.objects.exclude(
+ device_info__ralph_device_id__in=exclude_devices,
+ ).filter(
+ id=asset_id,

This comment has been minimized.

Show comment Hide comment
@vi4m

vi4m Aug 21, 2013

Member

pk= is better than id=

@vi4m

vi4m Aug 21, 2013

Member

pk= is better than id=

This comment has been minimized.

Show comment Hide comment
@vi4m

vi4m Aug 21, 2013

Member

One of reasons is that id is builtin attribute of every object, django manual prefers pk .

@vi4m

vi4m Aug 21, 2013

Member

One of reasons is that id is builtin attribute of every object, django manual prefers pk .

This comment has been minimized.

Show comment Hide comment
@andrzej-jankowski

andrzej-jankowski Aug 21, 2013

Member

done

src/ralph_assets/api_ralph.py
+ Q(model__name__icontains=q)
+ )
+ )
+ return self.get_base_objects().filter(query).order_by('sn')[:10]

This comment has been minimized.

Show comment Hide comment
@deshipu

deshipu Aug 23, 2013

Contributor

You probably also want distinct() here.

@deshipu

deshipu Aug 23, 2013

Contributor

You probably also want distinct() here.

This comment has been minimized.

Show comment Hide comment
@andrzej-jankowski

andrzej-jankowski Aug 23, 2013

Member

done

+ Q(sn__istartswith=q) |
+ Q(model__name__icontains=q)
+ )
+ )

This comment has been minimized.

Show comment Hide comment
@deshipu

deshipu Aug 23, 2013

Contributor

no need to wrap it in addintional Q()

        query = (
            Q(device_info__gt=0) & (
                Q(device_info__ralph_device_id__isnull=True) |
                Q(device_info__ralph_device_id=0)
            ) & (
                Q(barcode__istartswith=q) |
                Q(sn__istartswith=q) |
                Q(model__name__icontains=q)
            )
        )
@deshipu

deshipu Aug 23, 2013

Contributor

no need to wrap it in addintional Q()

        query = (
            Q(device_info__gt=0) & (
                Q(device_info__ralph_device_id__isnull=True) |
                Q(device_info__ralph_device_id=0)
            ) & (
                Q(barcode__istartswith=q) |
                Q(sn__istartswith=q) |
                Q(model__name__icontains=q)
            )
        )

This comment has been minimized.

Show comment Hide comment
@andrzej-jankowski

andrzej-jankowski Aug 23, 2013

Member

done

src/ralph_assets/api_ralph.py
+ 'support_type': asset.support_type,
+ 'support_void_reporting': asset.support_void_reporting,
+ 'provider': asset.provider,
+ 'status': unicode(AssetStatus.from_id(asset.status)),

This comment has been minimized.

Show comment Hide comment
@deshipu

deshipu Aug 23, 2013

Contributor

that gives you a translated string
it will break for a language other than English

@deshipu

deshipu Aug 23, 2013

Contributor

that gives you a translated string
it will break for a language other than English

This comment has been minimized.

Show comment Hide comment
@andrzej-jankowski

andrzej-jankowski Aug 23, 2013

Member

done

src/ralph_assets/api_ralph.py
+ 'asset_id': asset.id,
+ 'model': asset.model.name,
+ 'manufacturer': asset.model.manufacturer.name,
+ 'source': unicode(AssetSource.from_id(asset.source)),

This comment has been minimized.

Show comment Hide comment
@deshipu

deshipu Aug 23, 2013

Contributor

that gives you a translated string
it will break for a language other than English
You want AssetSource.from_id(asset.source).raw instead.

@deshipu

deshipu Aug 23, 2013

Contributor

that gives you a translated string
it will break for a language other than English
You want AssetSource.from_id(asset.source).raw instead.

This comment has been minimized.

Show comment Hide comment
@andrzej-jankowski

andrzej-jankowski Aug 23, 2013

Member

done

src/ralph_assets/api_ralph.py
+
+
+@commit_on_success
+def assign_asset(device, asset):

This comment has been minimized.

Show comment Hide comment
@deshipu

deshipu Aug 23, 2013

Contributor

Don't pass models between Ralph and Assets. Just pass the IDs.

@deshipu

deshipu Aug 23, 2013

Contributor

Don't pass models between Ralph and Assets. Just pass the IDs.

This comment has been minimized.

Show comment Hide comment
@andrzej-jankowski

andrzej-jankowski Aug 23, 2013

Member

done

src/ralph_assets/api_ralph.py
+ ).exists()
+
+
+@commit_on_success

This comment has been minimized.

Show comment Hide comment
@deshipu

deshipu Aug 23, 2013

Contributor

This makes it impossible to call this function from another function that already has @commit_on_success

@deshipu

deshipu Aug 23, 2013

Contributor

This makes it impossible to call this function from another function that already has @commit_on_success

This comment has been minimized.

Show comment Hide comment
@andrzej-jankowski

andrzej-jankowski Aug 23, 2013

Member

done

@deshipu deshipu referenced this pull request in allegro/ralph Aug 23, 2013

Merged

Support for assets in the scan form. #624

deshipu added a commit that referenced this pull request Aug 23, 2013

@deshipu deshipu merged commit 3a4aa6a into allegro:master Aug 23, 2013

quamilek pushed a commit to quamilek/ralph that referenced this pull request Dec 28, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment