Skip to content

Commit

Permalink
merge develop > synergy-scrooge
Browse files Browse the repository at this point in the history
  • Loading branch information
mkurek committed Sep 11, 2014
2 parents 0d807ed + 485c03e commit 2a4b6cd
Show file tree
Hide file tree
Showing 42 changed files with 1,956 additions and 3,319 deletions.
3 changes: 0 additions & 3 deletions src/ralph/account/models.py
Expand Up @@ -37,8 +37,6 @@ class AvailableHomePage(Choices):
ventures = _("Ventures list")
racks = _("Racks list")
networks = _("Network list")
reports = _("Reports")
catalog = _("Catalog")
cmdb_timeline = _("CMDB timeline")


Expand Down Expand Up @@ -75,7 +73,6 @@ class Perm(Choices):
list_devices_generic = _("list venture devices")
list_devices_financial = _("list venture devices financial info")
read_device_info_generic = _("read generic device info")
read_device_info_financial = _("read financial device info")
read_device_info_support = _("read device purchase info")
read_device_info_history = _("read device history info")
read_device_info_reports = _("read device reports")
Expand Down
23 changes: 0 additions & 23 deletions src/ralph/business/admin.py
Expand Up @@ -22,8 +22,6 @@
RolePropertyTypeValue,
RolePropertyValue,
Venture,
VentureExtraCost,
VentureExtraCostType,
VentureRole,
)
from ralph.cmdb.models_ci import CIOwner, CI, CIOwnershipType
Expand Down Expand Up @@ -68,20 +66,6 @@ class VentureRoleInline(ForeignKeyAutocompleteTabularInline):
}


class VentureExtraCostInline(admin.TabularInline):
model = VentureExtraCost
exclude = ('modified',)


class AutocompleteVentureExtraCostInline(ForeignKeyAutocompleteTabularInline):
model = VentureExtraCost
exclude = ('created', 'modified',)
extra = 3
related_search_fields = {
'venture': ['^name'],
}


class VentureRoleAdminForm(forms.ModelForm):

def clean_name(self):
Expand Down Expand Up @@ -123,12 +107,6 @@ def venture_path(self):
admin.site.register(VentureRole, VentureRoleAdmin)


class VentureExtraCostTypeAdmin(ModelAdmin):
inlines = [AutocompleteVentureExtraCostInline, ]

admin.site.register(VentureExtraCostType, VentureExtraCostTypeAdmin)


class RolePropertyValueInline(admin.TabularInline):
model = RolePropertyValue
extra = 0
Expand Down Expand Up @@ -217,7 +195,6 @@ def clean_symbol(self):
class VentureAdmin(ModelAdmin):
inlines = [
SubVentureInline,
VentureExtraCostInline,
VentureRoleInline,
VenturePropertyInline,
]
Expand Down

Large diffs are not rendered by default.

61 changes: 2 additions & 59 deletions src/ralph/business/models.py
Expand Up @@ -7,7 +7,6 @@
from __future__ import unicode_literals

import re
import datetime

from django.conf import settings
from django.db import models as db
Expand All @@ -16,12 +15,12 @@
from lck.django.common.models import WithConcurrentGetOrCreate
from dj.choices import Choices
from dj.choices.fields import ChoiceField
from django.db.models.signals import pre_save, post_save, pre_delete
from django.db.models.signals import pre_save, pre_delete
from django.dispatch import receiver

from ralph.discovery.history import field_changes as _field_changes
from ralph.discovery.models import DataCenter
from ralph.discovery.models_history import HistoryCost, HistoryChange
from ralph.discovery.models_history import HistoryChange
from ralph.discovery.models_util import SavingUser
from ralph.cmdb.models_ci import CI, CIOwner, CIOwnershipType, CIOwnership

Expand Down Expand Up @@ -514,62 +513,6 @@ class Meta:
ordering = ('name',)


class VentureExtraCostType(Named.NonUnique, TimeTrackable):

class Meta:
verbose_name = _("venture extra cost type")
verbose_name_plural = _("venture extra cost types")
ordering = ('name',)


class VentureExtraCost(TimeTrackable):

class Meta:
verbose_name = _("venture extra cost")
verbose_name_plural = _("venture extra costs")
unique_together = ('type', 'venture')
ordering = ('type',)

venture = db.ForeignKey(Venture, verbose_name=_("venture"))
type = db.ForeignKey(VentureExtraCostType, verbose_name=_("type"))
cost = db.FloatField(verbose_name=_("monthly cost"), default=0)
expire = db.DateField(default=None, null=True, blank=True)

@property
def name(self):
return self.type.name


@receiver(post_save, sender=VentureExtraCost, dispatch_uid='ralph.costhistory')
def cost_post_save(sender, instance, raw, using, **kwargs):
changed = False
if 'venture_id' in instance.dirty_fields:
changed = True
if 'expire' in instance.dirty_fields:
changed = True
if 'cost' in instance.dirty_fields:
old_cost = instance.dirty_fields['cost'] or 0
if not -1 < instance.cost - old_cost < 1:
# Ignore changes due to rounding errors
changed = True
if changed:
if instance.expire:
start = min(datetime.date.today(), instance.expire)
else:
start = datetime.datetime.now()
HistoryCost.start_span(
extra=instance, start=start, end=instance.expire)


@receiver(
pre_delete,
sender=VentureExtraCost,
dispatch_uid='ralph.costhistory',
)
def cost_pre_delete(sender, instance, using, **kwargs):
HistoryCost.end_span(extra=instance)


@receiver(pre_save, sender=RolePropertyValue, dispatch_uid='ralph.history')
def role_property_value_pre_save(sender, instance, raw, using, **kwargs):
for field, orig, new in _field_changes(instance):
Expand Down
38 changes: 3 additions & 35 deletions src/ralph/discovery/admin.py
Expand Up @@ -220,7 +220,7 @@ def count(self):
return models.Device.objects.filter(model=self).count()

list_display = ('name', 'type', count, 'created', 'modified')
list_filter = ('type', 'group')
list_filter = ('type',)
search_fields = ('name',)

admin.site.register(models.DeviceModel, DeviceModelAdmin)
Expand All @@ -232,17 +232,6 @@ class DeviceModelInline(admin.TabularInline):
extra = 0


class DeviceModelGroupAdmin(ModelAdmin):

def count(self):
return models.Device.objects.filter(model__group=self).count()

list_display = ('name', count, 'price')
inlines = (DeviceModelInline,)

admin.site.register(models.DeviceModelGroup, DeviceModelGroupAdmin)


class DeviceForm(forms.ModelForm):

class Meta:
Expand Down Expand Up @@ -461,8 +450,8 @@ class ComponentModelAdmin(ModelAdmin):
def count(self):
return self.get_count()

list_filter = ('type', 'group')
list_display = ('name', 'type', count, 'family', 'group')
list_filter = ('type',)
list_display = ('name', 'type', count, 'family',)
search_fields = ('name', 'type', 'group__name', 'family')

admin.site.register(models.ComponentModel, ComponentModelAdmin)
Expand All @@ -479,27 +468,6 @@ class GenericComponentAdmin(ModelAdmin):
admin.site.register(models.GenericComponent, GenericComponentAdmin)


class ComponentModelGroupAdmin(ModelAdmin):

def count(self):
return sum([
models.Memory.objects.filter(model__group=self).count(),
models.Processor.objects.filter(model__group=self).count(),
models.Storage.objects.filter(model__group=self).count(),
models.FibreChannel.objects.filter(model__group=self).count(),
models.DiskShare.objects.filter(model__group=self).count(),
models.Software.objects.filter(model__group=self).count(),
models.OperatingSystemodels.objects.filter(
model__group=self
).count(),
models.GenericComponent.objects.filter(model__group=self).count(),
])
inlines = [ComponentModelInline]
list_display = ('name', count, 'price')

admin.site.register(models.ComponentModelGroup, ComponentModelGroupAdmin)


class DiskShareMountInline(ForeignKeyAutocompleteTabularInline):
model = models.DiskShareMount
exclude = ('created', 'modified')
Expand Down
37 changes: 0 additions & 37 deletions src/ralph/discovery/api.py
Expand Up @@ -29,7 +29,6 @@
ComponentType,
Device,
DeviceModel,
DeviceModelGroup,
DeviceType,
IPAddress,
Network,
Expand Down Expand Up @@ -115,43 +114,7 @@ def dehydrate(self, bundle):
return bundle


class ModelGroupResource(MResource):

class Meta:
queryset = DeviceModelGroup.objects.all()
authentication = ApiKeyAuthentication()
authorization = RalphAuthorization(
required_perms=[
Perm.read_dc_structure,
]
)
filtering = {
'created': ALL,
'ip': ALL,
'modified': ALL,
'name': ALL,
'price': ALL,
'slots': ALL,
'type': ALL,
}
excludes = (
'cache_version',
)
cache = SimpleCache()
throttle = CacheThrottle(
throttle_at=THROTTLE_AT,
timeframe=TIMEFRAME,
expiration=EXPIRATION,
)


class ModelResource(MResource):
group = fields.ForeignKey(
ModelGroupResource,
'group',
null=True,
full=True,
)

class Meta:
queryset = DeviceModel.objects.all()
Expand Down

0 comments on commit 2a4b6cd

Please sign in to comment.