Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
class OCMDBMaintenanceCreate(CreateView):
template_name = 'ocmdb_maintenance/create.html'
form_class = MaintenanceForm
model = OCMDB_MaintenanceCI
success_url = reverse_lazy('ocmdb_maintenance_list')
object = None
def get(self, request, *args, **kwargs):
form_class = self.get_form_class()
form = self.get_form(form_class)
afields = OSD_Field.objects.filter(entity__model_name='ocmdb_maintenance').order_by('-pk')
return render_to_response(self.template_name, locals(), context_instance=RequestContext(request))
def get_form_kwargs(self):
kwargs = super(OCMDBMaintenanceCreate, self).get_form_kwargs()
kwargs['initial'] = {'project': self.request.session['project']}
return kwargs
"""
def form_valid(self, form):
form.instance.project = self.request.session['project']
form.instance.init_date = datetime.strptime(form.data['init_date'], '%Y/%m/%d %H:%M')
return super(OCMDBMaintenanceCreate, self).form_valid(form)
"""
def post(self, request, *args, **kwargs):
#import ipdb; ipdb.set_trace()
maintenance = OCMDB_MaintenanceCI.objects.create(
subject = request.POST['subject'],
maintenance_type_id = request.POST['maintenance_type'],
ci_id = request.POST['ci'],
priority_id = request.POST['priority'],
init_date = datetime.strptime(request.POST['init_date'], '%Y-%m-%d %H:%M:%S'),
finish_date = datetime.strptime(request.POST['finish_date'], '%Y-%m-%d %H:%M:%S'),
status_type_id = request.POST['status_type'],
description = request.POST['description'],
user_id = request.POST['user'],
solver_id = request.POST['solver'],
damage_type_id = request.POST['damage_type'],
project_id = request.session['project'],
status = True
)
maintenance.save()
for field in request.POST.keys():
if field.startswith('adf_text__'):
ofield = OSD_Field.objects.get(name=field[10:])
fv = OSD_FieldValue.objects.create(
object_id = maintenance.id,
value = request.POST[field],
status = True,
field = ofield,
is_select = False
)
fv.save()
if field.startswith('adf_select__'):
ofield = OSD_Field.objects.get(name=field[12:])
fv = OSD_FieldValue.objects.create(
object_id = maintenance.id,
value = request.POST[field],
status = True,
field = ofield,
is_select = True
)
fv.save()
#import ipdb; ipdb.set_trace()
return HttpResponseRedirect(self.success_url)
class OCMDBMaintenanceUpdate(UpdateView):
template_name = 'ocmdb_maintenance/update.html'
form_class = MaintenanceForm
model = OCMDB_MaintenanceCI
success_url = reverse_lazy('ocmdb_maintenance_list')
object = None
def get_form_kwargs(self):
kwargs = super(OCMDBMaintenanceUpdate, self).get_form_kwargs()
kwargs['initial'] = {'project': self.request.session['project']}
return kwargs
def get(self, request, *args, **kwargs):
form_class = self.get_form_class()
form = self.get_form(form_class)
#context = self.get_context_data(object=self.object, form=form)
afields = OSD_Field.objects.filter(entity__model_name='ocmdb_maintenance').order_by('-pk')
afvalue = OSD_FieldValue.objects.filter(object_id=int(kwargs['pk']))
#import ipdb; ipdb.set_trace()
self.object = self.get_object()
object = self.get_object()
#return super(OCMDBMaintenanceUpdate, self).get(request, *args, **kwargs)
return render_to_response(self.template_name, locals(), context_instance=RequestContext(request))
def post(self, request, *args, **kwargs):
OCMDB_MaintenanceCI.objects.filter(id=int(kwargs['pk'])).update(
subject = request.POST['subject'],
maintenance_type = request.POST['maintenance_type'],
ci = request.POST['ci'],
priority = request.POST['priority'],
init_date = datetime.strptime(request.POST['init_date'], '%Y-%m-%d %H:%M:%S'),
finish_date = datetime.strptime(request.POST['finish_date'], '%Y-%m-%d %H:%M:%S'),
status_type = request.POST['status_type'],
description = request.POST['description'],
user = request.POST['user'],
solver = request.POST['solver'],
damage_type = request.POST['damage_type'],
observations = request.POST['observations'],
)
return HttpResponseRedirect(self.success_url)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment