diff --git a/valuenetwork/valueaccounting/forms.py b/valuenetwork/valueaccounting/forms.py index a0ec36071..4564df0ca 100644 --- a/valuenetwork/valueaccounting/forms.py +++ b/valuenetwork/valueaccounting/forms.py @@ -20,12 +20,12 @@ class AgentModelChoiceField(forms.ModelChoiceField): def label_from_instance(self, obj): return obj.name - + class CashReceiptModelMultipleChoiceField(forms.ModelMultipleChoiceField): def label_from_instance(self, obj): return obj.undistributed_description() - + class WorkModelChoiceField(forms.ModelChoiceField): def label_from_instance(self, obj): if obj.description: @@ -33,7 +33,7 @@ def label_from_instance(self, obj): else: label = obj.name return label - + class ResourceModelChoiceField(forms.ModelChoiceField): def label_from_instance(self, obj): label = obj.__unicode__() @@ -42,7 +42,7 @@ def label_from_instance(self, obj): label = " ".join([label, "at", loc]) return label - + class ValueEquationModelChoiceField(forms.ModelChoiceField): def label_from_instance(self, obj): if obj.live: @@ -51,7 +51,7 @@ def label_from_instance(self, obj): label = ": ".join([obj.name , "Test Only"]) return label - + class AgentForm(forms.Form): nick = forms.CharField(label="ID", widget=forms.TextInput(attrs={'class': 'required-field',})) first_name = forms.CharField(widget=forms.TextInput(attrs={'class': 'input-xlarge',})) @@ -68,21 +68,21 @@ class AgentForm(forms.Form): widget=forms.Select( attrs={'class': 'chzn-select'})) is_context = forms.BooleanField( - required=False, + required=False, widget=forms.CheckboxInput()) class AgentCreateForm(forms.ModelForm): - name = forms.CharField(widget=forms.TextInput(attrs={'class': 'required-field input-xlarge',})) + name = forms.CharField(widget=forms.TextInput(attrs={'class': 'required-field input-xlarge',})) nick = forms.CharField( - label="ID", + label="ID", help_text="Must be unique, and no more than 32 characters", - widget=forms.TextInput(attrs={'class': 'required-field',})) + widget=forms.TextInput(attrs={'class': 'required-field',})) email = forms.EmailField(required=False, widget=forms.TextInput(attrs={'class': 'input-xxlarge',})) address = forms.CharField(required=False, widget=forms.TextInput(attrs={'class': 'input-xxlarge',})) url = forms.CharField(required=False, widget=forms.TextInput(attrs={'class': 'url input-xxlarge',})) description = forms.CharField( - required=False, + required=False, widget=forms.Textarea(attrs={'class': 'input-xxlarge',})) agent_type = forms.ModelChoiceField( queryset=AgentType.objects.all(), @@ -90,8 +90,8 @@ class AgentCreateForm(forms.ModelForm): widget=forms.Select( attrs={'class': 'chzn-select'})) is_context = forms.BooleanField( - required=False, - label="Is a context agent", + required=False, + label="Is a context agent", widget=forms.CheckboxInput()) class Meta: @@ -102,22 +102,22 @@ class Meta: #todo: queryset methods cd be cached class AgentSelectionForm(forms.Form): selected_agent = AgentModelChoiceField( - queryset=EconomicAgent.objects.individuals_without_user(), + queryset=EconomicAgent.objects.individuals_without_user(), label="Select an existing Agent", required=False) class ContextAgentSelectionForm(forms.Form): selected_agent = AgentModelChoiceField( - queryset=EconomicAgent.objects.context_agents(), + queryset=EconomicAgent.objects.context_agents(), label="Select a Context Agent", empty_label=None,) - + #changed to create context_agents class ProjectForm(forms.ModelForm): name = forms.CharField(widget=forms.TextInput(attrs={'class': 'input-xlarge',})) description = forms.CharField( - required=False, + required=False, widget=forms.Textarea(attrs={'class': 'input-xxlarge',})) class Meta: @@ -130,7 +130,7 @@ class LocationForm(forms.ModelForm): widget=forms.TextInput(attrs={'class': 'input-xxlarge',})) name = forms.CharField(widget=forms.TextInput(attrs={'class': 'input-xlarge',})) description = forms.CharField( - required=False, + required=False, widget=forms.Textarea(attrs={'class': 'input-xxlarge',})) latitude = forms.FloatField(required=False, widget=forms.HiddenInput) longitude = forms.FloatField(required=False, widget=forms.HiddenInput) @@ -138,13 +138,13 @@ class LocationForm(forms.ModelForm): class Meta: model = Location fields = ('address', 'name', 'description', 'latitude', 'longitude') - + class ChangeLocationForm(forms.ModelForm): address = forms.CharField( widget=forms.TextInput(attrs={'class': 'input-xxlarge',})) name = forms.CharField(widget=forms.TextInput(attrs={'class': 'input-xlarge',})) description = forms.CharField( - required=False, + required=False, widget=forms.Textarea(attrs={'class': 'input-xxlarge',})) agents = forms.ModelMultipleChoiceField( required=False, @@ -157,11 +157,11 @@ class ChangeLocationForm(forms.ModelForm): class Meta: model = Location fields = ('address', 'name', 'description', 'latitude', 'longitude') - + class SelectResourceForm(forms.Form): resource = ResourceModelChoiceField( - queryset=EconomicResource.objects.all(), + queryset=EconomicResource.objects.all(), label="Add quantity to selected resource", empty_label=None, widget=forms.Select(attrs={'class': 'resource input-xlarge chzn-select',})) @@ -173,39 +173,39 @@ def __init__(self, resource_type=None, *args, **kwargs): if resource_type: self.fields["resource"].queryset = EconomicResource.goods.filter(resource_type=resource_type) - + class SelectOrCreateResourceForm(forms.ModelForm): resource = ResourceModelChoiceField( - queryset=EconomicResource.objects.all(), + queryset=EconomicResource.objects.all(), label="Add to selected resource or create new resource below", required=False, widget=forms.Select(attrs={'class': 'input-xlarge chzn-select',})) quantity = forms.DecimalField(widget=forms.TextInput(attrs={'class': 'quantity input-small',})) #unit_of_quantity = forms.ModelChoiceField( - # queryset=Unit.objects.exclude(unit_type='value'), + # queryset=Unit.objects.exclude(unit_type='value'), # label=_("Unit"), # empty_label=None, # widget=forms.Select(attrs={'class': 'input-medium',})) identifier = forms.CharField( - required=False, + required=False, label="Identifier", help_text="For example, lot number or serial number.", widget=forms.TextInput(attrs={'class': 'item-name',})) current_location = forms.ModelChoiceField( - queryset=Location.objects.all(), + queryset=Location.objects.all(), required=False, label=_("Current Resource Location"), widget=forms.Select(attrs={'class': 'input-medium chzn-select',})) url = forms.CharField(required=False, widget=forms.TextInput(attrs={'class': 'url input-xxlarge',})) photo_url = forms.CharField(required=False, widget=forms.TextInput(attrs={'class': 'url input-xxlarge',})) notes = forms.CharField( - required=False, + required=False, widget=forms.Textarea(attrs={'class': 'input-xxlarge',})) - + class Meta: model = EconomicResource fields = ('quantity', 'identifier', 'current_location', 'url', 'photo_url', 'notes') - + def __init__(self, resource_type=None, qty_help=None, *args, **kwargs): super(SelectOrCreateResourceForm, self).__init__(*args, **kwargs) #import pdb; pdb.set_trace() @@ -223,7 +223,7 @@ class EconomicResourceForm(forms.ModelForm): widget=forms.HiddenInput) #widget=forms.TextInput(attrs={'value': '0.0', 'class': 'quantity'})) identifier = forms.CharField( - required=False, + required=False, label="Identifier", help_text="For example, lot number or serial number.", widget=forms.TextInput(attrs={'class': 'item-name',})) @@ -237,20 +237,20 @@ class EconomicResourceForm(forms.ModelForm): class Meta: model = EconomicResource - exclude = ('resource_type', - 'owner', - 'author', - 'custodian', - 'photo', - 'quantity', - 'quality', - 'independent_demand', - 'order_item', - 'stage', + exclude = ('resource_type', + 'owner', + 'author', + 'custodian', + 'photo', + 'quantity', + 'quality', + 'independent_demand', + 'order_item', + 'stage', 'exchange_stage', - 'state', - 'stage', - 'state', + 'state', + 'stage', + 'state', 'value_per_unit', ) @@ -259,18 +259,18 @@ def __init__(self, vpu_help=None, *args, **kwargs): if vpu_help: self.fields["value_per_unit_of_use"].widget=forms.TextInput(attrs={'value': '0.0', 'class': 'quantity'}) self.fields["value_per_unit_of_use"].help_text = vpu_help - - + + class CreateEconomicResourceForm(forms.ModelForm): from_agent = forms.ModelChoiceField( required=False, queryset=EconomicAgent.objects.all(), - label="Work done by", + label="Work done by", help_text="Required only if not logging work inputs", widget=forms.Select( attrs={'class': 'chzn-select'})) identifier = forms.CharField( - required=False, + required=False, label="Identifier", help_text="For example, lot number or serial number.", widget=forms.TextInput(attrs={'class': 'item-name',})) @@ -282,12 +282,16 @@ class Meta: model = EconomicResource exclude = ('resource_type', 'owner', 'author', 'custodian', 'quality', 'independent_demand', 'order_item', 'stage', 'state', 'value_per_unit_of_use', 'value_per_unit', 'exchange_stage') +class CreateUnquantifiedResourceForm(CreateEconomicResourceForm): + quantity = None + class Meta: + exclude = CreateEconomicResourceForm.Meta.exclude + ('quantity',) class TransformEconomicResourceForm(forms.ModelForm): from_agent = forms.ModelChoiceField( required=False, queryset=EconomicAgent.objects.all(), - label="Work done by", + label="Work done by", help_text="Required only if not logging work inputs", widget=forms.Select( attrs={'class': 'chzn-select'})) @@ -297,20 +301,20 @@ class TransformEconomicResourceForm(forms.ModelForm): class Meta: model = EconomicEvent fields = ("from_agent", "event_date", "quantity",) - + def __init__(self, qty_help=None, *args, **kwargs): super(TransformEconomicResourceForm, self).__init__(*args, **kwargs) if qty_help: self.fields["quantity"].help_text = qty_help - - + + class ResourceQuantityForm(forms.Form): quantity = forms.DecimalField(widget=forms.TextInput(attrs={'class': 'quantity input-small',})) - + class AddOrderItemForm(forms.Form): resource_type = FacetedModelChoiceField( - queryset=EconomicResourceType.objects.all(), + queryset=EconomicResourceType.objects.all(), empty_label=None, widget=forms.Select( attrs={'class': 'resource-type-selector chzn-select input-xlarge'})) @@ -319,41 +323,41 @@ class AddOrderItemForm(forms.Form): def __init__(self, resource_types, *args, **kwargs): super(AddOrderItemForm, self).__init__(*args, **kwargs) self.fields["resource_type"].queryset = resource_types - + class ResourceRoleAgentForm(forms.ModelForm): id = forms.CharField(required=False, widget=forms.HiddenInput) role = forms.ModelChoiceField( - queryset=AgentResourceRoleType.objects.all(), + queryset=AgentResourceRoleType.objects.all(), required=False, widget=forms.Select( attrs={'class': 'select-role'})) agent = AgentModelChoiceField( - queryset=EconomicAgent.objects.resource_role_agents(), + queryset=EconomicAgent.objects.resource_role_agents(), required=False, widget=forms.Select( attrs={'class': 'select-agent'})) is_contact = forms.BooleanField( - required=False, + required=False, widget=forms.CheckboxInput()) class Meta: model = AgentResourceRole fields = ('id', 'role', 'agent', 'is_contact') - + class FailedOutputForm(forms.ModelForm): quantity = forms.DecimalField(required=False, widget=forms.TextInput(attrs={'class': 'failed-quantity input-small',})) description = forms.CharField( label="Why failed", - required=False, + required=False, widget=forms.Textarea(attrs={'class': 'item-description',})) class Meta: model = EconomicEvent fields = ('quantity', 'description') - + class ResourceAdjustmentForm(forms.ModelForm): quantity = forms.DecimalField(widget=forms.TextInput(attrs={'class': 'quantity input-small',})) description = forms.CharField( @@ -364,10 +368,10 @@ class Meta: model = EconomicEvent fields = ('quantity', 'description') - + class DemandSelectionForm(forms.Form): demand = forms.ModelChoiceField( - queryset=Order.objects.exclude(order_type="holder"), + queryset=Order.objects.exclude(order_type="holder"), label="For customer or R&D order (optional)", required=False) @@ -390,8 +394,8 @@ def __init__(self, *args, **kwargs): super(OrderForm, self).__init__(*args, **kwargs) context_agents = EconomicAgent.objects.context_agents() self.fields["provider"].queryset = context_agents - - + + class ResourceTypeListForm(forms.ModelForm): name = forms.CharField(widget=forms.TextInput(attrs={'class': 'input-xxlarge', })) description = forms.CharField( @@ -401,47 +405,47 @@ class ResourceTypeListForm(forms.ModelForm): class Meta: model = ResourceTypeList - + class ResourceTypeListElementForm(forms.ModelForm): resource_type_id = forms.IntegerField(widget=forms.HiddenInput) resource_type_name = forms.CharField(widget=forms.TextInput(attrs={'readonly': 'readonly', 'class': 'input-xxlarge' })) #default_quantity = forms.DecimalField(required=False, # widget=forms.TextInput(attrs={'value': '1.0', 'class': 'quantity input-small'})) added = forms.BooleanField(required=False, widget=forms.CheckboxInput(attrs={'class': 'added',})) - + class Meta: model = ResourceTypeListElement exclude = ('resource_type_list', 'resource_type', 'default_quantity') - - + + class RandOrderForm(forms.ModelForm): receiver = forms.ModelChoiceField( queryset=EconomicAgent.objects.all(), - label="Receiver (optional)", + label="Receiver (optional)", required=False) provider = forms.ModelChoiceField( - queryset=EconomicAgent.objects.all(), - label="Provider (optional)", + queryset=EconomicAgent.objects.all(), + label="Provider (optional)", required=False) create_order = forms.BooleanField( label="R&D Order without receiver", - required=False, + required=False, widget=forms.CheckboxInput()) class Meta: model = Order fields = ('receiver', 'provider') - - + + class OrderChangeForm(forms.ModelForm): name = forms.CharField(widget=forms.TextInput(attrs={'class': '',})) receiver = forms.ModelChoiceField( queryset=EconomicAgent.objects.all(), - label="Receiver (optional)", + label="Receiver (optional)", required=False) provider = forms.ModelChoiceField( - queryset=EconomicAgent.objects.all(), - label="Provider (optional)", + queryset=EconomicAgent.objects.all(), + label="Provider (optional)", required=False) due_date = forms.DateField(widget=forms.TextInput(attrs={'class': 'input-small date-entry',})) description = forms.CharField( @@ -451,7 +455,7 @@ class OrderChangeForm(forms.ModelForm): class Meta: model = Order fields = ('name', 'receiver', 'provider', 'due_date', 'description') - + class ProcessForm(forms.ModelForm): name = forms.CharField(widget=forms.TextInput(attrs={'class': 'input-xlarge',})) @@ -459,8 +463,8 @@ class ProcessForm(forms.ModelForm): queryset=ProcessPattern.objects.none(), empty_label=None) context_agent = forms.ModelChoiceField( - queryset=EconomicAgent.objects.context_agents(), - empty_label=None, + queryset=EconomicAgent.objects.context_agents(), + empty_label=None, widget=forms.Select(attrs={'class': 'chzn-select'})) start_date = forms.DateField(required=False, widget=forms.TextInput(attrs={'class': 'input-small date-entry',})) end_date = forms.DateField(required=False, widget=forms.TextInput(attrs={'class': 'input-small date-entry',})) @@ -471,8 +475,8 @@ class Meta: def __init__(self, *args, **kwargs): super(ProcessForm, self).__init__(*args, **kwargs) - self.fields["process_pattern"].queryset = ProcessPattern.objects.production_patterns() - + self.fields["process_pattern"].queryset = ProcessPattern.objects.production_patterns() + class WorkflowProcessForm(forms.ModelForm): name = forms.CharField(widget=forms.TextInput(attrs={'class': 'input-xlarge name',})) process_pattern = forms.ModelChoiceField( @@ -489,27 +493,27 @@ class WorkflowProcessForm(forms.ModelForm): label=_("...or create a new Process Type named:"), widget=forms.TextInput(attrs={'class': 'new-pt-name process-info input-xlarge',})) context_agent = forms.ModelChoiceField( - queryset=EconomicAgent.objects.context_agents(), + queryset=EconomicAgent.objects.context_agents(), label=_("Context"), - empty_label=None, + empty_label=None, widget=forms.Select(attrs={'class': 'chzn-select'})) start_date = forms.DateField(required=False, widget=forms.TextInput(attrs={'class': 'input-small date-entry',})) end_date = forms.DateField(required=False, widget=forms.TextInput(attrs={'class': 'input-small date-entry',})) - + class Meta: model = Process fields = ('name', 'context_agent', 'process_pattern', 'process_type', 'start_date', 'end_date', 'notes' ) - + def __init__(self, order_item, next_date=None, *args, **kwargs): super(WorkflowProcessForm, self).__init__(*args, **kwargs) if next_date: self.fields["start_date"] = next_date self.fields["end_date"] = next_date - self.fields["process_pattern"].queryset = ProcessPattern.objects.recipe_patterns() + self.fields["process_pattern"].queryset = ProcessPattern.objects.recipe_patterns() #import pdb; pdb.set_trace() self.fields["process_type"].queryset = order_item.available_workflow_process_types() - + class ScheduleProcessForm(forms.ModelForm): start_date = forms.DateField(required=False, widget=forms.TextInput(attrs={'class': 'input-small date-entry',})) end_date = forms.DateField(required=False, widget=forms.TextInput(attrs={'class': 'input-small date-entry',})) @@ -517,13 +521,13 @@ class ScheduleProcessForm(forms.ModelForm): class Meta: model = Process fields = ('start_date', 'end_date', 'notes' ) - - + + class PlanProcessForm(forms.ModelForm): name = forms.CharField(widget=forms.TextInput(attrs={'class': 'input-xlarge',})) start_date = forms.DateField(required=False, widget=forms.TextInput(attrs={'class': 'input-small date-entry',})) end_date = forms.DateField(required=False, widget=forms.TextInput(attrs={'class': 'input-small date-entry',})) - + class Meta: model = Process fields = ('name', 'start_date', 'end_date') @@ -532,9 +536,9 @@ class Meta: class AddProcessFromResourceForm(forms.ModelForm): name = forms.CharField(widget=forms.TextInput(attrs={'class': 'input-xlarge',})) context_agent = forms.ModelChoiceField( - queryset=EconomicAgent.objects.context_agents(), + queryset=EconomicAgent.objects.context_agents(), label=_("Context"), - empty_label=None, + empty_label=None, widget=forms.Select(attrs={'class': 'chzn-select'})) process_pattern = forms.ModelChoiceField( queryset=ProcessPattern.objects.none(), @@ -554,18 +558,18 @@ def __init__(self, *args, **kwargs): class ProcessInputForm(forms.ModelForm): resource_type = FacetedModelChoiceField( - queryset=EconomicResourceType.objects.all(), + queryset=EconomicResourceType.objects.all(), widget=forms.Select( attrs={'class': 'resource-type-selector chzn-select input-xlarge'})) quantity = forms.DecimalField(required=False, widget=forms.TextInput(attrs={'value': '1.0', 'class': 'quantity input-small'})) unit_of_quantity = forms.ModelChoiceField( - queryset=Unit.objects.exclude(unit_type='value'), + queryset=Unit.objects.exclude(unit_type='value'), label=_("Unit"), empty_label=None, widget=forms.Select(attrs={'class': 'input-medium',})) description = forms.CharField( - required=False, + required=False, widget=forms.Textarea(attrs={'class': 'item-description',})) class Meta: @@ -590,12 +594,12 @@ class SpecialPriceForm(forms.Form): identifier = forms.CharField( widget=forms.TextInput(attrs={'class': 'item-name',})) description = forms.CharField( - required=False, + required=False, widget=forms.Textarea(attrs={'class': 'item-description',})) price_per_unit = forms.DecimalField( max_digits=8, decimal_places=2, widget=forms.TextInput(attrs={'value': '0.0', 'class': 'price'})) - + #new class UnplannedWorkEventForm(forms.ModelForm): event_date = forms.DateField(required=False, widget=forms.TextInput(attrs={'class': 'input-small date-entry',})) @@ -604,25 +608,25 @@ class UnplannedWorkEventForm(forms.ModelForm): label="Type of work done", empty_label=None, widget=forms.Select( - attrs={'class': 'resource-type-selector resourceType chzn-select'})) + attrs={'class': 'resource-type-selector resourceType chzn-select'})) from_agent = forms.ModelChoiceField( required=True, queryset=EconomicAgent.objects.all(), - label="Work done by", + label="Work done by", empty_label=None, widget=forms.Select( - attrs={'class': 'chzn-select'})) + attrs={'class': 'chzn-select'})) quantity = forms.DecimalField(required=False, widget=forms.TextInput(attrs={'value': '1.0', 'class': 'quantity input-small'})) unit_of_quantity = forms.ModelChoiceField( - queryset=Unit.objects.exclude(unit_type='value'), + queryset=Unit.objects.exclude(unit_type='value'), label=_("Unit"), empty_label=None, widget=forms.Select(attrs={'class': 'input-medium',})) description = forms.CharField( - required=False, + required=False, widget=forms.Textarea(attrs={'class': 'input-xxlarge',})) - + class Meta: model = EconomicEvent fields = ('event_date', 'resource_type', 'from_agent', 'quantity', 'unit_of_quantity', 'is_contribution', 'description') @@ -636,37 +640,37 @@ def __init__(self, pattern=None, context_agent=None, *args, **kwargs): if context_agent: self.context_agent = context_agent self.fields["from_agent"].queryset = context_agent.all_members() - + class UninventoriedProductionEventForm(forms.ModelForm): event_date = forms.DateField(required=False, widget=forms.TextInput(attrs={'class': 'input-small date-entry',})) from_agent = forms.ModelChoiceField( required=False, queryset=EconomicAgent.objects.all(), - label="Work done by", + label="Work done by", help_text="Required only if not logging work inputs", widget=forms.Select( - attrs={'class': 'chzn-select'})) + attrs={'class': 'chzn-select'})) quantity = forms.DecimalField(required=False, widget=forms.TextInput(attrs={'value': '1.0', 'class': 'quantity input-small'})) description = forms.CharField( - required=False, + required=False, widget=forms.Textarea(attrs={'class': 'input-xxlarge',})) url = forms.URLField( - required=False, + required=False, label="URL", widget=forms.TextInput(attrs={'class': 'url input-xxlarge',})) - + class Meta: model = EconomicEvent fields = ('event_date', 'from_agent', 'quantity', 'description', 'url') - + def __init__(self, qty_help=None, *args, **kwargs): super(UninventoriedProductionEventForm, self).__init__(*args, **kwargs) if qty_help: self.fields["quantity"].help_text = qty_help - + class PayoutForm(forms.ModelForm): event_date = forms.DateField( label="Payout Date", @@ -675,32 +679,32 @@ class PayoutForm(forms.ModelForm): widget=forms.TextInput(attrs={'value': '1.0', 'class': 'quantity input-small'})) max = forms.DecimalField(required=False, widget=forms.HiddenInput) event_reference = forms.CharField( - required=False, + required=False, label="Reference", widget=forms.TextInput(attrs={'class': 'input-xlarge',})) description = forms.CharField( - required=False, + required=False, widget=forms.Textarea(attrs={'class': 'input-xlarge',})) - + class Meta: model = EconomicEvent fields = ('event_date', 'quantity', 'event_reference', 'description') - + class ProcessConsumableForm(forms.ModelForm): resource_type = FacetedModelChoiceField( - queryset=EconomicResourceType.objects.all(), + queryset=EconomicResourceType.objects.all(), widget=forms.Select( attrs={'class': 'resource-type-selector resourceType chzn-select input-xlarge'})) quantity = forms.DecimalField(required=False, widget=forms.TextInput(attrs={'value': '1.0', 'class': 'quantity input-small'})) unit_of_quantity = forms.ModelChoiceField( - queryset=Unit.objects.exclude(unit_type='value'), + queryset=Unit.objects.exclude(unit_type='value'), label=_("Unit"), empty_label=None, widget=forms.Select(attrs={'class': 'input-medium',})) description = forms.CharField( - required=False, + required=False, widget=forms.Textarea(attrs={'class': 'item-description',})) class Meta: @@ -724,18 +728,18 @@ def __init__(self, pattern=None, *args, **kwargs): class ProcessUsableForm(forms.ModelForm): resource_type = FacetedModelChoiceField( - queryset=EconomicResourceType.objects.all(), + queryset=EconomicResourceType.objects.all(), widget=forms.Select( attrs={'class': 'resource-type-selector resourceType chzn-select input-xlarge'})) quantity = forms.DecimalField(required=False, widget=forms.TextInput(attrs={'value': '1.0', 'class': 'quantity input-small'})) unit_of_quantity = forms.ModelChoiceField( - queryset=Unit.objects.exclude(unit_type='value'), + queryset=Unit.objects.exclude(unit_type='value'), label=_("Unit"), empty_label=None, widget=forms.Select(attrs={'class': 'input-medium',})) description = forms.CharField( - required=False, + required=False, widget=forms.Textarea(attrs={'class': 'item-description',})) class Meta: @@ -760,18 +764,18 @@ def __init__(self, pattern=None, *args, **kwargs): #used in labnotes, create, copy and change_process, and create and change_rand class ProcessOutputForm(forms.ModelForm): resource_type = FacetedModelChoiceField( - queryset=EconomicResourceType.objects.all(), + queryset=EconomicResourceType.objects.all(), widget=forms.Select( attrs={'class': 'resource-type-selector resourceType chzn-select input-xlarge'})) quantity = forms.DecimalField(required=False, widget=forms.TextInput(attrs={'value': '1.0', 'class': 'quantity input-small'})) unit_of_quantity = forms.ModelChoiceField( - queryset=Unit.objects.exclude(unit_type='value').exclude(unit_type='time'), + queryset=Unit.objects.exclude(unit_type='value').exclude(unit_type='time'), empty_label=None, label=_("Unit"), widget=forms.Select(attrs={'class': 'input-medium',})) description = forms.CharField( - required=False, + required=False, widget=forms.Textarea(attrs={'class': 'item-description',})) class Meta: @@ -796,39 +800,39 @@ def __init__(self, pattern=None, *args, **kwargs): class UnplannedOutputForm(forms.ModelForm): resource_type = FacetedModelChoiceField( - queryset=EconomicResourceType.objects.all(), + queryset=EconomicResourceType.objects.all(), empty_label=None, widget=forms.Select( attrs={'class': 'resource-type-selector resourceType chzn-select input-xlarge'})) identifier = forms.CharField( - required=False, + required=False, label="Identifier", help_text="For example, lot number or serial number.", widget=forms.TextInput(attrs={'class': 'item-name',})) quantity = forms.DecimalField(required=False, widget=forms.TextInput(attrs={'value': '1.0', 'class': 'quantity input-small'})) unit_of_quantity = forms.ModelChoiceField( - queryset=Unit.objects.exclude(unit_type='value').exclude(unit_type='time'), + queryset=Unit.objects.exclude(unit_type='value').exclude(unit_type='time'), empty_label=None, label=_("Unit"), widget=forms.Select(attrs={'class': 'input-medium',})) url = forms.URLField( - required=False, + required=False, label="URL", widget=forms.TextInput(attrs={'class': 'url input-xlarge',})) photo_url = forms.URLField( - required=False, + required=False, label="Photo URL", widget=forms.TextInput(attrs={'class': 'url input-xlarge',})) notes = forms.CharField( required=False, - label="Notes", + label="Notes", widget=forms.Textarea(attrs={'class': 'item-description',})) access_rules = forms.CharField( required=False, - label="Resource Access Rules", + label="Resource Access Rules", widget=forms.Textarea(attrs={'class': 'item-description',})) - + class Meta: model = EconomicEvent fields = ('resource_type', 'quantity', 'unit_of_quantity',) @@ -843,18 +847,18 @@ def __init__(self, pattern=None, *args, **kwargs): class UnorderedReceiptForm(forms.ModelForm): event_date = forms.DateField( - required=True, + required=True, label="Received on", widget=forms.TextInput(attrs={'class': 'input-small date-entry', })) from_agent = forms.ModelChoiceField( required=True, queryset=EconomicAgent.objects.all(), - label="Supplier", + label="Supplier", empty_label=None, widget=forms.Select( - attrs={'class': 'chzn-select'})) + attrs={'class': 'chzn-select'})) resource_type = FacetedModelChoiceField( - queryset=EconomicResourceType.objects.all(), + queryset=EconomicResourceType.objects.all(), empty_label=None, help_text="If you don't see the resource type you want, please contact an admin.", widget=forms.Select( @@ -869,41 +873,41 @@ class UnorderedReceiptForm(forms.ModelForm): label="Quantity", widget=forms.TextInput(attrs={'value': '1', 'class': 'quantity input-small'})) unit_of_quantity = forms.ModelChoiceField( - queryset=Unit.objects.exclude(unit_type='value').exclude(unit_type='time'), + queryset=Unit.objects.exclude(unit_type='value').exclude(unit_type='time'), empty_label=None, label=_("Unit"), widget=forms.Select(attrs={'class': 'input-medium',})) description = forms.CharField( required=False, - label="Event Description", + label="Event Description", widget=forms.Textarea(attrs={'class': 'item-description',})) identifier = forms.CharField( - required=False, + required=False, label="Create the resource:

Identifier", help_text="For example, lot number or serial number.", widget=forms.TextInput(attrs={'class': 'item-name',})) url = forms.URLField( - required=False, + required=False, label="URL", widget=forms.TextInput(attrs={'class': 'url input-xlarge',})) photo_url = forms.URLField( - required=False, + required=False, label="Photo URL", widget=forms.TextInput(attrs={'class': 'url input-xlarge',})) current_location = forms.ModelChoiceField( - queryset=Location.objects.all(), + queryset=Location.objects.all(), required=False, label=_("Current Resource Location"), widget=forms.Select(attrs={'class': 'input-medium',})) notes = forms.CharField( required=False, - label="Resource Notes", + label="Resource Notes", widget=forms.Textarea(attrs={'class': 'item-description',})) access_rules = forms.CharField( required=False, - label="Resource Access Rules", + label="Resource Access Rules", widget=forms.Textarea(attrs={'class': 'item-description',})) - + class Meta: model = EconomicEvent fields = ('event_date', 'from_agent', 'resource_type', 'value', 'unit_of_value', 'quantity', 'unit_of_quantity', 'description') @@ -916,18 +920,18 @@ def __init__(self, pattern=None, context_agent=None, *args, **kwargs): self.fields["resource_type"].queryset = pattern.receipt_resource_types() if context_agent: self.context_agent = context_agent - self.fields["from_agent"].queryset = context_agent.all_suppliers() + self.fields["from_agent"].queryset = context_agent.all_suppliers() + - class SelectResourceOfTypeForm(forms.Form): resource_type = FacetedModelChoiceField( - queryset=EconomicResourceType.objects.all(), + queryset=EconomicResourceType.objects.all(), empty_label=None, help_text="If you don't see the resource type you want, please contact an admin.", widget=forms.Select( attrs={'class': 'resource-type-for-resource resourceType chzn-select input-xlarge'})) resource = ResourceModelChoiceField( - queryset=EconomicResource.objects.none(), + queryset=EconomicResource.objects.none(), label="Add quantity to selected resource", empty_label=None, widget=forms.Select(attrs={'class': 'resource input-xxlarge chzn-select',})) @@ -940,9 +944,9 @@ class SelectResourceOfTypeForm(forms.Form): queryset=Unit.objects.filter(unit_type='value')) description = forms.CharField( required=False, - label="Event Description", + label="Event Description", widget=forms.Textarea(attrs={'class': 'item-description',})) - + def __init__(self, pattern=None, posting=False, *args, **kwargs): super(SelectResourceOfTypeForm, self).__init__(*args, **kwargs) #import pdb; pdb.set_trace() @@ -956,27 +960,27 @@ def __init__(self, pattern=None, posting=False, *args, **kwargs): if rts: self.fields["resource"].queryset = EconomicResource.objects.filter(resource_type=rts[0]) - + class SelectContrResourceOfTypeForm(forms.Form): event_date = forms.DateField( - required=True, + required=True, label="Received on", widget=forms.TextInput(attrs={'class': 'input-small date-entry', })) from_agent = forms.ModelChoiceField( required=True, queryset=EconomicAgent.objects.all(), - label="Resource contributed by", + label="Resource contributed by", empty_label=None, widget=forms.Select( attrs={'class': 'chzn-select'})) resource_type = FacetedModelChoiceField( - queryset=EconomicResourceType.objects.all(), + queryset=EconomicResourceType.objects.all(), empty_label=None, help_text="If you don't see the resource type you want, please contact an admin.", widget=forms.Select( attrs={'class': 'resource-type-for-resource resourceType chzn-select input-xlarge'})) resource = ResourceModelChoiceField( - queryset=EconomicResource.objects.none(), + queryset=EconomicResource.objects.none(), label="Add quantity to selected resource", empty_label=None, widget=forms.Select(attrs={'class': 'resource input-xxlarge chzn-select',})) @@ -989,9 +993,9 @@ class SelectContrResourceOfTypeForm(forms.Form): queryset=Unit.objects.filter(unit_type='value')) description = forms.CharField( required=False, - label="Event Description", + label="Event Description", widget=forms.Textarea(attrs={'class': 'item-description',})) - + def __init__(self, pattern=None, posting=False, *args, **kwargs): super(SelectContrResourceOfTypeForm, self).__init__(*args, **kwargs) #import pdb; pdb.set_trace() @@ -1004,29 +1008,29 @@ def __init__(self, pattern=None, posting=False, *args, **kwargs): else: if rts: self.fields["resource"].queryset = EconomicResource.objects.filter(resource_type=rts[0]) - + class TodoForm(forms.ModelForm): from_agent = forms.ModelChoiceField( required=False, queryset=EconomicAgent.objects.individuals(), - label="Assigned to", + label="Assigned to", widget=forms.Select( attrs={'class': 'chzn-select'})) resource_type = WorkModelChoiceField( - queryset=EconomicResourceType.objects.all(), - label="Type of work", + queryset=EconomicResourceType.objects.all(), + label="Type of work", empty_label=None, widget=forms.Select( attrs={'class': 'chzn-select'})) context_agent = forms.ModelChoiceField( - queryset=EconomicAgent.objects.context_agents(), + queryset=EconomicAgent.objects.context_agents(), label=_("Context"), - empty_label=None, + empty_label=None, widget=forms.Select(attrs={'class': 'chzn-select'})) due_date = forms.DateField(widget=forms.TextInput(attrs={'class': 'input-small date-entry',})) description = forms.CharField( - required=False, + required=False, widget=forms.Textarea(attrs={'class': 'todo-description input-xlarge',})) url = forms.URLField(required=False, widget=forms.TextInput(attrs={'class': 'url input-xlarge',})) @@ -1044,10 +1048,10 @@ def __init__(self, pattern=None, *args, **kwargs): #used in labnotes class OldProcessCitationForm(forms.Form): #todo: this could now become a ModelChoiceField - resource_type = forms.ChoiceField( + resource_type = forms.ChoiceField( widget=forms.Select(attrs={'class': 'chzn-select input-xlarge'})) description = forms.CharField( - required=False, + required=False, widget=forms.Textarea(attrs={'class': 'item-description',})) def __init__(self, pattern=None, *args, **kwargs): @@ -1064,7 +1068,7 @@ class ProcessCitationForm(forms.ModelForm): queryset=EconomicResourceType.objects.all(), widget=forms.Select(attrs={'class': 'chzn-select input-xlarge'})) description = forms.CharField( - required=False, + required=False, widget=forms.Textarea(attrs={'class': 'item-description',})) class Meta: @@ -1079,16 +1083,16 @@ def __init__(self, pattern=None, *args, **kwargs): self.fields["resource_type"].queryset = pattern.citable_resource_types() -#used in change_process +#used in change_process class ProcessCitationCommitmentForm(forms.ModelForm): resource_type = FacetedModelChoiceField( queryset=EconomicResourceType.objects.all(), widget=forms.Select(attrs={'class': 'input-xlarge'})) quantity = forms.BooleanField( - required=False, + required=False, widget=forms.CheckboxInput()) description = forms.CharField( - required=False, + required=False, widget=forms.Textarea(attrs={'class': 'item-description',})) class Meta: @@ -1115,7 +1119,7 @@ class SelectCitationResourceForm(forms.Form): resource_type = FacetedModelChoiceField( queryset=EconomicResourceType.objects.none(), widget=forms.Select(attrs={'class': 'input-xxlarge', 'onchange': 'getResources();'})) - resource = forms.ChoiceField(widget=forms.Select(attrs={'class': 'input-xlarge'})) + resource = forms.ChoiceField(widget=forms.Select(attrs={'class': 'input-xlarge'})) def __init__(self, pattern, *args, **kwargs): #import pdb; pdb.set_trace() @@ -1128,13 +1132,13 @@ class UnplannedCiteEventForm(forms.Form): resource_type = FacetedModelChoiceField( queryset=EconomicResourceType.objects.all(), widget=forms.Select(attrs={'class': 'input-xxlarge res-ajax resourceType citation-selector'})) - resource = forms.ChoiceField(widget=forms.Select(attrs={'class': 'input-xlarge'})) + resource = forms.ChoiceField(widget=forms.Select(attrs={'class': 'input-xlarge'})) quantity = forms.DecimalField(widget=forms.TextInput(attrs={'class': 'quantity input-small',})) unit_of_quantity = forms.CharField(widget=forms.TextInput(attrs={'readonly': 'readonly' })) #unit_of_quantity = forms.ModelChoiceField( # required = False, # label = _("Unit"), - # queryset=Unit.objects.all(), + # queryset=Unit.objects.all(), # widget=forms.Select(attrs={'readonly': 'readonly' })) def __init__(self, pattern, load_resources=False, *args, **kwargs): @@ -1153,13 +1157,13 @@ class UnplannedInputEventForm(forms.Form): resource_type = FacetedModelChoiceField( queryset=EconomicResourceType.objects.none(), widget=forms.Select(attrs={'class': 'input-xxlarge resourceType resource-type-selector res-ajax'})) - resource = forms.ChoiceField(widget=forms.Select(attrs={'class': 'input-xlarge'})) + resource = forms.ChoiceField(widget=forms.Select(attrs={'class': 'input-xlarge'})) quantity = forms.DecimalField( widget=forms.TextInput(attrs={'class': 'quantity input-small',})) unit_of_quantity = forms.ModelChoiceField( required = False, label = _("Unit"), - queryset=Unit.objects.exclude(unit_type='value'), + queryset=Unit.objects.exclude(unit_type='value'), widget=forms.Select()) def __init__(self, pattern, load_resources=False, *args, **kwargs): @@ -1185,19 +1189,19 @@ class CashEventAgentForm(forms.ModelForm): label="Type of cash", empty_label=None, widget=forms.Select( - attrs={'class': 'chzn-select'})) + attrs={'class': 'chzn-select'})) quantity = forms.DecimalField( widget=forms.TextInput(attrs={'class': 'quantity input-small',})) description = forms.CharField( - required=False, + required=False, widget=forms.Textarea(attrs={'class': 'input-xxlarge',})) from_agent = forms.ModelChoiceField( required=True, queryset=EconomicAgent.objects.all(), - label="Cash contributed by", + label="Cash contributed by", widget=forms.Select( - attrs={'class': 'chzn-select'})) - + attrs={'class': 'chzn-select'})) + class Meta: model = EconomicEvent fields = ('event_date', 'resource_type','quantity', 'description', 'from_agent') @@ -1215,13 +1219,13 @@ def __init__(self, agent=None, date=None, pattern=None, context_agent=None, *arg if context_agent: self.context_agent = context_agent self.fields["from_agent"].queryset = context_agent.all_members() -''' +''' class CommitmentForm(forms.ModelForm): start_date = forms.DateField(widget=forms.TextInput(attrs={'class': 'input-small date-entry',})) quantity = forms.DecimalField( label="Estimated quantity (optional)", - required=False, + required=False, widget=forms.TextInput(attrs={'class': 'quantity input-small',})) description = forms.CharField(required=False, widget=forms.Textarea(attrs={'class': 'item-description',})) @@ -1244,7 +1248,7 @@ class Meta: class ChangeWorkCommitmentForm(forms.ModelForm): due_date = forms.DateField(widget=forms.TextInput(attrs={'class': 'input-small date-entry',})) quantity = forms.DecimalField( - required=False, + required=False, widget=forms.TextInput(attrs={'class': 'quantity input-small',})) description = forms.CharField(required=False, widget=forms.Textarea(attrs={'class': 'item-description',})) @@ -1256,16 +1260,16 @@ class Meta: class WorkbookForm(forms.ModelForm): work_done = forms.BooleanField( - required=False, + required=False, widget=forms.CheckboxInput()) process_done = forms.BooleanField( - required=False, + required=False, widget=forms.CheckboxInput()) description = forms.CharField(required=False, widget=forms.Textarea(attrs={'class': 'item-description',})) quantity = forms.DecimalField(required=False, widget=DecimalDurationWidget, help_text="hours, minutes") - + class Meta: model = EconomicEvent fields = ('quantity', 'description') @@ -1274,17 +1278,17 @@ class Meta: class PastWorkForm(forms.ModelForm): id = forms.CharField(required=False, widget=forms.HiddenInput) work_done = forms.BooleanField( - required=False, + required=False, widget=forms.CheckboxInput()) process_done = forms.BooleanField( - required=False, + required=False, widget=forms.CheckboxInput()) event_date = forms.DateField(required=False, widget=forms.TextInput(attrs={'class': 'input-small date-entry',})) description = forms.CharField(required=False, widget=forms.Textarea(attrs={'class': 'item-description',})) quantity = forms.DecimalField(required=False, widget=DecimalDurationWidget, help_text="hours, minutes") - + class Meta: model = EconomicEvent fields = ('id', 'event_date', 'quantity', 'description') @@ -1297,17 +1301,17 @@ class WorkEventAgentForm(forms.ModelForm): label="Type of work done", empty_label=None, widget=forms.Select( - attrs={'class': 'chzn-select'})) + attrs={'class': 'chzn-select'})) quantity = forms.DecimalField(required=True, label="Hours, up to 2 decimal places", widget=forms.TextInput(attrs={'class': 'quantity input-small',})) description = forms.CharField( - required=False, + required=False, widget=forms.Textarea(attrs={'class': 'item-description',})) from_agent = forms.ModelChoiceField( required=True, queryset=EconomicAgent.objects.all(), - label="Work done by", + label="Work done by", empty_label=None, widget=forms.Select( attrs={'class': 'chzn-select'})) @@ -1315,8 +1319,8 @@ class WorkEventAgentForm(forms.ModelForm): required=False, initial=True, label="Can be used in a value equation", - widget=forms.CheckboxInput()) - + widget=forms.CheckboxInput()) + class Meta: model = EconomicEvent fields = ('event_date', 'resource_type','quantity', 'description', 'from_agent', 'is_contribution') @@ -1328,7 +1332,7 @@ def __init__(self, context_agent=None, *args, **kwargs): self.context_agent = context_agent self.fields["from_agent"].queryset = context_agent.all_members() - + class WorkCommitmentForm(forms.ModelForm): due_date = forms.DateField(widget=forms.TextInput(attrs={'class': 'input-small date-entry',})) resource_type = WorkModelChoiceField( @@ -1336,13 +1340,13 @@ class WorkCommitmentForm(forms.ModelForm): label="Type of work", empty_label=None, widget=forms.Select( - attrs={'class': 'chzn-select resourceType resource-type-selector'})) + attrs={'class': 'chzn-select resourceType resource-type-selector'})) quantity = forms.DecimalField(required=True, widget=forms.TextInput(attrs={'class': 'quantity input-small',})) description = forms.CharField( - required=False, + required=False, widget=forms.Textarea(attrs={'class': 'input-xxlarge',})) - + class Meta: model = Commitment fields = ('due_date', 'resource_type','quantity', 'unit_of_quantity', 'description') @@ -1354,7 +1358,7 @@ def __init__(self, pattern=None, *args, **kwargs): self.pattern = pattern self.fields["resource_type"].queryset = pattern.work_resource_types() - + class InviteCollaboratorForm(forms.ModelForm): due_date = forms.DateField(widget=forms.TextInput(attrs={'class': 'input-small date-entry',})) quantity = forms.DecimalField( @@ -1362,9 +1366,9 @@ class InviteCollaboratorForm(forms.ModelForm): help_text="", widget=forms.TextInput(attrs={'class': 'quantity input-small',})) description = forms.CharField( - required=False, + required=False, widget=forms.Textarea(attrs={'class': 'input-xxlarge',})) - + class Meta: model = Commitment fields = ('due_date', 'quantity', 'description') @@ -1375,21 +1379,21 @@ def __init__(self, qty_help=None, *args, **kwargs): if qty_help: self.fields["quantity"].help_text = qty_help - + class ProcessWorkForm(forms.ModelForm): resource_type = WorkModelChoiceField( queryset=EconomicResourceType.objects.none(), label="Type of work", widget=forms.Select( - attrs={'class': 'chzn-select'})) + attrs={'class': 'chzn-select'})) quantity = forms.DecimalField(required=True, widget=DecimalDurationWidget, label="Estimated time", help_text="hours, minutes") description = forms.CharField( - required=False, + required=False, widget=forms.Textarea(attrs={'class': 'item-description',})) - + class Meta: model = Commitment fields = ('resource_type','quantity', 'description') @@ -1421,9 +1425,9 @@ class WorkEventChangeForm(forms.ModelForm): widget=DecimalDurationWidget, help_text="hours, minutes") description = forms.CharField( - required=False, + required=False, widget=forms.Textarea(attrs={'class': 'input-xxlarge',})) - + class Meta: model = EconomicEvent fields = ('id', 'event_date', 'quantity', 'is_contribution', 'description') @@ -1436,9 +1440,9 @@ class WorkEventForm(forms.ModelForm): widget=DecimalDurationWidget, help_text="hours, minutes") description = forms.CharField( - required=False, + required=False, widget=forms.Textarea(attrs={'class': 'input-xxlarge',})) - + class Meta: model = EconomicEvent fields = ('event_date', 'quantity', 'description') @@ -1451,9 +1455,9 @@ class TimeEventForm(forms.ModelForm): widget=DecimalDurationWidget, help_text="hours, minutes") description = forms.CharField( - required=False, + required=False, widget=forms.Textarea(attrs={'class': 'input-xxlarge',})) - + class Meta: model = EconomicEvent fields = ('id', 'event_date', 'quantity', 'description') @@ -1463,9 +1467,9 @@ class InputEventForm(forms.ModelForm): event_date = forms.DateField(required=False, widget=forms.TextInput(attrs={'class': 'input-small date-entry',})) quantity = forms.DecimalField(widget=forms.TextInput(attrs={'class': 'quantity input-small',})) description = forms.CharField( - required=False, + required=False, widget=forms.Textarea(attrs={'class': 'input-xxlarge',})) - + class Meta: model = EconomicEvent fields = ('event_date', 'quantity', 'description') @@ -1480,16 +1484,16 @@ class InputEventAgentForm(forms.ModelForm): from_agent = forms.ModelChoiceField( required=True, queryset=EconomicAgent.objects.individuals(), - label="Work done by", + label="Work done by", empty_label=None, widget=forms.Select( - attrs={'class': 'chzn-select'})) + attrs={'class': 'chzn-select'})) event_date = forms.DateField(required=False, widget=forms.TextInput(attrs={'class': 'input-small date-entry',})) quantity = forms.DecimalField(widget=forms.TextInput(attrs={'class': 'quantity input-small',})) description = forms.CharField( - required=False, + required=False, widget=forms.Textarea(attrs={'class': 'input-xxlarge',})) - + class Meta: model = EconomicEvent fields = ('event_date', 'from_agent', 'quantity', 'is_contribution', 'description', ) @@ -1498,21 +1502,21 @@ def __init__(self, qty_help=None, *args, **kwargs): super(InputEventAgentForm, self).__init__(*args, **kwargs) if qty_help: self.fields["quantity"].help_text = qty_help - + #may be obsolete class WorkContributionChangeForm(forms.ModelForm): id = forms.CharField(required=False, widget=forms.HiddenInput) event_date = forms.DateField(required=False, widget=forms.TextInput(attrs={'class': 'input-small date-entry',})) resource_type = WorkModelChoiceField( - queryset=EconomicResourceType.objects.all(), - label="Type of work", + queryset=EconomicResourceType.objects.all(), + label="Type of work", empty_label=None, widget=forms.Select( attrs={'class': 'chzn-select'})) context_agent = forms.ModelChoiceField( - queryset=EconomicAgent.objects.context_agents(), + queryset=EconomicAgent.objects.context_agents(), label=_("Context"), - empty_label=None, + empty_label=None, widget=forms.Select(attrs={'class': 'chzn-select'})) quantity = forms.DecimalField(required=False, widget=DecimalDurationWidget, @@ -1520,9 +1524,9 @@ class WorkContributionChangeForm(forms.ModelForm): help_text="hours, minutes") url = forms.CharField(required=False, widget=forms.TextInput(attrs={'class': 'url input-xxlarge',})) description = forms.CharField( - required=False, + required=False, widget=forms.Textarea(attrs={'class': 'input-xxlarge',})) - + class Meta: model = EconomicEvent fields = ('id', 'event_date', 'resource_type', 'context_agent', 'quantity', 'url', 'description') @@ -1531,7 +1535,7 @@ class Meta: class EventChangeDateForm(forms.ModelForm): id = forms.CharField(required=False, widget=forms.HiddenInput) event_date = forms.DateField(required=False, widget=forms.TextInput(attrs={'class': 'input-small date-entry',})) - + class Meta: model = EconomicEvent fields = ('id', 'event_date') @@ -1539,28 +1543,28 @@ class Meta: class EventChangeQuantityForm(forms.ModelForm): id = forms.CharField(required=False, widget=forms.HiddenInput) quantity = forms.DecimalField(widget=forms.TextInput(attrs={'class': 'quantity input-small',})) - + class Meta: model = EconomicEvent fields = ('id', 'quantity') class TransferForm(forms.Form): - event_date = forms.DateField(required=True, + event_date = forms.DateField(required=True, widget=forms.TextInput(attrs={'class': 'input-small date-entry',})) to_agent = forms.ModelChoiceField( required=False, queryset=EconomicAgent.objects.all(), - label="Transferred to", + label="Transferred to", empty_label=None, widget=forms.Select( - attrs={'class': 'chzn-select'})) + attrs={'class': 'chzn-select'})) from_agent = forms.ModelChoiceField( required=False, queryset=EconomicAgent.objects.all(), - label="Transferred from", + label="Transferred from", empty_label=None, widget=forms.Select( - attrs={'class': 'chzn-select'})) + attrs={'class': 'chzn-select'})) quantity = forms.DecimalField( label="Quantity transferred", initial=1, @@ -1590,7 +1594,7 @@ class TransferForm(forms.Form): required=False, queryset=Unit.objects.filter(unit_type='value')) description = forms.CharField( - required=False, + required=False, widget=forms.Textarea(attrs={'class': 'item-description',})) is_contribution = forms.BooleanField( required=False, @@ -1601,35 +1605,35 @@ class TransferForm(forms.Form): initial=True, widget=forms.CheckboxInput()) event_reference = forms.CharField( - required=False, + required=False, label="Reference", widget=forms.TextInput(attrs={'class': 'input-xlarge',})) identifier = forms.CharField( - required=False, + required=False, label="Create the resource:

Identifier", help_text="For example, lot number or serial number.", widget=forms.TextInput(attrs={'class': 'item-name',})) url = forms.URLField( - required=False, + required=False, label="URL", widget=forms.TextInput(attrs={'class': 'url input-xlarge',})) photo_url = forms.URLField( - required=False, + required=False, label="Photo URL", widget=forms.TextInput(attrs={'class': 'url input-xlarge',})) current_location = forms.ModelChoiceField( - queryset=Location.objects.all(), + queryset=Location.objects.all(), required=False, label=_("Current Resource Location"), widget=forms.Select(attrs={'class': 'input-medium',})) notes = forms.CharField( required=False, - label="Resource Notes", + label="Resource Notes", widget=forms.Textarea(attrs={'class': 'item-description',})) access_rules = forms.CharField( required=False, - label="Resource Access Rules", - widget=forms.Textarea(attrs={'class': 'item-description',})) + label="Resource Access Rules", + widget=forms.Textarea(attrs={'class': 'item-description',})) def __init__(self, transfer_type=None, context_agent=None, resource_type=None, posting=False, *args, **kwargs): #import pdb; pdb.set_trace() @@ -1655,24 +1659,24 @@ def __init__(self, transfer_type=None, context_agent=None, resource_type=None, p class TransferCommitmentForm(forms.Form): - commitment_date = forms.DateField(required=True, + commitment_date = forms.DateField(required=True, widget=forms.TextInput(attrs={'class': 'input-small date-entry',})) - due_date = forms.DateField(required=True, + due_date = forms.DateField(required=True, widget=forms.TextInput(attrs={'class': 'input-small date-entry',})) to_agent = forms.ModelChoiceField( required=False, queryset=EconomicAgent.objects.all(), - label="Transfer to", + label="Transfer to", empty_label=None, widget=forms.Select( - attrs={'class': 'chzn-select'})) + attrs={'class': 'chzn-select'})) from_agent = forms.ModelChoiceField( required=False, queryset=EconomicAgent.objects.all(), - label="Transfer from", + label="Transfer from", empty_label=None, widget=forms.Select( - attrs={'class': 'chzn-select'})) + attrs={'class': 'chzn-select'})) quantity = forms.DecimalField( label="Quantity", initial=1, @@ -1692,9 +1696,9 @@ class TransferCommitmentForm(forms.Form): required=False, queryset=Unit.objects.filter(unit_type='value')) description = forms.CharField( - required=False, + required=False, widget=forms.Textarea(attrs={'class': 'item-description',})) - + def __init__(self, transfer_type=None, context_agent=None, posting=False, *args, **kwargs): super(TransferCommitmentForm, self).__init__(*args, **kwargs) #import pdb; pdb.set_trace() @@ -1710,17 +1714,17 @@ class PaymentEventForm(forms.ModelForm): to_agent = forms.ModelChoiceField( required=True, queryset=EconomicAgent.objects.all(), - label="Payment made to", + label="Payment made to", empty_label=None, widget=forms.Select( - attrs={'class': 'chzn-select'})) + attrs={'class': 'chzn-select'})) from_agent = forms.ModelChoiceField( required=True, queryset=EconomicAgent.objects.all(), - label="Payment made by", + label="Payment made by", empty_label=None, widget=forms.Select( - attrs={'class': 'chzn-select'})) + attrs={'class': 'chzn-select'})) quantity = forms.DecimalField( label="Payment amount", widget=forms.TextInput(attrs={'class': 'quantity input-small',})) @@ -1731,12 +1735,12 @@ class PaymentEventForm(forms.ModelForm): widget=forms.Select( attrs={'class': 'resource-type-for-resource chzn-select'})) resource = ResourceModelChoiceField( - queryset=EconomicResource.objects.all(), + queryset=EconomicResource.objects.all(), label="Cash resource account or earmark to decrease", required=False, - widget=forms.Select(attrs={'class': 'resource input-xlarge chzn-select',})) + widget=forms.Select(attrs={'class': 'resource input-xlarge chzn-select',})) description = forms.CharField( - required=False, + required=False, widget=forms.Textarea(attrs={'class': 'input-xxlarge',})) class Meta: @@ -1771,16 +1775,16 @@ class CashReceiptForm(forms.ModelForm): to_agent = forms.ModelChoiceField( required=True, queryset=EconomicAgent.objects.all(), - label="Payment received by", + label="Payment received by", empty_label=None, widget=forms.Select( - attrs={'class': 'chzn-select'})) + attrs={'class': 'chzn-select'})) from_agent = forms.ModelChoiceField( required=False, queryset=EconomicAgent.objects.all(), label="Payment made by", widget=forms.Select( - attrs={'class': 'chzn-select'})) + attrs={'class': 'chzn-select'})) quantity = forms.DecimalField( label="Receipt amount", widget=forms.TextInput(attrs={'class': 'quantity input-small',})) @@ -1789,14 +1793,14 @@ class CashReceiptForm(forms.ModelForm): label="Cash resource type received into", empty_label=None, widget=forms.Select( - attrs={'class': 'resource-type-for-resource resourceType chzn-select'})) + attrs={'class': 'resource-type-for-resource resourceType chzn-select'})) resource = ResourceModelChoiceField( - queryset=EconomicResource.objects.all(), + queryset=EconomicResource.objects.all(), label="Cash resource account or earmark to increase", required=False, - widget=forms.Select(attrs={'class': 'resource input-xlarge chzn-select',})) + widget=forms.Select(attrs={'class': 'resource input-xlarge chzn-select',})) description = forms.CharField( - required=False, + required=False, widget=forms.Textarea(attrs={'class': 'input-xxlarge',})) class Meta: @@ -1830,23 +1834,23 @@ def __init__(self, pattern=None, context_agent=None, posting=False, *args, **kwa self.context_agent = context_agent self.fields["to_agent"].queryset = context_agent.all_ancestors() self.fields["from_agent"].choices = [('', '----------')] + [(ca.id, ca.nick) for ca in context_agent.all_customers()] - + class CashReceiptResourceForm(forms.ModelForm): event_date = forms.DateField(required=False, widget=forms.TextInput(attrs={'class': 'input-small date-entry',})) to_agent = forms.ModelChoiceField( required=True, queryset=EconomicAgent.objects.all(), - label="Payment received by", + label="Payment received by", empty_label=None, widget=forms.Select( - attrs={'class': 'chzn-select'})) + attrs={'class': 'chzn-select'})) from_agent = forms.ModelChoiceField( required=False, queryset=EconomicAgent.objects.all(), label="Payment made by", widget=forms.Select( - attrs={'class': 'chzn-select'})) + attrs={'class': 'chzn-select'})) quantity = forms.DecimalField( label="Receipt amount", widget=forms.TextInput(attrs={'class': 'quantity input-small',})) @@ -1855,22 +1859,22 @@ class CashReceiptResourceForm(forms.ModelForm): label="Cash resource type received into", empty_label=None, widget=forms.Select( - attrs={'class': 'chzn-select'})) + attrs={'class': 'chzn-select'})) description = forms.CharField( - required=False, + required=False, widget=forms.Textarea(attrs={'class': 'input-xxlarge',})) identifier = forms.CharField( - required=False, + required=False, label="Create the resource:

Identifier", widget=forms.TextInput(attrs={'class': 'item-name',})) current_location = forms.ModelChoiceField( - queryset=Location.objects.all(), + queryset=Location.objects.all(), required=False, label=_("Current Resource Location"), widget=forms.Select(attrs={'class': 'input-medium',})) notes = forms.CharField( required=False, - label="Resource Notes", + label="Resource Notes", widget=forms.Textarea(attrs={'class': 'item-description',})) class Meta: @@ -1892,16 +1896,16 @@ def __init__(self, pattern=None, context_agent=None, *args, **kwargs): self.context_agent = context_agent self.fields["to_agent"].queryset = context_agent.all_ancestors() self.fields["from_agent"].choices = [('', '----------')] + [(ca.id, ca.nick) for ca in context_agent.all_customers()] - + class DistributionEventForm(forms.ModelForm): event_date = forms.DateField(required=False, widget=forms.TextInput(attrs={'class': 'input-small date-entry',})) to_agent = forms.ModelChoiceField( required=True, queryset=EconomicAgent.objects.all(), - label="Distributed to", + label="Distributed to", empty_label=None, widget=forms.Select( - attrs={'class': 'chzn-select'})) + attrs={'class': 'chzn-select'})) quantity = forms.DecimalField( label="Distribution amount", widget=forms.TextInput(attrs={'class': 'quantity input-small',})) @@ -1912,12 +1916,12 @@ class DistributionEventForm(forms.ModelForm): widget=forms.Select( attrs={'class': 'resource-type-for-resource chzn-select'})) resource = ResourceModelChoiceField( - queryset=EconomicResource.objects.all(), + queryset=EconomicResource.objects.all(), label="Resource account or earmark to increase", required=False, widget=forms.Select(attrs={'class': 'resource input-xlarge chzn-select',})) description = forms.CharField( - required=False, + required=False, widget=forms.Textarea(attrs={'class': 'input-xxlarge',})) class Meta: @@ -1944,7 +1948,7 @@ def __init__(self, pattern=None, posting=False, *args, **kwargs): self.fields["resource"].queryset = EconomicResource.objects.filter(resource_type=rts[0]) else: self.fields["resource"].queryset = EconomicResource.objects.filter(resource_type=rts[0]) - + class DisbursementEventForm(forms.ModelForm): event_date = forms.DateField(required=False, widget=forms.TextInput(attrs={'class': 'input-small date-entry',})) @@ -1958,12 +1962,12 @@ class DisbursementEventForm(forms.ModelForm): widget=forms.Select( attrs={'class': 'resource-type-for-resource chzn-select'})) resource = ResourceModelChoiceField( - queryset=EconomicResource.objects.all(), + queryset=EconomicResource.objects.all(), label="Account or earmark to decrease", required=False, widget=forms.Select(attrs={'class': 'resource input-xlarge chzn-select',})) description = forms.CharField( - required=False, + required=False, widget=forms.Textarea(attrs={'class': 'input-xxlarge',})) class Meta: @@ -1991,21 +1995,21 @@ def __init__(self, pattern=None, posting=False, *args, **kwargs): else: self.fields["resource"].queryset = EconomicResource.objects.filter(resource_type=rts[0]) - + class ShipmentForm(forms.ModelForm): event_date = forms.DateField(required=False, widget=forms.TextInput(attrs={'class': 'input-small date-entry',})) from_agent = forms.ModelChoiceField( required=True, queryset=EconomicAgent.objects.all(), - label="From", + label="From", empty_label=None, widget=forms.Select( - attrs={'class': 'chzn-select'})) + attrs={'class': 'chzn-select'})) quantity = forms.DecimalField( label="Quantity shipped", widget=forms.TextInput(attrs={'class': 'quantity input-small',})) resource = ResourceModelChoiceField( - queryset=EconomicResource.objects.onhand(), + queryset=EconomicResource.objects.onhand(), label="Resource shipped", empty_label=None, widget=forms.Select(attrs={'class': 'resource input-xlarge chzn-select',})) @@ -2016,7 +2020,7 @@ class ShipmentForm(forms.ModelForm): empty_label=None, queryset=Unit.objects.filter(unit_type='value')) description = forms.CharField( - required=False, + required=False, widget=forms.Textarea(attrs={'class': 'input-xxlarge',})) class Meta: @@ -2037,10 +2041,10 @@ class UninventoriedShipmentForm(forms.ModelForm): from_agent = forms.ModelChoiceField( required=True, queryset=EconomicAgent.objects.all(), - label="From", + label="From", empty_label=None, widget=forms.Select( - attrs={'class': 'chzn-select'})) + attrs={'class': 'chzn-select'})) quantity = forms.DecimalField( label="Quantity shipped", widget=forms.TextInput(attrs={'class': 'quantity input-small',})) @@ -2054,7 +2058,7 @@ class UninventoriedShipmentForm(forms.ModelForm): empty_label=None, queryset=Unit.objects.filter(unit_type='value')) description = forms.CharField( - required=False, + required=False, widget=forms.Textarea(attrs={'class': 'input-xxlarge',})) class Meta: @@ -2075,10 +2079,10 @@ class ShipmentFromCommitmentForm(forms.ModelForm): from_agent = forms.ModelChoiceField( required=True, queryset=EconomicAgent.objects.all(), - label="From", + label="From", empty_label=None, widget=forms.Select( - attrs={'class': 'chzn-select'})) + attrs={'class': 'chzn-select'})) quantity = forms.DecimalField( label="Quantity shipped", widget=forms.TextInput(attrs={'class': 'quantity input-small',})) @@ -2088,7 +2092,7 @@ class ShipmentFromCommitmentForm(forms.ModelForm): empty_label=None, queryset=Unit.objects.filter(unit_type='value')) description = forms.CharField( - required=False, + required=False, widget=forms.Textarea(attrs={'class': 'input-xxlarge',})) class Meta: @@ -2100,7 +2104,7 @@ def __init__(self, context_agent=None, *args, **kwargs): if context_agent: self.context_agent = context_agent self.fields["from_agent"].queryset = context_agent.all_ancestors() - + class ExpenseEventForm(forms.ModelForm): event_date = forms.DateField(required=False, widget=forms.TextInput(attrs={'class': 'input-small date-entry',})) resource_type = forms.ModelChoiceField( @@ -2109,7 +2113,7 @@ class ExpenseEventForm(forms.ModelForm): empty_label=None, help_text="If you don't see the resource type you want, please contact an admin.", widget=forms.Select( - attrs={'class': 'chzn-select'})) + attrs={'class': 'chzn-select'})) unit_of_value = forms.ModelChoiceField( empty_label=None, queryset=Unit.objects.filter(unit_type='value')) @@ -2118,15 +2122,15 @@ class ExpenseEventForm(forms.ModelForm): queryset=EconomicAgent.objects.all(), label="Supplier", widget=forms.Select( - attrs={'class': 'chzn-select'})) + attrs={'class': 'chzn-select'})) description = forms.CharField( - required=False, + required=False, widget=forms.Textarea(attrs={'class': 'input-xxlarge',})) value = forms.DecimalField( widget=forms.TextInput(attrs={'class': 'value input-small',})) resource = ResourceModelChoiceField( required=False, - queryset=EconomicResource.objects.all(), + queryset=EconomicResource.objects.all(), label="Resource to reference", widget=forms.Select(attrs={'class': 'resource input-xlarge chzn-select',})) @@ -2143,7 +2147,7 @@ def __init__(self, pattern=None, context_agent=None, *args, **kwargs): if context_agent: self.context_agent = context_agent self.fields["from_agent"].queryset = context_agent.all_suppliers() - + class ProcessExpenseEventForm(forms.ModelForm): event_date = forms.DateField(required=False, widget=forms.TextInput(attrs={'class': 'input-small date-entry',})) resource_type = forms.ModelChoiceField( @@ -2152,7 +2156,7 @@ class ProcessExpenseEventForm(forms.ModelForm): empty_label=None, help_text="If you don't see the resource type you want, please contact an admin.", widget=forms.Select( - attrs={'class': 'chzn-select'})) + attrs={'class': 'chzn-select'})) unit_of_value = forms.ModelChoiceField( empty_label=None, queryset=Unit.objects.filter(unit_type='value')) @@ -2161,15 +2165,15 @@ class ProcessExpenseEventForm(forms.ModelForm): queryset=EconomicAgent.objects.all(), label="Contributor", widget=forms.Select( - attrs={'class': 'chzn-select'})) + attrs={'class': 'chzn-select'})) description = forms.CharField( - required=False, + required=False, widget=forms.Textarea(attrs={'class': 'input-xxlarge',})) value = forms.DecimalField( widget=forms.TextInput(attrs={'class': 'value input-small',})) #resource = ResourceModelChoiceField( # required=False, - # queryset=EconomicResource.objects.all(), + # queryset=EconomicResource.objects.all(), # label="Resource to reference", # widget=forms.Select(attrs={'class': 'resource input-xlarge chzn-select',})) @@ -2183,7 +2187,7 @@ def __init__(self, pattern=None, *args, **kwargs): self.pattern = pattern #import pdb; pdb.set_trace() self.fields["resource_type"].queryset = pattern.process_expense_resource_types() - + class CashContributionEventForm(forms.ModelForm): event_date = forms.DateField(required=False, widget=forms.TextInput(attrs={'class': 'input-small date-entry',})) from_agent = forms.ModelChoiceField( @@ -2205,12 +2209,12 @@ class CashContributionEventForm(forms.ModelForm): widget=forms.Select( attrs={'class': 'resource-type-for-resource chzn-select'})) resource = ResourceModelChoiceField( - queryset=EconomicResource.objects.all(), + queryset=EconomicResource.objects.all(), label="Cash resource account or earmark to increase", required=False, - widget=forms.Select(attrs={'class': 'resource input-xlarge chzn-select',})) + widget=forms.Select(attrs={'class': 'resource input-xlarge chzn-select',})) description = forms.CharField( - required=False, + required=False, widget=forms.Textarea(attrs={'class': 'input-xxlarge',})) event_type = forms.ModelChoiceField( queryset=EventType.objects.cash_event_types(), @@ -2243,9 +2247,9 @@ def __init__(self, pattern=None, context_agent=None, posting=False, *args, **kwa self.fields["resource"].queryset = EconomicResource.objects.filter(resource_type=rts_vas[0]) if context_agent: self.context_agent = context_agent - #self.fields["from_agent"].queryset = context_agent.all_members() + #self.fields["from_agent"].queryset = context_agent.all_members() + - class CashContributionResourceEventForm(forms.ModelForm): event_date = forms.DateField(required=False, widget=forms.TextInput(attrs={'class': 'input-small date-entry',})) value = forms.DecimalField( @@ -2255,15 +2259,15 @@ class CashContributionResourceEventForm(forms.ModelForm): label="Cash resource type", empty_label=None, widget=forms.Select( - attrs={'class': 'chzn-select'})) + attrs={'class': 'chzn-select'})) from_agent = forms.ModelChoiceField( required=False, queryset=EconomicAgent.objects.all(), label="Contributor", widget=forms.Select( - attrs={'class': 'chzn-select'})) + attrs={'class': 'chzn-select'})) description = forms.CharField( - required=False, + required=False, widget=forms.Textarea(attrs={'class': 'input-xxlarge',})) event_type = forms.ModelChoiceField( queryset=EventType.objects.cash_event_types(), @@ -2272,17 +2276,17 @@ class CashContributionResourceEventForm(forms.ModelForm): widget=forms.Select( attrs={'class': 'chzn-select'})) identifier = forms.CharField( - required=False, + required=False, label="Create the resource:

Identifier", widget=forms.TextInput(attrs={'class': 'item-name',})) current_location = forms.ModelChoiceField( - queryset=Location.objects.all(), + queryset=Location.objects.all(), required=False, label=_("Current Resource Location"), widget=forms.Select(attrs={'class': 'input-medium',})) notes = forms.CharField( required=False, - label="Resource Notes", + label="Resource Notes", widget=forms.Textarea(attrs={'class': 'item-description',})) class Meta: @@ -2304,18 +2308,18 @@ def __init__(self, pattern=None, context_agent=None, *args, **kwargs): if context_agent: self.context_agent = context_agent #self.fields["from_agent"].queryset = context_agent.all_members() - + class MaterialContributionEventForm(forms.ModelForm): event_date = forms.DateField(required=False, widget=forms.TextInput(attrs={'class': 'input-small date-entry',})) from_agent = forms.ModelChoiceField( required=True, queryset=EconomicAgent.objects.all(), - label="Resource contributed by", + label="Resource contributed by", empty_label=None, widget=forms.Select( - attrs={'class': 'chzn-select'})) + attrs={'class': 'chzn-select'})) resource_type = FacetedModelChoiceField( - queryset=EconomicResourceType.objects.all(), + queryset=EconomicResourceType.objects.all(), empty_label=None, help_text="If you don't see the resource type you want, please contact an admin.", widget=forms.Select( @@ -2324,7 +2328,7 @@ class MaterialContributionEventForm(forms.ModelForm): label="Quantity", widget=forms.TextInput(attrs={'value': '1', 'class': 'quantity input-small'})) unit_of_quantity = forms.ModelChoiceField( - queryset=Unit.objects.exclude(unit_type='value').exclude(unit_type='time'), + queryset=Unit.objects.exclude(unit_type='value').exclude(unit_type='time'), empty_label=None, label=_("Unit"), widget=forms.Select(attrs={'class': 'input-medium',})) @@ -2337,33 +2341,33 @@ class MaterialContributionEventForm(forms.ModelForm): widget=forms.Select(attrs={'class': 'input-medium',})) description = forms.CharField( required=False, - label="Event Description", + label="Event Description", widget=forms.Textarea(attrs={'class': 'item-description',})) identifier = forms.CharField( - required=False, + required=False, label="Create the resource:

Identifier", help_text="For example, lot number or serial number.", widget=forms.TextInput(attrs={'class': 'item-name',})) url = forms.URLField( - required=False, + required=False, label="URL", widget=forms.TextInput(attrs={'class': 'url input-xlarge',})) photo_url = forms.URLField( - required=False, + required=False, label="Photo URL", widget=forms.TextInput(attrs={'class': 'url input-xlarge',})) current_location = forms.ModelChoiceField( - queryset=Location.objects.all(), + queryset=Location.objects.all(), required=False, label=_("Current Resource Location"), widget=forms.Select(attrs={'class': 'input-medium',})) notes = forms.CharField( required=False, - label="Resource Notes", + label="Resource Notes", widget=forms.Textarea(attrs={'class': 'item-description',})) access_rules = forms.CharField( required=False, - label="Resource Access Rules", + label="Resource Access Rules", widget=forms.Textarea(attrs={'class': 'item-description',})) class Meta: @@ -2374,7 +2378,7 @@ def __init__(self, pattern=None, context_agent=None, *args, **kwargs): super(MaterialContributionEventForm, self).__init__(*args, **kwargs) if pattern: self.pattern = pattern - self.fields["resource_type"].queryset = pattern.material_contr_resource_types() + self.fields["resource_type"].queryset = pattern.material_contr_resource_types() if context_agent: self.context_agent = context_agent #self.fields["from_agent"].queryset = context_agent.all_members() @@ -2386,15 +2390,15 @@ class WorkSelectionForm(forms.Form): def __init__(self, *args, **kwargs): super(WorkSelectionForm, self).__init__(*args, **kwargs) self.fields["type_of_work"].choices = [('', '----------')] + [(rt.id, rt.name) for rt in EconomicResourceType.objects.all()] - - + + class EventTypeFilterForm(forms.Form): start_date = forms.DateField( - required=False, + required=False, label="Start date", widget=forms.TextInput(attrs={'class': 'input-small filter-date', })) end_date = forms.DateField( - required=False, + required=False, label="End date", widget=forms.TextInput(attrs={'class': 'input-small filter-date', })) event_types = forms.MultipleChoiceField(required=False) @@ -2446,11 +2450,11 @@ class NewExchangeTypeForm(forms.ModelForm): widget=forms.Select( attrs={'class': 'chzn-select'})) name = forms.CharField(required=True, widget=forms.TextInput(attrs={'class': 'input-xlarge',})) - + class Meta: model = ExchangeType fields = ('use_case', 'name') - + class ExchangeTypeForm(forms.ModelForm): name = forms.CharField(required=True, widget=forms.TextInput(attrs={'class': 'input-xlarge',})) use_case = forms.ModelChoiceField( @@ -2461,7 +2465,7 @@ class ExchangeTypeForm(forms.ModelForm): description = forms.CharField( required=False, widget=forms.Textarea(attrs={'class': 'item-description',})) - + class Meta: model = ExchangeType fields = ('name', 'use_case', 'description') @@ -2512,14 +2516,14 @@ class TransferTypeForm(forms.ModelForm): label=_("Transfer To (optional - this will limit the choices when creating a transfer)"), widget=forms.Select( attrs={'class': 'chzn-select'})) - + class Meta: model = TransferType - fields = ('sequence', 'name', 'description', 'is_reciprocal', 'is_contribution', 'is_to_distribute', - 'can_create_resource', 'is_currency', 'give_agent_is_context', 'give_agent_association_type', + fields = ('sequence', 'name', 'description', 'is_reciprocal', 'is_contribution', 'is_to_distribute', + 'can_create_resource', 'is_currency', 'give_agent_is_context', 'give_agent_association_type', 'receive_agent_is_context', 'receive_agent_association_type') - + class PatternProdSelectionForm(forms.Form): pattern = forms.ModelChoiceField( queryset=ProcessPattern.objects.none(), @@ -2529,12 +2533,12 @@ class PatternProdSelectionForm(forms.Form): def __init__(self, *args, **kwargs): super(PatternProdSelectionForm, self).__init__(*args, **kwargs) - self.fields["pattern"].queryset = ProcessPattern.objects.production_patterns() + self.fields["pattern"].queryset = ProcessPattern.objects.production_patterns() class PatternFacetValueForm(forms.ModelForm): facet_value = forms.ModelChoiceField( - queryset=FacetValue.objects.all(), + queryset=FacetValue.objects.all(), label="", widget=forms.Select(attrs={'class': 'chzn-select input-xlarge'})) @@ -2549,7 +2553,7 @@ class PatternAddFacetValueForm(forms.ModelForm): label="", widget=forms.Select(attrs={'class': 'chzn-select input-medium'})) facet_value = forms.ModelChoiceField( - queryset=FacetValue.objects.all(), + queryset=FacetValue.objects.all(), label="", widget=forms.Select(attrs={'class': 'chzn-select input-xlarge'})) @@ -2565,7 +2569,7 @@ def __init__(self, qs=None, *args, **kwargs): class TransferTypeFacetValueForm(forms.ModelForm): facet_value = forms.ModelChoiceField( - queryset=FacetValue.objects.all(), + queryset=FacetValue.objects.all(), label="", widget=forms.Select(attrs={'class': 'chzn-select input-xlarge'})) @@ -2576,7 +2580,7 @@ class Meta: class ResourceTypeSelectionForm(forms.Form): resource_type = forms.ModelChoiceField( - queryset=EconomicResourceType.objects.none(), + queryset=EconomicResourceType.objects.none(), label="Resource Type", widget=forms.Select(attrs={'class': 'chzn-select input-xlarge'})) @@ -2584,18 +2588,18 @@ def __init__(self, qs=None, *args, **kwargs): super(ResourceTypeSelectionForm, self).__init__(*args, **kwargs) #import pdb; pdb.set_trace() if qs: - self.fields["resource_type"].queryset = qs + self.fields["resource_type"].queryset = qs + - class CasualTimeContributionForm(forms.ModelForm): resource_type = WorkModelChoiceField( - queryset=EconomicResourceType.objects.all(), - empty_label=None, + queryset=EconomicResourceType.objects.all(), + empty_label=None, widget=forms.Select(attrs={'class': 'chzn-select'})) context_agent = forms.ModelChoiceField( - queryset=EconomicAgent.objects.context_agents(), + queryset=EconomicAgent.objects.context_agents(), label=_("Context"), - empty_label=None, + empty_label=None, widget=forms.Select(attrs={'class': 'chzn-select'})) event_date = forms.DateField(required=False, widget=forms.TextInput(attrs={'class': 'item-date date-entry',})) description = forms.CharField(required=False, widget=forms.Textarea(attrs={'class': 'item-description',})) @@ -2603,7 +2607,7 @@ class CasualTimeContributionForm(forms.ModelForm): quantity = forms.DecimalField(required=False, widget=DecimalDurationWidget, help_text="hrs, mins") - + class Meta: model = EconomicEvent fields = ('event_date', 'resource_type', 'context_agent', 'quantity', 'is_contribution', 'url', 'description') @@ -2618,23 +2622,23 @@ def __init__(self, *args, **kwargs): if pattern: self.fields["resource_type"].queryset = pattern.work_resource_types().order_by("name") - + class HasAssociateChoiceField(forms.ModelChoiceField): def label_from_instance(self, obj): return obj.inverse_label - + class HasAssociateForm(forms.ModelForm): id = forms.CharField(required=False, widget=forms.HiddenInput) association_type = HasAssociateChoiceField( - queryset=AgentAssociationType.objects.all(), - empty_label=None, + queryset=AgentAssociationType.objects.all(), + empty_label=None, widget=forms.Select(attrs={'class': 'chzn-select'})) is_associate = forms.ModelChoiceField( - queryset=EconomicAgent.objects.all(), + queryset=EconomicAgent.objects.all(), widget=forms.Select(attrs={'class': 'chzn-select'})) description = forms.CharField(required=False, widget=forms.Textarea(attrs={'class': 'description',})) - + class Meta: model = AgentAssociation fields = ('id', 'association_type', 'is_associate', 'description', 'state') @@ -2642,23 +2646,23 @@ class Meta: def __init__(self, *args, **kwargs): super(HasAssociateForm, self).__init__(*args, **kwargs) - + class IsAssociateChoiceField(forms.ModelChoiceField): def label_from_instance(self, obj): return obj.label - + class IsAssociateForm(forms.ModelForm): id = forms.CharField(required=False, widget=forms.HiddenInput) association_type = IsAssociateChoiceField( - queryset=AgentAssociationType.objects.all(), - empty_label=None, + queryset=AgentAssociationType.objects.all(), + empty_label=None, widget=forms.Select(attrs={'class': 'chzn-select'})) has_associate = forms.ModelChoiceField( - queryset=EconomicAgent.objects.all(), + queryset=EconomicAgent.objects.all(), widget=forms.Select(attrs={'class': 'chzn-select'})) description = forms.CharField(required=False, widget=forms.Textarea(attrs={'class': 'description',})) - + class Meta: model = AgentAssociation fields = ('id', 'association_type', 'has_associate', 'description', 'state') @@ -2666,10 +2670,10 @@ class Meta: def __init__(self, *args, **kwargs): super(IsAssociateForm, self).__init__(*args, **kwargs) - + class BalanceForm(forms.Form): starting_balance = forms.DecimalField(required=False, widget=forms.TextInput(attrs={'class': 'input-small',})) - + class DateSelectionForm(forms.Form): start_date = forms.DateField(widget=forms.TextInput(attrs={'class': 'input-small date-entry',})) @@ -2679,13 +2683,13 @@ class DateSelectionForm(forms.Form): class DueDateAndNameForm(forms.Form): due_date = forms.DateField(widget=forms.TextInput(attrs={'class': 'input-small date-entry',})) order_name = forms.CharField(required=False, widget=forms.TextInput(attrs={'class': 'input-xlarge',})) - + class StartDateAndNameForm(forms.Form): start_date = forms.DateField(widget=forms.TextInput(attrs={'class': 'input-small date-entry',})) order_name = forms.CharField(required=False, widget=forms.TextInput(attrs={'class': 'input-xlarge',})) - - + + class OrderDateAndNameForm(forms.Form): date = forms.DateField(widget=forms.TextInput(attrs={'class': 'input-small date-entry',})) start_date_or_due_date = forms.ChoiceField( @@ -2746,12 +2750,12 @@ def __init__(self, feature, *args, **kwargs): # options = EconomicResourceType.objects.all() options = EconomicResourceType.objects.all() self.fields["options"].choices = [(rt.id, rt.name) for rt in options] - - + + def possible_parent_resource_types(): rt_ids = [rt.id for rt in EconomicResourceType.objects.all() if rt.can_be_parent()] return EconomicResourceType.objects.filter(id__in=rt_ids) - + class EconomicResourceTypeForm(forms.ModelForm): name = forms.CharField(widget=forms.TextInput(attrs={'class': 'unique-name input-xlarge',})) @@ -2765,8 +2769,8 @@ class EconomicResourceTypeForm(forms.ModelForm): substitutable = forms.BooleanField( required=False, help_text=_('Can any resource of this type be substituted for any other resource of this type?'), - widget=forms.CheckboxInput()) - + widget=forms.CheckboxInput()) + class Meta: model = EconomicResourceType exclude = ('created_by', 'changed_by', 'value_per_unit_of_use', 'value_per_unit', 'unit_of_value') @@ -2775,13 +2779,13 @@ def __init__(self, *args, **kwargs): super(EconomicResourceTypeForm, self).__init__(*args, **kwargs) self.fields["substitutable"].initial = settings.SUBSTITUTABLE_DEFAULT self.fields["parent"].queryset = possible_parent_resource_types() - + class EconomicResourceTypeChangeForm(forms.ModelForm): name = forms.CharField(widget=forms.TextInput(attrs={'class': 'existing-name input-xlarge',})) parent = forms.ModelChoiceField( - queryset=EconomicResourceType.objects.all(), - required=False, + queryset=EconomicResourceType.objects.all(), + required=False, widget=forms.Select( attrs={'class': 'chzn-select'})) url = forms.CharField(required=False, widget=forms.TextInput(attrs={'class': 'url input-xxlarge',})) @@ -2791,11 +2795,11 @@ class EconomicResourceTypeChangeForm(forms.ModelForm): unit = forms.ModelChoiceField( empty_label=None, queryset=Unit.objects.all()) - + class Meta: model = EconomicResourceType exclude = ('created_by', 'changed_by', 'value_per_unit_of_use', 'value_per_unit', 'unit_of_value') - + def __init__(self, *args, **kwargs): super(EconomicResourceTypeChangeForm, self).__init__(*args, **kwargs) #import pdb; pdb.set_trace() @@ -2814,11 +2818,11 @@ class EconomicResourceTypeAjaxForm(forms.ModelForm): required=False, queryset=Unit.objects.all()) description = forms.CharField( - required=False, + required=False, widget=forms.Textarea(attrs={'class': 'item-description',})) url = forms.CharField(required=False, widget=forms.TextInput(attrs={'class': 'url input-xxlarge',})) photo_url = forms.CharField(required=False, widget=forms.TextInput(attrs={'class': 'url input-xxlarge',})) - + class Meta: model = EconomicResourceType exclude = ('parent', 'created_by', 'changed_by', 'photo', 'value_per_unit_of_use', 'value_per_unit', 'unit_of_value') @@ -2846,14 +2850,14 @@ class Meta: class XbillProcessTypeForm(forms.ModelForm): name = forms.CharField(widget=forms.TextInput(attrs={'class': 'name input-xlarge',})) process_pattern = forms.ModelChoiceField( - queryset=ProcessPattern.objects.none(), - empty_label=None, + queryset=ProcessPattern.objects.none(), + empty_label=None, widget=forms.Select( attrs={'class': 'pattern-selector'})) context_agent = forms.ModelChoiceField( - queryset=EconomicAgent.objects.context_agents(), + queryset=EconomicAgent.objects.context_agents(), label=_("Context"), - required=False, + required=False, #empty_label="---------", widget=forms.Select(attrs={'class': 'chzn-select'})) quantity = forms.DecimalField( @@ -2871,20 +2875,20 @@ class Meta: def __init__(self, *args, **kwargs): super(XbillProcessTypeForm, self).__init__(*args, **kwargs) - self.fields["process_pattern"].queryset = ProcessPattern.objects.production_patterns() + self.fields["process_pattern"].queryset = ProcessPattern.objects.production_patterns() + - class RecipeProcessTypeForm(forms.ModelForm): name = forms.CharField(widget=forms.TextInput(attrs={'class': 'name input-xlarge',})) process_pattern = forms.ModelChoiceField( - queryset=ProcessPattern.objects.none(), - empty_label=None, + queryset=ProcessPattern.objects.none(), + empty_label=None, widget=forms.Select( attrs={'class': 'pattern-selector'})) context_agent = forms.ModelChoiceField( - queryset=EconomicAgent.objects.context_agents(), + queryset=EconomicAgent.objects.context_agents(), label=_("Context"), - required=False, + required=False, #empty_label="---------", widget=forms.Select(attrs={'class': 'chzn-select'})) #quantity = forms.DecimalField( @@ -2894,37 +2898,37 @@ class RecipeProcessTypeForm(forms.ModelForm): widget=DurationWidget, help_text="days, hours, minutes") url = forms.CharField(required=False, widget=forms.TextInput(attrs={'class': 'url input-xxlarge',})) - + class Meta: model = ProcessType exclude = ('parent','project', 'quantity') - + def __init__(self, *args, **kwargs): super(RecipeProcessTypeForm, self).__init__(*args, **kwargs) - self.fields["process_pattern"].queryset = ProcessPattern.objects.recipe_patterns() + self.fields["process_pattern"].queryset = ProcessPattern.objects.recipe_patterns() + - class RecipeProcessTypeChangeForm(forms.ModelForm): process_pattern = forms.ModelChoiceField( - queryset=ProcessPattern.objects.none(), - empty_label=None, + queryset=ProcessPattern.objects.none(), + empty_label=None, widget=forms.Select( attrs={'class': 'pattern-selector'})) context_agent = forms.ModelChoiceField( - queryset=EconomicAgent.objects.context_agents(), + queryset=EconomicAgent.objects.context_agents(), label=_("Context"), - required=False, + required=False, #empty_label="---------", widget=forms.Select(attrs={'class': 'chzn-select'})) estimated_duration = forms.IntegerField(required=False, widget=DurationWidget, help_text="days, hours, minutes") url = forms.CharField(required=False, widget=forms.TextInput(attrs={'class': 'url input-xxlarge',})) - + class Meta: model = ProcessType exclude = ('parent',) - + def __init__(self, *args, **kwargs): super(RecipeProcessTypeChangeForm, self).__init__(*args, **kwargs) self.fields["process_pattern"].queryset = ProcessPattern.objects.recipe_patterns() @@ -2932,7 +2936,7 @@ def __init__(self, *args, **kwargs): pat = self.instance.process_pattern if pat: self.fields["process_pattern"].queryset = ProcessPattern.objects.filter(id=pat.id) - + class ChangeProcessTypeForm(forms.ModelForm): estimated_duration = forms.IntegerField(required=False, @@ -2952,8 +2956,8 @@ class Meta: class ProcessTypeResourceTypeForm(forms.ModelForm): resource_type = forms.ModelChoiceField( - queryset=EconomicResourceType.objects.all(), - empty_label=None, + queryset=EconomicResourceType.objects.all(), + empty_label=None, widget=forms.Select( attrs={'class': 'resource-type-selector'})) quantity = forms.DecimalField(required=False, @@ -2961,7 +2965,7 @@ class ProcessTypeResourceTypeForm(forms.ModelForm): unit_of_quantity = forms.ModelChoiceField( required = False, label=_("Unit"), - queryset=Unit.objects.all(), + queryset=Unit.objects.all(), widget=forms.Select()) class Meta: @@ -2971,7 +2975,7 @@ class Meta: class ProcessTypeInputForm(forms.ModelForm): resource_type = forms.ModelChoiceField( - queryset=EconomicResourceType.objects.all(), + queryset=EconomicResourceType.objects.all(), empty_label=None, widget=forms.Select( attrs={'class': 'resource-type-selector input-xlarge' })) @@ -2980,7 +2984,7 @@ class ProcessTypeInputForm(forms.ModelForm): unit_of_quantity = forms.ModelChoiceField( required = False, label = _("Unit"), - queryset=Unit.objects.all(), + queryset=Unit.objects.all(), widget=forms.Select()) class Meta: @@ -3010,7 +3014,7 @@ def __init__(self, process_type=None, *args, **kwargs): class ProcessTypeConsumableForm(forms.ModelForm): resource_type = forms.ModelChoiceField( - queryset=EconomicResourceType.objects.all(), + queryset=EconomicResourceType.objects.all(), empty_label=None, widget=forms.Select( attrs={'class': 'staged-selector resource-type-selector input-xlarge' })) @@ -3019,7 +3023,7 @@ class ProcessTypeConsumableForm(forms.ModelForm): unit_of_quantity = forms.ModelChoiceField( required = False, label = _("Unit"), - queryset=Unit.objects.exclude(unit_type='value').exclude(unit_type='time'), + queryset=Unit.objects.exclude(unit_type='value').exclude(unit_type='time'), widget=forms.Select()) class Meta: @@ -3045,7 +3049,7 @@ def __init__(self, process_type=None, *args, **kwargs): self.pattern = pattern output_ids = [pt.id for pt in process_type.produced_resource_types()] rts = pattern.consumable_resource_types().exclude(id__in=output_ids) - self.fields["resource_type"].queryset = rts + self.fields["resource_type"].queryset = rts if rts.count(): rt = rts[0] self.fields["stage"].queryset = rt.all_stages() @@ -3058,7 +3062,7 @@ def __init__(self, process_type=None, *args, **kwargs): class ProcessTypeUsableForm(forms.ModelForm): resource_type = forms.ModelChoiceField( - queryset=EconomicResourceType.objects.all(), + queryset=EconomicResourceType.objects.all(), empty_label=None, widget=forms.Select( attrs={'class': 'resource-type-selector input-xlarge' })) @@ -3067,7 +3071,7 @@ class ProcessTypeUsableForm(forms.ModelForm): unit_of_quantity = forms.ModelChoiceField( required = False, label = _("Unit"), - queryset=Unit.objects.exclude(unit_type='value'), + queryset=Unit.objects.exclude(unit_type='value'), widget=forms.Select()) class Meta: @@ -3098,15 +3102,15 @@ def __init__(self, process_type=None, *args, **kwargs): if len(self.fields["resource_type"].queryset) > 0: self.fields["unit_of_quantity"].initial = self.fields["resource_type"].queryset[0].unit_for_use() - + class ProcessTypeCitableForm(forms.ModelForm): resource_type = FacetedModelChoiceField( - queryset=EconomicResourceType.objects.all(), + queryset=EconomicResourceType.objects.all(), empty_label=None, widget=forms.Select( attrs={'class': 'resource-type-selector input-xlarge' })) description = forms.CharField( - required=False, + required=False, widget=forms.Textarea(attrs={'class': 'input-xxlarge',})) class Meta: @@ -3132,15 +3136,15 @@ def __init__(self, process_type=None, *args, **kwargs): output_ids = [pt.id for pt in process_type.produced_resource_types()] self.fields["resource_type"].queryset = pattern.citable_resource_types().exclude(id__in=output_ids) - + class ProcessTypeCitableStreamRecipeForm(forms.ModelForm): resource_type = FacetedModelChoiceField( - queryset=EconomicResourceType.objects.all(), + queryset=EconomicResourceType.objects.all(), empty_label=None, widget=forms.Select( attrs={'class': 'resource-type-selector input-xlarge' })) description = forms.CharField( - required=False, + required=False, widget=forms.Textarea(attrs={'class': 'input-xxlarge',})) class Meta: @@ -3164,11 +3168,11 @@ def __init__(self, process_type=None, *args, **kwargs): if use_pattern: self.pattern = pattern self.fields["resource_type"].queryset = pattern.citable_resource_types() - - + + class ProcessTypeWorkForm(forms.ModelForm): resource_type = forms.ModelChoiceField( - queryset=EconomicResourceType.objects.all(), + queryset=EconomicResourceType.objects.all(), label = _("Type of work"), empty_label=None, widget=forms.Select( @@ -3178,7 +3182,7 @@ class ProcessTypeWorkForm(forms.ModelForm): unit_of_quantity = forms.ModelChoiceField( required = False, label=_("Unit"), - queryset=Unit.objects.all(), + queryset=Unit.objects.all(), widget=forms.Select()) class Meta: @@ -3258,17 +3262,17 @@ def clean_equation(self): class ExchangeForm(forms.ModelForm): context_agent = forms.ModelChoiceField( - queryset=EconomicAgent.objects.context_agents(), + queryset=EconomicAgent.objects.context_agents(), label=_("Context"), - empty_label=None, + empty_label=None, widget=forms.Select(attrs={'class': 'chzn-select'})) - start_date = forms.DateField(required=True, + start_date = forms.DateField(required=True, label=_("Date"), widget=forms.TextInput(attrs={'class': 'item-date date-entry',})) - notes = forms.CharField(required=False, + notes = forms.CharField(required=False, label=_("Comments"), widget=forms.Textarea(attrs={'class': 'item-description',})) - url = forms.CharField(required=False, + url = forms.CharField(required=False, label=_("Link to receipt(s)"), widget=forms.TextInput(attrs={'class': 'url input-xxlarge',})) @@ -3279,14 +3283,14 @@ class Meta: #def __init__(self, *args, **kwargs): # super(ExchangeForm, self).__init__(*args, **kwargs) - + class ExchangeFlowForm(forms.Form): - start_date = forms.DateField(required=True, + start_date = forms.DateField(required=True, label=_("Transfer Date"), widget=forms.TextInput(attrs={'class': 'item-date date-entry',})) to_agent = forms.ModelChoiceField(required=False, queryset=EconomicAgent.objects.all(), - label="Transferred To", + label="Transferred To", widget=forms.Select( attrs={'class': 'chzn-select'})) quantity = forms.DecimalField(required=True, @@ -3318,23 +3322,23 @@ class InternalExchangeNavForm(forms.Form): empty_label=None, widget=forms.Select( attrs={'class': 'exchange-selector'})) - + class SaleForm(forms.ModelForm): exchange_type = forms.ModelChoiceField( queryset=ExchangeType.objects.sale_exchange_types(), widget=forms.Select( attrs={'class': 'exchange-selector'})) process_pattern = forms.ModelChoiceField( - queryset=ProcessPattern.objects.none(), + queryset=ProcessPattern.objects.none(), label=_("Pattern"), widget=forms.Select( attrs={'class': 'pattern-selector'})) context_agent = forms.ModelChoiceField( - queryset=EconomicAgent.objects.context_agents(), + queryset=EconomicAgent.objects.context_agents(), label=_("Context (who interacts with the payer)"), - empty_label=None, + empty_label=None, widget=forms.Select(attrs={'class': 'chzn-select'})) - start_date = forms.DateField(required=True, + start_date = forms.DateField(required=True, label=_("Date"), widget=forms.TextInput(attrs={'class': 'item-date date-entry',})) customer = forms.ModelChoiceField(required=False, @@ -3346,46 +3350,46 @@ class SaleForm(forms.ModelForm): queryset=Order.objects.customer_orders(), label="Order (optional)", widget=forms.Select(attrs={'class': 'resource chzn-select input-xxlarge',})) - notes = forms.CharField(required=False, + notes = forms.CharField(required=False, label=_("Comments"), widget=forms.Textarea(attrs={'class': 'item-description',})) - + class Meta: model = Exchange fields = ('exchange_type', 'process_pattern', 'context_agent', 'customer', 'order', 'start_date', 'notes') - + def __init__(self, context_agent=None, *args, **kwargs): #import pdb; pdb.set_trace() super(SaleForm, self).__init__(*args, **kwargs) use_case = UseCase.objects.get(identifier="sale") - self.fields["process_pattern"].queryset = ProcessPattern.objects.usecase_patterns(use_case) + self.fields["process_pattern"].queryset = ProcessPattern.objects.usecase_patterns(use_case) if context_agent: self.fields["customer"].queryset = context_agent.all_customers() - + class DistributionForm(forms.ModelForm): name = forms.CharField(widget=forms.TextInput(attrs={'class': 'name input-xlarge',})) context_agent = forms.ModelChoiceField( - queryset=EconomicAgent.objects.context_agents(), + queryset=EconomicAgent.objects.context_agents(), label=_("Context"), - empty_label=None, + empty_label=None, widget=forms.Select(attrs={'class': 'chzn-select'})) - distribution_date = forms.DateField(required=True, + distribution_date = forms.DateField(required=True, label=_("Distribution date"), widget=forms.TextInput(attrs={'class': 'item-date date-entry',})) - notes = forms.CharField(required=False, + notes = forms.CharField(required=False, label=_("Comments"), widget=forms.Textarea(attrs={'class': 'item-description',})) - + class Meta: model = Distribution fields = ('name', 'distribution_date', 'context_agent', 'notes') - + class DistributionValueEquationForm(forms.Form): value_equation = forms.ModelChoiceField( - queryset=ValueEquation.objects.all(), + queryset=ValueEquation.objects.all(), label=_("Value Equation"), - empty_label=None, + empty_label=None, widget=forms.Select( attrs={'class': 've-selector'})) #todo: partial - needs a custom ModelMultipleChoiceField showing the undistributed_amount @@ -3399,24 +3403,24 @@ class DistributionValueEquationForm(forms.Form): help_text = _("if you selected only one distribution source, you may distribute only part of it"), widget=forms.TextInput(attrs={'value': '', 'class': 'partial'})) resource = forms.ModelChoiceField( - queryset=EconomicResource.objects.all(), + queryset=EconomicResource.objects.all(), label="Distribute from account", required=False, widget=forms.Select(attrs={'class': 'resource input-xlarge',})) - start_date = forms.DateField(required=True, + start_date = forms.DateField(required=True, label=_("Date"), widget=forms.TextInput(attrs={'class': 'item-date date-entry date-required',})) - notes = forms.CharField(required=False, + notes = forms.CharField(required=False, label=_("Comments"), widget=forms.Textarea(attrs={'class': 'item-description',})) - + def __init__(self, context_agent=None, pattern=None, post=False, *args, **kwargs): #import pdb; pdb.set_trace() super(DistributionValueEquationForm, self).__init__(*args, **kwargs) if post == False: if context_agent: self.fields["value_equation"].queryset = context_agent.live_value_equations() - self.fields["events_to_distribute"].queryset = context_agent.undistributed_events() + self.fields["events_to_distribute"].queryset = context_agent.undistributed_events() resources = [] if pattern: rts = pattern.distribution_resource_types() @@ -3429,29 +3433,29 @@ def __init__(self, context_agent=None, pattern=None, post=False, *args, **kwargs resources.append(res) self.fields["resource"].choices = [('', '----------')] + [(res.id, res.identifier) for res in resources] #import pdb; pdb.set_trace() - + class ResourceFlowForm(forms.ModelForm): context_agent = forms.ModelChoiceField( - queryset=EconomicAgent.objects.context_agents(), - empty_label=None, + queryset=EconomicAgent.objects.context_agents(), + empty_label=None, widget=forms.Select(attrs={'class': 'chzn-select'})) event_date = forms.DateField( - required=True, + required=True, label="Received on", widget=forms.TextInput(attrs={'class': 'input-small date-entry', })) from_agent = forms.ModelChoiceField( required=True, queryset=EconomicAgent.objects.all(), widget=forms.Select( - attrs={'class': 'chzn-select'})) + attrs={'class': 'chzn-select'})) to_agent = forms.ModelChoiceField( required=True, queryset=EconomicAgent.objects.all(), - label="Supplier", + label="Supplier", widget=forms.Select( - attrs={'class': 'chzn-select'})) + attrs={'class': 'chzn-select'})) resource_type = forms.ModelChoiceField( - queryset=EconomicResourceType.objects.all(), + queryset=EconomicResourceType.objects.all(), help_text="If you don't see the resource type you want, please contact an admin.", widget=forms.Select( attrs={'class': 'resource-type-selector resourceType chzn-select input-large'})) @@ -3465,41 +3469,41 @@ class ResourceFlowForm(forms.ModelForm): label="Quantity", widget=forms.TextInput(attrs={'value': '1', 'class': 'quantity input-small'})) unit_of_quantity = forms.ModelChoiceField( - queryset=Unit.objects.exclude(unit_type='value').exclude(unit_type='time'), + queryset=Unit.objects.exclude(unit_type='value').exclude(unit_type='time'), empty_label=None, label=_("Unit"), widget=forms.Select(attrs={'class': 'input-medium',})) description = forms.CharField( required=False, - label="Event Description", + label="Event Description", widget=forms.Textarea(attrs={'class': 'item-description',})) identifier = forms.CharField( - required=False, + required=False, label="Create the resource:

Identifier", help_text="For example, lot number or serial number.", widget=forms.TextInput(attrs={'class': 'item-name',})) url = forms.URLField( - required=False, + required=False, label="URL", widget=forms.TextInput(attrs={'class': 'url input-xlarge',})) photo_url = forms.URLField( - required=False, + required=False, label="Photo URL", widget=forms.TextInput(attrs={'class': 'url input-xlarge',})) current_location = forms.ModelChoiceField( - queryset=Location.objects.all(), + queryset=Location.objects.all(), required=False, label=_("Current Resource Location"), widget=forms.Select(attrs={'class': 'input-medium',})) notes = forms.CharField( required=False, - label="Resource Notes", + label="Resource Notes", widget=forms.Textarea(attrs={'class': 'item-description',})) access_rules = forms.CharField( required=False, - label="Resource Access Rules", + label="Resource Access Rules", widget=forms.Textarea(attrs={'class': 'item-description',})) - + class Meta: model = EconomicEvent fields = ('event_date', 'from_agent', 'resource_type', 'value', 'unit_of_value', 'quantity', 'unit_of_quantity', 'description') @@ -3511,46 +3515,46 @@ def __init__(self, pattern, *args, **kwargs): self.pattern = pattern et = EventType.objects.get(name="Change") self.fields["resource_type"].queryset = pattern.get_resource_types(event_type=et) - + class AllContributionsFilterForm(forms.Form): context = forms.ModelMultipleChoiceField( - queryset=EconomicAgent.objects.context_agents(), + queryset=EconomicAgent.objects.context_agents(), required=False, widget=forms.SelectMultiple(attrs={'class': 'chzn-select',})) event_type = forms.ModelMultipleChoiceField( queryset=EventType.objects.all(), widget=forms.SelectMultiple(attrs={'class': 'chzn-select',})) from_agent = forms.ModelMultipleChoiceField( - queryset=EconomicAgent.objects.all(), - required=False, + queryset=EconomicAgent.objects.all(), + required=False, widget=forms.SelectMultiple(attrs={'class': 'chzn-select'})) start_date = forms.DateField( - required=False, + required=False, label="Start date", widget=forms.TextInput(attrs={'class': 'input-small date-entry', })) end_date = forms.DateField( - required=False, + required=False, label="End date", widget=forms.TextInput(attrs={'class': 'input-small date-entry', })) - + class ProjectContributionsFilterForm(forms.Form): event_types = forms.ModelMultipleChoiceField( required=False, queryset=EventType.objects.all(), widget=forms.SelectMultiple(attrs={'class': 'chzn-select',})) from_agents = forms.ModelMultipleChoiceField( - queryset=EconomicAgent.objects.all(), - required=False, + queryset=EconomicAgent.objects.all(), + required=False, widget=forms.SelectMultiple(attrs={'class': 'chzn-select'})) start_date = forms.DateField( - required=False, + required=False, label="Start date", widget=forms.TextInput(attrs={'class': 'input-small date-entry', })) end_date = forms.DateField( - required=False, + required=False, label="End date", widget=forms.TextInput(attrs={'class': 'input-small date-entry', })) - + def __init__(self, agents, *args, **kwargs): super(ProjectContributionsFilterForm, self).__init__(*args, **kwargs) self.fields["from_agents"].queryset = agents @@ -3558,20 +3562,20 @@ def __init__(self, agents, *args, **kwargs): class FilterSetHeaderForm(forms.Form): context = forms.ModelChoiceField( - queryset=EconomicAgent.objects.context_agents(), - empty_label=None, + queryset=EconomicAgent.objects.context_agents(), + empty_label=None, widget=forms.Select(attrs={'class': 'chzn-select',})) event_type = forms.ModelChoiceField( queryset=EventType.objects.all(), widget=forms.Select(attrs={'class': 'chzn-select',})) pattern = forms.ModelChoiceField( - queryset=ProcessPattern.objects.all(), - required=False, + queryset=ProcessPattern.objects.all(), + required=False, widget=forms.Select(attrs={'class': 'chzn-select'})) filter_set = forms.ChoiceField( choices=(("Order", "Order"),("Context", "Context"), ("Delivery", "Delivery")), widget=forms.Select(attrs={'class': 'input-small'})) - + class OrderFilterSetForm(forms.Form): order = forms.ModelChoiceField( @@ -3589,7 +3593,7 @@ class OrderFilterSetForm(forms.Form): queryset=EconomicResourceType.objects.none(), label=_("Select zero or more Resource Types"), widget=forms.SelectMultiple(attrs={'class': 'resource-type chzn-select input-xxlarge'})) - + def __init__(self, project, event_type, pattern, *args, **kwargs): super(OrderFilterSetForm, self).__init__(*args, **kwargs) self.fields["order"].queryset = project.orders_queryset() @@ -3599,19 +3603,19 @@ def __init__(self, project, event_type, pattern, *args, **kwargs): self.fields["resource_types"].queryset = pattern.get_resource_types(event_type=event_type) else: self.fields["resource_types"].queryset = EconomicResourceType.objects.all() - + class ProjectFilterSetForm(forms.Form): #or use django-filter DateRangeFilter start_date = forms.DateField( - required=False, + required=False, label="Start date", widget=forms.TextInput(attrs={'class': 'input-small date-entry', })) end_date = forms.DateField( - required=False, + required=False, label="End date", widget=forms.TextInput(attrs={'class': 'input-small date-entry', })) - #completeness = + #completeness = process_types = forms.ModelMultipleChoiceField( required=False, queryset=ProcessType.objects.none(), @@ -3622,7 +3626,7 @@ class ProjectFilterSetForm(forms.Form): queryset=EconomicResourceType.objects.none(), label=_("Select zero or more Resource Types"), widget=forms.SelectMultiple(attrs={'class': 'resource-type chzn-select input-xxlarge'})) - + def __init__(self, project, event_type, pattern, *args, **kwargs): super(ProjectFilterSetForm, self).__init__(*args, **kwargs) self.fields["process_types"].queryset = project.process_types_queryset() @@ -3632,7 +3636,7 @@ def __init__(self, project, event_type, pattern, *args, **kwargs): self.fields["resource_types"].queryset = pattern.get_resource_types(event_type=event_type) else: self.fields["resource_types"].queryset = EconomicResourceType.objects.all() - + def serialize(self): data = self.cleaned_data #import pdb; pdb.set_trace() @@ -3650,7 +3654,7 @@ def serialize(self): if resource_types: json["resource_types"] = [pt.id for pt in resource_types] return json - + def deserialize(self, json): dict = {} dict["method"] = json["method"] @@ -3673,8 +3677,8 @@ def deserialize(self, json): l.append(EconomicResourceType.objects.get(pk=pk)) dict["resource_types"] = l return dict - - + + class DeliveryFilterSetForm(forms.Form): shipment_events = forms.ModelMultipleChoiceField( required=False, @@ -3695,7 +3699,7 @@ class DeliveryFilterSetForm(forms.Form): queryset=EconomicResourceType.objects.none(), label=_("Select zero or more Resource Types"), widget=forms.SelectMultiple(attrs={'class': 'resource-type chzn-select input-xxlarge'})) - + def __init__(self, project, event_type, pattern, *args, **kwargs): super(DeliveryFilterSetForm, self).__init__(*args, **kwargs) ship = EventType.objects.get(label="ships") @@ -3709,14 +3713,14 @@ def __init__(self, project, event_type, pattern, *args, **kwargs): class SortResourceReportForm(forms.Form): - choice = forms.ChoiceField( + choice = forms.ChoiceField( widget=forms.Select(attrs={'class': 'input-xlarge'})) def __init__(self, *args, **kwargs): super(SortResourceReportForm, self).__init__(*args, **kwargs) self.fields["choice"].choices = [('1', 'Resource Type'), ('2', 'Resource (Lot)'), ('3', 'Order')] - + class ValueEquationForm(forms.ModelForm): context_agent = forms.ModelChoiceField( queryset=EconomicAgent.objects.context_agents(), @@ -3725,30 +3729,30 @@ class ValueEquationForm(forms.ModelForm): widget=forms.Select(attrs={'class': 'chzn-select',})) name = forms.CharField( widget=forms.TextInput(attrs={'class': 'input-xlarge required-field',})) - description = forms.CharField(required=False, + description = forms.CharField(required=False, widget=forms.Textarea(attrs={'class': 'item-description',})) class Meta: model = ValueEquation - fields = ('name', 'description', 'percentage_behavior', 'context_agent') - - + fields = ('name', 'description', 'percentage_behavior', 'context_agent') + + class ValueEquationBucketForm(forms.ModelForm): sequence = forms.IntegerField(widget=forms.TextInput(attrs={'class': 'input-small integer',})) percentage = forms.DecimalField( widget=forms.TextInput(attrs={'value': '0', 'class': 'quantity input-small'})) distribution_agent = forms.ModelChoiceField( queryset=EconomicAgent.objects.all(), - required=False, + required=False, help_text="Choose an agent to distribute this entire bucket to, OR choose a filter method below to gather contributions.", widget=forms.Select(attrs={'class': 'chzn-select',})) name = forms.CharField(widget=forms.TextInput(attrs={'class': 'input-xlarge',})) class Meta: model = ValueEquationBucket - fields = ('sequence', 'name', 'percentage', 'distribution_agent', 'filter_method') - - + fields = ('sequence', 'name', 'percentage', 'distribution_agent', 'filter_method') + + class ValueEquationBucketRuleForm(forms.ModelForm): event_type = forms.ModelChoiceField( queryset=EventType.objects.used_for_value_equations().order_by("name"), @@ -3758,45 +3762,45 @@ class ValueEquationBucketRuleForm(forms.ModelForm): widget=forms.Select(attrs={'class': 'chzn-select input-medium event-type-selector'})) claim_creation_equation = forms.CharField( required=False, - help_text="You may use any or all of the variables shown above in a mathematical equation.
Leave a space between each element, and do not change the names of the variables.", + help_text="You may use any or all of the variables shown above in a mathematical equation.
Leave a space between each element, and do not change the names of the variables.", widget=forms.Textarea(attrs={'class': 'equation',})) class Meta: model = ValueEquationBucketRule - fields = ('event_type', 'claim_rule_type', 'claim_creation_equation') + fields = ('event_type', 'claim_rule_type', 'claim_creation_equation') + - class ValueEquationSelectionForm(forms.Form): value_equation = ValueEquationModelChoiceField( - queryset=ValueEquation.objects.none(), + queryset=ValueEquation.objects.none(), label=_("Select a Value Equation"), - empty_label=None, + empty_label=None, widget=forms.Select( attrs={'class': 've-selector'})) - + def __init__(self, value_equations, *args, **kwargs): super(ValueEquationSelectionForm, self).__init__(*args, **kwargs) if value_equations: ve_ids = [ve.id for ve in value_equations] ve_qs = ValueEquation.objects.filter(id__in=ve_ids) self.fields["value_equation"].queryset = ve_qs - - + + class ValueEquationSandboxForm(forms.Form): #context_agent = forms.ModelChoiceField( - # queryset=EconomicAgent.objects.context_agents(), - # empty_label=None, + # queryset=EconomicAgent.objects.context_agents(), + # empty_label=None, # widget=forms.Select(attrs={'class': 'chzn-select',})) value_equation = forms.ModelChoiceField( - queryset=ValueEquation.objects.all(), + queryset=ValueEquation.objects.all(), label=_("Value Equation"), - empty_label=None, + empty_label=None, widget=forms.Select( attrs={'class': 've-selector'})) amount_to_distribute = forms.DecimalField(required=False, widget=forms.TextInput(attrs={'value': '0.00', 'class': 'money quantity input-small'})) - + class BucketRuleFilterSetForm(forms.Form): process_types = forms.ModelMultipleChoiceField( required=False, @@ -3808,7 +3812,7 @@ class BucketRuleFilterSetForm(forms.Form): queryset=EconomicResourceType.objects.none(), label=_("Select zero or more Resource Types"), widget=forms.SelectMultiple(attrs={'class': 'resource-type chzn-select input-xxlarge'})) - + def __init__(self, context_agent, event_type, pattern, *args, **kwargs): super(BucketRuleFilterSetForm, self).__init__(*args, **kwargs) if context_agent: @@ -3824,7 +3828,7 @@ def __init__(self, context_agent, event_type, pattern, *args, **kwargs): self.fields["resource_types"].queryset = pattern.all_resource_types() else: self.fields["resource_types"].queryset = EconomicResourceType.objects.all() - + def serialize(self): data = self.cleaned_data #import pdb; pdb.set_trace() @@ -3836,7 +3840,7 @@ def serialize(self): if resource_types: json["resource_types"] = [pt.id for pt in resource_types] #import pdb; pdb.set_trace() - string = simplejson.dumps(json) + string = simplejson.dumps(json) return string def deserialize(self, json): @@ -3860,18 +3864,18 @@ def deserialize(self, json): class DateRangeForm(forms.Form): start_date = forms.DateField( - required=False, + required=False, label="Start date", widget=forms.TextInput(attrs={'class': 'input-small date-entry validateMe', })) end_date = forms.DateField( - required=False, + required=False, label="End date", widget=forms.TextInput(attrs={'class': 'input-small date-entry validateMe', })) context_agent = forms.ModelChoiceField( - required=False, - queryset=EconomicAgent.objects.context_agents(), + required=False, + queryset=EconomicAgent.objects.context_agents(), label=_("Network/Project (optional)"), - widget=forms.Select(attrs={'class': 'chzn-select'})) + widget=forms.Select(attrs={'class': 'chzn-select'})) def serialize(self): data = self.cleaned_data @@ -3886,9 +3890,9 @@ def serialize(self): context_agent = data.get("context_agent") if context_agent: json["context_agent"] = context_agent.id - string = simplejson.dumps(json) + string = simplejson.dumps(json) return string - + def deserialize(self, json): json = simplejson.loads(json) dict = {} @@ -3903,15 +3907,15 @@ def deserialize(self, json): if context_agent_id: dict["context_agent"] = EconomicAgent.objects.get(id=context_agent_id) return dict - - + + class OrderMultiSelectForm(forms.Form): orders = forms.ModelMultipleChoiceField( required=True, queryset=Order.objects.all(), label=_("Select one or more Orders"), widget=forms.SelectMultiple(attrs={'class': 'order chzn-select input-xxlarge validateMe'})) - + def __init__(self, context_agent, *args, **kwargs): super(OrderMultiSelectForm, self).__init__(*args, **kwargs) #import pdb; pdb.set_trace() @@ -3919,7 +3923,7 @@ def __init__(self, context_agent, *args, **kwargs): self.fields["orders"].queryset = Order.objects.all() else: self.fields["orders"].queryset = context_agent.orders_queryset() - + def serialize(self): data = self.cleaned_data #import pdb; pdb.set_trace() @@ -3927,10 +3931,10 @@ def serialize(self): orders = data.get("orders") if orders: json["orders"] = [order.id for order in orders] - - string = simplejson.dumps(json) + + string = simplejson.dumps(json) return string - + def deserialize(self, json): json = simplejson.loads(json) dict = {} @@ -3956,11 +3960,11 @@ class ShipmentMultiSelectForm(forms.Form): label=_("Select one or more Delivery Events"), #empty_label=None, widget=forms.SelectMultiple(attrs={'class': 'shipment-event chzn-select input-xxlarge validateMe'})) - + def __init__(self, context_agent, *args, **kwargs): super(ShipmentMultiSelectForm, self).__init__(*args, **kwargs) self.fields["shipments"].queryset = context_agent.shipments_queryset() - + def serialize(self): data = self.cleaned_data #import pdb; pdb.set_trace() @@ -3968,9 +3972,9 @@ def serialize(self): shipments = data.get("shipments") if shipments: json["shipments"] = [s.id for s in shipments] - string = simplejson.dumps(json) + string = simplejson.dumps(json) return string - + def deserialize(self, json): json = simplejson.loads(json) dict = {} @@ -3983,14 +3987,14 @@ def deserialize(self, json): dict["shipments"] = l return dict - + class ProcessMultiSelectForm(forms.Form): processes = forms.ModelMultipleChoiceField( required=True, queryset=Process.objects.none(), label=_("Select one or more Processes"), widget=forms.SelectMultiple(attrs={'class': 'order chzn-select input-xxlarge validateMe'})) - + def __init__(self, context_agent, *args, **kwargs): super(ProcessMultiSelectForm, self).__init__(*args, **kwargs) #import pdb; pdb.set_trace() @@ -3999,7 +4003,7 @@ def __init__(self, context_agent, *args, **kwargs): #else: # self.fields["processes"].queryset = context_agent.processes_queryset() self.fields["processes"].queryset = context_agent.processes.all() - + def serialize(self): data = self.cleaned_data #import pdb; pdb.set_trace() @@ -4007,9 +4011,9 @@ def serialize(self): processes = data.get("processes") if processes: json["processes"] = [process.id for process in processes] - string = simplejson.dumps(json) + string = simplejson.dumps(json) return string - + def deserialize(self, json): json = simplejson.loads(json) dict = {} @@ -4021,4 +4025,3 @@ def deserialize(self, json): l.append(Process.objects.get(pk=pk)) dict["processes"] = l return dict - diff --git a/valuenetwork/valueaccounting/views.py b/valuenetwork/valueaccounting/views.py index 998cf1833..b38cb3e6a 100644 --- a/valuenetwork/valueaccounting/views.py +++ b/valuenetwork/valueaccounting/views.py @@ -45,7 +45,7 @@ def get_help(page_name): return Help.objects.get(page=page_name) except Help.DoesNotExist: return None - + def get_site_name(): return Site.objects.get_current().name @@ -109,9 +109,9 @@ def create_agent(request): agent.created_by=request.user agent.save() return HttpResponseRedirect('/%s/%s/' - % ('accounting/agent', agent.id)) + % ('accounting/agent', agent.id)) return HttpResponseRedirect("/accounting/agents/") - + @login_required def create_user(request, agent_id): if not request.user.is_superuser: @@ -129,8 +129,8 @@ def create_user(request, agent_id): user = user) au.save() return HttpResponseRedirect('/%s/%s/' - % ('accounting/agent', agent.id)) - + % ('accounting/agent', agent.id)) + @login_required def create_user_and_agent(request): #import pdb; pdb.set_trace() @@ -203,23 +203,23 @@ def create_user_and_agent(request): user.first_name = request.POST.get("first_name") user.last_name = request.POST.get("last_name") user.email = request.POST.get("email") - user.save() + user.save() au = AgentUser( agent = agent, user = user) au.save() return HttpResponseRedirect('/%s/%s/' % ('accounting/agent', agent.id)) - + return render_to_response("valueaccounting/create_user_and_agent.html", { "user_form": user_form, "agent_form": agent_form, "agent_selection_form": agent_selection_form, }, context_instance=RequestContext(request)) - + def projects(request): #import pdb; pdb.set_trace() - projects = EconomicAgent.objects.context_agents() + projects = EconomicAgent.objects.context_agents() roots = [p for p in projects if p.is_root()] for root in roots: root.nodes = root.child_tree() @@ -241,7 +241,7 @@ def projects(request): agent_form = AgentCreateForm() nicks = '~'.join([ agt.nick for agt in EconomicAgent.objects.all()]) - + return render_to_response("valueaccounting/projects.html", { "roots": roots, "agent": agent, @@ -270,8 +270,8 @@ def create_project(request): project.save() return HttpResponseRedirect("/accounting/projects/") -''' - +''' + def locations(request): agent = get_agent(request) locations = Location.objects.all() @@ -382,7 +382,7 @@ def change_agent(request, agent_id): agent = change_form.save() return HttpResponseRedirect('/%s/%s/' % ('accounting/agent', agent.id)) - + def agents(request): #import pdb; pdb.set_trace() user_agent = get_agent(request) @@ -398,7 +398,7 @@ def agents(request): "help": get_help("agents"), "nicks": nicks, }, context_instance=RequestContext(request)) - + def radial_graph(request, agent_id): agent = get_object_or_404(EconomicAgent, id=agent_id) agents = agent.with_all_associations() @@ -412,12 +412,12 @@ def radial_graph(request, agent_id): if cx not in connections: connections[cx] = 0 connections[cx] += 1 - + return render_to_response("valueaccounting/radial_graph.html", { "agents": agents, "root": agent, }, context_instance=RequestContext(request)) - + def agent(request, agent_id): #import pdb; pdb.set_trace() agent = get_object_or_404(EconomicAgent, id=agent_id) @@ -438,15 +438,15 @@ def agent(request, agent_id): init = {"username": agent.nick,} user_form = UserCreationForm(initial=init) has_associations = agent.all_has_associates() - is_associated_with = agent.all_is_associates() - + is_associated_with = agent.all_is_associates() + headings = [] member_hours_recent = [] member_hours_stats = [] individual_stats = [] member_hours_roles = [] roles_height = 400 - + if agent.is_individual(): contributions = agent.given_events.filter(is_contribution=True) agents_stats = {} @@ -456,9 +456,9 @@ def agent(request, agent_id): for key, value in agents_stats.items(): individual_stats.append((key, value)) individual_stats.sort(lambda x, y: cmp(y[1], x[1])) - + elif agent.is_context_agent(): - + subs = agent.with_all_sub_agents() end = datetime.date.today() #end = end - datetime.timedelta(days=77) @@ -467,7 +467,7 @@ def agent(request, agent_id): event_type__relationship="work", context_agent__in=subs, event_date__range=(start, end)) - + if events: agents_stats = {} for event in events: @@ -476,13 +476,13 @@ def agent(request, agent_id): for key, value in agents_stats.items(): member_hours_recent.append((key, value)) member_hours_recent.sort(lambda x, y: cmp(y[1], x[1])) - + #import pdb; pdb.set_trace() - + ces = CachedEventSummary.objects.filter( event_type__relationship="work", context_agent__in=subs) - + if ces.count(): agents_stats = {} for ce in ces: @@ -507,11 +507,11 @@ def agent(request, agent_id): agents_roles[key][idx] += ce.quantity headings = ["Member",] headings.extend(roles) - for row in agents_roles.values(): + for row in agents_roles.values(): member_hours_roles.append(row) member_hours_roles.sort(lambda x, y: cmp(x[0], y[0])) roles_height = len(member_hours_roles) * 20 - + return render_to_response("valueaccounting/agent.html", { "agent": agent, "photo_size": (128, 128), @@ -523,13 +523,13 @@ def agent(request, agent_id): "is_associated_with": is_associated_with, "headings": headings, "member_hours_recent": member_hours_recent, - "member_hours_stats": member_hours_stats, + "member_hours_stats": member_hours_stats, "member_hours_roles": member_hours_roles, "individual_stats": individual_stats, "roles_height": roles_height, "help": get_help("agent"), }, context_instance=RequestContext(request)) - + def accounting(request, agent_id): #import pdb; pdb.set_trace() agent = get_object_or_404(EconomicAgent, id=agent_id) @@ -540,7 +540,7 @@ def accounting(request, agent_id): "agent": agent, "accounts": accounts, }, context_instance=RequestContext(request)) - + @login_required def test_patterns(request): pattern_form = PatternSelectionForm(data=request.POST or None) @@ -554,7 +554,7 @@ def test_patterns(request): for slot in slots: slot.resource_types = pattern.get_resource_types(slot) slot.facets = pattern.facets_for_event_type(slot) - + return render_to_response("valueaccounting/test_patterns.html", { "pattern_form": pattern_form, "pattern": pattern, @@ -591,7 +591,7 @@ def maintain_patterns(request, use_case_id=None): allowed_pattern_ids = [p.id for p in allowed_patterns] qs = ProcessPattern.objects.filter(id__in=allowed_pattern_ids).exclude(id__in=pattern_ids) pattern_form = PatternSelectionForm(queryset=qs) - + return render_to_response("valueaccounting/maintain_patterns.html", { "use_case_form": use_case_form, "use_case": use_case, @@ -608,12 +608,12 @@ def exchange_types(request): ext = new_form.save(commit=False) ext.created_by = request.user ext.save() - + supply_exchange_types = ExchangeType.objects.supply_exchange_types() demand_exchange_types = ExchangeType.objects.demand_exchange_types() internal_exchange_types = ExchangeType.objects.internal_exchange_types() new_form = NewExchangeTypeForm() - + return render_to_response("valueaccounting/exchange_types.html", { "supply_exchange_types": supply_exchange_types, "demand_exchange_types": demand_exchange_types, @@ -624,10 +624,10 @@ def exchange_types(request): @login_required def change_exchange_type(request, exchange_type_id): exchange_type = get_object_or_404(ExchangeType, id=exchange_type_id) - slots = exchange_type.slots() + slots = exchange_type.slots() change_ext_form = ExchangeTypeForm(instance=exchange_type, data=request.POST or None) add_tt_form = TransferTypeForm(data=request.POST or None) - for slot in slots: + for slot in slots: FacetValueFormSet = modelformset_factory( TransferTypeFacetValue, form=TransferTypeFacetValueForm, @@ -641,7 +641,7 @@ def change_exchange_type(request, exchange_type_id): slot.rts = ResourceTypeSelectionForm( qs=slot.get_resource_types(), prefix=str(slot.id)) - + if request.method == "POST": #import pdb; pdb.set_trace() save_ext = request.POST.get("save_ext") @@ -651,9 +651,9 @@ def change_exchange_type(request, exchange_type_id): ext = change_ext_form.save(commit=False) ext.changed_by = request.user ext.save() - + else: #save transfer type facet values - for slot in slots: + for slot in slots: FacetValueFormSet = modelformset_factory( TransferTypeFacetValue, form=TransferTypeFacetValueForm, @@ -690,7 +690,7 @@ def change_exchange_type(request, exchange_type_id): return HttpResponseRedirect('/%s/%s/' % ('accounting/change-exchange-type', exchange_type.id)) - + return render_to_response("valueaccounting/change_exchange_type.html", { "exchange_type": exchange_type, "change_ext_form": change_ext_form, @@ -700,7 +700,7 @@ def change_exchange_type(request, exchange_type_id): @login_required def add_transfer_type(request, exchange_type_id): - exchange_type = get_object_or_404(ExchangeType, pk=exchange_type_id) + exchange_type = get_object_or_404(ExchangeType, pk=exchange_type_id) if request.method == "POST": #import pdb; pdb.set_trace() form = TransferTypeForm(data=request.POST or None) @@ -709,13 +709,13 @@ def add_transfer_type(request, exchange_type_id): tt.created_by = request.user tt.exchange_type = exchange_type tt.save() - + return HttpResponseRedirect('/%s/%s/' % ('accounting/change-exchange-type', exchange_type.id)) - + @login_required def change_transfer_type(request, transfer_type_id): - tt = get_object_or_404(TransferType, pk=transfer_type_id) + tt = get_object_or_404(TransferType, pk=transfer_type_id) if request.method == "POST": #import pdb; pdb.set_trace() form = TransferTypeForm(instance=tt, data=request.POST, prefix=tt.form_prefix()) @@ -723,18 +723,18 @@ def change_transfer_type(request, transfer_type_id): tt = form.save(commit=False) tt.changed_by = request.user tt.save() - + return HttpResponseRedirect('/%s/%s/' % ('accounting/change-exchange-type', tt.exchange_type.id)) -@login_required +@login_required def delete_transfer_type(request, transfer_type_id): tt = get_object_or_404(TransferType, id=transfer_type_id) if request.method == "POST": if tt.is_deletable(): tt.delete() return HttpResponseRedirect('/%s/%s/' - % ('accounting/change-exchange-type', tt.exchange_type.id)) + % ('accounting/change-exchange-type', tt.exchange_type.id)) class AddFacetValueFormFormSet(BaseModelFormSet): @@ -742,7 +742,7 @@ def __init__(self, *args, **kwargs): self.qs = kwargs.pop('qs', None) super(AddFacetValueFormFormSet, self).__init__(*args, **kwargs) - def _construct_forms(self): + def _construct_forms(self): self.forms = [] #import pdb; pdb.set_trace() for i in xrange(self.total_form_count()): @@ -753,11 +753,11 @@ def _construct_forms(self): def change_pattern(request, pattern_id, use_case_id): pattern = get_object_or_404(ProcessPattern, id=pattern_id) use_case = get_object_or_404(UseCase, id=use_case_id) - slots = use_case.allowed_event_types() + slots = use_case.allowed_event_types() #import pdb; pdb.set_trace() for slot in slots: slot.resource_types = pattern.get_resource_types(slot) - slot.facets = pattern.facets_for_event_type(slot) + slot.facets = pattern.facets_for_event_type(slot) FacetValueFormSet = modelformset_factory( PatternFacetValue, form=PatternFacetValueForm, @@ -799,13 +799,13 @@ def change_pattern(request, pattern_id, use_case_id): return HttpResponseRedirect('/%s/%s/%s/' % ('accounting/change-pattern', pattern.id, use_case.id)) - + return render_to_response("valueaccounting/change_pattern.html", { "pattern": pattern, "slots": slots, "use_case": use_case, }, context_instance=RequestContext(request)) - + @login_required def change_pattern_name(request): #import pdb; pdb.set_trace() @@ -849,16 +849,16 @@ def add_pattern_to_use_case(request, use_case_id): return HttpResponseRedirect('/%s/%s/' % ('accounting/maintain-patterns', use_case_id)) -@login_required +@login_required def remove_pattern_from_use_case(request, use_case_id, pattern_id): if request.method == "POST": puc = get_object_or_404(PatternUseCase, use_case__id=use_case_id, pattern__id=pattern_id) puc.delete() return HttpResponseRedirect('/%s/%s/' % ('accounting/maintain-patterns', use_case_id)) - -@login_required + +@login_required def delete_exchange_type(request, exchange_type_id): if request.method == "POST": ext = get_object_or_404(ExchangeType, id=exchange_type_id) @@ -894,7 +894,7 @@ def sessions(request): selected_session.user = "guest" except Session.DoesNotExist: pass - + return render_to_response("valueaccounting/sessions.html", { "sessions": sessions, "selected_session": selected_session, @@ -991,8 +991,8 @@ def resource_type(request, resource_type_id): names = EconomicResourceType.objects.values_list('name', flat=True).exclude(id=resource_type_id) resource_names = '~'.join(names) init = {"unit_of_quantity": resource_type.unit,} - create_form = CreateEconomicResourceForm( - data=request.POST or None, + create_form = CreateUnquantifiedResourceForm( + data=request.POST or None, files=request.FILES or None, initial=init) create_role_formset = resource_role_agent_formset(prefix="resource") @@ -1018,7 +1018,7 @@ def resource_type(request, resource_type_id): rra.save() return HttpResponseRedirect('/%s/%s/' % ('accounting/resource', resource.id)) - + return render_to_response("valueaccounting/resource_type.html", { "resource_type": resource_type, "photo_size": (128, 128), @@ -1099,7 +1099,7 @@ def resource_flow_report(request, resource_type_id): #otherwise new ones incorrectly arrive at the end of the flow #would be better to figure out how to insert in the correct place stages = [] - #import pdb; pdb.set_trace() + #import pdb; pdb.set_trace() stages.append(ExchangeType.objects.get(id=3)) stages.append(ExchangeType.objects.get(id=2)) stages.append(ExchangeType.objects.get(id=5)) @@ -1109,7 +1109,7 @@ def resource_flow_report(request, resource_type_id): sales = [] for lot in lot_list: #if lot.identifier == "direct345345": #70314 - # import pdb; pdb.set_trace() + # import pdb; pdb.set_trace() lot_process_exchange_flow = lot.process_exchange_flow() if lot_process_exchange_flow: #import pdb; pdb.set_trace() @@ -1118,7 +1118,7 @@ def resource_flow_report(request, resource_type_id): lot.lot_receipt = lot_receipt #redo: need exchange_types as well as process_types #lot_pts, inheritance = rt.staged_process_type_sequence_beyond_workflow() - + #this next is obsolete, I think #actually, it shd map lot_process_exchange_flow to stages #51515 has lots of pex, which now caused lots of extra columns @@ -1141,7 +1141,7 @@ def resource_flow_report(request, resource_type_id): stage_pex.append(pex) stage.stage_pex = stage_pex #if lot.identifier == "92714": #70314 AHtest - # import pdb; pdb.set_trace() + # import pdb; pdb.set_trace() lot.lot_stages = lot_stages lot.lot_process_exchange_flow = lot_process_exchange_flow lot_sales = [] @@ -1150,16 +1150,16 @@ def resource_flow_report(request, resource_type_id): if lot_sales: sales.extend(lot_sales) lot.sales = lot_sales - + # just commented out next section because I don't understand it yet """ for lot in lot_list: for stage in stages: if ptype not in lot.lot_pts: lot.lot_pts.append(ptype) - """ - - #import pdb; pdb.set_trace() + """ + + #import pdb; pdb.set_trace() paginator = Paginator(lot_list, 500) page = request.GET.get('page') try: @@ -1170,14 +1170,14 @@ def resource_flow_report(request, resource_type_id): except EmptyPage: # If page is out of range (e.g. 9999), deliver last page of results. lots = paginator.page(paginator.num_pages) - + return render_to_response("valueaccounting/resource_flow_report.html", { "lots": lots, "stages": stages, "rt": rt, #"sort_form": sort_form, }, context_instance=RequestContext(request)) - + def adjust_resource(request, resource_id): resource = get_object_or_404(EconomicResource, id=resource_id) form = ResourceAdjustmentForm(data=request.POST) @@ -1199,11 +1199,11 @@ def adjust_resource(request, resource_id): event.save() resource.quantity = new_quantity resource.save() - + return HttpResponseRedirect('/%s/%s/' % ('accounting/event-history', resource.id)) - - + + def event_history(request, resource_id): resource = get_object_or_404(EconomicResource, id=resource_id) event_list = resource.events.all() @@ -1211,7 +1211,7 @@ def event_history(request, resource_id): init = {"quantity": resource.quantity,} adjustment_form = ResourceAdjustmentForm(initial=init) unit = resource.resource_type.unit - + paginator = Paginator(event_list, 25) page = request.GET.get('page') @@ -1223,7 +1223,7 @@ def event_history(request, resource_id): except EmptyPage: # If page is out of range (e.g. 9999), deliver last page of results. events = paginator.page(paginator.num_pages) - + return render_to_response("valueaccounting/event_history.html", { "resource": resource, "agent": agent, @@ -1245,7 +1245,7 @@ def all_contributions(request): except EmptyPage: # If page is out of range (e.g. 9999), deliver last page of results. events = paginator.page(paginator.num_pages) - + return render_to_response("valueaccounting/all_contributions.html", { "events": events, }, context_instance=RequestContext(request)) @@ -1272,7 +1272,7 @@ def contributions(request, project_id): event_list = event_list.filter(event_date__gte=start) if end: event_list = event_list.filter(event_date__lte=end) - event_ids = ",".join([str(event.id) for event in event_list]) + event_ids = ",".join([str(event.id) for event in event_list]) paginator = Paginator(event_list, 25) page = request.GET.get('page') try: @@ -1283,7 +1283,7 @@ def contributions(request, project_id): except EmptyPage: # If page is out of range (e.g. 9999), deliver last page of results. events = paginator.page(paginator.num_pages) - + return render_to_response("valueaccounting/project_contributions.html", { "project": project, "events": events, @@ -1307,12 +1307,12 @@ def project_wip(request, project_id): except EmptyPage: # If page is out of range (e.g. 9999), deliver last page of results. processes = paginator.page(paginator.num_pages) - + return render_to_response("valueaccounting/project_wip.html", { "project": project, "processes": processes, }, context_instance=RequestContext(request)) - + def finished_processes(request, agent_id): #import pdb; pdb.set_trace() project = get_object_or_404(EconomicAgent, pk=agent_id) @@ -1328,7 +1328,7 @@ def finished_processes(request, agent_id): except EmptyPage: # If page is out of range (e.g. 9999), deliver last page of results. processes = paginator.page(paginator.num_pages) - + return render_to_response("valueaccounting/finished_processes.html", { "project": project, "processes": processes, @@ -1359,7 +1359,7 @@ def contribution_history(request, agent_id): #belt and suspenders: if no et_ids, form is not valid if et_ids: event_list = event_list.filter(event_type__id__in=et_ids) - event_ids = ",".join([str(event.id) for event in event_list]) + event_ids = ",".join([str(event.id) for event in event_list]) paginator = Paginator(event_list, 25) page = request.GET.get('page') @@ -1371,7 +1371,7 @@ def contribution_history(request, agent_id): except EmptyPage: # If page is out of range (e.g. 9999), deliver last page of results. events = paginator.page(paginator.num_pages) - + return render_to_response("valueaccounting/agent_contributions.html", { "agent": agent, "user_is_agent": user_is_agent, @@ -1379,7 +1379,7 @@ def contribution_history(request, agent_id): "filter_form": filter_form, "event_ids": event_ids, }, context_instance=RequestContext(request)) - + @login_required def agent_value_accounting(request, agent_id): #import pdb; pdb.set_trace() @@ -1411,7 +1411,7 @@ def agent_value_accounting(request, agent_id): all_distro_evts = EconomicEvent.objects.filter(to_agent=agent, event_type=et) other_distro_evts = [d for d in all_distro_evts if d not in claim_distro_events] other_distributions = sum(de.quantity for de in other_distro_evts) - + paginator = Paginator(event_list, 25) page = request.GET.get('page') try: @@ -1422,7 +1422,7 @@ def agent_value_accounting(request, agent_id): except EmptyPage: # If page is out of range (e.g. 9999), deliver last page of results. events = paginator.page(paginator.num_pages) - + return render_to_response("valueaccounting/agent_value_accounting.html", { "agent": agent, "events": events, @@ -1440,7 +1440,7 @@ def unscheduled_time_contributions(request): if not member: return HttpResponseRedirect('/%s/' % ('accounting/work')) - + TimeFormSet = modelformset_factory( EconomicEvent, form=CasualTimeContributionForm, @@ -1488,7 +1488,7 @@ def unscheduled_time_contributions(request): else: return HttpResponseRedirect('/%s/%s/' % ('accounting/contributionhistory', member.id)) - + return render_to_response("valueaccounting/unscheduled_time_contributions.html", { "member": member, "time_formset": time_formset, @@ -1561,13 +1561,13 @@ def json_resource_type_resources(request, resource_type_id): #import pdb; pdb.set_trace() json = serializers.serialize("json", EconomicResource.objects.filter(resource_type=resource_type_id), fields=('identifier')) return HttpResponse(json, mimetype='application/json') - + def json_resource_type_stages(request, resource_type_id): #import pdb; pdb.set_trace() rt = get_object_or_404(EconomicResourceType, pk=resource_type_id) json = serializers.serialize("json", rt.all_stages(), fields=('name')) return HttpResponse(json, mimetype='application/json') - + def json_resource_type_resources_with_locations(request, resource_type_id): #import pdb; pdb.set_trace() rs = EconomicResource.objects.filter(resource_type=resource_type_id) @@ -1584,7 +1584,7 @@ def json_resource_type_resources_with_locations(request, resource_type_id): resources.append({"fields": fields}) data = simplejson.dumps(resources, ensure_ascii=False) return HttpResponse(data, mimetype="text/json-comment-filtered") - + def json_resource(request, resource_id): #import pdb; pdb.set_trace() r = get_object_or_404(EconomicResource, pk=resource_id) @@ -1606,7 +1606,7 @@ def json_resource(request, resource_id): rdict["assignments"] = assignments data = simplejson.dumps(rdict) return HttpResponse(data, mimetype="text/json-comment-filtered") - + def json_organization(request): #import pdb; pdb.set_trace() agent_types = AgentType.objects.all() @@ -1657,7 +1657,7 @@ def json_organization(request): } data = simplejson.dumps(big_d) return HttpResponse(data, mimetype="text/json-comment-filtered") - + def json_distribution_related_shipment(request, distribution_id): d = get_object_or_404(EconomicEvent, pk=distribution_id) ship = d.get_shipment_for_distribution() @@ -1669,7 +1669,7 @@ def json_distribution_related_shipment(request, distribution_id): } data = simplejson.dumps(sd) return HttpResponse(data, mimetype="text/json-comment-filtered") - + def json_distribution_related_order(request, distribution_id): d = get_object_or_404(EconomicEvent, pk=distribution_id) #import pdb; pdb.set_trace() @@ -1682,7 +1682,7 @@ def json_distribution_related_order(request, distribution_id): } data = simplejson.dumps(od) return HttpResponse(data, mimetype="text/json-comment-filtered") - + class EventSummary(object): def __init__(self, agent, role, quantity, value=Decimal('0.0')): self.agent = agent @@ -1698,9 +1698,9 @@ def quantity_formatted(self): class AgentSummary(object): - def __init__(self, - agent, - value=Decimal('0.0'), + def __init__(self, + agent, + value=Decimal('0.0'), percentage=Decimal('0.0'), amount=Decimal('0.0'), ): @@ -1713,7 +1713,7 @@ def __init__(self, def value_equation(request, project_id): #import pdb; pdb.set_trace() return render_to_response('valueaccounting/no_permission.html') - project = get_object_or_404(EconomicAgent, pk=project_id) + project = get_object_or_404(EconomicAgent, pk=project_id) all_subs = project.with_all_sub_agents() summaries = CachedEventSummary.objects.select_related( 'agent', 'context_agent', 'resource_type').filter(context_agent__in=all_subs).order_by( @@ -1778,7 +1778,7 @@ def value_equation(request, project_id): except EmptyPage: # If page is out of range (e.g. 9999), deliver last page of results. events = paginator.page(paginator.num_pages) - + return render_to_response("valueaccounting/value_equation.html", { "project": project, "events": events, @@ -1890,7 +1890,7 @@ def edit_stream_recipe(request, resource_type_id): "resource_type_form": resource_type_form, "help": get_help("ed_wf_recipe"), }, context_instance=RequestContext(request)) - + def view_stream_recipe(request, resource_type_id): rt = get_object_or_404(EconomicResourceType, pk=resource_type_id) @@ -1907,8 +1907,8 @@ def view_stream_recipe(request, resource_type_id): "photo_size": (128, 128), "help": get_help("ed_wf_recipe"), }, context_instance=RequestContext(request)) - - + + @login_required def change_resource_type(request, resource_type_id): #import pdb; pdb.set_trace() @@ -1980,7 +1980,7 @@ def delete_resource(request, resource_id): else: return HttpResponseRedirect('/%s/' % ('accounting/cleanup-resources')) - + @login_required def delete_agent(request, agent_id): #import pdb; pdb.set_trace() @@ -2083,15 +2083,15 @@ def delete_order(request, order_id): % ('accounting/closed-work-orders')) @login_required -def delete_process_input(request, +def delete_process_input(request, process_input_id, resource_type_id): pi = get_object_or_404(ProcessTypeResourceType, pk=process_input_id) pi.delete() return HttpResponseRedirect('/%s/%s/' % ('accounting/edit-xbomfg', resource_type_id)) - + @login_required -def delete_process_type_input(request, +def delete_process_type_input(request, process_input_id, resource_type_id): pi = get_object_or_404(ProcessTypeResourceType, pk=process_input_id) pi.delete() @@ -2100,7 +2100,7 @@ def delete_process_type_input(request, @login_required -def delete_source(request, +def delete_source(request, source_id, resource_type_id): s = get_object_or_404(AgentResourceType, pk=source_id) #import pdb; pdb.set_trace() @@ -2109,7 +2109,7 @@ def delete_source(request, % ('accounting/edit-xbomfg', resource_type_id)) @login_required -def delete_process_type_confirmation(request, +def delete_process_type_confirmation(request, process_type_id, resource_type_id): pt = get_object_or_404(ProcessType, pk=process_type_id) side_effects = False @@ -2129,7 +2129,7 @@ def delete_process_type_confirmation(request, return HttpResponseRedirect(next) @login_required -def delete_feature_confirmation(request, +def delete_feature_confirmation(request, feature_id, resource_type_id): ft = get_object_or_404(Feature, pk=feature_id) side_effects = False @@ -2189,7 +2189,7 @@ def create_resource_type(request): form = EconomicResourceTypeForm(request.POST, request.FILES) if form.is_valid(): data = form.cleaned_data - rt = form.save(commit=False) + rt = form.save(commit=False) rt.created_by=request.user rt.save() formset = create_facet_formset(data=request.POST) @@ -2217,20 +2217,20 @@ def create_resource_type_ajax(request): #import pdb; pdb.set_trace() slot = request.POST.get("slot") pt_id = int(request.POST.get("pt-id").replace("ProcessType-","")) - process_type = ProcessType.objects.get(id=pt_id) + process_type = ProcessType.objects.get(id=pt_id) if slot == "cite": rt_prefix = process_type.xbill_citable_rt_prefix() rtf_prefix = process_type.xbill_citable_rt_facet_prefix() - elif slot == "use": - rt_prefix = process_type.xbill_usable_rt_prefix() + elif slot == "use": + rt_prefix = process_type.xbill_usable_rt_prefix() rtf_prefix = process_type.xbill_usable_rt_facet_prefix() else: - rt_prefix = process_type.xbill_consumable_rt_prefix() + rt_prefix = process_type.xbill_consumable_rt_prefix() rtf_prefix = process_type.xbill_consumable_rt_facet_prefix() form = EconomicResourceTypeAjaxForm(request.POST, request.FILES, prefix=rt_prefix) if form.is_valid(): data = form.cleaned_data - rt = form.save(commit=False) + rt = form.save(commit=False) rt.created_by=request.user rt.save() formset = process_type.create_facet_formset_filtered(data=request.POST, pre=rtf_prefix, slot=slot) @@ -2243,7 +2243,7 @@ def create_resource_type_ajax(request): rtfv.resource_type = rt rtfv.facet_value = fv rtfv.save() - return_data = serializers.serialize("json", EconomicResourceType.objects.filter(id=rt.id), fields=('id','name',)) + return_data = serializers.serialize("json", EconomicResourceType.objects.filter(id=rt.id), fields=('id','name',)) return HttpResponse(return_data, mimetype="text/json-comment-filtered") else: return HttpResponse(form.errors, mimetype="text/json-comment-filtered") @@ -2254,7 +2254,7 @@ def create_resource_type_simple_patterned_ajax(request): form = EconomicResourceTypeAjaxForm(request.POST, request.FILES) if form.is_valid(): data = form.cleaned_data - rt = form.save(commit=False) + rt = form.save(commit=False) rt.created_by=request.user rt.save() slot = request.POST["slot"] @@ -2270,7 +2270,7 @@ def create_resource_type_simple_patterned_ajax(request): rtfv.resource_type = rt rtfv.facet_value = fv rtfv.save() - return_data = serializers.serialize("json", EconomicResourceType.objects.filter(id=rt.id), fields=('id','name',)) + return_data = serializers.serialize("json", EconomicResourceType.objects.filter(id=rt.id), fields=('id','name',)) return HttpResponse(return_data, mimetype="text/json-comment-filtered") else: return HttpResponse(form.errors, mimetype="text/json-comment-filtered") @@ -2392,7 +2392,7 @@ def create_options_for_feature(request, feature_id): component=rt) opt.created_by=request.user opt.save() - + next = request.POST.get("next") return HttpResponseRedirect(next) else: @@ -2423,7 +2423,7 @@ def change_options_for_feature(request, feature_id): component=rt) opt.created_by=request.user opt.save() - + next = request.POST.get("next") return HttpResponseRedirect(next) else: @@ -2438,20 +2438,20 @@ def change_process_type_input(request, input_id): if ptrt.event_type.relationship == "work": form = ProcessTypeWorkForm( data=request.POST, - instance=ptrt, - process_type=ptrt.process_type, + instance=ptrt, + process_type=ptrt.process_type, prefix=prefix) elif ptrt.event_type.relationship == "cite": form = ProcessTypeCitableForm( data=request.POST, - instance=ptrt, - process_type=ptrt.process_type, + instance=ptrt, + process_type=ptrt.process_type, prefix=prefix) else: form = ProcessTypeInputForm( data=request.POST, - instance=ptrt, - process_type=ptrt.process_type, + instance=ptrt, + process_type=ptrt.process_type, prefix=prefix) if form.is_valid(): inp = form.save(commit=False) @@ -2535,7 +2535,7 @@ def change_process_type(request, process_type_id): return HttpResponseRedirect(next) else: raise ValidationError(form.errors) - + @login_required def change_mfg_process_type(request, process_type_id): #import pdb; pdb.set_trace() @@ -2590,7 +2590,7 @@ def create_process_type_for_resource_type(request, resource_type_id): return HttpResponseRedirect(next) else: raise ValidationError(form.errors) - + @login_required def create_process_type_for_streaming(request, resource_type_id, process_type_id=None): #import pdb; pdb.set_trace() @@ -2645,7 +2645,7 @@ def create_process_type_for_streaming(request, resource_type_id, process_type_id else: raise ValidationError(form.errors) - + def network(request, resource_type_id): #import pdb; pdb.set_trace() rt = get_object_or_404(EconomicResourceType, pk=resource_type_id) @@ -2703,7 +2703,7 @@ def json_timeline(request, from_date, to_date, context_id): events = {'dateTimeFormat': 'Gregorian','events':[]} processes = Process.objects.unfinished().filter( Q(start_date__range=(start, end)) | Q(end_date__range=(start, end)) | - Q(start_date__lt=start, end_date__gt=end)) + Q(start_date__lt=start, end_date__gt=end)) if context_agent: processes = processes.filter(context_agent=context_agent) orders = [p.independent_demand() for p in processes if p.independent_demand()] @@ -2712,11 +2712,11 @@ def json_timeline(request, from_date, to_date, context_id): data = simplejson.dumps(events, ensure_ascii=False) #import pdb; pdb.set_trace() return HttpResponse(data, mimetype="text/json-comment-filtered") - + def context_timeline(request, context_id): context_agent = get_object_or_404(EconomicAgent, pk=context_id) timeline_date = datetime.date.today().strftime("%b %e %Y 00:00:00 GMT-0600") - + unassigned = Commitment.objects.unfinished().filter( context_agent=context_agent, from_agent=None, @@ -2769,7 +2769,7 @@ def json_order_timeline(request, order_id): data = simplejson.dumps(events, ensure_ascii=False) #import pdb; pdb.set_trace() return HttpResponse(data, mimetype="text/json-comment-filtered") - + def json_processes(request, order_id=None): #import pdb; pdb.set_trace() @@ -2838,7 +2838,7 @@ def json_directional_unit(request, resource_type_id, direction): } data = simplejson.dumps(defaults, ensure_ascii=False) return HttpResponse(data, mimetype="text/json-comment-filtered") - + def json_default_equation(request, event_type_id): et = get_object_or_404(EventType, pk=event_type_id) equation = et.default_event_value_equation() @@ -2863,19 +2863,19 @@ def json_resource_type_defaults(request, resource_type_id): #import pdb; pdb.set_trace() data = simplejson.dumps(defaults, ensure_ascii=False) return HttpResponse(data, mimetype="text/json-comment-filtered") - + def json_context_agent_suppliers(request, agent_id): #import pdb; pdb.set_trace() agent = EconomicAgent.objects.get(id=agent_id) json = serializers.serialize("json", agent.all_suppliers(), fields=('pk', 'nick')) return HttpResponse(json, mimetype='application/json') - + def json_context_agent_customers(request, agent_id): #import pdb; pdb.set_trace() agent = EconomicAgent.objects.get(id=agent_id) json = serializers.serialize("json", agent.all_customers(), fields=('pk', 'nick')) return HttpResponse(json, mimetype='application/json') - + def json_order_customer(request, order_id, agent_id): #import pdb; pdb.set_trace() if order_id == '0': @@ -2887,8 +2887,8 @@ def json_order_customer(request, order_id, agent_id): if order.provider: customers.append(order.provider) json = serializers.serialize("json", customers, fields=('pk', 'nick')) - return HttpResponse(json, mimetype='application/json') - + return HttpResponse(json, mimetype='application/json') + def json_customer_orders(request, customer_id): #import pdb; pdb.set_trace() if customer_id == '0': @@ -2905,12 +2905,12 @@ def json_customer_orders(request, customer_id): orders.append({"fields": fields}) data = simplejson.dumps(orders, ensure_ascii=False) return HttpResponse(data, mimetype="text/json-comment-filtered") - - + + def explore(request): return render_to_response("valueaccounting/explore.html", { }, context_instance=RequestContext(request)) - + def unfold_commitment(request, commitment_id): commitment = get_object_or_404(Commitment, pk=commitment_id) process = commitment.process @@ -2918,7 +2918,7 @@ def unfold_commitment(request, commitment_id): "commitment": commitment, "process": process, }, context_instance=RequestContext(request)) - + def unfold_process(request, process_id): process = get_object_or_404(Process, pk=process_id) commitment = None @@ -2930,7 +2930,7 @@ def unfold_process(request, process_id): @login_required def cleanup(request): if not request.user.is_superuser: - return render_to_response('valueaccounting/no_permission.html') + return render_to_response('valueaccounting/no_permission.html') return render_to_response("valueaccounting/cleanup.html", { }, context_instance=RequestContext(request)) @@ -2938,8 +2938,8 @@ def cleanup(request): @login_required def misc(request): if not request.user.is_superuser: - return render_to_response('valueaccounting/no_permission.html') - + return render_to_response('valueaccounting/no_permission.html') + context_agent = None context_agents = EconomicAgent.objects.context_agents() if context_agents: @@ -2947,7 +2947,7 @@ def misc(request): for ca in context_agents: if ca.events.all().count() > context_agent.events.all().count(): context_agent = ca - + ca_form = ContextAgentSelectionForm() if request.method == "POST": form = ContextAgentSelectionForm(data=request.POST) @@ -2955,23 +2955,23 @@ def misc(request): data = form.cleaned_data agent = data["selected_agent"] return HttpResponseRedirect('/%s/%s/' - % ('accounting/create-distribution', agent.id)) + % ('accounting/create-distribution', agent.id)) return render_to_response("valueaccounting/misc.html", { "context_agent": context_agent, "ca_form": ca_form, }, context_instance=RequestContext(request)) - + @login_required def cleanup_processes(request): if not request.user.is_superuser: return render_to_response('valueaccounting/no_permission.html') - orphans = [p for p in Process.objects.all() if p.is_orphan()] + orphans = [p for p in Process.objects.all() if p.is_orphan()] return render_to_response("valueaccounting/cleanup_processes.html", { "orphans": orphans, }, context_instance=RequestContext(request)) - + @login_required def cleanup_old_processes(request): if not request.user.is_superuser: @@ -2988,27 +2988,27 @@ def cleanup_old_processes(request): def cleanup_resourcetypes(request): if not request.user.is_superuser: return render_to_response('valueaccounting/no_permission.html') - orphans = [rt for rt in EconomicResourceType.objects.all() if rt.is_orphan()] + orphans = [rt for rt in EconomicResourceType.objects.all() if rt.is_orphan()] return render_to_response("valueaccounting/cleanup_resourcetypes.html", { "orphans": orphans, }, context_instance=RequestContext(request)) - + @login_required def cleanup_work_resourcetypes(request): if not request.user.is_superuser: return render_to_response('valueaccounting/no_permission.html') - suspects = [rt for rt in EconomicResourceType.objects.all() if rt.work_without_value()] + suspects = [rt for rt in EconomicResourceType.objects.all() if rt.work_without_value()] return render_to_response("valueaccounting/cleanup_work_resourcetypes.html", { "suspects": suspects, }, context_instance=RequestContext(request)) - + @login_required def cleanup_resources(request): if not request.user.is_superuser: return render_to_response('valueaccounting/no_permission.html') - orphans = [er for er in EconomicResource.objects.all() if er.is_orphan()] + orphans = [er for er in EconomicResource.objects.all() if er.is_orphan()] return render_to_response("valueaccounting/cleanup_resources.html", { "orphans": orphans, @@ -3018,7 +3018,7 @@ def cleanup_resources(request): def cleanup_unsourced_resources(request): if not request.user.is_superuser: return render_to_response('valueaccounting/no_permission.html') - suspects = [er for er in EconomicResource.objects.all() if er.unsourced_consumption()] + suspects = [er for er in EconomicResource.objects.all() if er.unsourced_consumption()] return render_to_response("valueaccounting/cleanup_unsourced_resources.html", { "suspects": suspects, @@ -3028,12 +3028,12 @@ def cleanup_unsourced_resources(request): def cleanup_unvalued_resources(request): if not request.user.is_superuser: return render_to_response('valueaccounting/no_permission.html') - suspects = [er for er in EconomicResource.objects.all() if er.used_without_value()] + suspects = [er for er in EconomicResource.objects.all() if er.used_without_value()] return render_to_response("valueaccounting/cleanup_unvalued_resources.html", { "suspects": suspects, }, context_instance=RequestContext(request)) - + @login_required def create_order(request): #import pdb; pdb.set_trace() @@ -3064,12 +3064,12 @@ def create_order(request): order.save() uc = UseCase.objects.get(identifier="demand_xfer") ext_id = request.POST["exchange_type"] - exchange_type = ExchangeType.objects.get(id=ext_id) + exchange_type = ExchangeType.objects.get(id=ext_id) exchange = Exchange( name=exchange_type.name + " for customer order " + str(order.id), exchange_type=exchange_type, use_case=uc, - context_agent=order.provider, + context_agent=order.provider, start_date=order.due_date, order=order, created_by= request.user, @@ -3118,8 +3118,8 @@ def create_order(request): commitment.save() commitment.order_item = commitment commitment.save() - commitment.generate_producing_process(request.user, [], explode=True) - + commitment.generate_producing_process(request.user, [], explode=True) + oi_commitments = Commitment.objects.filter(order=order) tts = exchange.exchange_type.transfer_types_non_reciprocal() tt = None @@ -3132,13 +3132,13 @@ def create_order(request): transfer_type=tt, context_agent=exchange.context_agent, transfer_date=commit.commitment_date, - created_by=request.user, + created_by=request.user, ) xfer.save() commit.exchange = exchange commit.transfer = xfer commit.save() - + #todo: this should be able to figure out $ owed, including tax, etc. rec_tts = exchange.exchange_type.transfer_types_reciprocal() rec_tt = None @@ -3150,7 +3150,7 @@ def create_order(request): transfer_type=rec_tt, context_agent=exchange.context_agent, transfer_date=commit.commitment_date, - created_by=request.user, + created_by=request.user, ) cr_xfer.save() cr_commit = Commitment( @@ -3165,10 +3165,10 @@ def create_order(request): created_by=request.user ) cr_commit.save() - + return HttpResponseRedirect('/%s/%s/' % ('accounting/order-schedule', order.id)) - + return render_to_response("valueaccounting/create_order.html", { "order_form": order_form, "item_forms": item_forms, @@ -3178,11 +3178,11 @@ def create_order(request): #flow todo: shd order_item be used here? #I think not. Used only in delete_order_confirmation. def schedule_commitment( - commitment, - schedule, - reqs, - work, - tools, + commitment, + schedule, + reqs, + work, + tools, visited_resources, depth): #import pdb; pdb.set_trace() @@ -3219,7 +3219,7 @@ def schedule_commitment( schedule.append(art) return schedule - + def orders(request, agent_id): agent = get_object_or_404(EconomicAgent, id=agent_id) orders = agent.active_orders() @@ -3233,7 +3233,7 @@ def orders(request, agent_id): "agent": agent, "orders": orders, }, context_instance=RequestContext(request)) - + def order_schedule(request, order_id): agent = get_agent(request) @@ -3277,7 +3277,7 @@ def order_schedule(request, order_id): "error_message": error_message, }, context_instance=RequestContext(request)) -@login_required +@login_required def change_commitment_quantities(request, order_item_id): order_item = get_object_or_404(Commitment, pk=order_item_id) qty_form = ResourceQuantityForm(prefix=str(order_item.id), data=request.POST or None) @@ -3286,11 +3286,11 @@ def change_commitment_quantities(request, order_item_id): if qty_form.is_valid(): data = qty_form.cleaned_data new_qty = data["quantity"] - order_item.change_commitment_quantities(new_qty) + order_item.change_commitment_quantities(new_qty) next = request.POST.get("next") return HttpResponseRedirect(next) -@login_required +@login_required def change_workflow_project(request, order_item_id): order_item = get_object_or_404(Commitment, pk=order_item_id) project_form = ProjectSelectionForm(prefix=str(order_item.id), data=request.POST or None) @@ -3299,10 +3299,10 @@ def change_workflow_project(request, order_item_id): if project_form.is_valid(): data = project_form.cleaned_data new_proj = data["context_agent"] - order_item.change_workflow_project(new_proj) + order_item.change_workflow_project(new_proj) next = request.POST.get("next") return HttpResponseRedirect(next) - + @login_required def add_order_item( request, order_id): @@ -3320,9 +3320,9 @@ def add_order_item( user=request.user) next = request.POST.get("next") return HttpResponseRedirect(next) - - -@login_required + + +@login_required def change_process_plan(request, process_id): process = get_object_or_404(Process, pk=process_id) form = PlanProcessForm(prefix=process.plan_form_prefix(), data=request.POST or None) @@ -3343,11 +3343,11 @@ def change_process_plan(request, process_id): if ct.due_date != process.end_date: ct.due_date = process.end_date ct.save() - + next = request.POST.get("next") return HttpResponseRedirect(next) -@login_required +@login_required def create_process_for_streaming(request, order_item_id): #at the end of the order item order_item = get_object_or_404(Commitment, pk=order_item_id) form = WorkflowProcessForm(prefix=str(order_item.id), data=request.POST or None, order_item=order_item) @@ -3372,7 +3372,7 @@ def create_process_for_streaming(request, order_item_id): #at the end of the ord next = request.POST.get("next") return HttpResponseRedirect(next) -@login_required +@login_required def insert_process_for_streaming(request, order_item_id, process_id): order_item = get_object_or_404(Commitment, pk=order_item_id) next_process = Process.objects.get(id=process_id) @@ -3397,8 +3397,8 @@ def insert_process_for_streaming(request, order_item_id, process_id): order_item.adjust_workflow_commitments_process_inserted(process=process, next_process=next_process, user=request.user) next = request.POST.get("next") return HttpResponseRedirect(next) - -@login_required + +@login_required def delete_workflow_process(request, order_item_id, process_id): order_item = get_object_or_404(Commitment, pk=order_item_id) process = Process.objects.get(id=process_id) @@ -3410,7 +3410,7 @@ def delete_workflow_process(request, order_item_id, process_id): next = request.POST.get("next") return HttpResponseRedirect(next) - + def demand(request): agent = get_agent(request) orders = Order.objects.customer_orders() @@ -3425,15 +3425,15 @@ def demand(request): ext = data["exchange_type"] return HttpResponseRedirect('/%s/%s/%s/' % ('accounting/exchange', ext.id, 0)) - + return render_to_response("valueaccounting/demand.html", { "orders": orders, "rands": rands, "agent": agent, "nav_form": nav_form, "help": help, - }, context_instance=RequestContext(request)) - + }, context_instance=RequestContext(request)) + def closed_work_orders(request): agent = get_agent(request) orders = Order.objects.closed_work_orders() @@ -3442,8 +3442,8 @@ def closed_work_orders(request): "rands": orders, "agent": agent, #"help": help, - }, context_instance=RequestContext(request)) - + }, context_instance=RequestContext(request)) + def resource_type_lists(request): agent = get_agent(request) rt_lists = ResourceTypeList.objects.all() @@ -3462,14 +3462,14 @@ def resource_type_lists(request): elem.save() return HttpResponseRedirect('/%s/' % ('accounting/resource-type-lists')) - + return render_to_response("valueaccounting/resource_type_lists.html", { "rt_lists": rt_lists, "rtl_form": rtl_form, "agent": agent, #"help": help, - }, context_instance=RequestContext(request)) - + }, context_instance=RequestContext(request)) + @login_required def create_resource_type_list(request): rtl_form = ResourceTypeListForm(data=request.POST or None) @@ -3507,7 +3507,7 @@ def create_resource_type_list(request): "element_forms": element_forms, #"help": get_help("associations"), }, context_instance=RequestContext(request)) - + @login_required def change_resource_type_list(request, list_id): rt_list = get_object_or_404(ResourceTypeList, id=list_id) @@ -3547,7 +3547,7 @@ def change_resource_type_list(request, list_id): instance = None if elem.id: instance = True - if added: + if added: if instance: elem.save() else: @@ -3563,21 +3563,21 @@ def change_resource_type_list(request, list_id): return HttpResponseRedirect('/%s/' % ('accounting/resource-type-lists')) - + return render_to_response("valueaccounting/resource_type_list.html", { "rtl_form": rtl_form, "rt_list": rt_list, "element_forms": element_forms, #"help": get_help("associations"), }, context_instance=RequestContext(request)) - + @login_required def delete_resource_type_list(request, list_id): rt_list = get_object_or_404(ResourceTypeList, id=list_id) rt_list.delete() return HttpResponseRedirect('/%s/' % ('accounting/resource-type-lists')) - + def supply_older(request): mreqs = [] #todo: needs a lot of work @@ -3587,7 +3587,7 @@ def supply_older(request): suppliers = SortedDict() for commitment in mrqs: if not commitment.resource_type.producing_commitments(): - if not commitment.fulfilling_events(): + if not commitment.fulfilling_events(): mreqs.append(commitment) sources = commitment.resource_type.producing_agent_relationships().order_by("resource_type__name") for source in sources: @@ -3596,14 +3596,14 @@ def supply_older(request): suppliers[agent] = SortedDict() if source not in suppliers[agent]: suppliers[agent][source] = [] - suppliers[agent][source].append(commitment) + suppliers[agent][source].append(commitment) treqs = [] trqs = Commitment.objects.unfinished().filter( event_type__resource_effect="=", event_type__relationship="in").order_by("resource_type__name") for commitment in trqs: if not commitment.resource_type.producing_commitments(): - if not commitment.fulfilling_events(): + if not commitment.fulfilling_events(): treqs.append(commitment) sources = commitment.resource_type.producing_agent_relationships().order_by("resource_type__name") for source in sources: @@ -3612,14 +3612,14 @@ def supply_older(request): suppliers[agent] = SortedDict() if source not in suppliers[agent]: suppliers[agent][source] = [] - suppliers[agent][source].append(commitment) + suppliers[agent][source].append(commitment) return render_to_response("valueaccounting/supply.html", { "mreqs": mreqs, "treqs": treqs, "suppliers": suppliers, "help": get_help("supply"), }, context_instance=RequestContext(request)) - + def supply_old(request): agent = get_agent(request) mreqs = [] @@ -3627,7 +3627,7 @@ def supply_old(request): suppliers = SortedDict() #supplier_form = AgentSupplierForm(prefix="supplier") for commitment in mrqs: - if not commitment.fulfilling_events(): + if not commitment.fulfilling_events(): mreqs.append(commitment) sources = commitment.resource_type.producing_agent_relationships().order_by("resource_type__name") for source in sources: @@ -3636,7 +3636,7 @@ def supply_old(request): suppliers[agent] = SortedDict() if source not in suppliers[agent]: suppliers[agent][source] = [] - suppliers[agent][source].append(commitment) + suppliers[agent][source].append(commitment) treqs = [] return render_to_response("valueaccounting/supply.html", { "mreqs": mreqs, @@ -3668,7 +3668,7 @@ def supply(request): #todo: separate tool reqs from material reqs treqs = [] nav_form = SupplyExchangeNavForm(data=request.POST or None) - + if request.method == "POST": #import pdb; pdb.set_trace() if nav_form.is_valid(): @@ -3676,7 +3676,7 @@ def supply(request): ext = data["exchange_type"] return HttpResponseRedirect('/%s/%s/%s/' % ('accounting/exchange', ext.id, 0)) - + return render_to_response("valueaccounting/supply.html", { "mreqs": mreqs, "treqs": treqs, @@ -3705,7 +3705,7 @@ def assemble_schedule(start, end, context_agent=None): if start: processes = processes.filter( Q(start_date__range=(start, end)) | Q(end_date__range=(start, end)) | - Q(start_date__lt=start, end_date__gt=end)) + Q(start_date__lt=start, end_date__gt=end)) processes = processes.order_by("context_agent__name", "end_date", "start_date") context_agents = SortedDict() for proc in processes: @@ -3732,7 +3732,7 @@ def change_process_sked_ajax(request): process.end_date = data["end_date"] process.notes = data["notes"] process.save() - return_data = "OK" + return_data = "OK" return HttpResponse(return_data, mimetype="text/plain") else: return HttpResponse(form.errors, mimetype="text/json-comment-filtered") @@ -3767,7 +3767,7 @@ def work(request): if proj_id.isdigit: context_id = proj_id chosen_context_agent = EconomicAgent.objects.get(id=proj_id) - + start_date = start.strftime('%Y_%m_%d') end_date = end.strftime('%Y_%m_%d') processes, context_agents = assemble_schedule(start, end, chosen_context_agent) @@ -3788,7 +3788,7 @@ def work(request): "help": get_help("all_work"), }, context_instance=RequestContext(request)) -def schedule(request, context_agent_slug=None): +def schedule(request, context_agent_slug=None): context_agent = None if context_agent_slug: context_agent = get_object_or_404(EconomicAgent, slug=context_agent_slug) @@ -3815,9 +3815,9 @@ def today(request): "events": events, }, context_instance=RequestContext(request)) - + class EventProcessSummary(object): - def __init__(self, + def __init__(self, agent, context_agent, resource_type, process, quantity): self.agent = agent self.context_agent = context_agent @@ -3827,7 +3827,7 @@ def __init__(self, def key(self): return "-".join([ - str(self.agent.id), + str(self.agent.id), str(self.resource_type.id), str(self.project.id), str(self.process.id), @@ -3835,8 +3835,8 @@ def key(self): def quantity_formatted(self): return self.quantity.quantize(Decimal('.01'), rounding=ROUND_HALF_UP) - - + + def condense_events(event_list): condensed_events = [] if event_list: @@ -3856,22 +3856,22 @@ def condense_events(event_list): if process: process = process.id key = "-".join([ - str(from_agent), - str(context_agent), - str(resource_type), + str(from_agent), + str(context_agent), + str(resource_type), str(process) ]) if not key in summaries: summaries[key] = EventProcessSummary( - event.from_agent, - event.context_agent, - event.resource_type, - event.process, + event.from_agent, + event.context_agent, + event.resource_type, + event.process, Decimal('0.0')) summaries[key].quantity += event.quantity condensed_events = summaries.values() return condensed_events - + def assemble_weekly_activity(event_list): event_summaries = condense_events(event_list) @@ -3944,14 +3944,14 @@ def add_todo(request): if user: #import pdb; pdb.set_trace() notification.send( - [user.user,], - "valnet_new_todo", + [user.user,], + "valnet_new_todo", {"description": todo.description, "creator": agent, "site_name": site_name, } ) - + return HttpResponseRedirect(next) def create_event_from_todo(todo): @@ -4098,8 +4098,8 @@ def todo_delete(request, todo_id): if user: #import pdb; pdb.set_trace() notification.send( - [user.user,], - "valnet_deleted_todo", + [user.user,], + "valnet_deleted_todo", {"description": todo.description, "creator": agent, "site_name": site_name, @@ -4121,15 +4121,15 @@ def start(request): from_agent=agent) skill_ids = agent.resource_types.values_list('resource_type__id', flat=True) my_skillz = Commitment.objects.unfinished().filter( - from_agent=None, + from_agent=None, event_type__relationship="work", resource_type__id__in=skill_ids) other_unassigned = Commitment.objects.unfinished().filter( - from_agent=None, - event_type__relationship="work").exclude(resource_type__id__in=skill_ids) + from_agent=None, + event_type__relationship="work").exclude(resource_type__id__in=skill_ids) else: other_unassigned = Commitment.objects.unfinished().filter( - from_agent=None, + from_agent=None, event_type__relationship="work") todos = Commitment.objects.todos().filter(from_agent=agent) init = {"from_agent": agent,} @@ -4194,7 +4194,7 @@ def project_stats(request, context_agent_slug): "member_hours": member_hours, "page_title": "All-time project stats", }, context_instance=RequestContext(request)) - + def recent_stats(request, context_agent_slug): project = None member_hours = [] @@ -4250,7 +4250,7 @@ def project_roles(request, context_agent_slug): agents[key][idx] += ce.quantity headings = ["Member",] headings.extend(roles) - for row in agents.values(): + for row in agents.values(): member_hours.append(row) member_hours.sort(lambda x, y: cmp(x[0], y[0])) return render_to_response("valueaccounting/project_roles.html", { @@ -4269,7 +4269,7 @@ def processes_graph(request, object_type=None, object_id=None): url_extension = "" if object_type: url_extension = "".join([ object_type, "/", object_id, "/"]) - + return render_to_response("valueaccounting/processes_graph.html", { "url_extension": url_extension, }, context_instance=RequestContext(request)) @@ -4301,23 +4301,23 @@ def commit_to_task(request, commitment_id): ct.changed_by=request.user ct.save() #todo: commented out for now - #might need more logic so it doesn't needlessly + #might need more logic so it doesn't needlessly #push the next process out #if start_date != process.start_date: # if process.work_requirements().count() == 1: # if start_date > process.start_date: # delta = start_date - process.start_date # process.reschedule_forward(delta.days, request.user) - # else: + # else: # process.start_date = start_date # process.changed_by=request.user # process.save() if request.POST.get("start"): return HttpResponseRedirect('/%s/%s/%s/' % ('accounting/work-now', process.id, ct.id)) - + return HttpResponseRedirect(next) - + @login_required def join_task(request, commitment_id): if request.method == "POST": @@ -4366,8 +4366,8 @@ def join_task(request, commitment_id): site_name = get_site_name() if users: notification.send( - users, - "valnet_join_task", + users, + "valnet_join_task", {"resource_type": ct.resource_type, "due_date": ct.due_date, "hours": ct.quantity, @@ -4378,7 +4378,7 @@ def join_task(request, commitment_id): "site_name": site_name, } ) - + return HttpResponseRedirect('/%s/%s/' % ('accounting/process', process.id)) @@ -4401,7 +4401,7 @@ def change_commitment(request, commitment_id): rt = ct.resource_type demand = ct.independent_demand new_qty = data["quantity"] - old_ct = Commitment.objects.get(id=commitment_id) + old_ct = Commitment.objects.get(id=commitment_id) explode = handle_commitment_changes(old_ct, rt, new_qty, demand, demand) commitment = form.save() #flow todo: explode? @@ -4473,10 +4473,10 @@ def forward_schedule_process(request, process_id): else: return HttpResponseRedirect('/%s/%s/' % ('accounting/order-schedule', ct.independent_demand.id)) - + def create_labnotes_context( - request, - commitment, + request, + commitment, was_running=0, was_retrying=0): event = None @@ -4492,7 +4492,7 @@ def create_labnotes_context( "process_done": commitment.process.finished, } wb_form = WorkbookForm(instance=event, initial=init) - duration = event.quantity * 60 + duration = event.quantity * 60 else: init = { "description": commitment.description, @@ -4590,7 +4590,7 @@ def new_process_output(request, commitment_id): form = ProcessOutputForm(data=request.POST, prefix='output') if form.is_valid(): output_data = form.cleaned_data - qty = output_data["quantity"] + qty = output_data["quantity"] if qty: ct = form.save(commit=False) rt = output_data["resource_type"] @@ -4668,7 +4668,7 @@ def new_process_input(request, commitment_id, slot): ct.context_agent = ptrt.process_type.context_agent ct.save() #todo: this is used in labnotes; shd it explode? - #explode_dependent_demands(ct, request.user) + #explode_dependent_demands(ct, request.user) if reload == 'pastwork': return HttpResponseRedirect('/%s/%s/%s/%s/%s/' % ('accounting/pastwork-reload', commitment.id, event_id, was_running, was_retrying)) @@ -4722,7 +4722,7 @@ def new_process_citation(request, commitment_id): created_by=request.user, ) ct.save() - + if reload == 'pastwork': return HttpResponseRedirect('/%s/%s/%s/%s/%s/' % ('accounting/pastwork-reload', commitment.id, event_id, was_running, was_retrying)) @@ -4777,8 +4777,8 @@ def new_process_worker(request, commitment_id): site_name = get_site_name() if users: notification.send( - users, - "valnet_help_wanted", + users, + "valnet_help_wanted", {"resource_type": ct.resource_type, "due_date": ct.due_date, "hours": ct.quantity, @@ -4789,7 +4789,7 @@ def new_process_worker(request, commitment_id): "site_name": site_name, } ) - + if reload == 'pastwork': return HttpResponseRedirect('/%s/%s/%s/%s/%s/' % ('accounting/pastwork-reload', commitment.id, event_id, was_running, was_retrying)) @@ -4798,12 +4798,12 @@ def new_process_worker(request, commitment_id): % ('accounting/labnotes-reload', commitment.id, was_running, was_retrying)) def add_process_output(request, process_id): - process = get_object_or_404(Process, pk=process_id) + process = get_object_or_404(Process, pk=process_id) if request.method == "POST": form = ProcessOutputForm(data=request.POST, prefix='output') if form.is_valid(): output_data = form.cleaned_data - qty = output_data["quantity"] + qty = output_data["quantity"] if qty: ct = form.save(commit=False) rt = output_data["resource_type"] @@ -4833,18 +4833,18 @@ def add_process_output(request, process_id): if len(process.name) > 128: process.name = process.name[0:128] process.save() - + return HttpResponseRedirect('/%s/%s/' % ('accounting/process', process.id)) def add_unplanned_output(request, process_id): - process = get_object_or_404(Process, pk=process_id) + process = get_object_or_404(Process, pk=process_id) if request.method == "POST": #import pdb; pdb.set_trace() form = UnplannedOutputForm(data=request.POST, prefix='unplannedoutput') if form.is_valid(): output_data = form.cleaned_data - qty = output_data["quantity"] + qty = output_data["quantity"] if qty: event = form.save(commit=False) rt = output_data["resource_type"] @@ -4859,7 +4859,7 @@ def add_unplanned_output(request, process_id): #flow todo: add order_item ? [no] #N/A I think, but see also #add_process_output - + resource = EconomicResource( resource_type=rt, identifier=identifier, @@ -4873,7 +4873,7 @@ def add_unplanned_output(request, process_id): created_by=request.user, ) resource.save() - + event.resource = resource pattern = process.process_pattern event_type = pattern.event_type_for_resource_type("out", rt) @@ -4887,7 +4887,7 @@ def add_unplanned_output(request, process_id): event.created_by = request.user event.save() process.set_started(event.event_date, request.user) - + role_formset = resource_role_agent_formset(prefix="resource", data=request.POST) for form_rra in role_formset.forms: if form_rra.is_valid(): @@ -4902,14 +4902,14 @@ def add_unplanned_output(request, process_id): rra.resource = resource rra.is_contact = data_rra["is_contact"] rra.save() - + return HttpResponseRedirect('/%s/%s/' % ('accounting/process', process.id)) @login_required def add_unordered_receipt(request, exchange_id): - exchange = get_object_or_404(Exchange, pk=exchange_id) + exchange = get_object_or_404(Exchange, pk=exchange_id) if request.method == "POST": #import pdb; pdb.set_trace() pattern=exchange.process_pattern @@ -4917,7 +4917,7 @@ def add_unordered_receipt(request, exchange_id): form = UnorderedReceiptForm(data=request.POST, pattern=pattern, context_agent=context_agent, prefix='unorderedreceipt') if form.is_valid(): output_data = form.cleaned_data - value = output_data["value"] + value = output_data["value"] if value: event = form.save(commit=False) rt = output_data["resource_type"] @@ -4966,18 +4966,18 @@ def add_unordered_receipt(request, exchange_id): event.to_agent = event.default_agent() event.created_by = request.user event.save() - + return HttpResponseRedirect('/%s/%s/' % ('accounting/exchange', exchange.id)) def add_receipt_to_resource(request, exchange_id): - exchange = get_object_or_404(Exchange, pk=exchange_id) + exchange = get_object_or_404(Exchange, pk=exchange_id) if request.method == "POST": #import pdb; pdb.set_trace() pattern = exchange.process_pattern form = SelectResourceOfTypeForm( - prefix='addtoresource', - pattern=pattern, + prefix='addtoresource', + pattern=pattern, posting=True, data=request.POST) if form.is_valid(): @@ -4987,7 +4987,7 @@ def add_receipt_to_resource(request, exchange_id): quantity = output_data["quantity"] resource.quantity += quantity resource.save() - value = output_data["value"] + value = output_data["value"] unit_of_value = output_data["unit_of_value"] description = output_data["description"] context_agent = exchange.context_agent @@ -5011,18 +5011,18 @@ def add_receipt_to_resource(request, exchange_id): changed_by = request.user, ) event.save() - + return HttpResponseRedirect('/%s/%s/' % ('accounting/exchange', exchange.id)) - + def add_contribution_to_resource(request, exchange_id): - exchange = get_object_or_404(Exchange, pk=exchange_id) + exchange = get_object_or_404(Exchange, pk=exchange_id) if request.method == "POST": #import pdb; pdb.set_trace() pattern = exchange.process_pattern form = SelectContrResourceOfTypeForm( - prefix='addtoresource', - pattern=pattern, + prefix='addtoresource', + pattern=pattern, posting=True, data=request.POST) if form.is_valid(): @@ -5032,7 +5032,7 @@ def add_contribution_to_resource(request, exchange_id): quantity = output_data["quantity"] resource.quantity += quantity resource.save() - value = output_data["value"] + value = output_data["value"] unit_of_value = output_data["unit_of_value"] from_agent = output_data["from_agent"] description = output_data["description"] @@ -5057,14 +5057,14 @@ def add_contribution_to_resource(request, exchange_id): changed_by = request.user, ) event.save() - + return HttpResponseRedirect('/%s/%s/' % ('accounting/exchange', exchange.id)) @login_required def add_expense(request, exchange_id): - exchange = get_object_or_404(Exchange, pk=exchange_id) + exchange = get_object_or_404(Exchange, pk=exchange_id) if request.method == "POST": #import pdb; pdb.set_trace() pattern = exchange.process_pattern @@ -5072,7 +5072,7 @@ def add_expense(request, exchange_id): form = ExpenseEventForm(data=request.POST, pattern=pattern, context_agent=context_agent, prefix='expense') if form.is_valid(): expense_data = form.cleaned_data - value = expense_data["value"] + value = expense_data["value"] if value: event = form.save(commit=False) rt = expense_data["resource_type"] @@ -5085,13 +5085,13 @@ def add_expense(request, exchange_id): event.unit_of_quantity = rt.unit event.created_by = request.user event.save() - + return HttpResponseRedirect('/%s/%s/' % ('accounting/exchange', exchange.id)) @login_required def add_process_expense(request, process_id): - process = get_object_or_404(Process, pk=process_id) + process = get_object_or_404(Process, pk=process_id) if request.method == "POST": #import pdb; pdb.set_trace() pattern = process.process_pattern @@ -5099,7 +5099,7 @@ def add_process_expense(request, process_id): form = ProcessExpenseEventForm(data=request.POST, pattern=pattern, prefix='processexpense') if form.is_valid(): expense_data = form.cleaned_data - value = expense_data["value"] + value = expense_data["value"] if value: event = form.save(commit=False) rt = expense_data["resource_type"] @@ -5113,13 +5113,13 @@ def add_process_expense(request, process_id): event.created_by = request.user event.save() process.set_started(event.event_date, request.user) - + return HttpResponseRedirect('/%s/%s/' % ('accounting/process', process.id)) @login_required def add_material_contribution(request, exchange_id): - exchange = get_object_or_404(Exchange, pk=exchange_id) + exchange = get_object_or_404(Exchange, pk=exchange_id) if request.method == "POST": #import pdb; pdb.set_trace() pattern = exchange.process_pattern @@ -5127,7 +5127,7 @@ def add_material_contribution(request, exchange_id): form = MaterialContributionEventForm(data=request.POST, pattern=pattern, context_agent=context_agent, prefix='material') if form.is_valid(): material_data = form.cleaned_data - qty = material_data["quantity"] + qty = material_data["quantity"] if qty: event = form.save(commit=False) rt = material_data["resource_type"] @@ -5177,13 +5177,13 @@ def add_material_contribution(request, exchange_id): event.created_by = request.user event.save() - + return HttpResponseRedirect('/%s/%s/' % ('accounting/exchange', exchange.id)) @login_required def add_cash_contribution(request, exchange_id): - exchange = get_object_or_404(Exchange, pk=exchange_id) + exchange = get_object_or_404(Exchange, pk=exchange_id) if request.method == "POST": #import pdb; pdb.set_trace() pattern = exchange.process_pattern @@ -5191,7 +5191,7 @@ def add_cash_contribution(request, exchange_id): form = CashContributionEventForm(data=request.POST, pattern=pattern, context_agent=context_agent, posting=True, prefix='cash') if form.is_valid(): cash_data = form.cleaned_data - value = cash_data["value"] + value = cash_data["value"] if value: event = form.save(commit=False) rt = cash_data["resource_type"] @@ -5231,7 +5231,7 @@ def add_cash_contribution(request, exchange_id): unit_of_quantity = rt.unit, value = value, unit_of_value = rt.unit, - created_by = request.user, + created_by = request.user, ) from_event.save() return HttpResponseRedirect('/%s/%s/' @@ -5239,7 +5239,7 @@ def add_cash_contribution(request, exchange_id): @login_required def add_cash_resource_contribution(request, exchange_id): - exchange = get_object_or_404(Exchange, pk=exchange_id) + exchange = get_object_or_404(Exchange, pk=exchange_id) if request.method == "POST": #import pdb; pdb.set_trace() pattern = exchange.process_pattern @@ -5247,7 +5247,7 @@ def add_cash_resource_contribution(request, exchange_id): form = CashContributionResourceEventForm(data=request.POST, pattern=pattern, context_agent=context_agent, prefix='cashres') if form.is_valid(): cash_data = form.cleaned_data - value = cash_data["value"] + value = cash_data["value"] if value: event = form.save(commit=False) rt = cash_data["resource_type"] @@ -5277,7 +5277,7 @@ def add_cash_resource_contribution(request, exchange_id): @login_required def add_unplanned_payment(request, exchange_id): - exchange = get_object_or_404(Exchange, pk=exchange_id) + exchange = get_object_or_404(Exchange, pk=exchange_id) if request.method == "POST": #import pdb; pdb.set_trace() pattern = exchange.process_pattern @@ -5285,7 +5285,7 @@ def add_unplanned_payment(request, exchange_id): form = PaymentEventForm(data=request.POST, pattern=pattern, context_agent=context_agent, posting=True, prefix='pay') if form.is_valid(): payment_data = form.cleaned_data - qty = payment_data["quantity"] + qty = payment_data["quantity"] if qty: event = form.save(commit=False) rt = payment_data["resource_type"] @@ -5306,7 +5306,7 @@ def add_unplanned_payment(request, exchange_id): @login_required def add_cash_receipt(request, exchange_id): - exchange = get_object_or_404(Exchange, pk=exchange_id) + exchange = get_object_or_404(Exchange, pk=exchange_id) if request.method == "POST": #import pdb; pdb.set_trace() pattern = exchange.process_pattern @@ -5314,7 +5314,7 @@ def add_cash_receipt(request, exchange_id): form = CashReceiptForm(data=request.POST, pattern=pattern, context_agent=context_agent, posting=True, prefix='cr') if form.is_valid(): payment_data = form.cleaned_data - qty = payment_data["quantity"] + qty = payment_data["quantity"] if qty: event = form.save(commit=False) rt = payment_data["resource_type"] @@ -5330,13 +5330,13 @@ def add_cash_receipt(request, exchange_id): if resource: resource.quantity = resource.quantity + qty resource.save() - + return HttpResponseRedirect('/%s/%s/' % ('accounting/exchange', exchange.id)) @login_required def add_cash_receipt_resource(request, exchange_id): - exchange = get_object_or_404(Exchange, pk=exchange_id) + exchange = get_object_or_404(Exchange, pk=exchange_id) if request.method == "POST": #import pdb; pdb.set_trace() pattern = exchange.process_pattern @@ -5344,7 +5344,7 @@ def add_cash_receipt_resource(request, exchange_id): form = CashReceiptResourceForm(data=request.POST, pattern=pattern, context_agent=context_agent, prefix='crr') if form.is_valid(): payment_data = form.cleaned_data - qty = payment_data["quantity"] + qty = payment_data["quantity"] if qty: event = form.save(commit=False) rt = payment_data["resource_type"] @@ -5367,13 +5367,13 @@ def add_cash_receipt_resource(request, exchange_id): resource.save() event.resource = resource event.save() - + return HttpResponseRedirect('/%s/%s/' % ('accounting/exchange', exchange.id)) @login_required def add_shipment(request, exchange_id): - exchange = get_object_or_404(Exchange, pk=exchange_id) + exchange = get_object_or_404(Exchange, pk=exchange_id) if request.method == "POST": #import pdb; pdb.set_trace() pattern = exchange.process_pattern @@ -5381,7 +5381,7 @@ def add_shipment(request, exchange_id): form = ShipmentForm(data=request.POST, pattern=pattern, context_agent=context_agent, prefix='ship') if form.is_valid(): data = form.cleaned_data - qty = data["quantity"] + qty = data["quantity"] if qty: event = form.save(commit=False) resource = data["resource"] @@ -5400,13 +5400,13 @@ def add_shipment(request, exchange_id): if resource.quantity < 0: resource.quantity = 0 resource.save() - + return HttpResponseRedirect('/%s/%s/' % ('accounting/exchange', exchange.id)) @login_required def add_uninventoried_shipment(request, exchange_id): - exchange = get_object_or_404(Exchange, pk=exchange_id) + exchange = get_object_or_404(Exchange, pk=exchange_id) if request.method == "POST": #import pdb; pdb.set_trace() pattern = exchange.process_pattern @@ -5414,7 +5414,7 @@ def add_uninventoried_shipment(request, exchange_id): form = UninventoriedShipmentForm(data=request.POST, pattern=pattern, context_agent=context_agent, prefix='shipun') if form.is_valid(): data = form.cleaned_data - qty = data["quantity"] + qty = data["quantity"] if qty: event = form.save(commit=False) rt = data["resource_type"] @@ -5429,8 +5429,8 @@ def add_uninventoried_shipment(request, exchange_id): event.created_by = request.user event.save() return HttpResponseRedirect('/%s/%s/' - % ('accounting/exchange', exchange.id)) - + % ('accounting/exchange', exchange.id)) + @login_required def create_production_process(request, commitment_id): """ this creates a production process for a shipment commitment @@ -5458,10 +5458,10 @@ def create_production_process(request, commitment_id): state=None, from_agent=process.context_agent, to_agent=commitment.context_agent) - + return HttpResponseRedirect('/%s/%s/' % ('accounting/order-schedule', commitment.order.id)) - + @login_required def log_shipment(request, commitment_id, resource_id): ct = get_object_or_404(Commitment, pk=commitment_id) @@ -5490,7 +5490,7 @@ def log_shipment(request, commitment_id, resource_id): resource.save() return HttpResponseRedirect('/%s/%s/' % ('accounting/exchange', ct.exchange.id)) - + @login_required def log_uninventoried_shipment(request, commitment_id): ct = get_object_or_404(Commitment, pk=commitment_id) @@ -5513,7 +5513,7 @@ def log_uninventoried_shipment(request, commitment_id): event.save() return HttpResponseRedirect('/%s/%s/' % ('accounting/exchange', ct.exchange.id)) - + def delete_shipment_event(request, event_id): if request.method == "POST": event = get_object_or_404(EconomicEvent, pk=event_id) @@ -5528,7 +5528,7 @@ def delete_shipment_event(request, event_id): @login_required def add_distribution(request, distribution_id): - distribution = get_object_or_404(Distribution, pk=distribution_id) + distribution = get_object_or_404(Distribution, pk=distribution_id) if request.method == "POST": #import pdb; pdb.set_trace() pattern = distribution.process_pattern @@ -5536,7 +5536,7 @@ def add_distribution(request, distribution_id): form = DistributionEventForm(data=request.POST, pattern=pattern, posting=True, prefix='dist') if form.is_valid(): data = form.cleaned_data - qty = data["quantity"] + qty = data["quantity"] if qty: event = form.save(commit=False) rt = data["resource_type"] @@ -5554,13 +5554,13 @@ def add_distribution(request, distribution_id): if resource: resource.quantity = resource.quantity + qty resource.save() - + return HttpResponseRedirect('/%s/%s/' % ('accounting/distribution', distribution.id)) @login_required def add_disbursement(request, distribution_id): - distribution = get_object_or_404(Distribution, pk=distribution_id) + distribution = get_object_or_404(Distribution, pk=distribution_id) if request.method == "POST": #import pdb; pdb.set_trace() pattern = distribution.process_pattern @@ -5568,7 +5568,7 @@ def add_disbursement(request, distribution_id): form = DisbursementEventForm(data=request.POST, pattern=pattern, posting=True, prefix='disb') if form.is_valid(): data = form.cleaned_data - qty = data["quantity"] + qty = data["quantity"] if qty: event = form.save(commit=False) rt = data["resource_type"] @@ -5590,7 +5590,7 @@ def add_disbursement(request, distribution_id): if resource: resource.quantity = resource.quantity - qty resource.save() - + return HttpResponseRedirect('/%s/%s/' % ('accounting/distribution', distribution.id)) @@ -5604,8 +5604,8 @@ def add_transfer(request, exchange_id, transfer_type_id): context_agent = exchange.context_agent form = TransferForm(data=request.POST, transfer_type=transfer_type, context_agent=context_agent, posting=True, prefix="ATR" + str(transfer_type.id)) if form.is_valid(): - data = form.cleaned_data - qty = data["quantity"] + data = form.cleaned_data + qty = data["quantity"] res = None res_from = None et2 = None @@ -5622,7 +5622,7 @@ def add_transfer(request, exchange_id, transfer_type_id): if transfer_type.receive_agent_is_context: to_agent = context_agent else: - to_agent = data["to_agent"] + to_agent = data["to_agent"] rt = data["resource_type"] #if not transfer_type.can_create_resource: res = data["resource"] @@ -5728,7 +5728,7 @@ def add_transfer(request, exchange_id, transfer_type_id): context_agent = context_agent, transfer_date = event_date, notes = description, - created_by = request.user + created_by = request.user ) xfer.save() #import pdb; pdb.set_trace() @@ -5791,9 +5791,9 @@ def add_transfer(request, exchange_id, transfer_type_id): is_to_distribute = e2_is_to_distribute, event_reference=event_ref, created_by = request.user, - ) + ) event2.save() - + return HttpResponseRedirect('/%s/%s/%s/' % ('accounting/exchange', 0, exchange.id)) @@ -5819,7 +5819,7 @@ def transfer_from_commitment(request, transfer_id): if transfer_type.receive_agent_is_context: to_agent = context_agent else: - to_agent = data["to_agent"] + to_agent = data["to_agent"] rt = data["resource_type"] #if not transfer_type.can_create_resource: res = data["resource"] @@ -5872,7 +5872,7 @@ def transfer_from_commitment(request, transfer_id): rra.role = role rra.resource = res rra.is_contact = data_rra["is_contact"] - rra.save() + rra.save() for commit in transfer.commitments.all(): if commit.event_type == et_give and res_from: event_res = res_from @@ -5898,7 +5898,7 @@ def transfer_from_commitment(request, transfer_id): created_by = request.user, ) event.save() - if event_res: + if event_res: if event.event_type == et_give: event_res.quantity -= event.quantity else: @@ -5906,9 +5906,9 @@ def transfer_from_commitment(request, transfer_id): event_res.save() commit.finished = True commit.save() - + return HttpResponseRedirect('/%s/%s/%s/' - % ('accounting/exchange', 0, exchange.id)) + % ('accounting/exchange', 0, exchange.id)) @login_required def add_transfer_commitment(request, exchange_id, transfer_type_id): @@ -5921,7 +5921,7 @@ def add_transfer_commitment(request, exchange_id, transfer_type_id): form = TransferCommitmentForm(data=request.POST, transfer_type=transfer_type, context_agent=context_agent, posting=True, prefix="ACM" + str(transfer_type.id)) if form.is_valid(): data = form.cleaned_data - qty = data["quantity"] + qty = data["quantity"] et2 = None if qty: commitment_date = data["commitment_date"] @@ -5933,7 +5933,7 @@ def add_transfer_commitment(request, exchange_id, transfer_type_id): if transfer_type.receive_agent_is_context: to_agent = context_agent else: - to_agent = data["to_agent"] + to_agent = data["to_agent"] rt = data["resource_type"] description = data["description"] if transfer_type.is_currency: @@ -5957,10 +5957,10 @@ def add_transfer_commitment(request, exchange_id, transfer_type_id): exchange = exchange, context_agent = context_agent, transfer_date = commitment_date, - created_by = request.user + created_by = request.user ) xfer.save() - + if exchange.exchange_type.use_case == UseCase.objects.get(identifier="supply_xfer"): if transfer_type.is_reciprocal: et = EventType.objects.get(name="Give") @@ -6014,9 +6014,9 @@ def add_transfer_commitment(request, exchange_id, transfer_type_id): from_agent = from_agent, to_agent = to_agent, created_by = request.user, - ) + ) commit2.save() - + return HttpResponseRedirect('/%s/%s/%s/' % ('accounting/exchange', 0, exchange.id)) @@ -6044,7 +6044,7 @@ def change_transfer_events(request, transfer_id): if transfer_type.receive_agent_is_context: to_agent = context_agent else: - to_agent = data["to_agent"] + to_agent = data["to_agent"] rt = data["resource_type"] res = data["resource"] res_from = None @@ -6128,9 +6128,9 @@ def change_transfer_events(request, transfer_id): transfer.transfer_date = event_date transfer.save() - + return HttpResponseRedirect('/%s/%s/%s/' - % ('accounting/exchange', 0, exchange.id)) + % ('accounting/exchange', 0, exchange.id)) @login_required def change_transfer_commitments(request, transfer_id): @@ -6157,7 +6157,7 @@ def change_transfer_commitments(request, transfer_id): if transfer_type.receive_agent_is_context: to_agent = context_agent else: - to_agent = data["to_agent"] + to_agent = data["to_agent"] rt = data["resource_type"] description = data["description"] if transfer_type.is_currency: @@ -6183,9 +6183,9 @@ def change_transfer_commitments(request, transfer_id): commit.description=description commit.changed_by = request.user commit.save() - + return HttpResponseRedirect('/%s/%s/%s/' - % ('accounting/exchange', 0, exchange.id)) + % ('accounting/exchange', 0, exchange.id)) @login_required def delete_transfer_commitments(request, transfer_id): @@ -6198,7 +6198,7 @@ def delete_transfer_commitments(request, transfer_id): if transfer.is_deletable(): transfer.delete() return HttpResponseRedirect('/%s/%s/%s/' - % ('accounting/exchange', 0, exchange.id)) + % ('accounting/exchange', 0, exchange.id)) @login_required def delete_transfer_events(request, transfer_id): @@ -6235,7 +6235,7 @@ def delete_transfer_events(request, transfer_id): if transfer.is_deletable(): transfer.delete() return HttpResponseRedirect('/%s/%s/%s/' - % ('accounting/exchange', 0, exchange.id)) + % ('accounting/exchange', 0, exchange.id)) @login_required @@ -6275,7 +6275,7 @@ def add_process_input(request, process_id, slot): ct.context_agent = ptrt.process_type.context_agent ct.save() #todo: this is used in process logging; shd it explode? - #explode_dependent_demands(ct, request.user) + #explode_dependent_demands(ct, request.user) return HttpResponseRedirect('/%s/%s/' % ('accounting/process', process.id)) @@ -6312,7 +6312,7 @@ def add_process_citation(request, process_id): created_by=request.user, ) ct.save() - + return HttpResponseRedirect('/%s/%s/' % ('accounting/process', process.id)) @@ -6347,8 +6347,8 @@ def add_process_worker(request, process_id): site_name = get_site_name() if users: notification.send( - users, - "valnet_help_wanted", + users, + "valnet_help_wanted", {"resource_type": ct.resource_type, "due_date": ct.due_date, "hours": ct.quantity, @@ -6359,10 +6359,10 @@ def add_process_worker(request, process_id): "site_name": site_name, } ) - + return HttpResponseRedirect('/%s/%s/' % ('accounting/process', process.id)) - + @login_required def invite_collaborator(request, commitment_id): commitment = get_object_or_404(Commitment, pk=commitment_id) @@ -6396,8 +6396,8 @@ def invite_collaborator(request, commitment_id): site_name = get_site_name() if users: notification.send( - users, - "valnet_help_wanted", + users, + "valnet_help_wanted", {"resource_type": commitment.resource_type, "due_date": commitment.due_date, "hours": commitment.quantity, @@ -6408,7 +6408,7 @@ def invite_collaborator(request, commitment_id): "site_name": site_name, } ) - + return HttpResponseRedirect('/%s/%s/' % ('accounting/process', process.id)) @@ -6492,9 +6492,9 @@ def change_event(request, event_id): return render_to_response("valueaccounting/change_event.html", { "event_form": event_form, "page": page, - }, context_instance=RequestContext(request)) + }, context_instance=RequestContext(request)) -@login_required +@login_required def delete_event(request, event_id): #import pdb; pdb.set_trace() if request.method == "POST": @@ -6528,7 +6528,7 @@ def delete_event(request, event_id): resource.save() else: event.delete() - + next = request.POST.get("next") if next == "process": return HttpResponseRedirect('/%s/%s/' @@ -6548,7 +6548,7 @@ def delete_event(request, event_id): % ('accounting/resource', resource_id)) elif next == "contributions": page = request.POST.get("page") - + if page: return HttpResponseRedirect('/%s/%s/?page=%s' % ('accounting/contributionhistory', agent.id, page)) @@ -6556,7 +6556,7 @@ def delete_event(request, event_id): return HttpResponseRedirect('/%s/%s/' % ('accounting/contributionhistory', agent.id)) -@login_required +@login_required def delete_citation_event(request, commitment_id, resource_id): #import pdb; pdb.set_trace() if request.method == "POST": @@ -6564,8 +6564,8 @@ def delete_citation_event(request, commitment_id, resource_id): resource = get_object_or_404(EconomicResource, pk=resource_id) process = ct.process events = ct.fulfillment_events.filter(resource=resource) - for event in events: - event.delete() + for event in events: + event.delete() next = request.POST.get("next") if next == "process": return HttpResponseRedirect('/%s/%s/' @@ -6576,13 +6576,13 @@ def delete_citation_event(request, commitment_id, resource_id): % ('accounting/resource', resource_id)) -@login_required -def delete_exchange(request, exchange_id): +@login_required +def delete_exchange(request, exchange_id): #import pdb; pdb.set_trace() if request.method == "POST": exchange = get_object_or_404(Exchange, pk=exchange_id) if exchange.is_deletable: - exchange.delete() + exchange.delete() next = request.POST.get("next") if next == "exchanges": return HttpResponseRedirect('/%s/' @@ -6614,7 +6614,7 @@ def work_done(request): commitment.save() return HttpResponse("Ok", mimetype="text/plain") - + @login_required def commitment_finished(request, commitment_id): #import pdb; pdb.set_trace() @@ -6695,18 +6695,18 @@ def delete_process(request, process_id): % ('accounting/cleanup-old-processes')) return HttpResponseRedirect('/%s/' % ('accounting/cleanup-processes')) - + @login_required def labnotes_reload( - request, - commitment_id, + request, + commitment_id, was_running=0, was_retrying=0): ct = get_object_or_404(Commitment, id=commitment_id) #import pdb; pdb.set_trace() template_params = create_labnotes_context( - request, - ct, + request, + ct, was_running, was_retrying, ) @@ -6716,7 +6716,7 @@ def labnotes_reload( @login_required def work_commitment( - request, + request, commitment_id): ct = get_object_or_404(Commitment, id=commitment_id) #import pdb; pdb.set_trace() @@ -6725,8 +6725,8 @@ def work_commitment( if agent != ct.from_agent: return render_to_response('valueaccounting/no_permission.html') template_params = create_labnotes_context( - request, - ct, + request, + ct, ) event = template_params["event"] if request.method == "POST": @@ -6757,7 +6757,7 @@ def work_commitment( event.unit_of_quantity = ct.unit_of_quantity event.created_by = request.user event.changed_by = request.user - + event.save() description = data["description"] if description != ct.description: @@ -6770,7 +6770,7 @@ def work_commitment( context_instance=RequestContext(request)) def create_worknow_context( - request, + request, process, agent, commitment): @@ -6787,7 +6787,7 @@ def create_worknow_context( is_contribution=True, created_by = request.user, ) - + if commitment: event.commitment = commitment event.event_type = commitment.event_type @@ -6837,26 +6837,26 @@ def work_now( process_id, commitment_id=None): process = get_object_or_404(Process, id=process_id) - agent = get_agent(request) - ct = None + agent = get_agent(request) + ct = None if commitment_id: - ct = get_object_or_404(Commitment, id=commitment_id) + ct = get_object_or_404(Commitment, id=commitment_id) #if not request.user.is_superuser: # if agent != ct.from_agent: # return render_to_response('valueaccounting/no_permission.html') template_params = create_worknow_context( - request, + request, process, agent, - ct, + ct, ) return render_to_response("valueaccounting/work_now.html", template_params, context_instance=RequestContext(request)) def create_past_work_context( - request, - commitment, + request, + commitment, was_running=0, was_retrying=0, event=None): @@ -6871,7 +6871,7 @@ def create_past_work_context( "process_done": commitment.process.finished, } wb_form = PastWorkForm(instance=event, initial=init) - duration = event.quantity * 60 + duration = event.quantity * 60 event_date=event.event_date else: init = { @@ -6951,8 +6951,8 @@ def create_past_work_context( @login_required def pastwork_reload( - request, - commitment_id, + request, + commitment_id, event_id, was_running=0, was_retrying=0, @@ -6967,8 +6967,8 @@ def pastwork_reload( if event_id: event = get_object_or_404(EconomicEvent, id=event_id) template_params = create_past_work_context( - request, - ct, + request, + ct, was_running, was_retrying, event, @@ -6983,7 +6983,7 @@ def pastwork_reload( #obsolete? @login_required def log_past_work( - request, + request, commitment_id): ct = get_object_or_404(Commitment, id=commitment_id) #import pdb; pdb.set_trace() @@ -6992,7 +6992,7 @@ def log_past_work( if agent != ct.from_agent: return render_to_response('valueaccounting/no_permission.html') template_params = create_past_work_context( - request, + request, ct, ) event = template_params["event"] @@ -7007,7 +7007,7 @@ def log_past_work( def save_work_now(request, event_id): #import pdb; pdb.set_trace() if request.method == "POST": - event = get_object_or_404(EconomicEvent, id=event_id) + event = get_object_or_404(EconomicEvent, id=event_id) form = WorkbookForm(instance=event, data=request.POST) if form.is_valid(): data = form.cleaned_data @@ -7018,7 +7018,7 @@ def save_work_now(request, event_id): if not process.started: process.started = event.event_date process.changed_by=request.user - process.save() + process.save() data = "ok" else: data = form.errors @@ -7146,7 +7146,7 @@ def process_details(request, process_id): "help": get_help("process"), }, context_instance=RequestContext(request)) -def process_oriented_logging(request, process_id): +def process_oriented_logging(request, process_id): process = get_object_or_404(Process, id=process_id) pattern = process.process_pattern context_agent = process.context_agent @@ -7175,12 +7175,12 @@ def process_oriented_logging(request, process_id): work_now = settings.USE_WORK_NOW to_be_changed_requirement = None changeable_requirement = None - + work_reqs = process.work_requirements() consume_reqs = process.consumed_input_requirements() use_reqs = process.used_input_requirements() unplanned_work = process.uncommitted_work_events() - + if agent and pattern: slots = pattern.slots() event_types = pattern.event_types() @@ -7193,8 +7193,8 @@ def process_oriented_logging(request, process_id): req.changeform = req.change_work_form() if agent == req.from_agent: logger = True - worker = True - init = {"from_agent": agent, + worker = True + init = {"from_agent": agent, "event_date": todays_date, "is_contribution": True,} req.input_work_form_init = req.input_event_form_init(init=init) @@ -7206,9 +7206,9 @@ def process_oriented_logging(request, process_id): event.changeform = UnplannedWorkEventForm( pattern=pattern, context_agent=context_agent, - instance=event, + instance=event, prefix=str(event.id)) - output_resource_types = pattern.output_resource_types() + output_resource_types = pattern.output_resource_types() unplanned_output_form = UnplannedOutputForm(prefix='unplannedoutput') unplanned_output_form.fields["resource_type"].queryset = output_resource_types role_formset = resource_role_agent_formset(prefix="resource") @@ -7232,7 +7232,7 @@ def process_oriented_logging(request, process_id): work_init = { "from_agent": agent, "is_contribution": True, - } + } work_resource_types = pattern.work_resource_types() if work_resource_types: work_unit = work_resource_types[0].unit @@ -7241,7 +7241,7 @@ def process_oriented_logging(request, process_id): "from_agent": agent, "unit_of_quantity": work_unit, "is_contribution": True, - } + } unplanned_work_form = UnplannedWorkEventForm(prefix="unplanned", context_agent=context_agent, initial=work_init) unplanned_work_form.fields["resource_type"].queryset = work_resource_types #if logger: @@ -7258,7 +7258,7 @@ def process_oriented_logging(request, process_id): if context_agent.unit_of_claim_value: cite_unit = context_agent.unit_of_claim_value if logger: - add_citation_form = ProcessCitationForm(prefix='citation', pattern=pattern) + add_citation_form = ProcessCitationForm(prefix='citation', pattern=pattern) if "consume" in slots: unplanned_consumption_form = UnplannedInputEventForm(prefix='unplannedconsumption', pattern=pattern) if logger: @@ -7269,7 +7269,7 @@ def process_oriented_logging(request, process_id): add_usable_form = ProcessUsableForm(prefix='usable', pattern=pattern) if "payexpense" in slots: process_expense_form = ProcessExpenseEventForm(prefix='processexpense', pattern=pattern) - + cited_ids = [c.resource.id for c in process.citations()] #import pdb; pdb.set_trace() citation_requirements = process.citation_requirements() @@ -7279,9 +7279,9 @@ def process_oriented_logging(request, process_id): resource = evt.resource resource.event = evt cr.resources.append(resource) - + output_resource_ids = [e.resource.id for e in process.production_events() if e.resource] - + return render_to_response("valueaccounting/process_oriented_logging.html", { "process": process, "change_process_form": change_process_form, @@ -7308,7 +7308,7 @@ def process_oriented_logging(request, process_id): "slots": slots, "to_be_changed_requirement": to_be_changed_requirement, "changeable_requirement": changeable_requirement, - "work_reqs": work_reqs, + "work_reqs": work_reqs, "consume_reqs": consume_reqs, "uncommitted_consumption": process.uncommitted_consumption_events(), "use_reqs": use_reqs, @@ -7324,10 +7324,10 @@ def add_unplanned_cite_event(request, process_id): process = get_object_or_404(Process, pk=process_id) pattern = process.process_pattern #import pdb; pdb.set_trace() - if pattern: + if pattern: form = UnplannedCiteEventForm( - prefix='unplannedcite', - data=request.POST, + prefix='unplannedcite', + data=request.POST, pattern=pattern, load_resources=True) if form.is_valid(): @@ -7361,10 +7361,10 @@ def add_unplanned_cite_event(request, process_id): ) event.save() process.set_started(event.event_date, request.user) - + return HttpResponseRedirect('/%s/%s/' % ('accounting/process', process.id)) - + @login_required def log_stage_change_event(request, commitment_id, resource_id): if request.method == "POST": @@ -7424,7 +7424,7 @@ def log_stage_change_event(request, commitment_id, resource_id): resource.quantity = quantity resource.save() process.set_started(event.event_date, request.user) - + return HttpResponseRedirect('/%s/%s/' % ('accounting/process', process.id)) @@ -7435,14 +7435,14 @@ def add_unplanned_input_event(request, process_id, slot): #import pdb; pdb.set_trace() if pattern: if slot == "c": - prefix = "unplannedconsumption" - et = "consume" + prefix = "unplannedconsumption" + et = "consume" else: - prefix = "unplannedusable" - et = "use" + prefix = "unplannedusable" + et = "use" form = UnplannedInputEventForm( - prefix=prefix, - data=request.POST, + prefix=prefix, + data=request.POST, pattern=pattern, load_resources=True) if form.is_valid(): @@ -7475,16 +7475,16 @@ def add_unplanned_input_event(request, process_id, slot): changed_by = request.user, ) event.save() - if event_type.consumes_resources(): + if event_type.consumes_resources(): resource.quantity -= event.quantity resource.changed_by=request.user resource.save() process.set_started(event.event_date, request.user) - + return HttpResponseRedirect('/%s/%s/' % ('accounting/process', process.id)) -@login_required +@login_required def log_resource_for_commitment(request, commitment_id): ct = get_object_or_404(Commitment, pk=commitment_id) #prefix = ct.form_prefix() @@ -7533,11 +7533,11 @@ def log_resource_for_commitment(request, commitment_id): ) event.save() ct.process.set_started(event.event_date, request.user) - + return HttpResponseRedirect('/%s/%s/' % ('accounting/process', ct.process.id)) - -@login_required + +@login_required def add_to_resource_for_commitment(request, commitment_id): ct = get_object_or_404(Commitment, pk=commitment_id) form = ct.select_resource_form(data=request.POST) @@ -7570,10 +7570,10 @@ def add_to_resource_for_commitment(request, commitment_id): ) event.save() ct.process.set_started(event.event_date, request.user) - + return HttpResponseRedirect('/%s/%s/' % ('accounting/process', ct.process.id)) - + ''' @login_required #todo: make this work for payments when we add payment commitments, check form etc. @@ -7627,7 +7627,7 @@ def add_work_event(request, commitment_id): event.changed_by = request.user event.save() ct.process.set_started(event.event_date, request.user) - + return HttpResponseRedirect('/%s/%s/' % ('accounting/process', ct.process.id)) @@ -7654,7 +7654,7 @@ def add_unplanned_work_event(request, process_id): event.changed_by = request.user event.save() process.set_started(event.event_date, request.user) - + return HttpResponseRedirect('/%s/%s/' % ('accounting/process', process.id)) @@ -7705,10 +7705,10 @@ def add_use_event(request, commitment_id, resource_id): event.changed_by = request.user event.save() ct.process.set_started(event.event_date, request.user) - + return HttpResponseRedirect('/%s/%s/' % ('accounting/process', ct.process.id)) - + @login_required def add_citation_event(request, commitment_id, resource_id): #import pdb; pdb.set_trace() @@ -7737,7 +7737,7 @@ def add_citation_event(request, commitment_id, resource_id): event.changed_by = request.user event.save() ct.process.set_started(event.event_date, request.user) - + return HttpResponseRedirect('/%s/%s/' % ('accounting/process', ct.process.id)) @@ -7764,12 +7764,12 @@ def add_consumption_event(request, commitment_id, resource_id): event.created_by = request.user event.changed_by = request.user event.save() - if ct.consumes_resources(): + if ct.consumes_resources(): resource.quantity -= event.quantity resource.changed_by=request.user resource.save() ct.process.set_started(event.event_date, request.user) - + return HttpResponseRedirect('/%s/%s/' % ('accounting/process', ct.process.id)) @@ -7800,11 +7800,11 @@ def log_citation(request, commitment_id, resource_id): ) event.save() ct.process.set_started(event.event_date, request.user) - + return HttpResponseRedirect('/%s/%s/' % ('accounting/process', ct.process.id)) - + def labnotes_history(request): agent = get_agent(request) procs = Process.objects.all().order_by("-start_date") @@ -7815,7 +7815,7 @@ def labnotes_history(request): if e.description: if p not in process_list: process_list.append(p) - + paginator = Paginator(process_list, 25) page = request.GET.get('page') try: @@ -7826,7 +7826,7 @@ def labnotes_history(request): except EmptyPage: # If page is out of range (e.g. 9999), deliver last page of results. processes = paginator.page(paginator.num_pages) - + return render_to_response("valueaccounting/labnotes_history.html", { "processes": processes, "photo_size": (128, 128), @@ -7836,7 +7836,7 @@ def labnotes_history(request): def todo_history(request): #import pdb; pdb.set_trace() todo_list = Commitment.objects.finished_todos().order_by('-due_date',) - + paginator = Paginator(todo_list, 25) page = request.GET.get('page') try: @@ -7847,7 +7847,7 @@ def todo_history(request): except EmptyPage: # If page is out of range (e.g. 9999), deliver last page of results. todos = paginator.page(paginator.num_pages) - + return render_to_response("valueaccounting/todo_history.html", { "todos": todos, }, context_instance=RequestContext(request)) @@ -7856,7 +7856,7 @@ def todo_history(request): def open_todos(request): #import pdb; pdb.set_trace() todo_list = Commitment.objects.todos().order_by('-due_date',) - + paginator = Paginator(todo_list, 25) page = request.GET.get('page') try: @@ -7867,7 +7867,7 @@ def open_todos(request): except EmptyPage: # If page is out of range (e.g. 9999), deliver last page of results. todos = paginator.page(paginator.num_pages) - + return render_to_response("valueaccounting/open_todos.html", { "todos": todos, }, context_instance=RequestContext(request)) @@ -7886,16 +7886,16 @@ def resource(request, resource_id): extra=4, ) role_formset = RraFormSet( - prefix="role", + prefix="role", queryset=resource.agent_resource_roles.all() ) process = None pattern = None - if resource.producing_events(): + if resource.producing_events(): process = resource.producing_events()[0].process pattern = None if process: - pattern = process.process_pattern + pattern = process.process_pattern else: if agent: form_data = {'name': 'Create ' + resource.identifier, 'start_date': resource.created_date, 'end_date': resource.created_date} @@ -7912,14 +7912,14 @@ def resource(request, resource_id): process.started = process.start_date process.finished = True process.created_by = request.user - process.save() + process.save() event = EconomicEvent() event.context_agent = process.context_agent event.event_date = process.end_date event.event_type = process.process_pattern.event_type_for_resource_type("out", resource.resource_type) event.process = process - event.resource_type = resource.resource_type - event.quantity = resource.quantity + event.resource_type = resource.resource_type + event.quantity = resource.quantity event.unit_of_quantity = resource.unit_of_quantity() event.resource = resource event.to_agent = event.context_agent @@ -7928,7 +7928,7 @@ def resource(request, resource_id): event.save() return HttpResponseRedirect('/%s/%s/' % ('accounting/resource', resource.id)) - + return render_to_response("valueaccounting/resource.html", { "resource": resource, "photo_size": (128, 128), @@ -7968,7 +7968,7 @@ def plan_work_order_for_resource(request, resource_id): if order: return HttpResponseRedirect('/%s/%s/' % ('accounting/order-schedule', order.id)) - + def incoming_value_flows(request, resource_id): resource = get_object_or_404(EconomicResource, id=resource_id) #flows = resource.incoming_value_flows() @@ -8035,7 +8035,7 @@ def change_resource(request, resource_id): extra=4, ) role_formset = RraFormSet( - prefix="role", + prefix="role", queryset=resource.agent_resource_roles.all(), data=request.POST ) @@ -8079,7 +8079,7 @@ def get_labnote_context(commitment, request_agent): "used": used, "citations": citations, } - + def labnotes(request, process_id): process = get_object_or_404(Process, id=process_id) agent = get_agent(request) @@ -8268,7 +8268,7 @@ def consumption_event_for_commitment(request): resource.changed_by=request.user resource.save() else: - if ct.consumes_resources(): + if ct.consumes_resources(): resource.quantity -= quantity resource.changed_by=request.user resource.save() @@ -8370,7 +8370,7 @@ def time_use_event_for_commitment(request): resource.changed_by=request.user resource.save() else: - if ct.consumes_resources(): + if ct.consumes_resources(): resource.quantity -= quantity resource.changed_by=request.user resource.save() @@ -8437,8 +8437,8 @@ def failed_outputs(request, commitment_id): notes = description, created_by=request.user, ) - resource.save() - event.resource = resource + resource.save() + event.resource = resource event.event_date = event_date event.event_type = event_type event.from_agent = agent @@ -8466,22 +8466,22 @@ def copy_process(request, process_id): "project": process.context_agent, "url": process.url, "notes": process.notes, - } + } process_form = ProcessForm(initial=process_init, data=request.POST or None) output_init = [] for op in process.outgoing_commitments(): output_init.append({ - 'resource_type': op.resource_type, - 'quantity': op.quantity, - 'description': op.description, + 'resource_type': op.resource_type, + 'quantity': op.quantity, + 'description': op.description, 'unit_of_quantity': op.unit_of_quantity, }) input_init = [] for ip in process.incoming_commitments(): input_init.append({ - 'resource_type': ip.resource_type, - 'quantity': ip.quantity, - 'description': ip.description, + 'resource_type': ip.resource_type, + 'quantity': ip.quantity, + 'description': ip.description, 'unit_of_quantity': ip.unit_of_quantity, }) OutputFormSet = modelformset_factory( @@ -8524,7 +8524,7 @@ def copy_process(request, process_id): if qty: ct = form.save(commit=False) rt = output_data["resource_type"] - #rel = + #rel = ct.relationship = rel ct.event_type = rel.event_type ct.process = process @@ -8542,7 +8542,7 @@ def copy_process(request, process_id): if qty: ct = form.save(commit=False) rt = input_data["resource_type"] - #rel = + #rel = ct.relationship = rel ct.event_type = rel.event_type ct.process = process @@ -8602,8 +8602,8 @@ def change_unplanned_work_event(request, event_id): if request.method == "POST": form = UnplannedWorkEventForm( pattern=pattern, - instance=event, - prefix=str(event.id), + instance=event, + prefix=str(event.id), data=request.POST) if form.is_valid(): data = form.cleaned_data @@ -8620,7 +8620,7 @@ def change_exchange_work_event(request, event_id): if request.method == "POST": form = WorkEventAgentForm( context_agent=context_agent, - instance=event, + instance=event, data=request.POST, prefix=str(event.id)) if form.is_valid(): @@ -8643,7 +8643,7 @@ def change_unplanned_payment_event(request, event_id): pattern=pattern, instance=event, posting=True, - prefix=str(event.id), + prefix=str(event.id), data=request.POST) if form.is_valid(): form.save(commit=False) @@ -8681,8 +8681,8 @@ def change_receipt_event(request, event_id): if request.method == "POST": form = UnorderedReceiptForm( pattern=pattern, - instance=event, - prefix=str(event.id), + instance=event, + prefix=str(event.id), data=request.POST) if form.is_valid(): data = form.cleaned_data @@ -8704,7 +8704,7 @@ def change_cash_receipt_event(request, event_id): pattern=pattern, instance=event, posting=True, - prefix=str(event.id), + prefix=str(event.id), data=request.POST) if form.is_valid(): form.save(commit=False) @@ -8744,8 +8744,8 @@ def change_shipment_event(request, event_id): if request.method == "POST": form = ShipmentForm( pattern=pattern, - instance=event, - prefix=str(event.id), + instance=event, + prefix=str(event.id), data=request.POST) if form.is_valid(): data = form.cleaned_data @@ -8776,15 +8776,15 @@ def change_uninventoried_shipment_event(request, event_id): if request.method == "POST": form = UninventoriedShipmentForm( pattern=pattern, - instance=event, - prefix=str(event.id), + instance=event, + prefix=str(event.id), data=request.POST) if form.is_valid(): data = form.cleaned_data form.save() return HttpResponseRedirect('/%s/%s/' % ('accounting/exchange', exchange.id)) - + @login_required def change_distribution_event(request, event_id): #import pdb; pdb.set_trace() @@ -8796,9 +8796,9 @@ def change_distribution_event(request, event_id): if request.method == "POST": form = DistributionEventForm( pattern=pattern, - instance=event, + instance=event, posting=True, - prefix=event.form_prefix(), + prefix=event.form_prefix(), data=request.POST) if form.is_valid(): form.save(commit=False) @@ -8838,9 +8838,9 @@ def change_disbursement_event(request, event_id): if request.method == "POST": form = DisbursementEventForm( pattern=pattern, - instance=event, + instance=event, posting=True, - prefix=event.form_prefix(), + prefix=event.form_prefix(), data=request.POST) if form.is_valid(): form.save(commit=False) @@ -8879,8 +8879,8 @@ def change_expense_event(request, event_id): if request.method == "POST": form = ExpenseEventForm( pattern=pattern, - instance=event, - prefix=str(event.id), + instance=event, + prefix=str(event.id), data=request.POST) if form.is_valid(): data = form.cleaned_data @@ -8889,7 +8889,7 @@ def change_expense_event(request, event_id): % ('accounting/exchange', exchange.id)) def handle_commitment_changes(old_ct, new_rt, new_qty, old_demand, new_demand): - propagators = [] + propagators = [] explode = True if old_ct.event_type.relationship == "out": dependants = old_ct.process.incoming_commitments() @@ -8897,42 +8897,42 @@ def handle_commitment_changes(old_ct, new_rt, new_qty, old_demand, new_demand): if new_qty != old_ct.quantity: explode = False else: - dependants = old_ct.associated_producing_commitments() + dependants = old_ct.associated_producing_commitments() old_rt = old_ct.resource_type order_item = old_ct.order_item - + if not propagators: for dep in dependants: if order_item: if dep.order_item == order_item: - propagators.append(dep) + propagators.append(dep) explode = False else: if dep.due_date == old_ct.process.start_date: if dep.quantity == old_ct.quantity: propagators.append(dep) - explode = False + explode = False if new_rt != old_rt: for ex_ct in old_ct.associated_producing_commitments(): if ex_ct.order_item == order_item: ex_ct.delete_dependants() old_ct.delete() - explode = True + explode = True elif new_qty != old_ct.quantity: delta = new_qty - old_ct.quantity for pc in propagators: if new_demand != old_demand: propagate_changes(pc, delta, old_demand, new_demand, []) else: - propagate_qty_change(pc, delta, []) + propagate_qty_change(pc, delta, []) else: if new_demand != old_demand: #this is because we are just changing the order delta = Decimal("0") for pc in propagators: - propagate_changes(pc, delta, old_demand, new_demand, []) + propagate_changes(pc, delta, old_demand, new_demand, []) explode = False - + return explode class ProcessOutputFormSet(BaseModelFormSet): @@ -8940,7 +8940,7 @@ def __init__(self, *args, **kwargs): self.pattern = kwargs.pop('pattern', None) super(ProcessOutputFormSet, self).__init__(*args, **kwargs) - def _construct_forms(self): + def _construct_forms(self): self.forms = [] #import pdb; pdb.set_trace() for i in xrange(self.total_form_count()): @@ -8952,7 +8952,7 @@ def __init__(self, *args, **kwargs): self.pattern = kwargs.pop('pattern', None) super(ProcessInputFormSet, self).__init__(*args, **kwargs) - def _construct_forms(self): + def _construct_forms(self): self.forms = [] #import pdb; pdb.set_trace() for i in xrange(self.total_form_count()): @@ -8964,7 +8964,7 @@ def __init__(self, *args, **kwargs): self.pattern = kwargs.pop('pattern', None) super(ProcessCitationFormSet, self).__init__(*args, **kwargs) - def _construct_forms(self): + def _construct_forms(self): self.forms = [] #import pdb; pdb.set_trace() for i in xrange(self.total_form_count()): @@ -8976,7 +8976,7 @@ def __init__(self, *args, **kwargs): self.pattern = kwargs.pop('pattern', None) super(ProcessWorkFormSet, self).__init__(*args, **kwargs) - def _construct_forms(self): + def _construct_forms(self): self.forms = [] #import pdb; pdb.set_trace() for i in xrange(self.total_form_count()): @@ -8989,7 +8989,7 @@ def change_process(request, process_id): #import pdb; pdb.set_trace() if request.method == "POST": form = ProcessForm( - instance=process, + instance=process, data=request.POST) if form.is_valid(): data = form.cleaned_data @@ -9014,13 +9014,13 @@ def change_process(request, process_id): initial=init) demand_init = {"demand": demand,} demand_form = DemandSelectionForm( - data=request.POST or None, + data=request.POST or None, initial=demand_init) else: - demand_form = DemandSelectionForm(data=request.POST or None) + demand_form = DemandSelectionForm(data=request.POST or None) rand_form = RandOrderForm(data=request.POST or None) else: - demand_form = DemandSelectionForm(data=request.POST or None) + demand_form = DemandSelectionForm(data=request.POST or None) rand_form = RandOrderForm(data=request.POST or None) process_form = ProcessForm(instance=process, data=request.POST or None) pattern = None @@ -9086,7 +9086,7 @@ def change_process(request, process_id): data=request.POST or None, prefix='usable', pattern=pattern) - + if request.method == "POST": #import pdb; pdb.set_trace() keep_going = request.POST.get("keep-going") @@ -9134,7 +9134,7 @@ def change_process(request, process_id): if demand_form.is_valid(): selected_demand = demand_form.cleaned_data["demand"] if selected_demand: - demand = selected_demand + demand = selected_demand for form in output_formset.forms: #flow todo: output changes shd propagate to dependants too if form.is_valid(): @@ -9204,7 +9204,7 @@ def change_process(request, process_id): ct.save() elif ct_from_id: ct = form.save() - ct.delete() + ct.delete() for form in work_formset.forms: #import pdb; pdb.set_trace() @@ -9246,8 +9246,8 @@ def change_process(request, process_id): site_name = get_site_name() if users: notification.send( - users, - "valnet_new_task", + users, + "valnet_new_task", {"resource_type": ct.resource_type, "due_date": ct.due_date, "hours": ct.quantity, @@ -9260,7 +9260,7 @@ def change_process(request, process_id): ) elif ct_from_id: ct = form.save() - ct.delete() + ct.delete() for form in consumable_formset.forms: #import pdb; pdb.set_trace() @@ -9328,7 +9328,7 @@ def change_process(request, process_id): ct.independent_demand = demand if ct_from_id: old_ct = Commitment.objects.get(id=ct_from_id.id) - explode = handle_commitment_changes(old_ct, ct.resource_type, qty, existing_demand, demand) + explode = handle_commitment_changes(old_ct, ct.resource_type, qty, existing_demand, demand) ct.changed_by = request.user rt = input_data["resource_type"] event_type = pattern.event_type_for_resource_type("use", rt) @@ -9353,7 +9353,7 @@ def change_process(request, process_id): #if explode: # explode_dependent_demands(ct, request.user) - + if just_save: return HttpResponseRedirect('/%s/%s/' % ('accounting/process', process.id)) @@ -9376,7 +9376,7 @@ def change_process(request, process_id): #todo: soon to be obsolete (is it obsolete now?) def explode_dependent_demands(commitment, user): """This method assumes an input commitment""" - + #import pdb; pdb.set_trace() qty_to_explode = commitment.net() if qty_to_explode: @@ -9415,7 +9415,7 @@ def explode_dependent_demands(commitment, user): ) output_commitment.save() recursively_explode_demands(feeder_process, demand, user, []) - + def propagate_qty_change(commitment, delta, visited): #import pdb; pdb.set_trace() process = commitment.process @@ -9427,7 +9427,7 @@ def propagate_qty_change(commitment, delta, visited): output_ctype = commitment.commitment_type() ratio = input_ctype.quantity / output_ctype.quantity new_delta = (delta * ratio).quantize(Decimal('.01'), rounding=ROUND_UP) - + ic.quantity += new_delta ic.save() #import pdb; pdb.set_trace() @@ -9446,7 +9446,7 @@ def propagate_qty_change(commitment, delta, visited): if pc.order_item == order_item: propagate_qty_change(pc, new_delta, visited) commitment.quantity += delta - commitment.save() + commitment.save() def propagate_changes(commitment, delta, old_demand, new_demand, visited): #import pdb; pdb.set_trace() @@ -9455,7 +9455,7 @@ def propagate_changes(commitment, delta, old_demand, new_demand, visited): if process not in visited: visited.append(process) for ic in process.incoming_commitments(): - ratio = ic.quantity / commitment.quantity + ratio = ic.quantity / commitment.quantity new_delta = (delta * ratio).quantize(Decimal('.01'), rounding=ROUND_UP) ic.quantity += new_delta ic.order_item = order_item @@ -9467,7 +9467,7 @@ def propagate_changes(commitment, delta, old_demand, new_demand, visited): commitment.quantity += delta commitment.independent_demand = new_demand commitment.save() - + @login_required def change_order(request, order_id): order = get_object_or_404(Order, id=order_id) @@ -9541,9 +9541,9 @@ def process_selections(request, rand=0): demand = None added_to_order = False if demand_form.is_valid(): - demand = demand_form.cleaned_data["demand"] + demand = demand_form.cleaned_data["demand"] if demand: - added_to_order = True + added_to_order = True produced_rts = [] cited_rts = [] consumed_rts = [] @@ -9594,7 +9594,7 @@ def process_selections(request, rand=0): work_rts.append(work_rt) continue - if rand: + if rand: if not demand: demand = Order( order_type="rand", @@ -9619,8 +9619,8 @@ def process_selections(request, rand=0): context_agent=selected_context_agent ) process.save() - - #import pdb; pdb.set_trace() + + #import pdb; pdb.set_trace() for rt in produced_rts: #import pdb; pdb.set_trace() resource_types.append(rt) @@ -9686,7 +9686,7 @@ def process_selections(request, rand=0): unit=rt.unit, description="", user=request.user) - + for rt in consumed_rts: if rt not in resource_types: resource_types.append(rt) @@ -9701,7 +9701,7 @@ def process_selections(request, rand=0): unit=rt.unit, description="", user=request.user) - + for rt in work_rts: #import pdb; pdb.set_trace() agent = None @@ -9727,8 +9727,8 @@ def process_selections(request, rand=0): site_name = get_site_name() if users: notification.send( - users, - "valnet_new_task", + users, + "valnet_new_task", {"resource_type": work_commitment.resource_type, "due_date": work_commitment.due_date, "hours": work_commitment.quantity, @@ -9740,19 +9740,19 @@ def process_selections(request, rand=0): } ) - if done_process: + if done_process: #if demand: # return HttpResponseRedirect('/%s/%s/' # % ('accounting/order-schedule', demand.id)) #else: return HttpResponseRedirect('/%s/%s/' % ('accounting/process', process.id)) - if add_another: + if add_another: return HttpResponseRedirect('/%s/%s/' - % ('accounting/process-selections', rand)) + % ('accounting/process-selections', rand)) if edit_process: return HttpResponseRedirect('/%s/%s/' - % ('accounting/change-process', process.id)) + % ('accounting/change-process', process.id)) if labnotes: return HttpResponseRedirect('/%s/%s/%s/' % ('accounting/work-now', process.id, work_commitment.id)) @@ -9833,7 +9833,7 @@ def plan_from_recipe(request): if produced_rt.recipe_is_staged(): forward_schedule = True if produced_rt.recipe_needs_starting_resource(): - resource_driven = True + resource_driven = True if "resourcesFor" in key: #import pdb; pdb.set_trace() resource_id = int(value[0]) @@ -9844,7 +9844,7 @@ def plan_from_recipe(request): else: forward_schedule = False - #import pdb; pdb.set_trace() + #import pdb; pdb.set_trace() if not forward_schedule: demand = Order( order_type="rand", @@ -9853,7 +9853,7 @@ def plan_from_recipe(request): name=order_name, created_by=request.user) demand.save() - + for produced_rt in rts_to_produce: if forward_schedule: #Todo: apply selected_context_agent to all of the above generators @@ -9889,20 +9889,20 @@ def plan_from_recipe(request): #import pdb; pdb.set_trace() #Todo: apply selected_context_agent here? process = commitment.generate_producing_process(request.user, [], inheritance=inheritance, explode=True) - + if notification: #import pdb; pdb.set_trace() agent = get_agent(request) work_cts = Commitment.objects.filter( - independent_demand=demand, + independent_demand=demand, event_type__relationship="work") - for ct in work_cts: + for ct in work_cts: users = ct.possible_work_users() site_name = get_site_name() if users: notification.send( - users, - "valnet_new_task", + users, + "valnet_new_task", {"resource_type": ct.resource_type, "due_date": ct.due_date, "hours": ct.quantity, @@ -9913,10 +9913,10 @@ def plan_from_recipe(request): "site_name": site_name, } ) - + return HttpResponseRedirect('/%s/%s/' - % ('accounting/order-schedule', demand.id)) - + % ('accounting/order-schedule', demand.id)) + return render_to_response("valueaccounting/plan_from_recipe.html", { "selected_context_agent": selected_context_agent, "ca_form": ca_form, @@ -9938,7 +9938,7 @@ def plan_from_rt(request, resource_type_id): if form.is_valid(): process = form.save(commit=False) process.created_by = request.user - process.save() + process.save() demand = Order( order_type="rand", @@ -9956,16 +9956,16 @@ def plan_from_rt(request, resource_type_id): com.event_type = process.process_pattern.event_type_for_resource_type("out", resource_type) com.process = process com.due_date = process.end_date - com.resource_type = resource_type + com.resource_type = resource_type com.quantity = Decimal("1") - com.unit_of_quantity = resource_type.unit + com.unit_of_quantity = resource_type.unit com.created_by = request.user com.save() #todo: if demand.add_commitment gets further developed, could use it instead of the above return HttpResponseRedirect('/%s/%s/' % ('accounting/process', process.id)) - + return render_to_response("valueaccounting/plan_from_rt.html", { "form": form, "resource_type": resource_type, @@ -10045,15 +10045,15 @@ def plan_from_rt_recipe(request, resource_type_id): #import pdb; pdb.set_trace() agent = get_agent(request) work_cts = Commitment.objects.filter( - independent_demand=demand, + independent_demand=demand, event_type__relationship="work") - for ct in work_cts: + for ct in work_cts: users = ct.possible_work_users() site_name = get_site_name() if users: notification.send( - users, - "valnet_new_task", + users, + "valnet_new_task", {"resource_type": ct.resource_type, "due_date": ct.due_date, "hours": ct.quantity, @@ -10064,10 +10064,10 @@ def plan_from_rt_recipe(request, resource_type_id): "site_name": site_name, } ) - + return HttpResponseRedirect('/%s/%s/' - % ('accounting/order-schedule', demand.id)) - + % ('accounting/order-schedule', demand.id)) + return render_to_response("valueaccounting/plan_from_rt_recipe.html", { "date_name_form": date_name_form, "resource_type": resource_type, @@ -10091,7 +10091,7 @@ def resource_facet_table(request): for rf in rt.facets.all(): cell = headings.index(rf.facet_value.facet) row[cell] = rf - rows.append(row) + rows.append(row) return render_to_response("valueaccounting/resource_facets.html", { "headings": headings, "rows": rows, @@ -10180,7 +10180,7 @@ def exchanges(request, agent_id=None): dt_selection_form = DateSelectionForm(initial=init, data=request.POST or None) #et_donation = EventType.objects.get(name="Donation") #et_cash = EventType.objects.get(name="Cash Contribution") - #et_pay = EventType.objects.get(name="Payment") + #et_pay = EventType.objects.get(name="Payment") #et_receive = EventType.objects.get(name="Receipt") #et_expense = EventType.objects.get(name="Expense") et_give = EventType.objects.get(name="Give") @@ -10224,16 +10224,16 @@ def exchanges(request, agent_id=None): # for event in transfer.events.all(): # if event.resource_type.accounting_reference: # if event.resource_type.accounting_reference.code in vals: - # transfers_included.append(transfer) - # if transfers_included != []: + # transfers_included.append(transfer) + # if transfers_included != []: # ex.transfer_list = transfers_included # exchanges_included.append(ex) # transfers_included = [] #for event in ex.events.all(): #work events not part of a transfer # if event.resource_type.accounting_reference: # if event.resource_type.accounting_reference.code in vals: - # events_included.append(event) - # if events_included != []: + # events_included.append(event) + # if events_included != []: # ex.event_list = events_included # events_included = [] #ex.event_list = events_included @@ -10276,7 +10276,7 @@ def exchanges(request, agent_id=None): #import pdb; pdb.set_trace() return render_to_response("valueaccounting/exchanges.html", { - "exchanges": exchanges, + "exchanges": exchanges, "dt_selection_form": dt_selection_form, "total_transfers": total_transfers, "total_rec_transfers": total_rec_transfers, @@ -10297,7 +10297,7 @@ def exchanges_old(request): dt_selection_form = DateSelectionForm(initial=init, data=request.POST or None) et_donation = EventType.objects.get(name="Donation") et_cash = EventType.objects.get(name="Cash Contribution") - et_pay = EventType.objects.get(name="Payment") + et_pay = EventType.objects.get(name="Payment") et_receive = EventType.objects.get(name="Receipt") et_expense = EventType.objects.get(name="Expense") #et_process_expense = EventType.objects.get(name="Process Expense") @@ -10313,7 +10313,7 @@ def exchanges_old(request): end = dt_selection_form.cleaned_data["end_date"] exchanges = Exchange.objects.financial_contributions(start, end) else: - exchanges = Exchange.objects.financial_contributions() + exchanges = Exchange.objects.financial_contributions() selected_values = request.POST["categories"] if selected_values: sv = selected_values.split(",") @@ -10335,7 +10335,7 @@ def exchanges_old(request): #else: #process # if event.event_type == et_process_expense: # events_included.append(event) - if events_included != []: + if events_included != []: ex.event_list = events_included exchanges_included.append(ex) events_included = [] @@ -10382,7 +10382,7 @@ def exchanges_old(request): #import pdb; pdb.set_trace() return render_to_response("valueaccounting/exchanges.html", { - "exchanges": exchanges, + "exchanges": exchanges, "dt_selection_form": dt_selection_form, "total_cash": total_cash, "total_receipts": total_receipts, @@ -10463,7 +10463,7 @@ def internal_exchanges(request, agent_id=None): if ea in selected_agents: exchanges_included.append(ex) exchanges = exchanges_included - + else: if agent_id: exchanges = agent.internal_exchanges(start, end) @@ -10500,12 +10500,12 @@ def internal_exchanges(request, agent_id=None): if event.to_agent not in agents: agents.append(event.to_agent) #todo: get sort to work - + #import pdb; pdb.set_trace() return render_to_response("valueaccounting/internal_exchanges.html", { - "exchanges": exchanges, + "exchanges": exchanges, "dt_selection_form": dt_selection_form, "total_transfers": total_transfers, "total_rec_transfers": total_rec_transfers, @@ -10518,7 +10518,7 @@ def internal_exchanges(request, agent_id=None): "agents": agents, }, context_instance=RequestContext(request)) -#obsolete +#obsolete def material_contributions(request): #import pdb; pdb.set_trace() end = datetime.date.today() @@ -10633,7 +10633,7 @@ def demand_exchanges(request, agent_id=None): #import pdb; pdb.set_trace() return render_to_response("valueaccounting/demand_exchanges.html", { - "exchanges": exchanges, + "exchanges": exchanges, "dt_selection_form": dt_selection_form, "total_transfers": total_transfers, "total_rec_transfers": total_rec_transfers, @@ -10657,8 +10657,8 @@ def sales_and_distributions(request, agent_id=None): init = {"start_date": start, "end_date": end} dt_selection_form = DateSelectionForm(initial=init, data=request.POST or None) et_cash_receipt = EventType.objects.get(name="Cash Receipt") - et_shipment = EventType.objects.get(name="Shipment") - et_distribution = EventType.objects.get(name="Distribution") + et_shipment = EventType.objects.get(name="Shipment") + et_distribution = EventType.objects.get(name="Distribution") references = AccountingReference.objects.all() event_ids = "" select_all = True @@ -10691,7 +10691,7 @@ def sales_and_distributions(request, agent_id=None): if event.resource_type.accounting_reference: if event.resource_type.accounting_reference.code in vals: events_included.append(event) - if events_included != []: + if events_included != []: ex.event_list = events_included exchanges_included.append(ex) events_included = [] @@ -10748,7 +10748,7 @@ def distributions(request, agent_id=None): init = {"start_date": start, "end_date": end} dt_selection_form = DateSelectionForm(initial=init, data=request.POST or None) event_ids = "" - distributions = Distribution.objects.filter(distribution_date__range=[start, end]) + distributions = Distribution.objects.filter(distribution_date__range=[start, end]) if agent_id: distributions = distributions.filter(context_agent=agent) if request.method == "POST": @@ -10785,8 +10785,8 @@ def distributions(request, agent_id=None): "agent": agent, "user_agent": user_agent, }, context_instance=RequestContext(request)) - -@login_required + +@login_required def exchange_events_csv(request): #import pdb; pdb.set_trace() event_ids = request.GET.get("event-ids") @@ -10804,18 +10804,18 @@ def exchange_events_csv(request): if event.to_agent == None: to_agent = "" else: - to_agent = event.to_agent.nick + to_agent = event.to_agent.nick if event.url == "": if event.transfer: if event.transfer.exchange.url == "": - url = "" + url = "" else: url = event.transfer.exchange.url else: if event.exchange.url == "": - url = "" + url = "" else: - url = event.exchange.url + url = event.exchange.url else: url = "" if event.exchange: @@ -10837,7 +10837,7 @@ def exchange_events_csv(request): exchange_id, transfer_name, transfer_id, - event.id, + event.id, event.event_date, event.event_type.name, event.resource_type.name, @@ -10849,13 +10849,13 @@ def exchange_events_csv(request): to_agent, event.context_agent.name, event.description, - url, + url, ] ) return response - - -@login_required + + +@login_required def contribution_events_csv(request): #import pdb; pdb.set_trace() event_ids = request.GET.get("event-ids") @@ -10882,7 +10882,7 @@ def contribution_events_csv(request): return response -def exchange_logging(request, exchange_type_id=None, exchange_id=None, context_agent_id=None): +def exchange_logging(request, exchange_type_id=None, exchange_id=None, context_agent_id=None): #import pdb; pdb.set_trace() agent = get_agent(request) logger = False @@ -10890,12 +10890,12 @@ def exchange_logging(request, exchange_type_id=None, exchange_id=None, context_a if agent: if request.user.is_superuser: logger = True - + if exchange_type_id != "0": #new exchange if agent: exchange_type = get_object_or_404(ExchangeType, id=exchange_type_id) use_case = exchange_type.use_case - + if request.method == "POST": exchange_form = ExchangeForm(data=request.POST) if exchange_form.is_valid(): @@ -10906,8 +10906,8 @@ def exchange_logging(request, exchange_type_id=None, exchange_id=None, context_a exchange.save() return HttpResponseRedirect('/%s/%s/%s/' - % ('accounting/exchange', 0, exchange.id)) - + % ('accounting/exchange', 0, exchange.id)) + if context_agent_id: context_agent = EconomicAgent.objects.get(id=context_agent_id) init = { "context_agent": context_agent } @@ -10932,27 +10932,27 @@ def exchange_logging(request, exchange_type_id=None, exchange_id=None, context_a elif exchange_id != "0": #existing exchange exchange = get_object_or_404(Exchange, id=exchange_id) - + if request.method == "POST": #import pdb; pdb.set_trace() exchange_form = ExchangeForm(instance=exchange, data=request.POST) if exchange_form.is_valid(): exchange = exchange_form.save() return HttpResponseRedirect('/%s/%s/%s/' - % ('accounting/exchange', 0, exchange.id)) - + % ('accounting/exchange', 0, exchange.id)) + context_agent = exchange.context_agent exchange_type = exchange.exchange_type use_case = exchange_type.use_case exchange_form = ExchangeForm(instance=exchange) - + slots = [] total_t = 0 total_rect = 0 #import pdb; pdb.set_trace() work_events = exchange.work_events() slots = exchange.slots_with_detail() - + for slot in slots: if slot.is_reciprocal: total_rect = total_rect + slot.total @@ -10967,14 +10967,14 @@ def exchange_logging(request, exchange_type_id=None, exchange_id=None, context_a for event in work_events: event.changeform = WorkEventAgentForm( context_agent=context_agent, - instance=event, + instance=event, prefix=str(event.id)) work_init = { "from_agent": agent, "event_date": datetime.date.today() } add_work_form = WorkEventAgentForm(initial=work_init, context_agent=context_agent) - + #import pdb; pdb.set_trace() for slot in slots: ta_init = slot.default_to_agent @@ -10993,11 +10993,11 @@ def exchange_logging(request, exchange_type_id=None, exchange_id=None, context_a commit_init = { "from_agent": fa_init, "to_agent": ta_init, - "commitment_date": datetime.date.today(), + "commitment_date": datetime.date.today(), "due_date": exchange.start_date, } slot.add_commit_form = TransferCommitmentForm(initial=commit_init, prefix="ACM" + str(slot.id), context_agent=context_agent, transfer_type=slot) - + else: raise ValidationError("System Error: No exchange or use case.") @@ -11084,7 +11084,7 @@ def exchange_logging_old(request, exchange_id): distribution_events = exchange.distribution_events() disbursement_events = exchange.disbursement_events() fee_events = exchange.fee_events() - transfer_events = exchange.transfer_events() + transfer_events = exchange.transfer_events() if agent and pattern: #import pdb; pdb.set_trace() @@ -11101,7 +11101,7 @@ def exchange_logging_old(request, exchange_id): event.changeform = PaymentEventForm( pattern=pattern, context_agent=context_agent, - instance=event, + instance=event, prefix=str(event.id)) for event in expense_events: expense_total = expense_total + event.value @@ -11109,13 +11109,13 @@ def exchange_logging_old(request, exchange_id): event.changeform = ExpenseEventForm( pattern=pattern, context_agent=context_agent, - instance=event, + instance=event, prefix=str(event.id)) for event in work_events: event.changeform = WorkEventAgentForm( pattern=pattern, context_agent=context_agent, - instance=event, + instance=event, prefix=str(event.id)) for event in receipt_events: receipt_total = receipt_total + event.value @@ -11123,7 +11123,7 @@ def exchange_logging_old(request, exchange_id): event.changeform = UnorderedReceiptForm( pattern=pattern, context_agent=context_agent, - instance=event, + instance=event, prefix=str(event.id)) for event in cash_receipt_events: total_in = total_in + event.quantity @@ -11132,7 +11132,7 @@ def exchange_logging_old(request, exchange_id): event.changeform = CashReceiptForm( pattern=pattern, context_agent=context_agent, - instance=event, + instance=event, prefix=str(event.id)) for event in shipment_events: total_out = total_out + event.value @@ -11142,34 +11142,34 @@ def exchange_logging_old(request, exchange_id): event.changeform = ShipmentForm( pattern=pattern, context_agent=context_agent, - instance=event, + instance=event, prefix=str(event.id)) else: event.changeform = UninventoriedShipmentForm( pattern=pattern, context_agent=context_agent, - instance=event, - prefix=str(event.id)) + instance=event, + prefix=str(event.id)) for event in distribution_events: total_out = total_out + event.quantity distribution_total = distribution_total + event.quantity event.changeform = DistributionEventForm( pattern=pattern, - instance=event, + instance=event, prefix=str(event.id)) for event in disbursement_events: total_in = total_in + event.quantity disburse_total = disburse_total + event.quantity event.changeform = DisbursementEventForm( pattern=pattern, - instance=event, + instance=event, prefix=str(event.id)) for event in cash_events: total_in = total_in + event.value cash_contr_total = cash_contr_total + event.value #event.changeform = CashEventForm( # pattern=pattern, - # instance=event, + # instance=event, # prefix=str(event.id)) for event in material_events: total_in = total_in + event.value @@ -11183,12 +11183,12 @@ def exchange_logging_old(request, exchange_id): #for event in cash_events: # event.changeform = CashContributionEventForm( # pattern=pattern, - # instance=event, + # instance=event, # prefix=str(event.id)) #for event in material_events: # event.changeform = MaterialContributionEventForm( # pattern=pattern, - # instance=event, + # instance=event, # prefix=str(event.id)) if "pay" in slots: @@ -11208,13 +11208,13 @@ def exchange_logging_old(request, exchange_id): work_init = { "from_agent": agent, "event_date": exchange.start_date - } + } add_work_form = WorkEventAgentForm(prefix='work', initial=work_init, pattern=pattern, context_agent=context_agent) if "receive" in slots: receipt_init = { "event_date": exchange.start_date, "from_agent": exchange.supplier - } + } add_receipt_form = UnorderedReceiptForm(prefix='unorderedreceipt', initial=receipt_init, pattern=pattern, context_agent=context_agent) #import pdb; pdb.set_trace() create_receipt_role_formset = resource_role_agent_formset(prefix='receiptrole') @@ -11223,14 +11223,14 @@ def exchange_logging_old(request, exchange_id): cash_init = { "event_date": exchange.start_date, "from_agent": agent - } + } add_cash_form = CashContributionEventForm(prefix='cash', initial=cash_init, pattern=pattern, context_agent=context_agent) add_cash_resource_form = CashContributionResourceEventForm(prefix='cashres', initial=cash_init, pattern=pattern, context_agent=context_agent) if "resource" in slots: matl_init = { "event_date": exchange.start_date, "from_agent": agent - } + } add_material_form = MaterialContributionEventForm(prefix='material', initial=matl_init, pattern=pattern, context_agent=context_agent) #import pdb; pdb.set_trace() create_material_role_formset = resource_role_agent_formset(prefix='materialrole') @@ -11240,7 +11240,7 @@ def exchange_logging_old(request, exchange_id): cr_init = { "event_date": exchange.start_date, "to_agent": context_agent, - } + } add_cash_receipt_form = CashReceiptForm(prefix='cr', initial=cr_init, pattern=pattern, context_agent=context_agent) add_cash_receipt_resource_form = CashReceiptResourceForm(prefix='crr', initial=cr_init, pattern=pattern, context_agent=context_agent) if "shipment" in slots: @@ -11248,7 +11248,7 @@ def exchange_logging_old(request, exchange_id): ship_init = { "event_date": exchange.start_date, "from_agent": context_agent, - } + } add_shipment_form = ShipmentForm(prefix='ship', initial=ship_init, pattern=pattern, context_agent=context_agent) add_uninventoried_shipment_form = UninventoriedShipmentForm(prefix='shipun', initial=ship_init, pattern=pattern, context_agent=context_agent) shipped_ids = [c.resource.id for c in exchange.shipment_events() if c.resource] @@ -11256,14 +11256,14 @@ def exchange_logging_old(request, exchange_id): #import pdb; pdb.set_trace() dist_init = { "event_date": exchange.start_date, - } + } add_distribution_form = DistributionEventForm(prefix='dist', initial=dist_init, pattern=pattern) if "disburse" in slots: #import pdb; pdb.set_trace() disb_init = { "event_date": exchange.start_date, - } - add_disbursement_form = DisbursementEventForm(prefix='disb', initial=disb_init, pattern=pattern) + } + add_disbursement_form = DisbursementEventForm(prefix='disb', initial=disb_init, pattern=pattern) if request.method == "POST": #import pdb; pdb.set_trace() @@ -11363,7 +11363,7 @@ def create_exchange(request, use_case_identifier): "help": get_help("create_exchange"), }, context_instance=RequestContext(request)) -#obsolete +#obsolete @login_required def create_sale(request): #import pdb; pdb.set_trace() @@ -11415,7 +11415,7 @@ def create_distribution(request, agent_id): "help": get_help("create_distribution"), }, context_instance=RequestContext(request)) ''' - + def distribution_logging(request, distribution_id=None): #import pdb; pdb.set_trace() agent = get_agent(request) @@ -11436,7 +11436,7 @@ def distribution_logging(request, distribution_id=None): total_dist = 0 add_distribution_form = None add_disbursement_form = None - + if not distribution_id: #new distribution if agent: if request.method == "POST": @@ -11447,33 +11447,33 @@ def distribution_logging(request, distribution_id=None): dist.created_by = request.user dist.save() return HttpResponseRedirect('/%s/%s/' - % ('accounting/distribution', dist.id)) - + % ('accounting/distribution', dist.id)) + main_form = DistributionForm() - + else: raise ValidationError("System Error: No agent, not allowed to create distribution.") else: #existing distribution dist = get_object_or_404(Distribution, id=distribution_id) - + if request.method == "POST": #import pdb; pdb.set_trace() main_form = DistributionForm(instance=dist, data=request.POST) if main_form.is_valid(): dist = main_form.save() return HttpResponseRedirect('/%s/%s/' - % ('accounting/distribution', dist.id)) - + % ('accounting/distribution', dist.id)) + main_form = DistributionForm(instance=dist) dist_init = { "event_date": dist.distribution_date, - } + } add_distribution_form = DistributionEventForm(prefix='dist', initial=dist_init, pattern=pattern) disb_init = { "event_date": dist.distribution_date, - } - add_disbursement_form = DisbursementEventForm(prefix='disb', initial=disb_init, pattern=pattern) + } + add_disbursement_form = DisbursementEventForm(prefix='disb', initial=disb_init, pattern=pattern) return render_to_response("valueaccounting/distribution_logging.html", { "main_form": main_form, @@ -11547,9 +11547,9 @@ def create_distribution_using_value_equation(request, agent_id, value_equation_i serialized_filters=serialized_filters) if not agent_totals: no_totals = "No contributions found." - - else: - distribution = Distribution( + + else: + distribution = Distribution( name="Distribution for " + context_agent.nick, process_pattern=pattern, distribution_date=dist_date, @@ -11558,19 +11558,19 @@ def create_distribution_using_value_equation(request, agent_id, value_equation_i created_by=request.user, ) #exchange.save() - + distribution = ve.run_value_equation_and_save( events_to_distribute=etd, - distribution=distribution, - money_resource=resource, - amount_to_distribute=amount, + distribution=distribution, + money_resource=resource, + amount_to_distribute=amount, serialized_filters=serialized_filters) for event in distribution.distribution_events(): send_distribution_notification(event) - + return HttpResponseRedirect('/%s/%s/' % ('accounting/distribution', distribution.id)) - + else: #import pdb; pdb.set_trace() ves = context_agent.live_value_equations() @@ -11587,7 +11587,7 @@ def create_distribution_using_value_equation(request, agent_id, value_equation_i if bucket.filter_method: bucket.form = bucket.filter_entry_form() #end_time = time.time() - #print("views.create_distribution_using_value_equation elapsed time was %g seconds" % (end_time - start_time)) + #print("views.create_distribution_using_value_equation elapsed time was %g seconds" % (end_time - start_time)) return render_to_response("valueaccounting/create_distribution_using_value_equation.html", { "events_to_distribute": events_to_distribute, "header_form": header_form, @@ -11598,7 +11598,7 @@ def create_distribution_using_value_equation(request, agent_id, value_equation_i "no_totals": no_totals, "help": get_help("create_distribution"), }, context_instance=RequestContext(request)) - + def send_distribution_notification(distribution_event): if notification: @@ -11608,8 +11608,8 @@ def send_distribution_notification(distribution_event): site_name = get_site_name() if users: notification.send( - users, - "valnet_distribution", + users, + "valnet_distribution", {"distribution": distribution_event, "account": distribution_event.resource, "site_name": site_name, @@ -11617,7 +11617,7 @@ def send_distribution_notification(distribution_event): ) ''' -#todo: this is not tested, is for exchange +#todo: this is not tested, is for exchange @login_required def payment_event_for_commitment(request): id = request.POST.get("id") @@ -11669,12 +11669,12 @@ def resource_flow(request): pattern = ProcessPattern.objects.get(name="Change") resource_form = ResourceFlowForm(pattern=pattern) role_formset = resource_role_agent_formset(prefix='role') - + return render_to_response("valueaccounting/resource_flow.html", { "resource_form": resource_form, "role_formset": role_formset, }, context_instance=RequestContext(request)) - + #demo page for DHEN and GT #@login_required def workflow_board_demo(request): @@ -11682,12 +11682,12 @@ def workflow_board_demo(request): pattern = ProcessPattern.objects.get(name="Change") resource_form = ResourceFlowForm(pattern=pattern) process_form = PlanProcessForm() - + return render_to_response("valueaccounting/workflow_board_demo.html", { "resource_form": resource_form, "process_form": process_form, }, context_instance=RequestContext(request)) - + #demo page for DHEN #@login_required def inventory_board_demo(request): @@ -11698,7 +11698,7 @@ def inventory_board_demo(request): move_harvester_form = ExchangeFlowForm() move_dryer_form = ExchangeFlowForm() move_seller_form = ExchangeFlowForm() - + return render_to_response("valueaccounting/inventory_board_demo.html", { "resource_form": resource_form, "process_form": process_form, @@ -11709,8 +11709,8 @@ def inventory_board_demo(request): def lots(request): #import pdb; pdb.set_trace() - - + + return render_to_response("valueaccounting/lots.html", { "resource_form": resource_form, "process_form": process_form, @@ -11737,7 +11737,7 @@ def bucket_filter_header(request): return render_to_response("valueaccounting/bucket_filter_header.html", { "header_form": header_form, }, context_instance=RequestContext(request)) - + #@login_required def bucket_filter(request, agent_id, event_type_id, pattern_id, filter_set): agent = get_object_or_404(EconomicAgent, pk=agent_id) @@ -11796,7 +11796,7 @@ def bucket_filter(request, agent_id, event_type_id, pattern_id, filter_set): if resource_types: events = [e for e in events if e.resource_type in resource_types] count = len(events) - + return render_to_response("valueaccounting/bucket_filter.html", { "filter_set": filter_set, "context_agent": agent, @@ -11821,7 +11821,7 @@ def key(self): def quantity_formatted(self): return self.quantity.quantize(Decimal('.01'), rounding=ROUND_UP) - + @login_required def value_equation_sandbox(request, value_equation_id=None): @@ -11927,13 +11927,13 @@ def json_value_equation_bucket(request, value_equation_id): } buckets.append({"fields": fields}) json = simplejson.dumps(buckets, ensure_ascii=False) - return HttpResponse(json, mimetype='application/json') - + return HttpResponse(json, mimetype='application/json') + def value_equations(request): #import pdb; pdb.set_trace() value_equations = ValueEquation.objects.all() - agent = get_agent(request) - + agent = get_agent(request) + return render_to_response("valueaccounting/value_equations.html", { "value_equations": value_equations, "agent": agent, @@ -11967,7 +11967,7 @@ def edit_value_equation(request, value_equation_id=None): test_results.append(tr[count]) count+=1 rpt_heading = "Bucket " + str(vebr.value_equation_bucket.sequence) + " " + vebr.event_type.name - + return render_to_response("valueaccounting/edit_value_equation.html", { "value_equation": value_equation, "agent": agent, @@ -11976,7 +11976,7 @@ def edit_value_equation(request, value_equation_id=None): "test_results": test_results, "rpt_heading": rpt_heading, }, context_instance=RequestContext(request)) - + @login_required def create_value_equation(request): if request.method == "POST": @@ -11987,8 +11987,8 @@ def create_value_equation(request): ve.created_by = request.user ve.save() return HttpResponseRedirect('/%s/%s/' - % ('accounting/edit-value-equation', ve.id)) - + % ('accounting/edit-value-equation', ve.id)) + @login_required def change_value_equation(request, value_equation_id): ve = get_object_or_404(ValueEquation, id=value_equation_id) @@ -12000,17 +12000,17 @@ def change_value_equation(request, value_equation_id): ve.changed_by = request.user ve.save() return HttpResponseRedirect('/%s/%s/' - % ('accounting/edit-value-equation', ve.id)) + % ('accounting/edit-value-equation', ve.id)) + - @login_required def delete_value_equation(request, value_equation_id): ve = get_object_or_404(ValueEquation, id=value_equation_id) ve.delete() return HttpResponseRedirect('/%s/' - % ('accounting/value-equations')) - - + % ('accounting/value-equations')) + + @login_required def create_value_equation_bucket(request, value_equation_id): ve = get_object_or_404(ValueEquation, id=value_equation_id) @@ -12023,8 +12023,8 @@ def create_value_equation_bucket(request, value_equation_id): veb.created_by = request.user veb.save() return HttpResponseRedirect('/%s/%s/' - % ('accounting/edit-value-equation', ve.id)) - + % ('accounting/edit-value-equation', ve.id)) + @login_required def change_value_equation_bucket(request, bucket_id): veb = get_object_or_404(ValueEquationBucket, id=bucket_id) @@ -12037,16 +12037,16 @@ def change_value_equation_bucket(request, bucket_id): veb.changed_by = request.user veb.save() return HttpResponseRedirect('/%s/%s/' - % ('accounting/edit-value-equation', ve.id)) - + % ('accounting/edit-value-equation', ve.id)) + @login_required def delete_value_equation_bucket(request, bucket_id): veb = get_object_or_404(ValueEquationBucket, id=bucket_id) ve = veb.value_equation veb.delete() return HttpResponseRedirect('/%s/%s/' - % ('accounting/edit-value-equation', ve.id)) - + % ('accounting/edit-value-equation', ve.id)) + @login_required def create_value_equation_bucket_rule(request, bucket_id): veb = get_object_or_404(ValueEquationBucket, id=bucket_id) @@ -12063,8 +12063,8 @@ def create_value_equation_bucket_rule(request, bucket_id): vebr.filter_rule = filter_form.serialize() vebr.save() return HttpResponseRedirect('/%s/%s/' - % ('accounting/edit-value-equation', ve.id)) - + % ('accounting/edit-value-equation', ve.id)) + @login_required def change_value_equation_bucket_rule(request, rule_id): vebr = get_object_or_404(ValueEquationBucketRule, id=rule_id) @@ -12080,15 +12080,15 @@ def change_value_equation_bucket_rule(request, rule_id): vebr.filter_rule = filter_form.serialize() vebr.save() return HttpResponseRedirect('/%s/%s/' - % ('accounting/edit-value-equation', ve.id)) - + % ('accounting/edit-value-equation', ve.id)) + @login_required def delete_value_equation_bucket_rule(request, rule_id): vebr = get_object_or_404(ValueEquationBucketRule, id=rule_id) ve = vebr.value_equation_bucket.value_equation vebr.delete() return HttpResponseRedirect('/%s/%s/' - % ('accounting/edit-value-equation', ve.id)) + % ('accounting/edit-value-equation', ve.id)) @login_required def value_equation_live_test(request, value_equation_id): @@ -12121,7 +12121,7 @@ def cash_report(request): external_accounts = None virtual_accounts = EconomicResource.objects.virtual_accounts() option = "S" - + if request.method == "POST": #import pdb; pdb.set_trace() if dt_selection_form.is_valid(): @@ -12155,7 +12155,7 @@ def cash_report(request): events = events_included else: events = EconomicEvent.objects.virtual_account_events(start_date=start, end_date=end) - + in_total = 0 out_total = 0 comma = "" @@ -12178,10 +12178,10 @@ def cash_report(request): summary[event.account] = summary[event.account] + event.quantity else: summary[event.account] = event.quantity - + balance = starting_balance + in_total - out_total summary_list = sorted(summary.iteritems()) - + return render_to_response("valueaccounting/cash_report.html", { "events": events, "summary_list": summary_list, @@ -12198,8 +12198,8 @@ def cash_report(request): "event_ids": event_ids, "option": option, }, context_instance=RequestContext(request)) - -@login_required + +@login_required def cash_events_csv(request): #import pdb; pdb.set_trace() event_ids = request.GET.get("event-ids") @@ -12217,14 +12217,14 @@ def cash_events_csv(request): if event.to_agent == None: to_agent = "" else: - to_agent = event.to_agent.nick + to_agent = event.to_agent.nick if event.url == "": if event.exchange.url == "": - url = "" + url = "" else: url = event.exchange.url else: - url = "" + url = "" writer.writerow( [event.event_date, event.event_type.name, @@ -12241,7 +12241,7 @@ def cash_events_csv(request): url, event.exchange.use_case, event.id, - event.exchange.id + event.exchange.id ] ) return response @@ -12253,13 +12253,13 @@ def virtual_accounts(request): if agent: for va in virtual_accounts: va.payout = va.allow_payout_by(agent, request.user) - + return render_to_response("valueaccounting/virtual_accounts.html", { "virtual_accounts": virtual_accounts, "agent": agent, }, context_instance=RequestContext(request)) -@login_required +@login_required def payout_from_virtual_account(request, account_id): if request.method == "POST": acct = get_object_or_404(EconomicResource, pk=account_id) @@ -12285,7 +12285,7 @@ def payout_from_virtual_account(request, account_id): event.save() acct.quantity -= event.quantity acct.save() - + return HttpResponseRedirect('/%s/' % ('accounting/virtual-accounts')) @@ -12298,10 +12298,10 @@ def get_lod_setup_items(): from rdflib import Graph from rdflib.namespace import FOAF, RDF, RDFS, OWL, SKOS from rdflib import Namespace - + path = get_url_starter() + "/accounting/" instance_abbrv = Site.objects.get_current().domain.split(".")[0] - + context = { "vf": "https://w3id.org/valueflows/", "owl": "http://www.w3.org/2002/07/owl#", @@ -12329,7 +12329,7 @@ def get_lod_setup_items(): "inverseOf": "owl:inverseOf", instance_abbrv: path, } - + store = Graph() #store.bind("foaf", FOAF) store.bind("rdf", RDF) @@ -12348,29 +12348,29 @@ def get_lod_setup_items(): store.bind("vf", vf_ns) instance_ns = Namespace(path) store.bind("instance", instance_ns) - + return path, instance_abbrv, context, store, vf_ns def agent_type_lod(request, agent_type_name): ats = AgentType.objects.all() agent_type = None - + #import pdb; pdb.set_trace() for at in ats: if camelcase(at.name) == agent_type_name: agent_type = at if not agent_type: - return HttpResponse({}, mimetype='application/json') - + return HttpResponse({}, mimetype='application/json') + from rdflib import Graph, Literal, BNode from rdflib.namespace import FOAF, RDF, RDFS, OWL, SKOS from rdflib.serializer import Serializer from rdflib import Namespace, URIRef path, instance_abbrv, context, store, vf_ns = get_lod_setup_items() - + if agent_type.name != "Person" and agent_type.name != "Group" and agent_type.name != "Individual": class_name = camelcase(agent_type.name) ref = URIRef(instance_abbrv + ":agent-type-lod/" +class_name) @@ -12378,14 +12378,14 @@ def agent_type_lod(request, agent_type_name): store.add((ref, SKOS.prefLabel, Literal(class_name, lang="en"))) if agent_type.party_type == "individual": store.add((ref, RDFS.subClassOf, vf_ns.Person)) - else: + else: store.add((ref, RDFS.subClassOf, vf_ns.Group)) - + ser = store.serialize(format='json-ld', context=context, indent=4) - return HttpResponse(ser, mimetype='application/json') + return HttpResponse(ser, mimetype='application/json') #return render_to_response("valueaccounting/agent_type.html", { # "agent_type": agent_type, - #}, context_instance=RequestContext(request)) + #}, context_instance=RequestContext(request)) def agent_relationship_type_lod(request, agent_assoc_type_name): #import pdb; pdb.set_trace() @@ -12400,15 +12400,15 @@ def agent_relationship_type_lod(request, agent_assoc_type_name): inverse = True if not agent_assoc_type: - return HttpResponse({}, mimetype='application/json') - + return HttpResponse({}, mimetype='application/json') + from rdflib import Graph, Literal, BNode from rdflib.namespace import FOAF, RDF, RDFS, OWL, SKOS from rdflib.serializer import Serializer from rdflib import Namespace, URIRef path, instance_abbrv, context, store, vf_ns = get_lod_setup_items() - + if inverse: property_name = camelcase_lower(agent_assoc_type.inverse_label) inverse_property_name = camelcase_lower(agent_assoc_type.label) @@ -12424,10 +12424,10 @@ def agent_relationship_type_lod(request, agent_assoc_type_name): store.add((ref, OWL.inverseOf, inv_ref)) ser = store.serialize(format='json-ld', context=context, indent=4) - return HttpResponse(ser, mimetype='application/json') + return HttpResponse(ser, mimetype='application/json') #return render_to_response("valueaccounting/agent_assoc_type.html", { # "agent_assoc_type": agent_assoc_type, - #}, context_instance=RequestContext(request)) + #}, context_instance=RequestContext(request)) def agent_relationship_lod(request, agent_assoc_id): aa = AgentAssociation.objects.filter(id=agent_assoc_id) @@ -12435,14 +12435,14 @@ def agent_relationship_lod(request, agent_assoc_id): return HttpResponse({}, mimetype='application/json') else: agent_association = aa[0] - + from rdflib import Graph, Literal, BNode from rdflib.namespace import FOAF, RDF, RDFS, OWL, SKOS from rdflib.serializer import Serializer from rdflib import Namespace, URIRef path, instance_abbrv, context, store, vf_ns = get_lod_setup_items() - + ref = URIRef(instance_abbrv + ":agent-relationship-lod/" + str(agent_association.id) + "/") inv_ref = URIRef(instance_abbrv + ":agent-relationship-inv-lod/" + str(agent_association.id) + "/") ref_subject = URIRef(instance_abbrv + ":agent-lod/" + str(agent_association.is_associate.id) + "/") @@ -12450,17 +12450,17 @@ def agent_relationship_lod(request, agent_assoc_id): property_name = camelcase_lower(agent_association.association_type.label) ref_relationship = URIRef(instance_abbrv + ":agent-relationship-type/" + property_name) store.add((ref, RDF.type, vf_ns["Relationship"])) - store.add((ref, vf_ns["subject"], ref_subject)) + store.add((ref, vf_ns["subject"], ref_subject)) store.add((ref, vf_ns["object"], ref_object)) store.add((ref, vf_ns["relationship"], ref_relationship)) store.add((ref, OWL.inverseOf, inv_ref)) ser = store.serialize(format='json-ld', context=context, indent=4) - return HttpResponse(ser, mimetype='application/json') + return HttpResponse(ser, mimetype='application/json') #return render_to_response("valueaccounting/agent_association.html", { # "agent_association": agent_association, - #}, context_instance=RequestContext(request)) - + #}, context_instance=RequestContext(request)) + def agent_relationship_inv_lod(request, agent_assoc_id): aa = AgentAssociation.objects.filter(id=agent_assoc_id) @@ -12468,14 +12468,14 @@ def agent_relationship_inv_lod(request, agent_assoc_id): return HttpResponse({}, mimetype='application/json') else: agent_association = aa[0] - + from rdflib import Graph, Literal, BNode from rdflib.namespace import FOAF, RDF, RDFS, OWL, SKOS from rdflib.serializer import Serializer from rdflib import Namespace, URIRef path, instance_abbrv, context, store, vf_ns = get_lod_setup_items() - + ref = URIRef(instance_abbrv + ":agent-relationship-inv-lod/" + str(agent_association.id) + "/") inv_ref = URIRef(instance_abbrv + ":agent-relationship-lod/" + str(agent_association.id) + "/") ref_object = URIRef(instance_abbrv + ":agent-lod/" + str(agent_association.is_associate.id) + "/") @@ -12483,16 +12483,16 @@ def agent_relationship_inv_lod(request, agent_assoc_id): property_name = camelcase_lower(agent_association.association_type.inverse_label) ref_relationship = URIRef(instance_abbrv + ":agent-relationship-type-lod/" + property_name) store.add((ref, RDF.type, vf_ns["Relationship"])) - store.add((ref, vf_ns["subject"], ref_subject)) + store.add((ref, vf_ns["subject"], ref_subject)) store.add((ref, vf_ns["object"], ref_object)) store.add((ref, vf_ns["relationship"], ref_relationship)) store.add((ref, OWL.inverseOf, inv_ref)) ser = store.serialize(format='json-ld', context=context, indent=4) - return HttpResponse(ser, mimetype='application/json') + return HttpResponse(ser, mimetype='application/json') #return render_to_response("valueaccounting/agent_association.html", { # "agent_association": agent_association, - #}, context_instance=RequestContext(request)) + #}, context_instance=RequestContext(request)) def agent_lod(request, agent_id): agents = EconomicAgent.objects.filter(id=agent_id) @@ -12509,7 +12509,7 @@ def agent_lod(request, agent_id): from rdflib import Namespace, URIRef path, instance_abbrv, context, store, vf_ns = get_lod_setup_items() - + #Lynn: I made a change here for consistency. Please check and fix if needed. ref = URIRef(instance_abbrv + ":agent-lod/" + str(agent.id) + "/") if agent.agent_type.name == "Individual" or agent.agent_type.name == "Person": @@ -12523,7 +12523,7 @@ def agent_lod(request, agent_id): store.add((ref, vf_ns["label"], Literal(agent.name, lang="en"))) #if agent.photo_url: # store.add((ref, vf_ns["image"], agent.photo_url)) - + #if subject_assocs or object_assocs: # store.add(( )) if subject_assocs: @@ -12540,8 +12540,8 @@ def agent_lod(request, agent_id): store.add((ref, inv_ref_relationship, subj_ref)) ser = store.serialize(format='json-ld', context=context, indent=4) - return HttpResponse(ser, mimetype='application/json') - + return HttpResponse(ser, mimetype='application/json') + #following method supplied by Niklas at rdflib-jsonld support to get the desired output for nested rdf inputs for rdflib def simplyframe(data): #import pdb; pdb.set_trace() @@ -12562,7 +12562,7 @@ def simplyframe(data): ref.update(items.pop(ref['@id'])) del ref['@id'] data['@graph'] = items.values() - + def agent_jsonld(request): #test = "{'@context': 'http://json-ld.org/contexts/person.jsonld', '@id': 'http://dbpedia.org/resource/John_Lennon', 'name': 'John Lennon', 'born': '1940-10-09', 'spouse': 'http://dbpedia.org/resource/Cynthia_Lennon' }" #test = '{ "@id": "http://nrp.webfactional.com/accounting/agent-lod/1", "@type": "Person", "vf:label": { "@language": "en", "@value": "Bob Haugen" } }' @@ -12575,7 +12575,7 @@ def agent_jsonld(request): #mport pdb; pdb.set_trace() path, instance_abbrv, context, store, vf_ns = get_lod_setup_items() - + agent_types = AgentType.objects.all() #import pdb; pdb.set_trace() for at in agent_types: @@ -12588,9 +12588,9 @@ def agent_jsonld(request): store.add((ref, SKOS.prefLabel, Literal(class_name, lang="en"))) if at.party_type == "individual": store.add((ref, RDFS.subClassOf, vf_ns.Person)) - else: + else: store.add((ref, RDFS.subClassOf, vf_ns.Group)) - + aa_types = AgentAssociationType.objects.all() #import pdb; pdb.set_trace() for aat in aa_types: @@ -12614,7 +12614,7 @@ def agent_jsonld(request): agents = [assn.is_associate for assn in associations] agents.extend([assn.has_associate for assn in associations]) agents = list(set(agents)) - + for agent in agents: ref = URIRef(instance_abbrv + ":agent-lod/" + str(agent.id) + "/") if agent.agent_type.name == "Individual" or agent.agent_type.name == "Person": @@ -12630,7 +12630,7 @@ def agent_jsonld(request): # store.add((ref, FOAF.nick, Literal(agent.nick, lang="en"))) #if agent.photo_url: # store.add((ref, vf_ns["image"], agent.photo_url)) - + for a in associations: ref = URIRef(instance_abbrv + ":agent-relationship-lod/" + str(a.id) + "/") inv_ref = URIRef(instance_abbrv + ":agent-relationship-inv-lod/" + str(a.id) + "/") @@ -12641,20 +12641,20 @@ def agent_jsonld(request): ref_relationship = URIRef(instance_abbrv + ":agent-relationship-type-lod/" + property_name) inv_ref_relationship = URIRef(instance_abbrv + ":agent-relationship-type-lod/" + inv_property_name) store.add((ref, RDF.type, vf_ns["Relationship"])) - store.add((ref, vf_ns["subject"], ref_subject)) + store.add((ref, vf_ns["subject"], ref_subject)) store.add((ref, vf_ns["object"], ref_object)) store.add((ref, vf_ns["relationship"], ref_relationship)) store.add((inv_ref, RDF.type, vf_ns["Relationship"])) - store.add((inv_ref, vf_ns["object"], ref_subject)) + store.add((inv_ref, vf_ns["object"], ref_subject)) store.add((inv_ref, vf_ns["subject"], ref_object)) store.add((inv_ref, vf_ns["relationship"], inv_ref_relationship)) - + ser = store.serialize(format='json-ld', context=context, indent=4) #import pdb; pdb.set_trace() #import json #data = json.loads(ser) #simplyframe(data) - #return HttpResponse(json.dumps(data, indent=4), mimetype='application/json') + #return HttpResponse(json.dumps(data, indent=4), mimetype='application/json') return HttpResponse(ser, mimetype='application/json') def agent_jsonld_query(request): @@ -12675,17 +12675,17 @@ def agent_jsonld_query(request): g.parse(StringIO(unicode(local_graph)), context=context, format="json-ld") local_expanded_json = g.serialize(format="json-ld", indent=4) local_expanded_dict = simplejson.loads(local_expanded_json) - + #import pdb; pdb.set_trace() - - result = "" + + result = "" agents = [x for x in graph if x['@id'].find('agent-lod') > -1] agent_dict = {} for a in agents: agent_dict[str(a['@id'])] = a - + rels = [x for x in graph if x['@type']=='Relationship'] - + agent_rels = [] for r in rels: d = {} @@ -12693,7 +12693,7 @@ def agent_jsonld_query(request): d["object"] = agent_dict[r["object"]] d["relationship"] = r["relationship"] agent_rels.append(d) - + for ar in agent_rels: object = ar['object'] object_type = object['@type'] @@ -12714,7 +12714,7 @@ def agent_jsonld_query(request): result += line + "\n" result += "\n" result += "========== Gory details from http://nrp.webfactional.com/accounting/agent-jsonld/ ==========\n" - + for item in local_expanded_dict: for key, value in item.iteritems(): if type(value) is list: @@ -12725,9 +12725,9 @@ def agent_jsonld_query(request): valist.append(": ".join([key2, value2])) value = ", ".join(valist) line = ": ".join([key, value]) - result += line + "\n" + result += line + "\n" result += "========== \n" - + #result = "Number of triples: " + str(len(g)) + "\n" #for s,p,o in g.triples( (None, None, None) ): # result += s + " " + p + " " + o + "\n"