prompt
large_stringlengths
72
9.34k
completion
large_stringlengths
0
7.61k
<|file_name|>models.py<|end_file_name|><|fim▁begin|>"""Data models for referral system.""" from __future__ import unicode_literals from builtins import map from django.db import models from django.core.urlresolvers import reverse from pttrack.models import (ReferralType, ReferralLocation, Note, ContactMethod, CompletableMixin,) from followup.models import ContactResult, NoAptReason, NoShowReason class Referral(Note): """A record of a particular patient's referral to a particular center.""" STATUS_SUCCESSFUL = 'S' STATUS_PENDING = 'P' STATUS_UNSUCCESSFUL = 'U' # Status if there are no referrals of a specific type # Used in aggregate_referral_status NO_REFERRALS_CURRENTLY = "No referrals currently" REFERRAL_STATUSES = ( (STATUS_SUCCESSFUL, 'Successful'), (STATUS_PENDING, 'Pending'), (STATUS_UNSUCCESSFUL, 'Unsuccessful'), ) location = models.ManyToManyField(ReferralLocation) comments = models.TextField(blank=True) status = models.CharField( max_length=50, choices=REFERRAL_STATUSES, default=STATUS_PENDING) kind = models.ForeignKey( ReferralType, help_text="The kind of care the patient should recieve at the " "referral location.") def __str__(self): """Provides string to display on front end for referral. For FQHC referrals, returns referral kind and date. For non-FQHC referrals, returns referral location and date. """ formatted_date = self.written_datetime.strftime("%D") if self.kind.is_fqhc: return "%s referral on %s" % (self.kind, formatted_date) else: location_names = [loc.name for loc in self.location.all()] locations = " ,".join(location_names) return "Referral to %s on %s" % (locations, formatted_date) @staticmethod def aggregate_referral_status(referrals): referral_status_output = "" if referrals: all_successful = all(referral.status == Referral.STATUS_SUCCESSFUL for referral in referrals) if all_successful: referral_status_output = (dict(Referral.REFERRAL_STATUSES) [Referral.STATUS_SUCCESSFUL]) else: # Determine referral status based on the last FQHC referral referral_status_output = (dict(Referral.REFERRAL_STATUSES) [referrals.last().status]) else: referral_status_output = Referral.NO_REFERRALS_CURRENTLY return referral_status_output class FollowupRequest(Note, CompletableMixin): referral = models.ForeignKey(Referral) contact_instructions = models.TextField() MARK_DONE_URL_NAME = 'new-patient-contact' ADMIN_URL_NAME = '' def class_name(self): <|fim_middle|> def short_name(self): return "Referral" def summary(self): return self.contact_instructions def mark_done_url(self): return reverse(self.MARK_DONE_URL_NAME, args=(self.referral.patient.id, self.referral.id, self.id)) def admin_url(self): return reverse( 'admin:referral_followuprequest_change', args=(self.id,) ) def __str__(self): formatted_date = self.due_date.strftime("%D") return 'Followup with %s on %s about %s' % (self.patient, formatted_date, self.referral) class PatientContact(Note): followup_request = models.ForeignKey(FollowupRequest) referral = models.ForeignKey(Referral) contact_method = models.ForeignKey( ContactMethod, null=False, blank=False, help_text="What was the method of contact?") contact_status = models.ForeignKey( ContactResult, blank=False, null=False, help_text="Did you make contact with the patient about this referral?") PTSHOW_YES = "Y" PTSHOW_NO = "N" PTSHOW_OPTS = [(PTSHOW_YES, "Yes"), (PTSHOW_NO, "No")] has_appointment = models.CharField( choices=PTSHOW_OPTS, blank=True, max_length=1, verbose_name="Appointment scheduled?", help_text="Did the patient make an appointment?") no_apt_reason = models.ForeignKey( NoAptReason, blank=True, null=True, verbose_name="No appointment reason", help_text="If the patient didn't make an appointment, why not?") appointment_location = models.ManyToManyField( ReferralLocation, blank=True, help_text="Where did the patient make an appointment?") pt_showed = models.CharField( max_length=1, choices=PTSHOW_OPTS, blank=True, null=True, verbose_name="Appointment attended?", help_text="Did the patient show up to the appointment?") no_show_reason = models.ForeignKey( NoShowReason, blank=True, null=True, help_text="If the patient didn't go to the appointment, why not?") def short_text(self): """Return a short text description of this followup and what happened. Used on the patient chart view as the text in the list of followups. """ text = "" locations = " ,".join(map(str, self.appointment_location.all())) if self.pt_showed == self.PTSHOW_YES: text = "Patient went to appointment at " + locations + "." else: if self.has_appointment == self.PTSHOW_YES: text = ("Patient made appointment at " + locations + "but has not yet gone.") else: if self.contact_status.patient_reached: text = ("Successfully contacted patient but the " "patient has not made an appointment yet.") else: text = "Did not successfully contact patient" return text <|fim▁end|>
return self.__class__.__name__
<|file_name|>models.py<|end_file_name|><|fim▁begin|>"""Data models for referral system.""" from __future__ import unicode_literals from builtins import map from django.db import models from django.core.urlresolvers import reverse from pttrack.models import (ReferralType, ReferralLocation, Note, ContactMethod, CompletableMixin,) from followup.models import ContactResult, NoAptReason, NoShowReason class Referral(Note): """A record of a particular patient's referral to a particular center.""" STATUS_SUCCESSFUL = 'S' STATUS_PENDING = 'P' STATUS_UNSUCCESSFUL = 'U' # Status if there are no referrals of a specific type # Used in aggregate_referral_status NO_REFERRALS_CURRENTLY = "No referrals currently" REFERRAL_STATUSES = ( (STATUS_SUCCESSFUL, 'Successful'), (STATUS_PENDING, 'Pending'), (STATUS_UNSUCCESSFUL, 'Unsuccessful'), ) location = models.ManyToManyField(ReferralLocation) comments = models.TextField(blank=True) status = models.CharField( max_length=50, choices=REFERRAL_STATUSES, default=STATUS_PENDING) kind = models.ForeignKey( ReferralType, help_text="The kind of care the patient should recieve at the " "referral location.") def __str__(self): """Provides string to display on front end for referral. For FQHC referrals, returns referral kind and date. For non-FQHC referrals, returns referral location and date. """ formatted_date = self.written_datetime.strftime("%D") if self.kind.is_fqhc: return "%s referral on %s" % (self.kind, formatted_date) else: location_names = [loc.name for loc in self.location.all()] locations = " ,".join(location_names) return "Referral to %s on %s" % (locations, formatted_date) @staticmethod def aggregate_referral_status(referrals): referral_status_output = "" if referrals: all_successful = all(referral.status == Referral.STATUS_SUCCESSFUL for referral in referrals) if all_successful: referral_status_output = (dict(Referral.REFERRAL_STATUSES) [Referral.STATUS_SUCCESSFUL]) else: # Determine referral status based on the last FQHC referral referral_status_output = (dict(Referral.REFERRAL_STATUSES) [referrals.last().status]) else: referral_status_output = Referral.NO_REFERRALS_CURRENTLY return referral_status_output class FollowupRequest(Note, CompletableMixin): referral = models.ForeignKey(Referral) contact_instructions = models.TextField() MARK_DONE_URL_NAME = 'new-patient-contact' ADMIN_URL_NAME = '' def class_name(self): return self.__class__.__name__ def short_name(self): <|fim_middle|> def summary(self): return self.contact_instructions def mark_done_url(self): return reverse(self.MARK_DONE_URL_NAME, args=(self.referral.patient.id, self.referral.id, self.id)) def admin_url(self): return reverse( 'admin:referral_followuprequest_change', args=(self.id,) ) def __str__(self): formatted_date = self.due_date.strftime("%D") return 'Followup with %s on %s about %s' % (self.patient, formatted_date, self.referral) class PatientContact(Note): followup_request = models.ForeignKey(FollowupRequest) referral = models.ForeignKey(Referral) contact_method = models.ForeignKey( ContactMethod, null=False, blank=False, help_text="What was the method of contact?") contact_status = models.ForeignKey( ContactResult, blank=False, null=False, help_text="Did you make contact with the patient about this referral?") PTSHOW_YES = "Y" PTSHOW_NO = "N" PTSHOW_OPTS = [(PTSHOW_YES, "Yes"), (PTSHOW_NO, "No")] has_appointment = models.CharField( choices=PTSHOW_OPTS, blank=True, max_length=1, verbose_name="Appointment scheduled?", help_text="Did the patient make an appointment?") no_apt_reason = models.ForeignKey( NoAptReason, blank=True, null=True, verbose_name="No appointment reason", help_text="If the patient didn't make an appointment, why not?") appointment_location = models.ManyToManyField( ReferralLocation, blank=True, help_text="Where did the patient make an appointment?") pt_showed = models.CharField( max_length=1, choices=PTSHOW_OPTS, blank=True, null=True, verbose_name="Appointment attended?", help_text="Did the patient show up to the appointment?") no_show_reason = models.ForeignKey( NoShowReason, blank=True, null=True, help_text="If the patient didn't go to the appointment, why not?") def short_text(self): """Return a short text description of this followup and what happened. Used on the patient chart view as the text in the list of followups. """ text = "" locations = " ,".join(map(str, self.appointment_location.all())) if self.pt_showed == self.PTSHOW_YES: text = "Patient went to appointment at " + locations + "." else: if self.has_appointment == self.PTSHOW_YES: text = ("Patient made appointment at " + locations + "but has not yet gone.") else: if self.contact_status.patient_reached: text = ("Successfully contacted patient but the " "patient has not made an appointment yet.") else: text = "Did not successfully contact patient" return text <|fim▁end|>
return "Referral"
<|file_name|>models.py<|end_file_name|><|fim▁begin|>"""Data models for referral system.""" from __future__ import unicode_literals from builtins import map from django.db import models from django.core.urlresolvers import reverse from pttrack.models import (ReferralType, ReferralLocation, Note, ContactMethod, CompletableMixin,) from followup.models import ContactResult, NoAptReason, NoShowReason class Referral(Note): """A record of a particular patient's referral to a particular center.""" STATUS_SUCCESSFUL = 'S' STATUS_PENDING = 'P' STATUS_UNSUCCESSFUL = 'U' # Status if there are no referrals of a specific type # Used in aggregate_referral_status NO_REFERRALS_CURRENTLY = "No referrals currently" REFERRAL_STATUSES = ( (STATUS_SUCCESSFUL, 'Successful'), (STATUS_PENDING, 'Pending'), (STATUS_UNSUCCESSFUL, 'Unsuccessful'), ) location = models.ManyToManyField(ReferralLocation) comments = models.TextField(blank=True) status = models.CharField( max_length=50, choices=REFERRAL_STATUSES, default=STATUS_PENDING) kind = models.ForeignKey( ReferralType, help_text="The kind of care the patient should recieve at the " "referral location.") def __str__(self): """Provides string to display on front end for referral. For FQHC referrals, returns referral kind and date. For non-FQHC referrals, returns referral location and date. """ formatted_date = self.written_datetime.strftime("%D") if self.kind.is_fqhc: return "%s referral on %s" % (self.kind, formatted_date) else: location_names = [loc.name for loc in self.location.all()] locations = " ,".join(location_names) return "Referral to %s on %s" % (locations, formatted_date) @staticmethod def aggregate_referral_status(referrals): referral_status_output = "" if referrals: all_successful = all(referral.status == Referral.STATUS_SUCCESSFUL for referral in referrals) if all_successful: referral_status_output = (dict(Referral.REFERRAL_STATUSES) [Referral.STATUS_SUCCESSFUL]) else: # Determine referral status based on the last FQHC referral referral_status_output = (dict(Referral.REFERRAL_STATUSES) [referrals.last().status]) else: referral_status_output = Referral.NO_REFERRALS_CURRENTLY return referral_status_output class FollowupRequest(Note, CompletableMixin): referral = models.ForeignKey(Referral) contact_instructions = models.TextField() MARK_DONE_URL_NAME = 'new-patient-contact' ADMIN_URL_NAME = '' def class_name(self): return self.__class__.__name__ def short_name(self): return "Referral" def summary(self): <|fim_middle|> def mark_done_url(self): return reverse(self.MARK_DONE_URL_NAME, args=(self.referral.patient.id, self.referral.id, self.id)) def admin_url(self): return reverse( 'admin:referral_followuprequest_change', args=(self.id,) ) def __str__(self): formatted_date = self.due_date.strftime("%D") return 'Followup with %s on %s about %s' % (self.patient, formatted_date, self.referral) class PatientContact(Note): followup_request = models.ForeignKey(FollowupRequest) referral = models.ForeignKey(Referral) contact_method = models.ForeignKey( ContactMethod, null=False, blank=False, help_text="What was the method of contact?") contact_status = models.ForeignKey( ContactResult, blank=False, null=False, help_text="Did you make contact with the patient about this referral?") PTSHOW_YES = "Y" PTSHOW_NO = "N" PTSHOW_OPTS = [(PTSHOW_YES, "Yes"), (PTSHOW_NO, "No")] has_appointment = models.CharField( choices=PTSHOW_OPTS, blank=True, max_length=1, verbose_name="Appointment scheduled?", help_text="Did the patient make an appointment?") no_apt_reason = models.ForeignKey( NoAptReason, blank=True, null=True, verbose_name="No appointment reason", help_text="If the patient didn't make an appointment, why not?") appointment_location = models.ManyToManyField( ReferralLocation, blank=True, help_text="Where did the patient make an appointment?") pt_showed = models.CharField( max_length=1, choices=PTSHOW_OPTS, blank=True, null=True, verbose_name="Appointment attended?", help_text="Did the patient show up to the appointment?") no_show_reason = models.ForeignKey( NoShowReason, blank=True, null=True, help_text="If the patient didn't go to the appointment, why not?") def short_text(self): """Return a short text description of this followup and what happened. Used on the patient chart view as the text in the list of followups. """ text = "" locations = " ,".join(map(str, self.appointment_location.all())) if self.pt_showed == self.PTSHOW_YES: text = "Patient went to appointment at " + locations + "." else: if self.has_appointment == self.PTSHOW_YES: text = ("Patient made appointment at " + locations + "but has not yet gone.") else: if self.contact_status.patient_reached: text = ("Successfully contacted patient but the " "patient has not made an appointment yet.") else: text = "Did not successfully contact patient" return text <|fim▁end|>
return self.contact_instructions
<|file_name|>models.py<|end_file_name|><|fim▁begin|>"""Data models for referral system.""" from __future__ import unicode_literals from builtins import map from django.db import models from django.core.urlresolvers import reverse from pttrack.models import (ReferralType, ReferralLocation, Note, ContactMethod, CompletableMixin,) from followup.models import ContactResult, NoAptReason, NoShowReason class Referral(Note): """A record of a particular patient's referral to a particular center.""" STATUS_SUCCESSFUL = 'S' STATUS_PENDING = 'P' STATUS_UNSUCCESSFUL = 'U' # Status if there are no referrals of a specific type # Used in aggregate_referral_status NO_REFERRALS_CURRENTLY = "No referrals currently" REFERRAL_STATUSES = ( (STATUS_SUCCESSFUL, 'Successful'), (STATUS_PENDING, 'Pending'), (STATUS_UNSUCCESSFUL, 'Unsuccessful'), ) location = models.ManyToManyField(ReferralLocation) comments = models.TextField(blank=True) status = models.CharField( max_length=50, choices=REFERRAL_STATUSES, default=STATUS_PENDING) kind = models.ForeignKey( ReferralType, help_text="The kind of care the patient should recieve at the " "referral location.") def __str__(self): """Provides string to display on front end for referral. For FQHC referrals, returns referral kind and date. For non-FQHC referrals, returns referral location and date. """ formatted_date = self.written_datetime.strftime("%D") if self.kind.is_fqhc: return "%s referral on %s" % (self.kind, formatted_date) else: location_names = [loc.name for loc in self.location.all()] locations = " ,".join(location_names) return "Referral to %s on %s" % (locations, formatted_date) @staticmethod def aggregate_referral_status(referrals): referral_status_output = "" if referrals: all_successful = all(referral.status == Referral.STATUS_SUCCESSFUL for referral in referrals) if all_successful: referral_status_output = (dict(Referral.REFERRAL_STATUSES) [Referral.STATUS_SUCCESSFUL]) else: # Determine referral status based on the last FQHC referral referral_status_output = (dict(Referral.REFERRAL_STATUSES) [referrals.last().status]) else: referral_status_output = Referral.NO_REFERRALS_CURRENTLY return referral_status_output class FollowupRequest(Note, CompletableMixin): referral = models.ForeignKey(Referral) contact_instructions = models.TextField() MARK_DONE_URL_NAME = 'new-patient-contact' ADMIN_URL_NAME = '' def class_name(self): return self.__class__.__name__ def short_name(self): return "Referral" def summary(self): return self.contact_instructions def mark_done_url(self): <|fim_middle|> def admin_url(self): return reverse( 'admin:referral_followuprequest_change', args=(self.id,) ) def __str__(self): formatted_date = self.due_date.strftime("%D") return 'Followup with %s on %s about %s' % (self.patient, formatted_date, self.referral) class PatientContact(Note): followup_request = models.ForeignKey(FollowupRequest) referral = models.ForeignKey(Referral) contact_method = models.ForeignKey( ContactMethod, null=False, blank=False, help_text="What was the method of contact?") contact_status = models.ForeignKey( ContactResult, blank=False, null=False, help_text="Did you make contact with the patient about this referral?") PTSHOW_YES = "Y" PTSHOW_NO = "N" PTSHOW_OPTS = [(PTSHOW_YES, "Yes"), (PTSHOW_NO, "No")] has_appointment = models.CharField( choices=PTSHOW_OPTS, blank=True, max_length=1, verbose_name="Appointment scheduled?", help_text="Did the patient make an appointment?") no_apt_reason = models.ForeignKey( NoAptReason, blank=True, null=True, verbose_name="No appointment reason", help_text="If the patient didn't make an appointment, why not?") appointment_location = models.ManyToManyField( ReferralLocation, blank=True, help_text="Where did the patient make an appointment?") pt_showed = models.CharField( max_length=1, choices=PTSHOW_OPTS, blank=True, null=True, verbose_name="Appointment attended?", help_text="Did the patient show up to the appointment?") no_show_reason = models.ForeignKey( NoShowReason, blank=True, null=True, help_text="If the patient didn't go to the appointment, why not?") def short_text(self): """Return a short text description of this followup and what happened. Used on the patient chart view as the text in the list of followups. """ text = "" locations = " ,".join(map(str, self.appointment_location.all())) if self.pt_showed == self.PTSHOW_YES: text = "Patient went to appointment at " + locations + "." else: if self.has_appointment == self.PTSHOW_YES: text = ("Patient made appointment at " + locations + "but has not yet gone.") else: if self.contact_status.patient_reached: text = ("Successfully contacted patient but the " "patient has not made an appointment yet.") else: text = "Did not successfully contact patient" return text <|fim▁end|>
return reverse(self.MARK_DONE_URL_NAME, args=(self.referral.patient.id, self.referral.id, self.id))
<|file_name|>models.py<|end_file_name|><|fim▁begin|>"""Data models for referral system.""" from __future__ import unicode_literals from builtins import map from django.db import models from django.core.urlresolvers import reverse from pttrack.models import (ReferralType, ReferralLocation, Note, ContactMethod, CompletableMixin,) from followup.models import ContactResult, NoAptReason, NoShowReason class Referral(Note): """A record of a particular patient's referral to a particular center.""" STATUS_SUCCESSFUL = 'S' STATUS_PENDING = 'P' STATUS_UNSUCCESSFUL = 'U' # Status if there are no referrals of a specific type # Used in aggregate_referral_status NO_REFERRALS_CURRENTLY = "No referrals currently" REFERRAL_STATUSES = ( (STATUS_SUCCESSFUL, 'Successful'), (STATUS_PENDING, 'Pending'), (STATUS_UNSUCCESSFUL, 'Unsuccessful'), ) location = models.ManyToManyField(ReferralLocation) comments = models.TextField(blank=True) status = models.CharField( max_length=50, choices=REFERRAL_STATUSES, default=STATUS_PENDING) kind = models.ForeignKey( ReferralType, help_text="The kind of care the patient should recieve at the " "referral location.") def __str__(self): """Provides string to display on front end for referral. For FQHC referrals, returns referral kind and date. For non-FQHC referrals, returns referral location and date. """ formatted_date = self.written_datetime.strftime("%D") if self.kind.is_fqhc: return "%s referral on %s" % (self.kind, formatted_date) else: location_names = [loc.name for loc in self.location.all()] locations = " ,".join(location_names) return "Referral to %s on %s" % (locations, formatted_date) @staticmethod def aggregate_referral_status(referrals): referral_status_output = "" if referrals: all_successful = all(referral.status == Referral.STATUS_SUCCESSFUL for referral in referrals) if all_successful: referral_status_output = (dict(Referral.REFERRAL_STATUSES) [Referral.STATUS_SUCCESSFUL]) else: # Determine referral status based on the last FQHC referral referral_status_output = (dict(Referral.REFERRAL_STATUSES) [referrals.last().status]) else: referral_status_output = Referral.NO_REFERRALS_CURRENTLY return referral_status_output class FollowupRequest(Note, CompletableMixin): referral = models.ForeignKey(Referral) contact_instructions = models.TextField() MARK_DONE_URL_NAME = 'new-patient-contact' ADMIN_URL_NAME = '' def class_name(self): return self.__class__.__name__ def short_name(self): return "Referral" def summary(self): return self.contact_instructions def mark_done_url(self): return reverse(self.MARK_DONE_URL_NAME, args=(self.referral.patient.id, self.referral.id, self.id)) def admin_url(self): <|fim_middle|> def __str__(self): formatted_date = self.due_date.strftime("%D") return 'Followup with %s on %s about %s' % (self.patient, formatted_date, self.referral) class PatientContact(Note): followup_request = models.ForeignKey(FollowupRequest) referral = models.ForeignKey(Referral) contact_method = models.ForeignKey( ContactMethod, null=False, blank=False, help_text="What was the method of contact?") contact_status = models.ForeignKey( ContactResult, blank=False, null=False, help_text="Did you make contact with the patient about this referral?") PTSHOW_YES = "Y" PTSHOW_NO = "N" PTSHOW_OPTS = [(PTSHOW_YES, "Yes"), (PTSHOW_NO, "No")] has_appointment = models.CharField( choices=PTSHOW_OPTS, blank=True, max_length=1, verbose_name="Appointment scheduled?", help_text="Did the patient make an appointment?") no_apt_reason = models.ForeignKey( NoAptReason, blank=True, null=True, verbose_name="No appointment reason", help_text="If the patient didn't make an appointment, why not?") appointment_location = models.ManyToManyField( ReferralLocation, blank=True, help_text="Where did the patient make an appointment?") pt_showed = models.CharField( max_length=1, choices=PTSHOW_OPTS, blank=True, null=True, verbose_name="Appointment attended?", help_text="Did the patient show up to the appointment?") no_show_reason = models.ForeignKey( NoShowReason, blank=True, null=True, help_text="If the patient didn't go to the appointment, why not?") def short_text(self): """Return a short text description of this followup and what happened. Used on the patient chart view as the text in the list of followups. """ text = "" locations = " ,".join(map(str, self.appointment_location.all())) if self.pt_showed == self.PTSHOW_YES: text = "Patient went to appointment at " + locations + "." else: if self.has_appointment == self.PTSHOW_YES: text = ("Patient made appointment at " + locations + "but has not yet gone.") else: if self.contact_status.patient_reached: text = ("Successfully contacted patient but the " "patient has not made an appointment yet.") else: text = "Did not successfully contact patient" return text <|fim▁end|>
return reverse( 'admin:referral_followuprequest_change', args=(self.id,) )
<|file_name|>models.py<|end_file_name|><|fim▁begin|>"""Data models for referral system.""" from __future__ import unicode_literals from builtins import map from django.db import models from django.core.urlresolvers import reverse from pttrack.models import (ReferralType, ReferralLocation, Note, ContactMethod, CompletableMixin,) from followup.models import ContactResult, NoAptReason, NoShowReason class Referral(Note): """A record of a particular patient's referral to a particular center.""" STATUS_SUCCESSFUL = 'S' STATUS_PENDING = 'P' STATUS_UNSUCCESSFUL = 'U' # Status if there are no referrals of a specific type # Used in aggregate_referral_status NO_REFERRALS_CURRENTLY = "No referrals currently" REFERRAL_STATUSES = ( (STATUS_SUCCESSFUL, 'Successful'), (STATUS_PENDING, 'Pending'), (STATUS_UNSUCCESSFUL, 'Unsuccessful'), ) location = models.ManyToManyField(ReferralLocation) comments = models.TextField(blank=True) status = models.CharField( max_length=50, choices=REFERRAL_STATUSES, default=STATUS_PENDING) kind = models.ForeignKey( ReferralType, help_text="The kind of care the patient should recieve at the " "referral location.") def __str__(self): """Provides string to display on front end for referral. For FQHC referrals, returns referral kind and date. For non-FQHC referrals, returns referral location and date. """ formatted_date = self.written_datetime.strftime("%D") if self.kind.is_fqhc: return "%s referral on %s" % (self.kind, formatted_date) else: location_names = [loc.name for loc in self.location.all()] locations = " ,".join(location_names) return "Referral to %s on %s" % (locations, formatted_date) @staticmethod def aggregate_referral_status(referrals): referral_status_output = "" if referrals: all_successful = all(referral.status == Referral.STATUS_SUCCESSFUL for referral in referrals) if all_successful: referral_status_output = (dict(Referral.REFERRAL_STATUSES) [Referral.STATUS_SUCCESSFUL]) else: # Determine referral status based on the last FQHC referral referral_status_output = (dict(Referral.REFERRAL_STATUSES) [referrals.last().status]) else: referral_status_output = Referral.NO_REFERRALS_CURRENTLY return referral_status_output class FollowupRequest(Note, CompletableMixin): referral = models.ForeignKey(Referral) contact_instructions = models.TextField() MARK_DONE_URL_NAME = 'new-patient-contact' ADMIN_URL_NAME = '' def class_name(self): return self.__class__.__name__ def short_name(self): return "Referral" def summary(self): return self.contact_instructions def mark_done_url(self): return reverse(self.MARK_DONE_URL_NAME, args=(self.referral.patient.id, self.referral.id, self.id)) def admin_url(self): return reverse( 'admin:referral_followuprequest_change', args=(self.id,) ) def __str__(self): <|fim_middle|> class PatientContact(Note): followup_request = models.ForeignKey(FollowupRequest) referral = models.ForeignKey(Referral) contact_method = models.ForeignKey( ContactMethod, null=False, blank=False, help_text="What was the method of contact?") contact_status = models.ForeignKey( ContactResult, blank=False, null=False, help_text="Did you make contact with the patient about this referral?") PTSHOW_YES = "Y" PTSHOW_NO = "N" PTSHOW_OPTS = [(PTSHOW_YES, "Yes"), (PTSHOW_NO, "No")] has_appointment = models.CharField( choices=PTSHOW_OPTS, blank=True, max_length=1, verbose_name="Appointment scheduled?", help_text="Did the patient make an appointment?") no_apt_reason = models.ForeignKey( NoAptReason, blank=True, null=True, verbose_name="No appointment reason", help_text="If the patient didn't make an appointment, why not?") appointment_location = models.ManyToManyField( ReferralLocation, blank=True, help_text="Where did the patient make an appointment?") pt_showed = models.CharField( max_length=1, choices=PTSHOW_OPTS, blank=True, null=True, verbose_name="Appointment attended?", help_text="Did the patient show up to the appointment?") no_show_reason = models.ForeignKey( NoShowReason, blank=True, null=True, help_text="If the patient didn't go to the appointment, why not?") def short_text(self): """Return a short text description of this followup and what happened. Used on the patient chart view as the text in the list of followups. """ text = "" locations = " ,".join(map(str, self.appointment_location.all())) if self.pt_showed == self.PTSHOW_YES: text = "Patient went to appointment at " + locations + "." else: if self.has_appointment == self.PTSHOW_YES: text = ("Patient made appointment at " + locations + "but has not yet gone.") else: if self.contact_status.patient_reached: text = ("Successfully contacted patient but the " "patient has not made an appointment yet.") else: text = "Did not successfully contact patient" return text <|fim▁end|>
formatted_date = self.due_date.strftime("%D") return 'Followup with %s on %s about %s' % (self.patient, formatted_date, self.referral)
<|file_name|>models.py<|end_file_name|><|fim▁begin|>"""Data models for referral system.""" from __future__ import unicode_literals from builtins import map from django.db import models from django.core.urlresolvers import reverse from pttrack.models import (ReferralType, ReferralLocation, Note, ContactMethod, CompletableMixin,) from followup.models import ContactResult, NoAptReason, NoShowReason class Referral(Note): """A record of a particular patient's referral to a particular center.""" STATUS_SUCCESSFUL = 'S' STATUS_PENDING = 'P' STATUS_UNSUCCESSFUL = 'U' # Status if there are no referrals of a specific type # Used in aggregate_referral_status NO_REFERRALS_CURRENTLY = "No referrals currently" REFERRAL_STATUSES = ( (STATUS_SUCCESSFUL, 'Successful'), (STATUS_PENDING, 'Pending'), (STATUS_UNSUCCESSFUL, 'Unsuccessful'), ) location = models.ManyToManyField(ReferralLocation) comments = models.TextField(blank=True) status = models.CharField( max_length=50, choices=REFERRAL_STATUSES, default=STATUS_PENDING) kind = models.ForeignKey( ReferralType, help_text="The kind of care the patient should recieve at the " "referral location.") def __str__(self): """Provides string to display on front end for referral. For FQHC referrals, returns referral kind and date. For non-FQHC referrals, returns referral location and date. """ formatted_date = self.written_datetime.strftime("%D") if self.kind.is_fqhc: return "%s referral on %s" % (self.kind, formatted_date) else: location_names = [loc.name for loc in self.location.all()] locations = " ,".join(location_names) return "Referral to %s on %s" % (locations, formatted_date) @staticmethod def aggregate_referral_status(referrals): referral_status_output = "" if referrals: all_successful = all(referral.status == Referral.STATUS_SUCCESSFUL for referral in referrals) if all_successful: referral_status_output = (dict(Referral.REFERRAL_STATUSES) [Referral.STATUS_SUCCESSFUL]) else: # Determine referral status based on the last FQHC referral referral_status_output = (dict(Referral.REFERRAL_STATUSES) [referrals.last().status]) else: referral_status_output = Referral.NO_REFERRALS_CURRENTLY return referral_status_output class FollowupRequest(Note, CompletableMixin): referral = models.ForeignKey(Referral) contact_instructions = models.TextField() MARK_DONE_URL_NAME = 'new-patient-contact' ADMIN_URL_NAME = '' def class_name(self): return self.__class__.__name__ def short_name(self): return "Referral" def summary(self): return self.contact_instructions def mark_done_url(self): return reverse(self.MARK_DONE_URL_NAME, args=(self.referral.patient.id, self.referral.id, self.id)) def admin_url(self): return reverse( 'admin:referral_followuprequest_change', args=(self.id,) ) def __str__(self): formatted_date = self.due_date.strftime("%D") return 'Followup with %s on %s about %s' % (self.patient, formatted_date, self.referral) class PatientContact(Note): <|fim_middle|> <|fim▁end|>
followup_request = models.ForeignKey(FollowupRequest) referral = models.ForeignKey(Referral) contact_method = models.ForeignKey( ContactMethod, null=False, blank=False, help_text="What was the method of contact?") contact_status = models.ForeignKey( ContactResult, blank=False, null=False, help_text="Did you make contact with the patient about this referral?") PTSHOW_YES = "Y" PTSHOW_NO = "N" PTSHOW_OPTS = [(PTSHOW_YES, "Yes"), (PTSHOW_NO, "No")] has_appointment = models.CharField( choices=PTSHOW_OPTS, blank=True, max_length=1, verbose_name="Appointment scheduled?", help_text="Did the patient make an appointment?") no_apt_reason = models.ForeignKey( NoAptReason, blank=True, null=True, verbose_name="No appointment reason", help_text="If the patient didn't make an appointment, why not?") appointment_location = models.ManyToManyField( ReferralLocation, blank=True, help_text="Where did the patient make an appointment?") pt_showed = models.CharField( max_length=1, choices=PTSHOW_OPTS, blank=True, null=True, verbose_name="Appointment attended?", help_text="Did the patient show up to the appointment?") no_show_reason = models.ForeignKey( NoShowReason, blank=True, null=True, help_text="If the patient didn't go to the appointment, why not?") def short_text(self): """Return a short text description of this followup and what happened. Used on the patient chart view as the text in the list of followups. """ text = "" locations = " ,".join(map(str, self.appointment_location.all())) if self.pt_showed == self.PTSHOW_YES: text = "Patient went to appointment at " + locations + "." else: if self.has_appointment == self.PTSHOW_YES: text = ("Patient made appointment at " + locations + "but has not yet gone.") else: if self.contact_status.patient_reached: text = ("Successfully contacted patient but the " "patient has not made an appointment yet.") else: text = "Did not successfully contact patient" return text
<|file_name|>models.py<|end_file_name|><|fim▁begin|>"""Data models for referral system.""" from __future__ import unicode_literals from builtins import map from django.db import models from django.core.urlresolvers import reverse from pttrack.models import (ReferralType, ReferralLocation, Note, ContactMethod, CompletableMixin,) from followup.models import ContactResult, NoAptReason, NoShowReason class Referral(Note): """A record of a particular patient's referral to a particular center.""" STATUS_SUCCESSFUL = 'S' STATUS_PENDING = 'P' STATUS_UNSUCCESSFUL = 'U' # Status if there are no referrals of a specific type # Used in aggregate_referral_status NO_REFERRALS_CURRENTLY = "No referrals currently" REFERRAL_STATUSES = ( (STATUS_SUCCESSFUL, 'Successful'), (STATUS_PENDING, 'Pending'), (STATUS_UNSUCCESSFUL, 'Unsuccessful'), ) location = models.ManyToManyField(ReferralLocation) comments = models.TextField(blank=True) status = models.CharField( max_length=50, choices=REFERRAL_STATUSES, default=STATUS_PENDING) kind = models.ForeignKey( ReferralType, help_text="The kind of care the patient should recieve at the " "referral location.") def __str__(self): """Provides string to display on front end for referral. For FQHC referrals, returns referral kind and date. For non-FQHC referrals, returns referral location and date. """ formatted_date = self.written_datetime.strftime("%D") if self.kind.is_fqhc: return "%s referral on %s" % (self.kind, formatted_date) else: location_names = [loc.name for loc in self.location.all()] locations = " ,".join(location_names) return "Referral to %s on %s" % (locations, formatted_date) @staticmethod def aggregate_referral_status(referrals): referral_status_output = "" if referrals: all_successful = all(referral.status == Referral.STATUS_SUCCESSFUL for referral in referrals) if all_successful: referral_status_output = (dict(Referral.REFERRAL_STATUSES) [Referral.STATUS_SUCCESSFUL]) else: # Determine referral status based on the last FQHC referral referral_status_output = (dict(Referral.REFERRAL_STATUSES) [referrals.last().status]) else: referral_status_output = Referral.NO_REFERRALS_CURRENTLY return referral_status_output class FollowupRequest(Note, CompletableMixin): referral = models.ForeignKey(Referral) contact_instructions = models.TextField() MARK_DONE_URL_NAME = 'new-patient-contact' ADMIN_URL_NAME = '' def class_name(self): return self.__class__.__name__ def short_name(self): return "Referral" def summary(self): return self.contact_instructions def mark_done_url(self): return reverse(self.MARK_DONE_URL_NAME, args=(self.referral.patient.id, self.referral.id, self.id)) def admin_url(self): return reverse( 'admin:referral_followuprequest_change', args=(self.id,) ) def __str__(self): formatted_date = self.due_date.strftime("%D") return 'Followup with %s on %s about %s' % (self.patient, formatted_date, self.referral) class PatientContact(Note): followup_request = models.ForeignKey(FollowupRequest) referral = models.ForeignKey(Referral) contact_method = models.ForeignKey( ContactMethod, null=False, blank=False, help_text="What was the method of contact?") contact_status = models.ForeignKey( ContactResult, blank=False, null=False, help_text="Did you make contact with the patient about this referral?") PTSHOW_YES = "Y" PTSHOW_NO = "N" PTSHOW_OPTS = [(PTSHOW_YES, "Yes"), (PTSHOW_NO, "No")] has_appointment = models.CharField( choices=PTSHOW_OPTS, blank=True, max_length=1, verbose_name="Appointment scheduled?", help_text="Did the patient make an appointment?") no_apt_reason = models.ForeignKey( NoAptReason, blank=True, null=True, verbose_name="No appointment reason", help_text="If the patient didn't make an appointment, why not?") appointment_location = models.ManyToManyField( ReferralLocation, blank=True, help_text="Where did the patient make an appointment?") pt_showed = models.CharField( max_length=1, choices=PTSHOW_OPTS, blank=True, null=True, verbose_name="Appointment attended?", help_text="Did the patient show up to the appointment?") no_show_reason = models.ForeignKey( NoShowReason, blank=True, null=True, help_text="If the patient didn't go to the appointment, why not?") def short_text(self): <|fim_middle|> <|fim▁end|>
"""Return a short text description of this followup and what happened. Used on the patient chart view as the text in the list of followups. """ text = "" locations = " ,".join(map(str, self.appointment_location.all())) if self.pt_showed == self.PTSHOW_YES: text = "Patient went to appointment at " + locations + "." else: if self.has_appointment == self.PTSHOW_YES: text = ("Patient made appointment at " + locations + "but has not yet gone.") else: if self.contact_status.patient_reached: text = ("Successfully contacted patient but the " "patient has not made an appointment yet.") else: text = "Did not successfully contact patient" return text
<|file_name|>models.py<|end_file_name|><|fim▁begin|>"""Data models for referral system.""" from __future__ import unicode_literals from builtins import map from django.db import models from django.core.urlresolvers import reverse from pttrack.models import (ReferralType, ReferralLocation, Note, ContactMethod, CompletableMixin,) from followup.models import ContactResult, NoAptReason, NoShowReason class Referral(Note): """A record of a particular patient's referral to a particular center.""" STATUS_SUCCESSFUL = 'S' STATUS_PENDING = 'P' STATUS_UNSUCCESSFUL = 'U' # Status if there are no referrals of a specific type # Used in aggregate_referral_status NO_REFERRALS_CURRENTLY = "No referrals currently" REFERRAL_STATUSES = ( (STATUS_SUCCESSFUL, 'Successful'), (STATUS_PENDING, 'Pending'), (STATUS_UNSUCCESSFUL, 'Unsuccessful'), ) location = models.ManyToManyField(ReferralLocation) comments = models.TextField(blank=True) status = models.CharField( max_length=50, choices=REFERRAL_STATUSES, default=STATUS_PENDING) kind = models.ForeignKey( ReferralType, help_text="The kind of care the patient should recieve at the " "referral location.") def __str__(self): """Provides string to display on front end for referral. For FQHC referrals, returns referral kind and date. For non-FQHC referrals, returns referral location and date. """ formatted_date = self.written_datetime.strftime("%D") if self.kind.is_fqhc: <|fim_middle|> else: location_names = [loc.name for loc in self.location.all()] locations = " ,".join(location_names) return "Referral to %s on %s" % (locations, formatted_date) @staticmethod def aggregate_referral_status(referrals): referral_status_output = "" if referrals: all_successful = all(referral.status == Referral.STATUS_SUCCESSFUL for referral in referrals) if all_successful: referral_status_output = (dict(Referral.REFERRAL_STATUSES) [Referral.STATUS_SUCCESSFUL]) else: # Determine referral status based on the last FQHC referral referral_status_output = (dict(Referral.REFERRAL_STATUSES) [referrals.last().status]) else: referral_status_output = Referral.NO_REFERRALS_CURRENTLY return referral_status_output class FollowupRequest(Note, CompletableMixin): referral = models.ForeignKey(Referral) contact_instructions = models.TextField() MARK_DONE_URL_NAME = 'new-patient-contact' ADMIN_URL_NAME = '' def class_name(self): return self.__class__.__name__ def short_name(self): return "Referral" def summary(self): return self.contact_instructions def mark_done_url(self): return reverse(self.MARK_DONE_URL_NAME, args=(self.referral.patient.id, self.referral.id, self.id)) def admin_url(self): return reverse( 'admin:referral_followuprequest_change', args=(self.id,) ) def __str__(self): formatted_date = self.due_date.strftime("%D") return 'Followup with %s on %s about %s' % (self.patient, formatted_date, self.referral) class PatientContact(Note): followup_request = models.ForeignKey(FollowupRequest) referral = models.ForeignKey(Referral) contact_method = models.ForeignKey( ContactMethod, null=False, blank=False, help_text="What was the method of contact?") contact_status = models.ForeignKey( ContactResult, blank=False, null=False, help_text="Did you make contact with the patient about this referral?") PTSHOW_YES = "Y" PTSHOW_NO = "N" PTSHOW_OPTS = [(PTSHOW_YES, "Yes"), (PTSHOW_NO, "No")] has_appointment = models.CharField( choices=PTSHOW_OPTS, blank=True, max_length=1, verbose_name="Appointment scheduled?", help_text="Did the patient make an appointment?") no_apt_reason = models.ForeignKey( NoAptReason, blank=True, null=True, verbose_name="No appointment reason", help_text="If the patient didn't make an appointment, why not?") appointment_location = models.ManyToManyField( ReferralLocation, blank=True, help_text="Where did the patient make an appointment?") pt_showed = models.CharField( max_length=1, choices=PTSHOW_OPTS, blank=True, null=True, verbose_name="Appointment attended?", help_text="Did the patient show up to the appointment?") no_show_reason = models.ForeignKey( NoShowReason, blank=True, null=True, help_text="If the patient didn't go to the appointment, why not?") def short_text(self): """Return a short text description of this followup and what happened. Used on the patient chart view as the text in the list of followups. """ text = "" locations = " ,".join(map(str, self.appointment_location.all())) if self.pt_showed == self.PTSHOW_YES: text = "Patient went to appointment at " + locations + "." else: if self.has_appointment == self.PTSHOW_YES: text = ("Patient made appointment at " + locations + "but has not yet gone.") else: if self.contact_status.patient_reached: text = ("Successfully contacted patient but the " "patient has not made an appointment yet.") else: text = "Did not successfully contact patient" return text <|fim▁end|>
return "%s referral on %s" % (self.kind, formatted_date)
<|file_name|>models.py<|end_file_name|><|fim▁begin|>"""Data models for referral system.""" from __future__ import unicode_literals from builtins import map from django.db import models from django.core.urlresolvers import reverse from pttrack.models import (ReferralType, ReferralLocation, Note, ContactMethod, CompletableMixin,) from followup.models import ContactResult, NoAptReason, NoShowReason class Referral(Note): """A record of a particular patient's referral to a particular center.""" STATUS_SUCCESSFUL = 'S' STATUS_PENDING = 'P' STATUS_UNSUCCESSFUL = 'U' # Status if there are no referrals of a specific type # Used in aggregate_referral_status NO_REFERRALS_CURRENTLY = "No referrals currently" REFERRAL_STATUSES = ( (STATUS_SUCCESSFUL, 'Successful'), (STATUS_PENDING, 'Pending'), (STATUS_UNSUCCESSFUL, 'Unsuccessful'), ) location = models.ManyToManyField(ReferralLocation) comments = models.TextField(blank=True) status = models.CharField( max_length=50, choices=REFERRAL_STATUSES, default=STATUS_PENDING) kind = models.ForeignKey( ReferralType, help_text="The kind of care the patient should recieve at the " "referral location.") def __str__(self): """Provides string to display on front end for referral. For FQHC referrals, returns referral kind and date. For non-FQHC referrals, returns referral location and date. """ formatted_date = self.written_datetime.strftime("%D") if self.kind.is_fqhc: return "%s referral on %s" % (self.kind, formatted_date) else: <|fim_middle|> @staticmethod def aggregate_referral_status(referrals): referral_status_output = "" if referrals: all_successful = all(referral.status == Referral.STATUS_SUCCESSFUL for referral in referrals) if all_successful: referral_status_output = (dict(Referral.REFERRAL_STATUSES) [Referral.STATUS_SUCCESSFUL]) else: # Determine referral status based on the last FQHC referral referral_status_output = (dict(Referral.REFERRAL_STATUSES) [referrals.last().status]) else: referral_status_output = Referral.NO_REFERRALS_CURRENTLY return referral_status_output class FollowupRequest(Note, CompletableMixin): referral = models.ForeignKey(Referral) contact_instructions = models.TextField() MARK_DONE_URL_NAME = 'new-patient-contact' ADMIN_URL_NAME = '' def class_name(self): return self.__class__.__name__ def short_name(self): return "Referral" def summary(self): return self.contact_instructions def mark_done_url(self): return reverse(self.MARK_DONE_URL_NAME, args=(self.referral.patient.id, self.referral.id, self.id)) def admin_url(self): return reverse( 'admin:referral_followuprequest_change', args=(self.id,) ) def __str__(self): formatted_date = self.due_date.strftime("%D") return 'Followup with %s on %s about %s' % (self.patient, formatted_date, self.referral) class PatientContact(Note): followup_request = models.ForeignKey(FollowupRequest) referral = models.ForeignKey(Referral) contact_method = models.ForeignKey( ContactMethod, null=False, blank=False, help_text="What was the method of contact?") contact_status = models.ForeignKey( ContactResult, blank=False, null=False, help_text="Did you make contact with the patient about this referral?") PTSHOW_YES = "Y" PTSHOW_NO = "N" PTSHOW_OPTS = [(PTSHOW_YES, "Yes"), (PTSHOW_NO, "No")] has_appointment = models.CharField( choices=PTSHOW_OPTS, blank=True, max_length=1, verbose_name="Appointment scheduled?", help_text="Did the patient make an appointment?") no_apt_reason = models.ForeignKey( NoAptReason, blank=True, null=True, verbose_name="No appointment reason", help_text="If the patient didn't make an appointment, why not?") appointment_location = models.ManyToManyField( ReferralLocation, blank=True, help_text="Where did the patient make an appointment?") pt_showed = models.CharField( max_length=1, choices=PTSHOW_OPTS, blank=True, null=True, verbose_name="Appointment attended?", help_text="Did the patient show up to the appointment?") no_show_reason = models.ForeignKey( NoShowReason, blank=True, null=True, help_text="If the patient didn't go to the appointment, why not?") def short_text(self): """Return a short text description of this followup and what happened. Used on the patient chart view as the text in the list of followups. """ text = "" locations = " ,".join(map(str, self.appointment_location.all())) if self.pt_showed == self.PTSHOW_YES: text = "Patient went to appointment at " + locations + "." else: if self.has_appointment == self.PTSHOW_YES: text = ("Patient made appointment at " + locations + "but has not yet gone.") else: if self.contact_status.patient_reached: text = ("Successfully contacted patient but the " "patient has not made an appointment yet.") else: text = "Did not successfully contact patient" return text <|fim▁end|>
location_names = [loc.name for loc in self.location.all()] locations = " ,".join(location_names) return "Referral to %s on %s" % (locations, formatted_date)
<|file_name|>models.py<|end_file_name|><|fim▁begin|>"""Data models for referral system.""" from __future__ import unicode_literals from builtins import map from django.db import models from django.core.urlresolvers import reverse from pttrack.models import (ReferralType, ReferralLocation, Note, ContactMethod, CompletableMixin,) from followup.models import ContactResult, NoAptReason, NoShowReason class Referral(Note): """A record of a particular patient's referral to a particular center.""" STATUS_SUCCESSFUL = 'S' STATUS_PENDING = 'P' STATUS_UNSUCCESSFUL = 'U' # Status if there are no referrals of a specific type # Used in aggregate_referral_status NO_REFERRALS_CURRENTLY = "No referrals currently" REFERRAL_STATUSES = ( (STATUS_SUCCESSFUL, 'Successful'), (STATUS_PENDING, 'Pending'), (STATUS_UNSUCCESSFUL, 'Unsuccessful'), ) location = models.ManyToManyField(ReferralLocation) comments = models.TextField(blank=True) status = models.CharField( max_length=50, choices=REFERRAL_STATUSES, default=STATUS_PENDING) kind = models.ForeignKey( ReferralType, help_text="The kind of care the patient should recieve at the " "referral location.") def __str__(self): """Provides string to display on front end for referral. For FQHC referrals, returns referral kind and date. For non-FQHC referrals, returns referral location and date. """ formatted_date = self.written_datetime.strftime("%D") if self.kind.is_fqhc: return "%s referral on %s" % (self.kind, formatted_date) else: location_names = [loc.name for loc in self.location.all()] locations = " ,".join(location_names) return "Referral to %s on %s" % (locations, formatted_date) @staticmethod def aggregate_referral_status(referrals): referral_status_output = "" if referrals: <|fim_middle|> else: referral_status_output = Referral.NO_REFERRALS_CURRENTLY return referral_status_output class FollowupRequest(Note, CompletableMixin): referral = models.ForeignKey(Referral) contact_instructions = models.TextField() MARK_DONE_URL_NAME = 'new-patient-contact' ADMIN_URL_NAME = '' def class_name(self): return self.__class__.__name__ def short_name(self): return "Referral" def summary(self): return self.contact_instructions def mark_done_url(self): return reverse(self.MARK_DONE_URL_NAME, args=(self.referral.patient.id, self.referral.id, self.id)) def admin_url(self): return reverse( 'admin:referral_followuprequest_change', args=(self.id,) ) def __str__(self): formatted_date = self.due_date.strftime("%D") return 'Followup with %s on %s about %s' % (self.patient, formatted_date, self.referral) class PatientContact(Note): followup_request = models.ForeignKey(FollowupRequest) referral = models.ForeignKey(Referral) contact_method = models.ForeignKey( ContactMethod, null=False, blank=False, help_text="What was the method of contact?") contact_status = models.ForeignKey( ContactResult, blank=False, null=False, help_text="Did you make contact with the patient about this referral?") PTSHOW_YES = "Y" PTSHOW_NO = "N" PTSHOW_OPTS = [(PTSHOW_YES, "Yes"), (PTSHOW_NO, "No")] has_appointment = models.CharField( choices=PTSHOW_OPTS, blank=True, max_length=1, verbose_name="Appointment scheduled?", help_text="Did the patient make an appointment?") no_apt_reason = models.ForeignKey( NoAptReason, blank=True, null=True, verbose_name="No appointment reason", help_text="If the patient didn't make an appointment, why not?") appointment_location = models.ManyToManyField( ReferralLocation, blank=True, help_text="Where did the patient make an appointment?") pt_showed = models.CharField( max_length=1, choices=PTSHOW_OPTS, blank=True, null=True, verbose_name="Appointment attended?", help_text="Did the patient show up to the appointment?") no_show_reason = models.ForeignKey( NoShowReason, blank=True, null=True, help_text="If the patient didn't go to the appointment, why not?") def short_text(self): """Return a short text description of this followup and what happened. Used on the patient chart view as the text in the list of followups. """ text = "" locations = " ,".join(map(str, self.appointment_location.all())) if self.pt_showed == self.PTSHOW_YES: text = "Patient went to appointment at " + locations + "." else: if self.has_appointment == self.PTSHOW_YES: text = ("Patient made appointment at " + locations + "but has not yet gone.") else: if self.contact_status.patient_reached: text = ("Successfully contacted patient but the " "patient has not made an appointment yet.") else: text = "Did not successfully contact patient" return text <|fim▁end|>
all_successful = all(referral.status == Referral.STATUS_SUCCESSFUL for referral in referrals) if all_successful: referral_status_output = (dict(Referral.REFERRAL_STATUSES) [Referral.STATUS_SUCCESSFUL]) else: # Determine referral status based on the last FQHC referral referral_status_output = (dict(Referral.REFERRAL_STATUSES) [referrals.last().status])
<|file_name|>models.py<|end_file_name|><|fim▁begin|>"""Data models for referral system.""" from __future__ import unicode_literals from builtins import map from django.db import models from django.core.urlresolvers import reverse from pttrack.models import (ReferralType, ReferralLocation, Note, ContactMethod, CompletableMixin,) from followup.models import ContactResult, NoAptReason, NoShowReason class Referral(Note): """A record of a particular patient's referral to a particular center.""" STATUS_SUCCESSFUL = 'S' STATUS_PENDING = 'P' STATUS_UNSUCCESSFUL = 'U' # Status if there are no referrals of a specific type # Used in aggregate_referral_status NO_REFERRALS_CURRENTLY = "No referrals currently" REFERRAL_STATUSES = ( (STATUS_SUCCESSFUL, 'Successful'), (STATUS_PENDING, 'Pending'), (STATUS_UNSUCCESSFUL, 'Unsuccessful'), ) location = models.ManyToManyField(ReferralLocation) comments = models.TextField(blank=True) status = models.CharField( max_length=50, choices=REFERRAL_STATUSES, default=STATUS_PENDING) kind = models.ForeignKey( ReferralType, help_text="The kind of care the patient should recieve at the " "referral location.") def __str__(self): """Provides string to display on front end for referral. For FQHC referrals, returns referral kind and date. For non-FQHC referrals, returns referral location and date. """ formatted_date = self.written_datetime.strftime("%D") if self.kind.is_fqhc: return "%s referral on %s" % (self.kind, formatted_date) else: location_names = [loc.name for loc in self.location.all()] locations = " ,".join(location_names) return "Referral to %s on %s" % (locations, formatted_date) @staticmethod def aggregate_referral_status(referrals): referral_status_output = "" if referrals: all_successful = all(referral.status == Referral.STATUS_SUCCESSFUL for referral in referrals) if all_successful: <|fim_middle|> else: # Determine referral status based on the last FQHC referral referral_status_output = (dict(Referral.REFERRAL_STATUSES) [referrals.last().status]) else: referral_status_output = Referral.NO_REFERRALS_CURRENTLY return referral_status_output class FollowupRequest(Note, CompletableMixin): referral = models.ForeignKey(Referral) contact_instructions = models.TextField() MARK_DONE_URL_NAME = 'new-patient-contact' ADMIN_URL_NAME = '' def class_name(self): return self.__class__.__name__ def short_name(self): return "Referral" def summary(self): return self.contact_instructions def mark_done_url(self): return reverse(self.MARK_DONE_URL_NAME, args=(self.referral.patient.id, self.referral.id, self.id)) def admin_url(self): return reverse( 'admin:referral_followuprequest_change', args=(self.id,) ) def __str__(self): formatted_date = self.due_date.strftime("%D") return 'Followup with %s on %s about %s' % (self.patient, formatted_date, self.referral) class PatientContact(Note): followup_request = models.ForeignKey(FollowupRequest) referral = models.ForeignKey(Referral) contact_method = models.ForeignKey( ContactMethod, null=False, blank=False, help_text="What was the method of contact?") contact_status = models.ForeignKey( ContactResult, blank=False, null=False, help_text="Did you make contact with the patient about this referral?") PTSHOW_YES = "Y" PTSHOW_NO = "N" PTSHOW_OPTS = [(PTSHOW_YES, "Yes"), (PTSHOW_NO, "No")] has_appointment = models.CharField( choices=PTSHOW_OPTS, blank=True, max_length=1, verbose_name="Appointment scheduled?", help_text="Did the patient make an appointment?") no_apt_reason = models.ForeignKey( NoAptReason, blank=True, null=True, verbose_name="No appointment reason", help_text="If the patient didn't make an appointment, why not?") appointment_location = models.ManyToManyField( ReferralLocation, blank=True, help_text="Where did the patient make an appointment?") pt_showed = models.CharField( max_length=1, choices=PTSHOW_OPTS, blank=True, null=True, verbose_name="Appointment attended?", help_text="Did the patient show up to the appointment?") no_show_reason = models.ForeignKey( NoShowReason, blank=True, null=True, help_text="If the patient didn't go to the appointment, why not?") def short_text(self): """Return a short text description of this followup and what happened. Used on the patient chart view as the text in the list of followups. """ text = "" locations = " ,".join(map(str, self.appointment_location.all())) if self.pt_showed == self.PTSHOW_YES: text = "Patient went to appointment at " + locations + "." else: if self.has_appointment == self.PTSHOW_YES: text = ("Patient made appointment at " + locations + "but has not yet gone.") else: if self.contact_status.patient_reached: text = ("Successfully contacted patient but the " "patient has not made an appointment yet.") else: text = "Did not successfully contact patient" return text <|fim▁end|>
referral_status_output = (dict(Referral.REFERRAL_STATUSES) [Referral.STATUS_SUCCESSFUL])
<|file_name|>models.py<|end_file_name|><|fim▁begin|>"""Data models for referral system.""" from __future__ import unicode_literals from builtins import map from django.db import models from django.core.urlresolvers import reverse from pttrack.models import (ReferralType, ReferralLocation, Note, ContactMethod, CompletableMixin,) from followup.models import ContactResult, NoAptReason, NoShowReason class Referral(Note): """A record of a particular patient's referral to a particular center.""" STATUS_SUCCESSFUL = 'S' STATUS_PENDING = 'P' STATUS_UNSUCCESSFUL = 'U' # Status if there are no referrals of a specific type # Used in aggregate_referral_status NO_REFERRALS_CURRENTLY = "No referrals currently" REFERRAL_STATUSES = ( (STATUS_SUCCESSFUL, 'Successful'), (STATUS_PENDING, 'Pending'), (STATUS_UNSUCCESSFUL, 'Unsuccessful'), ) location = models.ManyToManyField(ReferralLocation) comments = models.TextField(blank=True) status = models.CharField( max_length=50, choices=REFERRAL_STATUSES, default=STATUS_PENDING) kind = models.ForeignKey( ReferralType, help_text="The kind of care the patient should recieve at the " "referral location.") def __str__(self): """Provides string to display on front end for referral. For FQHC referrals, returns referral kind and date. For non-FQHC referrals, returns referral location and date. """ formatted_date = self.written_datetime.strftime("%D") if self.kind.is_fqhc: return "%s referral on %s" % (self.kind, formatted_date) else: location_names = [loc.name for loc in self.location.all()] locations = " ,".join(location_names) return "Referral to %s on %s" % (locations, formatted_date) @staticmethod def aggregate_referral_status(referrals): referral_status_output = "" if referrals: all_successful = all(referral.status == Referral.STATUS_SUCCESSFUL for referral in referrals) if all_successful: referral_status_output = (dict(Referral.REFERRAL_STATUSES) [Referral.STATUS_SUCCESSFUL]) else: # Determine referral status based on the last FQHC referral <|fim_middle|> else: referral_status_output = Referral.NO_REFERRALS_CURRENTLY return referral_status_output class FollowupRequest(Note, CompletableMixin): referral = models.ForeignKey(Referral) contact_instructions = models.TextField() MARK_DONE_URL_NAME = 'new-patient-contact' ADMIN_URL_NAME = '' def class_name(self): return self.__class__.__name__ def short_name(self): return "Referral" def summary(self): return self.contact_instructions def mark_done_url(self): return reverse(self.MARK_DONE_URL_NAME, args=(self.referral.patient.id, self.referral.id, self.id)) def admin_url(self): return reverse( 'admin:referral_followuprequest_change', args=(self.id,) ) def __str__(self): formatted_date = self.due_date.strftime("%D") return 'Followup with %s on %s about %s' % (self.patient, formatted_date, self.referral) class PatientContact(Note): followup_request = models.ForeignKey(FollowupRequest) referral = models.ForeignKey(Referral) contact_method = models.ForeignKey( ContactMethod, null=False, blank=False, help_text="What was the method of contact?") contact_status = models.ForeignKey( ContactResult, blank=False, null=False, help_text="Did you make contact with the patient about this referral?") PTSHOW_YES = "Y" PTSHOW_NO = "N" PTSHOW_OPTS = [(PTSHOW_YES, "Yes"), (PTSHOW_NO, "No")] has_appointment = models.CharField( choices=PTSHOW_OPTS, blank=True, max_length=1, verbose_name="Appointment scheduled?", help_text="Did the patient make an appointment?") no_apt_reason = models.ForeignKey( NoAptReason, blank=True, null=True, verbose_name="No appointment reason", help_text="If the patient didn't make an appointment, why not?") appointment_location = models.ManyToManyField( ReferralLocation, blank=True, help_text="Where did the patient make an appointment?") pt_showed = models.CharField( max_length=1, choices=PTSHOW_OPTS, blank=True, null=True, verbose_name="Appointment attended?", help_text="Did the patient show up to the appointment?") no_show_reason = models.ForeignKey( NoShowReason, blank=True, null=True, help_text="If the patient didn't go to the appointment, why not?") def short_text(self): """Return a short text description of this followup and what happened. Used on the patient chart view as the text in the list of followups. """ text = "" locations = " ,".join(map(str, self.appointment_location.all())) if self.pt_showed == self.PTSHOW_YES: text = "Patient went to appointment at " + locations + "." else: if self.has_appointment == self.PTSHOW_YES: text = ("Patient made appointment at " + locations + "but has not yet gone.") else: if self.contact_status.patient_reached: text = ("Successfully contacted patient but the " "patient has not made an appointment yet.") else: text = "Did not successfully contact patient" return text <|fim▁end|>
referral_status_output = (dict(Referral.REFERRAL_STATUSES) [referrals.last().status])
<|file_name|>models.py<|end_file_name|><|fim▁begin|>"""Data models for referral system.""" from __future__ import unicode_literals from builtins import map from django.db import models from django.core.urlresolvers import reverse from pttrack.models import (ReferralType, ReferralLocation, Note, ContactMethod, CompletableMixin,) from followup.models import ContactResult, NoAptReason, NoShowReason class Referral(Note): """A record of a particular patient's referral to a particular center.""" STATUS_SUCCESSFUL = 'S' STATUS_PENDING = 'P' STATUS_UNSUCCESSFUL = 'U' # Status if there are no referrals of a specific type # Used in aggregate_referral_status NO_REFERRALS_CURRENTLY = "No referrals currently" REFERRAL_STATUSES = ( (STATUS_SUCCESSFUL, 'Successful'), (STATUS_PENDING, 'Pending'), (STATUS_UNSUCCESSFUL, 'Unsuccessful'), ) location = models.ManyToManyField(ReferralLocation) comments = models.TextField(blank=True) status = models.CharField( max_length=50, choices=REFERRAL_STATUSES, default=STATUS_PENDING) kind = models.ForeignKey( ReferralType, help_text="The kind of care the patient should recieve at the " "referral location.") def __str__(self): """Provides string to display on front end for referral. For FQHC referrals, returns referral kind and date. For non-FQHC referrals, returns referral location and date. """ formatted_date = self.written_datetime.strftime("%D") if self.kind.is_fqhc: return "%s referral on %s" % (self.kind, formatted_date) else: location_names = [loc.name for loc in self.location.all()] locations = " ,".join(location_names) return "Referral to %s on %s" % (locations, formatted_date) @staticmethod def aggregate_referral_status(referrals): referral_status_output = "" if referrals: all_successful = all(referral.status == Referral.STATUS_SUCCESSFUL for referral in referrals) if all_successful: referral_status_output = (dict(Referral.REFERRAL_STATUSES) [Referral.STATUS_SUCCESSFUL]) else: # Determine referral status based on the last FQHC referral referral_status_output = (dict(Referral.REFERRAL_STATUSES) [referrals.last().status]) else: <|fim_middle|> return referral_status_output class FollowupRequest(Note, CompletableMixin): referral = models.ForeignKey(Referral) contact_instructions = models.TextField() MARK_DONE_URL_NAME = 'new-patient-contact' ADMIN_URL_NAME = '' def class_name(self): return self.__class__.__name__ def short_name(self): return "Referral" def summary(self): return self.contact_instructions def mark_done_url(self): return reverse(self.MARK_DONE_URL_NAME, args=(self.referral.patient.id, self.referral.id, self.id)) def admin_url(self): return reverse( 'admin:referral_followuprequest_change', args=(self.id,) ) def __str__(self): formatted_date = self.due_date.strftime("%D") return 'Followup with %s on %s about %s' % (self.patient, formatted_date, self.referral) class PatientContact(Note): followup_request = models.ForeignKey(FollowupRequest) referral = models.ForeignKey(Referral) contact_method = models.ForeignKey( ContactMethod, null=False, blank=False, help_text="What was the method of contact?") contact_status = models.ForeignKey( ContactResult, blank=False, null=False, help_text="Did you make contact with the patient about this referral?") PTSHOW_YES = "Y" PTSHOW_NO = "N" PTSHOW_OPTS = [(PTSHOW_YES, "Yes"), (PTSHOW_NO, "No")] has_appointment = models.CharField( choices=PTSHOW_OPTS, blank=True, max_length=1, verbose_name="Appointment scheduled?", help_text="Did the patient make an appointment?") no_apt_reason = models.ForeignKey( NoAptReason, blank=True, null=True, verbose_name="No appointment reason", help_text="If the patient didn't make an appointment, why not?") appointment_location = models.ManyToManyField( ReferralLocation, blank=True, help_text="Where did the patient make an appointment?") pt_showed = models.CharField( max_length=1, choices=PTSHOW_OPTS, blank=True, null=True, verbose_name="Appointment attended?", help_text="Did the patient show up to the appointment?") no_show_reason = models.ForeignKey( NoShowReason, blank=True, null=True, help_text="If the patient didn't go to the appointment, why not?") def short_text(self): """Return a short text description of this followup and what happened. Used on the patient chart view as the text in the list of followups. """ text = "" locations = " ,".join(map(str, self.appointment_location.all())) if self.pt_showed == self.PTSHOW_YES: text = "Patient went to appointment at " + locations + "." else: if self.has_appointment == self.PTSHOW_YES: text = ("Patient made appointment at " + locations + "but has not yet gone.") else: if self.contact_status.patient_reached: text = ("Successfully contacted patient but the " "patient has not made an appointment yet.") else: text = "Did not successfully contact patient" return text <|fim▁end|>
referral_status_output = Referral.NO_REFERRALS_CURRENTLY
<|file_name|>models.py<|end_file_name|><|fim▁begin|>"""Data models for referral system.""" from __future__ import unicode_literals from builtins import map from django.db import models from django.core.urlresolvers import reverse from pttrack.models import (ReferralType, ReferralLocation, Note, ContactMethod, CompletableMixin,) from followup.models import ContactResult, NoAptReason, NoShowReason class Referral(Note): """A record of a particular patient's referral to a particular center.""" STATUS_SUCCESSFUL = 'S' STATUS_PENDING = 'P' STATUS_UNSUCCESSFUL = 'U' # Status if there are no referrals of a specific type # Used in aggregate_referral_status NO_REFERRALS_CURRENTLY = "No referrals currently" REFERRAL_STATUSES = ( (STATUS_SUCCESSFUL, 'Successful'), (STATUS_PENDING, 'Pending'), (STATUS_UNSUCCESSFUL, 'Unsuccessful'), ) location = models.ManyToManyField(ReferralLocation) comments = models.TextField(blank=True) status = models.CharField( max_length=50, choices=REFERRAL_STATUSES, default=STATUS_PENDING) kind = models.ForeignKey( ReferralType, help_text="The kind of care the patient should recieve at the " "referral location.") def __str__(self): """Provides string to display on front end for referral. For FQHC referrals, returns referral kind and date. For non-FQHC referrals, returns referral location and date. """ formatted_date = self.written_datetime.strftime("%D") if self.kind.is_fqhc: return "%s referral on %s" % (self.kind, formatted_date) else: location_names = [loc.name for loc in self.location.all()] locations = " ,".join(location_names) return "Referral to %s on %s" % (locations, formatted_date) @staticmethod def aggregate_referral_status(referrals): referral_status_output = "" if referrals: all_successful = all(referral.status == Referral.STATUS_SUCCESSFUL for referral in referrals) if all_successful: referral_status_output = (dict(Referral.REFERRAL_STATUSES) [Referral.STATUS_SUCCESSFUL]) else: # Determine referral status based on the last FQHC referral referral_status_output = (dict(Referral.REFERRAL_STATUSES) [referrals.last().status]) else: referral_status_output = Referral.NO_REFERRALS_CURRENTLY return referral_status_output class FollowupRequest(Note, CompletableMixin): referral = models.ForeignKey(Referral) contact_instructions = models.TextField() MARK_DONE_URL_NAME = 'new-patient-contact' ADMIN_URL_NAME = '' def class_name(self): return self.__class__.__name__ def short_name(self): return "Referral" def summary(self): return self.contact_instructions def mark_done_url(self): return reverse(self.MARK_DONE_URL_NAME, args=(self.referral.patient.id, self.referral.id, self.id)) def admin_url(self): return reverse( 'admin:referral_followuprequest_change', args=(self.id,) ) def __str__(self): formatted_date = self.due_date.strftime("%D") return 'Followup with %s on %s about %s' % (self.patient, formatted_date, self.referral) class PatientContact(Note): followup_request = models.ForeignKey(FollowupRequest) referral = models.ForeignKey(Referral) contact_method = models.ForeignKey( ContactMethod, null=False, blank=False, help_text="What was the method of contact?") contact_status = models.ForeignKey( ContactResult, blank=False, null=False, help_text="Did you make contact with the patient about this referral?") PTSHOW_YES = "Y" PTSHOW_NO = "N" PTSHOW_OPTS = [(PTSHOW_YES, "Yes"), (PTSHOW_NO, "No")] has_appointment = models.CharField( choices=PTSHOW_OPTS, blank=True, max_length=1, verbose_name="Appointment scheduled?", help_text="Did the patient make an appointment?") no_apt_reason = models.ForeignKey( NoAptReason, blank=True, null=True, verbose_name="No appointment reason", help_text="If the patient didn't make an appointment, why not?") appointment_location = models.ManyToManyField( ReferralLocation, blank=True, help_text="Where did the patient make an appointment?") pt_showed = models.CharField( max_length=1, choices=PTSHOW_OPTS, blank=True, null=True, verbose_name="Appointment attended?", help_text="Did the patient show up to the appointment?") no_show_reason = models.ForeignKey( NoShowReason, blank=True, null=True, help_text="If the patient didn't go to the appointment, why not?") def short_text(self): """Return a short text description of this followup and what happened. Used on the patient chart view as the text in the list of followups. """ text = "" locations = " ,".join(map(str, self.appointment_location.all())) if self.pt_showed == self.PTSHOW_YES: <|fim_middle|> else: if self.has_appointment == self.PTSHOW_YES: text = ("Patient made appointment at " + locations + "but has not yet gone.") else: if self.contact_status.patient_reached: text = ("Successfully contacted patient but the " "patient has not made an appointment yet.") else: text = "Did not successfully contact patient" return text <|fim▁end|>
text = "Patient went to appointment at " + locations + "."
<|file_name|>models.py<|end_file_name|><|fim▁begin|>"""Data models for referral system.""" from __future__ import unicode_literals from builtins import map from django.db import models from django.core.urlresolvers import reverse from pttrack.models import (ReferralType, ReferralLocation, Note, ContactMethod, CompletableMixin,) from followup.models import ContactResult, NoAptReason, NoShowReason class Referral(Note): """A record of a particular patient's referral to a particular center.""" STATUS_SUCCESSFUL = 'S' STATUS_PENDING = 'P' STATUS_UNSUCCESSFUL = 'U' # Status if there are no referrals of a specific type # Used in aggregate_referral_status NO_REFERRALS_CURRENTLY = "No referrals currently" REFERRAL_STATUSES = ( (STATUS_SUCCESSFUL, 'Successful'), (STATUS_PENDING, 'Pending'), (STATUS_UNSUCCESSFUL, 'Unsuccessful'), ) location = models.ManyToManyField(ReferralLocation) comments = models.TextField(blank=True) status = models.CharField( max_length=50, choices=REFERRAL_STATUSES, default=STATUS_PENDING) kind = models.ForeignKey( ReferralType, help_text="The kind of care the patient should recieve at the " "referral location.") def __str__(self): """Provides string to display on front end for referral. For FQHC referrals, returns referral kind and date. For non-FQHC referrals, returns referral location and date. """ formatted_date = self.written_datetime.strftime("%D") if self.kind.is_fqhc: return "%s referral on %s" % (self.kind, formatted_date) else: location_names = [loc.name for loc in self.location.all()] locations = " ,".join(location_names) return "Referral to %s on %s" % (locations, formatted_date) @staticmethod def aggregate_referral_status(referrals): referral_status_output = "" if referrals: all_successful = all(referral.status == Referral.STATUS_SUCCESSFUL for referral in referrals) if all_successful: referral_status_output = (dict(Referral.REFERRAL_STATUSES) [Referral.STATUS_SUCCESSFUL]) else: # Determine referral status based on the last FQHC referral referral_status_output = (dict(Referral.REFERRAL_STATUSES) [referrals.last().status]) else: referral_status_output = Referral.NO_REFERRALS_CURRENTLY return referral_status_output class FollowupRequest(Note, CompletableMixin): referral = models.ForeignKey(Referral) contact_instructions = models.TextField() MARK_DONE_URL_NAME = 'new-patient-contact' ADMIN_URL_NAME = '' def class_name(self): return self.__class__.__name__ def short_name(self): return "Referral" def summary(self): return self.contact_instructions def mark_done_url(self): return reverse(self.MARK_DONE_URL_NAME, args=(self.referral.patient.id, self.referral.id, self.id)) def admin_url(self): return reverse( 'admin:referral_followuprequest_change', args=(self.id,) ) def __str__(self): formatted_date = self.due_date.strftime("%D") return 'Followup with %s on %s about %s' % (self.patient, formatted_date, self.referral) class PatientContact(Note): followup_request = models.ForeignKey(FollowupRequest) referral = models.ForeignKey(Referral) contact_method = models.ForeignKey( ContactMethod, null=False, blank=False, help_text="What was the method of contact?") contact_status = models.ForeignKey( ContactResult, blank=False, null=False, help_text="Did you make contact with the patient about this referral?") PTSHOW_YES = "Y" PTSHOW_NO = "N" PTSHOW_OPTS = [(PTSHOW_YES, "Yes"), (PTSHOW_NO, "No")] has_appointment = models.CharField( choices=PTSHOW_OPTS, blank=True, max_length=1, verbose_name="Appointment scheduled?", help_text="Did the patient make an appointment?") no_apt_reason = models.ForeignKey( NoAptReason, blank=True, null=True, verbose_name="No appointment reason", help_text="If the patient didn't make an appointment, why not?") appointment_location = models.ManyToManyField( ReferralLocation, blank=True, help_text="Where did the patient make an appointment?") pt_showed = models.CharField( max_length=1, choices=PTSHOW_OPTS, blank=True, null=True, verbose_name="Appointment attended?", help_text="Did the patient show up to the appointment?") no_show_reason = models.ForeignKey( NoShowReason, blank=True, null=True, help_text="If the patient didn't go to the appointment, why not?") def short_text(self): """Return a short text description of this followup and what happened. Used on the patient chart view as the text in the list of followups. """ text = "" locations = " ,".join(map(str, self.appointment_location.all())) if self.pt_showed == self.PTSHOW_YES: text = "Patient went to appointment at " + locations + "." else: <|fim_middle|> return text <|fim▁end|>
if self.has_appointment == self.PTSHOW_YES: text = ("Patient made appointment at " + locations + "but has not yet gone.") else: if self.contact_status.patient_reached: text = ("Successfully contacted patient but the " "patient has not made an appointment yet.") else: text = "Did not successfully contact patient"
<|file_name|>models.py<|end_file_name|><|fim▁begin|>"""Data models for referral system.""" from __future__ import unicode_literals from builtins import map from django.db import models from django.core.urlresolvers import reverse from pttrack.models import (ReferralType, ReferralLocation, Note, ContactMethod, CompletableMixin,) from followup.models import ContactResult, NoAptReason, NoShowReason class Referral(Note): """A record of a particular patient's referral to a particular center.""" STATUS_SUCCESSFUL = 'S' STATUS_PENDING = 'P' STATUS_UNSUCCESSFUL = 'U' # Status if there are no referrals of a specific type # Used in aggregate_referral_status NO_REFERRALS_CURRENTLY = "No referrals currently" REFERRAL_STATUSES = ( (STATUS_SUCCESSFUL, 'Successful'), (STATUS_PENDING, 'Pending'), (STATUS_UNSUCCESSFUL, 'Unsuccessful'), ) location = models.ManyToManyField(ReferralLocation) comments = models.TextField(blank=True) status = models.CharField( max_length=50, choices=REFERRAL_STATUSES, default=STATUS_PENDING) kind = models.ForeignKey( ReferralType, help_text="The kind of care the patient should recieve at the " "referral location.") def __str__(self): """Provides string to display on front end for referral. For FQHC referrals, returns referral kind and date. For non-FQHC referrals, returns referral location and date. """ formatted_date = self.written_datetime.strftime("%D") if self.kind.is_fqhc: return "%s referral on %s" % (self.kind, formatted_date) else: location_names = [loc.name for loc in self.location.all()] locations = " ,".join(location_names) return "Referral to %s on %s" % (locations, formatted_date) @staticmethod def aggregate_referral_status(referrals): referral_status_output = "" if referrals: all_successful = all(referral.status == Referral.STATUS_SUCCESSFUL for referral in referrals) if all_successful: referral_status_output = (dict(Referral.REFERRAL_STATUSES) [Referral.STATUS_SUCCESSFUL]) else: # Determine referral status based on the last FQHC referral referral_status_output = (dict(Referral.REFERRAL_STATUSES) [referrals.last().status]) else: referral_status_output = Referral.NO_REFERRALS_CURRENTLY return referral_status_output class FollowupRequest(Note, CompletableMixin): referral = models.ForeignKey(Referral) contact_instructions = models.TextField() MARK_DONE_URL_NAME = 'new-patient-contact' ADMIN_URL_NAME = '' def class_name(self): return self.__class__.__name__ def short_name(self): return "Referral" def summary(self): return self.contact_instructions def mark_done_url(self): return reverse(self.MARK_DONE_URL_NAME, args=(self.referral.patient.id, self.referral.id, self.id)) def admin_url(self): return reverse( 'admin:referral_followuprequest_change', args=(self.id,) ) def __str__(self): formatted_date = self.due_date.strftime("%D") return 'Followup with %s on %s about %s' % (self.patient, formatted_date, self.referral) class PatientContact(Note): followup_request = models.ForeignKey(FollowupRequest) referral = models.ForeignKey(Referral) contact_method = models.ForeignKey( ContactMethod, null=False, blank=False, help_text="What was the method of contact?") contact_status = models.ForeignKey( ContactResult, blank=False, null=False, help_text="Did you make contact with the patient about this referral?") PTSHOW_YES = "Y" PTSHOW_NO = "N" PTSHOW_OPTS = [(PTSHOW_YES, "Yes"), (PTSHOW_NO, "No")] has_appointment = models.CharField( choices=PTSHOW_OPTS, blank=True, max_length=1, verbose_name="Appointment scheduled?", help_text="Did the patient make an appointment?") no_apt_reason = models.ForeignKey( NoAptReason, blank=True, null=True, verbose_name="No appointment reason", help_text="If the patient didn't make an appointment, why not?") appointment_location = models.ManyToManyField( ReferralLocation, blank=True, help_text="Where did the patient make an appointment?") pt_showed = models.CharField( max_length=1, choices=PTSHOW_OPTS, blank=True, null=True, verbose_name="Appointment attended?", help_text="Did the patient show up to the appointment?") no_show_reason = models.ForeignKey( NoShowReason, blank=True, null=True, help_text="If the patient didn't go to the appointment, why not?") def short_text(self): """Return a short text description of this followup and what happened. Used on the patient chart view as the text in the list of followups. """ text = "" locations = " ,".join(map(str, self.appointment_location.all())) if self.pt_showed == self.PTSHOW_YES: text = "Patient went to appointment at " + locations + "." else: if self.has_appointment == self.PTSHOW_YES: <|fim_middle|> else: if self.contact_status.patient_reached: text = ("Successfully contacted patient but the " "patient has not made an appointment yet.") else: text = "Did not successfully contact patient" return text <|fim▁end|>
text = ("Patient made appointment at " + locations + "but has not yet gone.")
<|file_name|>models.py<|end_file_name|><|fim▁begin|>"""Data models for referral system.""" from __future__ import unicode_literals from builtins import map from django.db import models from django.core.urlresolvers import reverse from pttrack.models import (ReferralType, ReferralLocation, Note, ContactMethod, CompletableMixin,) from followup.models import ContactResult, NoAptReason, NoShowReason class Referral(Note): """A record of a particular patient's referral to a particular center.""" STATUS_SUCCESSFUL = 'S' STATUS_PENDING = 'P' STATUS_UNSUCCESSFUL = 'U' # Status if there are no referrals of a specific type # Used in aggregate_referral_status NO_REFERRALS_CURRENTLY = "No referrals currently" REFERRAL_STATUSES = ( (STATUS_SUCCESSFUL, 'Successful'), (STATUS_PENDING, 'Pending'), (STATUS_UNSUCCESSFUL, 'Unsuccessful'), ) location = models.ManyToManyField(ReferralLocation) comments = models.TextField(blank=True) status = models.CharField( max_length=50, choices=REFERRAL_STATUSES, default=STATUS_PENDING) kind = models.ForeignKey( ReferralType, help_text="The kind of care the patient should recieve at the " "referral location.") def __str__(self): """Provides string to display on front end for referral. For FQHC referrals, returns referral kind and date. For non-FQHC referrals, returns referral location and date. """ formatted_date = self.written_datetime.strftime("%D") if self.kind.is_fqhc: return "%s referral on %s" % (self.kind, formatted_date) else: location_names = [loc.name for loc in self.location.all()] locations = " ,".join(location_names) return "Referral to %s on %s" % (locations, formatted_date) @staticmethod def aggregate_referral_status(referrals): referral_status_output = "" if referrals: all_successful = all(referral.status == Referral.STATUS_SUCCESSFUL for referral in referrals) if all_successful: referral_status_output = (dict(Referral.REFERRAL_STATUSES) [Referral.STATUS_SUCCESSFUL]) else: # Determine referral status based on the last FQHC referral referral_status_output = (dict(Referral.REFERRAL_STATUSES) [referrals.last().status]) else: referral_status_output = Referral.NO_REFERRALS_CURRENTLY return referral_status_output class FollowupRequest(Note, CompletableMixin): referral = models.ForeignKey(Referral) contact_instructions = models.TextField() MARK_DONE_URL_NAME = 'new-patient-contact' ADMIN_URL_NAME = '' def class_name(self): return self.__class__.__name__ def short_name(self): return "Referral" def summary(self): return self.contact_instructions def mark_done_url(self): return reverse(self.MARK_DONE_URL_NAME, args=(self.referral.patient.id, self.referral.id, self.id)) def admin_url(self): return reverse( 'admin:referral_followuprequest_change', args=(self.id,) ) def __str__(self): formatted_date = self.due_date.strftime("%D") return 'Followup with %s on %s about %s' % (self.patient, formatted_date, self.referral) class PatientContact(Note): followup_request = models.ForeignKey(FollowupRequest) referral = models.ForeignKey(Referral) contact_method = models.ForeignKey( ContactMethod, null=False, blank=False, help_text="What was the method of contact?") contact_status = models.ForeignKey( ContactResult, blank=False, null=False, help_text="Did you make contact with the patient about this referral?") PTSHOW_YES = "Y" PTSHOW_NO = "N" PTSHOW_OPTS = [(PTSHOW_YES, "Yes"), (PTSHOW_NO, "No")] has_appointment = models.CharField( choices=PTSHOW_OPTS, blank=True, max_length=1, verbose_name="Appointment scheduled?", help_text="Did the patient make an appointment?") no_apt_reason = models.ForeignKey( NoAptReason, blank=True, null=True, verbose_name="No appointment reason", help_text="If the patient didn't make an appointment, why not?") appointment_location = models.ManyToManyField( ReferralLocation, blank=True, help_text="Where did the patient make an appointment?") pt_showed = models.CharField( max_length=1, choices=PTSHOW_OPTS, blank=True, null=True, verbose_name="Appointment attended?", help_text="Did the patient show up to the appointment?") no_show_reason = models.ForeignKey( NoShowReason, blank=True, null=True, help_text="If the patient didn't go to the appointment, why not?") def short_text(self): """Return a short text description of this followup and what happened. Used on the patient chart view as the text in the list of followups. """ text = "" locations = " ,".join(map(str, self.appointment_location.all())) if self.pt_showed == self.PTSHOW_YES: text = "Patient went to appointment at " + locations + "." else: if self.has_appointment == self.PTSHOW_YES: text = ("Patient made appointment at " + locations + "but has not yet gone.") else: <|fim_middle|> return text <|fim▁end|>
if self.contact_status.patient_reached: text = ("Successfully contacted patient but the " "patient has not made an appointment yet.") else: text = "Did not successfully contact patient"
<|file_name|>models.py<|end_file_name|><|fim▁begin|>"""Data models for referral system.""" from __future__ import unicode_literals from builtins import map from django.db import models from django.core.urlresolvers import reverse from pttrack.models import (ReferralType, ReferralLocation, Note, ContactMethod, CompletableMixin,) from followup.models import ContactResult, NoAptReason, NoShowReason class Referral(Note): """A record of a particular patient's referral to a particular center.""" STATUS_SUCCESSFUL = 'S' STATUS_PENDING = 'P' STATUS_UNSUCCESSFUL = 'U' # Status if there are no referrals of a specific type # Used in aggregate_referral_status NO_REFERRALS_CURRENTLY = "No referrals currently" REFERRAL_STATUSES = ( (STATUS_SUCCESSFUL, 'Successful'), (STATUS_PENDING, 'Pending'), (STATUS_UNSUCCESSFUL, 'Unsuccessful'), ) location = models.ManyToManyField(ReferralLocation) comments = models.TextField(blank=True) status = models.CharField( max_length=50, choices=REFERRAL_STATUSES, default=STATUS_PENDING) kind = models.ForeignKey( ReferralType, help_text="The kind of care the patient should recieve at the " "referral location.") def __str__(self): """Provides string to display on front end for referral. For FQHC referrals, returns referral kind and date. For non-FQHC referrals, returns referral location and date. """ formatted_date = self.written_datetime.strftime("%D") if self.kind.is_fqhc: return "%s referral on %s" % (self.kind, formatted_date) else: location_names = [loc.name for loc in self.location.all()] locations = " ,".join(location_names) return "Referral to %s on %s" % (locations, formatted_date) @staticmethod def aggregate_referral_status(referrals): referral_status_output = "" if referrals: all_successful = all(referral.status == Referral.STATUS_SUCCESSFUL for referral in referrals) if all_successful: referral_status_output = (dict(Referral.REFERRAL_STATUSES) [Referral.STATUS_SUCCESSFUL]) else: # Determine referral status based on the last FQHC referral referral_status_output = (dict(Referral.REFERRAL_STATUSES) [referrals.last().status]) else: referral_status_output = Referral.NO_REFERRALS_CURRENTLY return referral_status_output class FollowupRequest(Note, CompletableMixin): referral = models.ForeignKey(Referral) contact_instructions = models.TextField() MARK_DONE_URL_NAME = 'new-patient-contact' ADMIN_URL_NAME = '' def class_name(self): return self.__class__.__name__ def short_name(self): return "Referral" def summary(self): return self.contact_instructions def mark_done_url(self): return reverse(self.MARK_DONE_URL_NAME, args=(self.referral.patient.id, self.referral.id, self.id)) def admin_url(self): return reverse( 'admin:referral_followuprequest_change', args=(self.id,) ) def __str__(self): formatted_date = self.due_date.strftime("%D") return 'Followup with %s on %s about %s' % (self.patient, formatted_date, self.referral) class PatientContact(Note): followup_request = models.ForeignKey(FollowupRequest) referral = models.ForeignKey(Referral) contact_method = models.ForeignKey( ContactMethod, null=False, blank=False, help_text="What was the method of contact?") contact_status = models.ForeignKey( ContactResult, blank=False, null=False, help_text="Did you make contact with the patient about this referral?") PTSHOW_YES = "Y" PTSHOW_NO = "N" PTSHOW_OPTS = [(PTSHOW_YES, "Yes"), (PTSHOW_NO, "No")] has_appointment = models.CharField( choices=PTSHOW_OPTS, blank=True, max_length=1, verbose_name="Appointment scheduled?", help_text="Did the patient make an appointment?") no_apt_reason = models.ForeignKey( NoAptReason, blank=True, null=True, verbose_name="No appointment reason", help_text="If the patient didn't make an appointment, why not?") appointment_location = models.ManyToManyField( ReferralLocation, blank=True, help_text="Where did the patient make an appointment?") pt_showed = models.CharField( max_length=1, choices=PTSHOW_OPTS, blank=True, null=True, verbose_name="Appointment attended?", help_text="Did the patient show up to the appointment?") no_show_reason = models.ForeignKey( NoShowReason, blank=True, null=True, help_text="If the patient didn't go to the appointment, why not?") def short_text(self): """Return a short text description of this followup and what happened. Used on the patient chart view as the text in the list of followups. """ text = "" locations = " ,".join(map(str, self.appointment_location.all())) if self.pt_showed == self.PTSHOW_YES: text = "Patient went to appointment at " + locations + "." else: if self.has_appointment == self.PTSHOW_YES: text = ("Patient made appointment at " + locations + "but has not yet gone.") else: if self.contact_status.patient_reached: <|fim_middle|> else: text = "Did not successfully contact patient" return text <|fim▁end|>
text = ("Successfully contacted patient but the " "patient has not made an appointment yet.")
<|file_name|>models.py<|end_file_name|><|fim▁begin|>"""Data models for referral system.""" from __future__ import unicode_literals from builtins import map from django.db import models from django.core.urlresolvers import reverse from pttrack.models import (ReferralType, ReferralLocation, Note, ContactMethod, CompletableMixin,) from followup.models import ContactResult, NoAptReason, NoShowReason class Referral(Note): """A record of a particular patient's referral to a particular center.""" STATUS_SUCCESSFUL = 'S' STATUS_PENDING = 'P' STATUS_UNSUCCESSFUL = 'U' # Status if there are no referrals of a specific type # Used in aggregate_referral_status NO_REFERRALS_CURRENTLY = "No referrals currently" REFERRAL_STATUSES = ( (STATUS_SUCCESSFUL, 'Successful'), (STATUS_PENDING, 'Pending'), (STATUS_UNSUCCESSFUL, 'Unsuccessful'), ) location = models.ManyToManyField(ReferralLocation) comments = models.TextField(blank=True) status = models.CharField( max_length=50, choices=REFERRAL_STATUSES, default=STATUS_PENDING) kind = models.ForeignKey( ReferralType, help_text="The kind of care the patient should recieve at the " "referral location.") def __str__(self): """Provides string to display on front end for referral. For FQHC referrals, returns referral kind and date. For non-FQHC referrals, returns referral location and date. """ formatted_date = self.written_datetime.strftime("%D") if self.kind.is_fqhc: return "%s referral on %s" % (self.kind, formatted_date) else: location_names = [loc.name for loc in self.location.all()] locations = " ,".join(location_names) return "Referral to %s on %s" % (locations, formatted_date) @staticmethod def aggregate_referral_status(referrals): referral_status_output = "" if referrals: all_successful = all(referral.status == Referral.STATUS_SUCCESSFUL for referral in referrals) if all_successful: referral_status_output = (dict(Referral.REFERRAL_STATUSES) [Referral.STATUS_SUCCESSFUL]) else: # Determine referral status based on the last FQHC referral referral_status_output = (dict(Referral.REFERRAL_STATUSES) [referrals.last().status]) else: referral_status_output = Referral.NO_REFERRALS_CURRENTLY return referral_status_output class FollowupRequest(Note, CompletableMixin): referral = models.ForeignKey(Referral) contact_instructions = models.TextField() MARK_DONE_URL_NAME = 'new-patient-contact' ADMIN_URL_NAME = '' def class_name(self): return self.__class__.__name__ def short_name(self): return "Referral" def summary(self): return self.contact_instructions def mark_done_url(self): return reverse(self.MARK_DONE_URL_NAME, args=(self.referral.patient.id, self.referral.id, self.id)) def admin_url(self): return reverse( 'admin:referral_followuprequest_change', args=(self.id,) ) def __str__(self): formatted_date = self.due_date.strftime("%D") return 'Followup with %s on %s about %s' % (self.patient, formatted_date, self.referral) class PatientContact(Note): followup_request = models.ForeignKey(FollowupRequest) referral = models.ForeignKey(Referral) contact_method = models.ForeignKey( ContactMethod, null=False, blank=False, help_text="What was the method of contact?") contact_status = models.ForeignKey( ContactResult, blank=False, null=False, help_text="Did you make contact with the patient about this referral?") PTSHOW_YES = "Y" PTSHOW_NO = "N" PTSHOW_OPTS = [(PTSHOW_YES, "Yes"), (PTSHOW_NO, "No")] has_appointment = models.CharField( choices=PTSHOW_OPTS, blank=True, max_length=1, verbose_name="Appointment scheduled?", help_text="Did the patient make an appointment?") no_apt_reason = models.ForeignKey( NoAptReason, blank=True, null=True, verbose_name="No appointment reason", help_text="If the patient didn't make an appointment, why not?") appointment_location = models.ManyToManyField( ReferralLocation, blank=True, help_text="Where did the patient make an appointment?") pt_showed = models.CharField( max_length=1, choices=PTSHOW_OPTS, blank=True, null=True, verbose_name="Appointment attended?", help_text="Did the patient show up to the appointment?") no_show_reason = models.ForeignKey( NoShowReason, blank=True, null=True, help_text="If the patient didn't go to the appointment, why not?") def short_text(self): """Return a short text description of this followup and what happened. Used on the patient chart view as the text in the list of followups. """ text = "" locations = " ,".join(map(str, self.appointment_location.all())) if self.pt_showed == self.PTSHOW_YES: text = "Patient went to appointment at " + locations + "." else: if self.has_appointment == self.PTSHOW_YES: text = ("Patient made appointment at " + locations + "but has not yet gone.") else: if self.contact_status.patient_reached: text = ("Successfully contacted patient but the " "patient has not made an appointment yet.") else: <|fim_middle|> return text <|fim▁end|>
text = "Did not successfully contact patient"
<|file_name|>models.py<|end_file_name|><|fim▁begin|>"""Data models for referral system.""" from __future__ import unicode_literals from builtins import map from django.db import models from django.core.urlresolvers import reverse from pttrack.models import (ReferralType, ReferralLocation, Note, ContactMethod, CompletableMixin,) from followup.models import ContactResult, NoAptReason, NoShowReason class Referral(Note): """A record of a particular patient's referral to a particular center.""" STATUS_SUCCESSFUL = 'S' STATUS_PENDING = 'P' STATUS_UNSUCCESSFUL = 'U' # Status if there are no referrals of a specific type # Used in aggregate_referral_status NO_REFERRALS_CURRENTLY = "No referrals currently" REFERRAL_STATUSES = ( (STATUS_SUCCESSFUL, 'Successful'), (STATUS_PENDING, 'Pending'), (STATUS_UNSUCCESSFUL, 'Unsuccessful'), ) location = models.ManyToManyField(ReferralLocation) comments = models.TextField(blank=True) status = models.CharField( max_length=50, choices=REFERRAL_STATUSES, default=STATUS_PENDING) kind = models.ForeignKey( ReferralType, help_text="The kind of care the patient should recieve at the " "referral location.") def <|fim_middle|>(self): """Provides string to display on front end for referral. For FQHC referrals, returns referral kind and date. For non-FQHC referrals, returns referral location and date. """ formatted_date = self.written_datetime.strftime("%D") if self.kind.is_fqhc: return "%s referral on %s" % (self.kind, formatted_date) else: location_names = [loc.name for loc in self.location.all()] locations = " ,".join(location_names) return "Referral to %s on %s" % (locations, formatted_date) @staticmethod def aggregate_referral_status(referrals): referral_status_output = "" if referrals: all_successful = all(referral.status == Referral.STATUS_SUCCESSFUL for referral in referrals) if all_successful: referral_status_output = (dict(Referral.REFERRAL_STATUSES) [Referral.STATUS_SUCCESSFUL]) else: # Determine referral status based on the last FQHC referral referral_status_output = (dict(Referral.REFERRAL_STATUSES) [referrals.last().status]) else: referral_status_output = Referral.NO_REFERRALS_CURRENTLY return referral_status_output class FollowupRequest(Note, CompletableMixin): referral = models.ForeignKey(Referral) contact_instructions = models.TextField() MARK_DONE_URL_NAME = 'new-patient-contact' ADMIN_URL_NAME = '' def class_name(self): return self.__class__.__name__ def short_name(self): return "Referral" def summary(self): return self.contact_instructions def mark_done_url(self): return reverse(self.MARK_DONE_URL_NAME, args=(self.referral.patient.id, self.referral.id, self.id)) def admin_url(self): return reverse( 'admin:referral_followuprequest_change', args=(self.id,) ) def __str__(self): formatted_date = self.due_date.strftime("%D") return 'Followup with %s on %s about %s' % (self.patient, formatted_date, self.referral) class PatientContact(Note): followup_request = models.ForeignKey(FollowupRequest) referral = models.ForeignKey(Referral) contact_method = models.ForeignKey( ContactMethod, null=False, blank=False, help_text="What was the method of contact?") contact_status = models.ForeignKey( ContactResult, blank=False, null=False, help_text="Did you make contact with the patient about this referral?") PTSHOW_YES = "Y" PTSHOW_NO = "N" PTSHOW_OPTS = [(PTSHOW_YES, "Yes"), (PTSHOW_NO, "No")] has_appointment = models.CharField( choices=PTSHOW_OPTS, blank=True, max_length=1, verbose_name="Appointment scheduled?", help_text="Did the patient make an appointment?") no_apt_reason = models.ForeignKey( NoAptReason, blank=True, null=True, verbose_name="No appointment reason", help_text="If the patient didn't make an appointment, why not?") appointment_location = models.ManyToManyField( ReferralLocation, blank=True, help_text="Where did the patient make an appointment?") pt_showed = models.CharField( max_length=1, choices=PTSHOW_OPTS, blank=True, null=True, verbose_name="Appointment attended?", help_text="Did the patient show up to the appointment?") no_show_reason = models.ForeignKey( NoShowReason, blank=True, null=True, help_text="If the patient didn't go to the appointment, why not?") def short_text(self): """Return a short text description of this followup and what happened. Used on the patient chart view as the text in the list of followups. """ text = "" locations = " ,".join(map(str, self.appointment_location.all())) if self.pt_showed == self.PTSHOW_YES: text = "Patient went to appointment at " + locations + "." else: if self.has_appointment == self.PTSHOW_YES: text = ("Patient made appointment at " + locations + "but has not yet gone.") else: if self.contact_status.patient_reached: text = ("Successfully contacted patient but the " "patient has not made an appointment yet.") else: text = "Did not successfully contact patient" return text <|fim▁end|>
__str__
<|file_name|>models.py<|end_file_name|><|fim▁begin|>"""Data models for referral system.""" from __future__ import unicode_literals from builtins import map from django.db import models from django.core.urlresolvers import reverse from pttrack.models import (ReferralType, ReferralLocation, Note, ContactMethod, CompletableMixin,) from followup.models import ContactResult, NoAptReason, NoShowReason class Referral(Note): """A record of a particular patient's referral to a particular center.""" STATUS_SUCCESSFUL = 'S' STATUS_PENDING = 'P' STATUS_UNSUCCESSFUL = 'U' # Status if there are no referrals of a specific type # Used in aggregate_referral_status NO_REFERRALS_CURRENTLY = "No referrals currently" REFERRAL_STATUSES = ( (STATUS_SUCCESSFUL, 'Successful'), (STATUS_PENDING, 'Pending'), (STATUS_UNSUCCESSFUL, 'Unsuccessful'), ) location = models.ManyToManyField(ReferralLocation) comments = models.TextField(blank=True) status = models.CharField( max_length=50, choices=REFERRAL_STATUSES, default=STATUS_PENDING) kind = models.ForeignKey( ReferralType, help_text="The kind of care the patient should recieve at the " "referral location.") def __str__(self): """Provides string to display on front end for referral. For FQHC referrals, returns referral kind and date. For non-FQHC referrals, returns referral location and date. """ formatted_date = self.written_datetime.strftime("%D") if self.kind.is_fqhc: return "%s referral on %s" % (self.kind, formatted_date) else: location_names = [loc.name for loc in self.location.all()] locations = " ,".join(location_names) return "Referral to %s on %s" % (locations, formatted_date) @staticmethod def <|fim_middle|>(referrals): referral_status_output = "" if referrals: all_successful = all(referral.status == Referral.STATUS_SUCCESSFUL for referral in referrals) if all_successful: referral_status_output = (dict(Referral.REFERRAL_STATUSES) [Referral.STATUS_SUCCESSFUL]) else: # Determine referral status based on the last FQHC referral referral_status_output = (dict(Referral.REFERRAL_STATUSES) [referrals.last().status]) else: referral_status_output = Referral.NO_REFERRALS_CURRENTLY return referral_status_output class FollowupRequest(Note, CompletableMixin): referral = models.ForeignKey(Referral) contact_instructions = models.TextField() MARK_DONE_URL_NAME = 'new-patient-contact' ADMIN_URL_NAME = '' def class_name(self): return self.__class__.__name__ def short_name(self): return "Referral" def summary(self): return self.contact_instructions def mark_done_url(self): return reverse(self.MARK_DONE_URL_NAME, args=(self.referral.patient.id, self.referral.id, self.id)) def admin_url(self): return reverse( 'admin:referral_followuprequest_change', args=(self.id,) ) def __str__(self): formatted_date = self.due_date.strftime("%D") return 'Followup with %s on %s about %s' % (self.patient, formatted_date, self.referral) class PatientContact(Note): followup_request = models.ForeignKey(FollowupRequest) referral = models.ForeignKey(Referral) contact_method = models.ForeignKey( ContactMethod, null=False, blank=False, help_text="What was the method of contact?") contact_status = models.ForeignKey( ContactResult, blank=False, null=False, help_text="Did you make contact with the patient about this referral?") PTSHOW_YES = "Y" PTSHOW_NO = "N" PTSHOW_OPTS = [(PTSHOW_YES, "Yes"), (PTSHOW_NO, "No")] has_appointment = models.CharField( choices=PTSHOW_OPTS, blank=True, max_length=1, verbose_name="Appointment scheduled?", help_text="Did the patient make an appointment?") no_apt_reason = models.ForeignKey( NoAptReason, blank=True, null=True, verbose_name="No appointment reason", help_text="If the patient didn't make an appointment, why not?") appointment_location = models.ManyToManyField( ReferralLocation, blank=True, help_text="Where did the patient make an appointment?") pt_showed = models.CharField( max_length=1, choices=PTSHOW_OPTS, blank=True, null=True, verbose_name="Appointment attended?", help_text="Did the patient show up to the appointment?") no_show_reason = models.ForeignKey( NoShowReason, blank=True, null=True, help_text="If the patient didn't go to the appointment, why not?") def short_text(self): """Return a short text description of this followup and what happened. Used on the patient chart view as the text in the list of followups. """ text = "" locations = " ,".join(map(str, self.appointment_location.all())) if self.pt_showed == self.PTSHOW_YES: text = "Patient went to appointment at " + locations + "." else: if self.has_appointment == self.PTSHOW_YES: text = ("Patient made appointment at " + locations + "but has not yet gone.") else: if self.contact_status.patient_reached: text = ("Successfully contacted patient but the " "patient has not made an appointment yet.") else: text = "Did not successfully contact patient" return text <|fim▁end|>
aggregate_referral_status
<|file_name|>models.py<|end_file_name|><|fim▁begin|>"""Data models for referral system.""" from __future__ import unicode_literals from builtins import map from django.db import models from django.core.urlresolvers import reverse from pttrack.models import (ReferralType, ReferralLocation, Note, ContactMethod, CompletableMixin,) from followup.models import ContactResult, NoAptReason, NoShowReason class Referral(Note): """A record of a particular patient's referral to a particular center.""" STATUS_SUCCESSFUL = 'S' STATUS_PENDING = 'P' STATUS_UNSUCCESSFUL = 'U' # Status if there are no referrals of a specific type # Used in aggregate_referral_status NO_REFERRALS_CURRENTLY = "No referrals currently" REFERRAL_STATUSES = ( (STATUS_SUCCESSFUL, 'Successful'), (STATUS_PENDING, 'Pending'), (STATUS_UNSUCCESSFUL, 'Unsuccessful'), ) location = models.ManyToManyField(ReferralLocation) comments = models.TextField(blank=True) status = models.CharField( max_length=50, choices=REFERRAL_STATUSES, default=STATUS_PENDING) kind = models.ForeignKey( ReferralType, help_text="The kind of care the patient should recieve at the " "referral location.") def __str__(self): """Provides string to display on front end for referral. For FQHC referrals, returns referral kind and date. For non-FQHC referrals, returns referral location and date. """ formatted_date = self.written_datetime.strftime("%D") if self.kind.is_fqhc: return "%s referral on %s" % (self.kind, formatted_date) else: location_names = [loc.name for loc in self.location.all()] locations = " ,".join(location_names) return "Referral to %s on %s" % (locations, formatted_date) @staticmethod def aggregate_referral_status(referrals): referral_status_output = "" if referrals: all_successful = all(referral.status == Referral.STATUS_SUCCESSFUL for referral in referrals) if all_successful: referral_status_output = (dict(Referral.REFERRAL_STATUSES) [Referral.STATUS_SUCCESSFUL]) else: # Determine referral status based on the last FQHC referral referral_status_output = (dict(Referral.REFERRAL_STATUSES) [referrals.last().status]) else: referral_status_output = Referral.NO_REFERRALS_CURRENTLY return referral_status_output class FollowupRequest(Note, CompletableMixin): referral = models.ForeignKey(Referral) contact_instructions = models.TextField() MARK_DONE_URL_NAME = 'new-patient-contact' ADMIN_URL_NAME = '' def <|fim_middle|>(self): return self.__class__.__name__ def short_name(self): return "Referral" def summary(self): return self.contact_instructions def mark_done_url(self): return reverse(self.MARK_DONE_URL_NAME, args=(self.referral.patient.id, self.referral.id, self.id)) def admin_url(self): return reverse( 'admin:referral_followuprequest_change', args=(self.id,) ) def __str__(self): formatted_date = self.due_date.strftime("%D") return 'Followup with %s on %s about %s' % (self.patient, formatted_date, self.referral) class PatientContact(Note): followup_request = models.ForeignKey(FollowupRequest) referral = models.ForeignKey(Referral) contact_method = models.ForeignKey( ContactMethod, null=False, blank=False, help_text="What was the method of contact?") contact_status = models.ForeignKey( ContactResult, blank=False, null=False, help_text="Did you make contact with the patient about this referral?") PTSHOW_YES = "Y" PTSHOW_NO = "N" PTSHOW_OPTS = [(PTSHOW_YES, "Yes"), (PTSHOW_NO, "No")] has_appointment = models.CharField( choices=PTSHOW_OPTS, blank=True, max_length=1, verbose_name="Appointment scheduled?", help_text="Did the patient make an appointment?") no_apt_reason = models.ForeignKey( NoAptReason, blank=True, null=True, verbose_name="No appointment reason", help_text="If the patient didn't make an appointment, why not?") appointment_location = models.ManyToManyField( ReferralLocation, blank=True, help_text="Where did the patient make an appointment?") pt_showed = models.CharField( max_length=1, choices=PTSHOW_OPTS, blank=True, null=True, verbose_name="Appointment attended?", help_text="Did the patient show up to the appointment?") no_show_reason = models.ForeignKey( NoShowReason, blank=True, null=True, help_text="If the patient didn't go to the appointment, why not?") def short_text(self): """Return a short text description of this followup and what happened. Used on the patient chart view as the text in the list of followups. """ text = "" locations = " ,".join(map(str, self.appointment_location.all())) if self.pt_showed == self.PTSHOW_YES: text = "Patient went to appointment at " + locations + "." else: if self.has_appointment == self.PTSHOW_YES: text = ("Patient made appointment at " + locations + "but has not yet gone.") else: if self.contact_status.patient_reached: text = ("Successfully contacted patient but the " "patient has not made an appointment yet.") else: text = "Did not successfully contact patient" return text <|fim▁end|>
class_name
<|file_name|>models.py<|end_file_name|><|fim▁begin|>"""Data models for referral system.""" from __future__ import unicode_literals from builtins import map from django.db import models from django.core.urlresolvers import reverse from pttrack.models import (ReferralType, ReferralLocation, Note, ContactMethod, CompletableMixin,) from followup.models import ContactResult, NoAptReason, NoShowReason class Referral(Note): """A record of a particular patient's referral to a particular center.""" STATUS_SUCCESSFUL = 'S' STATUS_PENDING = 'P' STATUS_UNSUCCESSFUL = 'U' # Status if there are no referrals of a specific type # Used in aggregate_referral_status NO_REFERRALS_CURRENTLY = "No referrals currently" REFERRAL_STATUSES = ( (STATUS_SUCCESSFUL, 'Successful'), (STATUS_PENDING, 'Pending'), (STATUS_UNSUCCESSFUL, 'Unsuccessful'), ) location = models.ManyToManyField(ReferralLocation) comments = models.TextField(blank=True) status = models.CharField( max_length=50, choices=REFERRAL_STATUSES, default=STATUS_PENDING) kind = models.ForeignKey( ReferralType, help_text="The kind of care the patient should recieve at the " "referral location.") def __str__(self): """Provides string to display on front end for referral. For FQHC referrals, returns referral kind and date. For non-FQHC referrals, returns referral location and date. """ formatted_date = self.written_datetime.strftime("%D") if self.kind.is_fqhc: return "%s referral on %s" % (self.kind, formatted_date) else: location_names = [loc.name for loc in self.location.all()] locations = " ,".join(location_names) return "Referral to %s on %s" % (locations, formatted_date) @staticmethod def aggregate_referral_status(referrals): referral_status_output = "" if referrals: all_successful = all(referral.status == Referral.STATUS_SUCCESSFUL for referral in referrals) if all_successful: referral_status_output = (dict(Referral.REFERRAL_STATUSES) [Referral.STATUS_SUCCESSFUL]) else: # Determine referral status based on the last FQHC referral referral_status_output = (dict(Referral.REFERRAL_STATUSES) [referrals.last().status]) else: referral_status_output = Referral.NO_REFERRALS_CURRENTLY return referral_status_output class FollowupRequest(Note, CompletableMixin): referral = models.ForeignKey(Referral) contact_instructions = models.TextField() MARK_DONE_URL_NAME = 'new-patient-contact' ADMIN_URL_NAME = '' def class_name(self): return self.__class__.__name__ def <|fim_middle|>(self): return "Referral" def summary(self): return self.contact_instructions def mark_done_url(self): return reverse(self.MARK_DONE_URL_NAME, args=(self.referral.patient.id, self.referral.id, self.id)) def admin_url(self): return reverse( 'admin:referral_followuprequest_change', args=(self.id,) ) def __str__(self): formatted_date = self.due_date.strftime("%D") return 'Followup with %s on %s about %s' % (self.patient, formatted_date, self.referral) class PatientContact(Note): followup_request = models.ForeignKey(FollowupRequest) referral = models.ForeignKey(Referral) contact_method = models.ForeignKey( ContactMethod, null=False, blank=False, help_text="What was the method of contact?") contact_status = models.ForeignKey( ContactResult, blank=False, null=False, help_text="Did you make contact with the patient about this referral?") PTSHOW_YES = "Y" PTSHOW_NO = "N" PTSHOW_OPTS = [(PTSHOW_YES, "Yes"), (PTSHOW_NO, "No")] has_appointment = models.CharField( choices=PTSHOW_OPTS, blank=True, max_length=1, verbose_name="Appointment scheduled?", help_text="Did the patient make an appointment?") no_apt_reason = models.ForeignKey( NoAptReason, blank=True, null=True, verbose_name="No appointment reason", help_text="If the patient didn't make an appointment, why not?") appointment_location = models.ManyToManyField( ReferralLocation, blank=True, help_text="Where did the patient make an appointment?") pt_showed = models.CharField( max_length=1, choices=PTSHOW_OPTS, blank=True, null=True, verbose_name="Appointment attended?", help_text="Did the patient show up to the appointment?") no_show_reason = models.ForeignKey( NoShowReason, blank=True, null=True, help_text="If the patient didn't go to the appointment, why not?") def short_text(self): """Return a short text description of this followup and what happened. Used on the patient chart view as the text in the list of followups. """ text = "" locations = " ,".join(map(str, self.appointment_location.all())) if self.pt_showed == self.PTSHOW_YES: text = "Patient went to appointment at " + locations + "." else: if self.has_appointment == self.PTSHOW_YES: text = ("Patient made appointment at " + locations + "but has not yet gone.") else: if self.contact_status.patient_reached: text = ("Successfully contacted patient but the " "patient has not made an appointment yet.") else: text = "Did not successfully contact patient" return text <|fim▁end|>
short_name
<|file_name|>models.py<|end_file_name|><|fim▁begin|>"""Data models for referral system.""" from __future__ import unicode_literals from builtins import map from django.db import models from django.core.urlresolvers import reverse from pttrack.models import (ReferralType, ReferralLocation, Note, ContactMethod, CompletableMixin,) from followup.models import ContactResult, NoAptReason, NoShowReason class Referral(Note): """A record of a particular patient's referral to a particular center.""" STATUS_SUCCESSFUL = 'S' STATUS_PENDING = 'P' STATUS_UNSUCCESSFUL = 'U' # Status if there are no referrals of a specific type # Used in aggregate_referral_status NO_REFERRALS_CURRENTLY = "No referrals currently" REFERRAL_STATUSES = ( (STATUS_SUCCESSFUL, 'Successful'), (STATUS_PENDING, 'Pending'), (STATUS_UNSUCCESSFUL, 'Unsuccessful'), ) location = models.ManyToManyField(ReferralLocation) comments = models.TextField(blank=True) status = models.CharField( max_length=50, choices=REFERRAL_STATUSES, default=STATUS_PENDING) kind = models.ForeignKey( ReferralType, help_text="The kind of care the patient should recieve at the " "referral location.") def __str__(self): """Provides string to display on front end for referral. For FQHC referrals, returns referral kind and date. For non-FQHC referrals, returns referral location and date. """ formatted_date = self.written_datetime.strftime("%D") if self.kind.is_fqhc: return "%s referral on %s" % (self.kind, formatted_date) else: location_names = [loc.name for loc in self.location.all()] locations = " ,".join(location_names) return "Referral to %s on %s" % (locations, formatted_date) @staticmethod def aggregate_referral_status(referrals): referral_status_output = "" if referrals: all_successful = all(referral.status == Referral.STATUS_SUCCESSFUL for referral in referrals) if all_successful: referral_status_output = (dict(Referral.REFERRAL_STATUSES) [Referral.STATUS_SUCCESSFUL]) else: # Determine referral status based on the last FQHC referral referral_status_output = (dict(Referral.REFERRAL_STATUSES) [referrals.last().status]) else: referral_status_output = Referral.NO_REFERRALS_CURRENTLY return referral_status_output class FollowupRequest(Note, CompletableMixin): referral = models.ForeignKey(Referral) contact_instructions = models.TextField() MARK_DONE_URL_NAME = 'new-patient-contact' ADMIN_URL_NAME = '' def class_name(self): return self.__class__.__name__ def short_name(self): return "Referral" def <|fim_middle|>(self): return self.contact_instructions def mark_done_url(self): return reverse(self.MARK_DONE_URL_NAME, args=(self.referral.patient.id, self.referral.id, self.id)) def admin_url(self): return reverse( 'admin:referral_followuprequest_change', args=(self.id,) ) def __str__(self): formatted_date = self.due_date.strftime("%D") return 'Followup with %s on %s about %s' % (self.patient, formatted_date, self.referral) class PatientContact(Note): followup_request = models.ForeignKey(FollowupRequest) referral = models.ForeignKey(Referral) contact_method = models.ForeignKey( ContactMethod, null=False, blank=False, help_text="What was the method of contact?") contact_status = models.ForeignKey( ContactResult, blank=False, null=False, help_text="Did you make contact with the patient about this referral?") PTSHOW_YES = "Y" PTSHOW_NO = "N" PTSHOW_OPTS = [(PTSHOW_YES, "Yes"), (PTSHOW_NO, "No")] has_appointment = models.CharField( choices=PTSHOW_OPTS, blank=True, max_length=1, verbose_name="Appointment scheduled?", help_text="Did the patient make an appointment?") no_apt_reason = models.ForeignKey( NoAptReason, blank=True, null=True, verbose_name="No appointment reason", help_text="If the patient didn't make an appointment, why not?") appointment_location = models.ManyToManyField( ReferralLocation, blank=True, help_text="Where did the patient make an appointment?") pt_showed = models.CharField( max_length=1, choices=PTSHOW_OPTS, blank=True, null=True, verbose_name="Appointment attended?", help_text="Did the patient show up to the appointment?") no_show_reason = models.ForeignKey( NoShowReason, blank=True, null=True, help_text="If the patient didn't go to the appointment, why not?") def short_text(self): """Return a short text description of this followup and what happened. Used on the patient chart view as the text in the list of followups. """ text = "" locations = " ,".join(map(str, self.appointment_location.all())) if self.pt_showed == self.PTSHOW_YES: text = "Patient went to appointment at " + locations + "." else: if self.has_appointment == self.PTSHOW_YES: text = ("Patient made appointment at " + locations + "but has not yet gone.") else: if self.contact_status.patient_reached: text = ("Successfully contacted patient but the " "patient has not made an appointment yet.") else: text = "Did not successfully contact patient" return text <|fim▁end|>
summary
<|file_name|>models.py<|end_file_name|><|fim▁begin|>"""Data models for referral system.""" from __future__ import unicode_literals from builtins import map from django.db import models from django.core.urlresolvers import reverse from pttrack.models import (ReferralType, ReferralLocation, Note, ContactMethod, CompletableMixin,) from followup.models import ContactResult, NoAptReason, NoShowReason class Referral(Note): """A record of a particular patient's referral to a particular center.""" STATUS_SUCCESSFUL = 'S' STATUS_PENDING = 'P' STATUS_UNSUCCESSFUL = 'U' # Status if there are no referrals of a specific type # Used in aggregate_referral_status NO_REFERRALS_CURRENTLY = "No referrals currently" REFERRAL_STATUSES = ( (STATUS_SUCCESSFUL, 'Successful'), (STATUS_PENDING, 'Pending'), (STATUS_UNSUCCESSFUL, 'Unsuccessful'), ) location = models.ManyToManyField(ReferralLocation) comments = models.TextField(blank=True) status = models.CharField( max_length=50, choices=REFERRAL_STATUSES, default=STATUS_PENDING) kind = models.ForeignKey( ReferralType, help_text="The kind of care the patient should recieve at the " "referral location.") def __str__(self): """Provides string to display on front end for referral. For FQHC referrals, returns referral kind and date. For non-FQHC referrals, returns referral location and date. """ formatted_date = self.written_datetime.strftime("%D") if self.kind.is_fqhc: return "%s referral on %s" % (self.kind, formatted_date) else: location_names = [loc.name for loc in self.location.all()] locations = " ,".join(location_names) return "Referral to %s on %s" % (locations, formatted_date) @staticmethod def aggregate_referral_status(referrals): referral_status_output = "" if referrals: all_successful = all(referral.status == Referral.STATUS_SUCCESSFUL for referral in referrals) if all_successful: referral_status_output = (dict(Referral.REFERRAL_STATUSES) [Referral.STATUS_SUCCESSFUL]) else: # Determine referral status based on the last FQHC referral referral_status_output = (dict(Referral.REFERRAL_STATUSES) [referrals.last().status]) else: referral_status_output = Referral.NO_REFERRALS_CURRENTLY return referral_status_output class FollowupRequest(Note, CompletableMixin): referral = models.ForeignKey(Referral) contact_instructions = models.TextField() MARK_DONE_URL_NAME = 'new-patient-contact' ADMIN_URL_NAME = '' def class_name(self): return self.__class__.__name__ def short_name(self): return "Referral" def summary(self): return self.contact_instructions def <|fim_middle|>(self): return reverse(self.MARK_DONE_URL_NAME, args=(self.referral.patient.id, self.referral.id, self.id)) def admin_url(self): return reverse( 'admin:referral_followuprequest_change', args=(self.id,) ) def __str__(self): formatted_date = self.due_date.strftime("%D") return 'Followup with %s on %s about %s' % (self.patient, formatted_date, self.referral) class PatientContact(Note): followup_request = models.ForeignKey(FollowupRequest) referral = models.ForeignKey(Referral) contact_method = models.ForeignKey( ContactMethod, null=False, blank=False, help_text="What was the method of contact?") contact_status = models.ForeignKey( ContactResult, blank=False, null=False, help_text="Did you make contact with the patient about this referral?") PTSHOW_YES = "Y" PTSHOW_NO = "N" PTSHOW_OPTS = [(PTSHOW_YES, "Yes"), (PTSHOW_NO, "No")] has_appointment = models.CharField( choices=PTSHOW_OPTS, blank=True, max_length=1, verbose_name="Appointment scheduled?", help_text="Did the patient make an appointment?") no_apt_reason = models.ForeignKey( NoAptReason, blank=True, null=True, verbose_name="No appointment reason", help_text="If the patient didn't make an appointment, why not?") appointment_location = models.ManyToManyField( ReferralLocation, blank=True, help_text="Where did the patient make an appointment?") pt_showed = models.CharField( max_length=1, choices=PTSHOW_OPTS, blank=True, null=True, verbose_name="Appointment attended?", help_text="Did the patient show up to the appointment?") no_show_reason = models.ForeignKey( NoShowReason, blank=True, null=True, help_text="If the patient didn't go to the appointment, why not?") def short_text(self): """Return a short text description of this followup and what happened. Used on the patient chart view as the text in the list of followups. """ text = "" locations = " ,".join(map(str, self.appointment_location.all())) if self.pt_showed == self.PTSHOW_YES: text = "Patient went to appointment at " + locations + "." else: if self.has_appointment == self.PTSHOW_YES: text = ("Patient made appointment at " + locations + "but has not yet gone.") else: if self.contact_status.patient_reached: text = ("Successfully contacted patient but the " "patient has not made an appointment yet.") else: text = "Did not successfully contact patient" return text <|fim▁end|>
mark_done_url
<|file_name|>models.py<|end_file_name|><|fim▁begin|>"""Data models for referral system.""" from __future__ import unicode_literals from builtins import map from django.db import models from django.core.urlresolvers import reverse from pttrack.models import (ReferralType, ReferralLocation, Note, ContactMethod, CompletableMixin,) from followup.models import ContactResult, NoAptReason, NoShowReason class Referral(Note): """A record of a particular patient's referral to a particular center.""" STATUS_SUCCESSFUL = 'S' STATUS_PENDING = 'P' STATUS_UNSUCCESSFUL = 'U' # Status if there are no referrals of a specific type # Used in aggregate_referral_status NO_REFERRALS_CURRENTLY = "No referrals currently" REFERRAL_STATUSES = ( (STATUS_SUCCESSFUL, 'Successful'), (STATUS_PENDING, 'Pending'), (STATUS_UNSUCCESSFUL, 'Unsuccessful'), ) location = models.ManyToManyField(ReferralLocation) comments = models.TextField(blank=True) status = models.CharField( max_length=50, choices=REFERRAL_STATUSES, default=STATUS_PENDING) kind = models.ForeignKey( ReferralType, help_text="The kind of care the patient should recieve at the " "referral location.") def __str__(self): """Provides string to display on front end for referral. For FQHC referrals, returns referral kind and date. For non-FQHC referrals, returns referral location and date. """ formatted_date = self.written_datetime.strftime("%D") if self.kind.is_fqhc: return "%s referral on %s" % (self.kind, formatted_date) else: location_names = [loc.name for loc in self.location.all()] locations = " ,".join(location_names) return "Referral to %s on %s" % (locations, formatted_date) @staticmethod def aggregate_referral_status(referrals): referral_status_output = "" if referrals: all_successful = all(referral.status == Referral.STATUS_SUCCESSFUL for referral in referrals) if all_successful: referral_status_output = (dict(Referral.REFERRAL_STATUSES) [Referral.STATUS_SUCCESSFUL]) else: # Determine referral status based on the last FQHC referral referral_status_output = (dict(Referral.REFERRAL_STATUSES) [referrals.last().status]) else: referral_status_output = Referral.NO_REFERRALS_CURRENTLY return referral_status_output class FollowupRequest(Note, CompletableMixin): referral = models.ForeignKey(Referral) contact_instructions = models.TextField() MARK_DONE_URL_NAME = 'new-patient-contact' ADMIN_URL_NAME = '' def class_name(self): return self.__class__.__name__ def short_name(self): return "Referral" def summary(self): return self.contact_instructions def mark_done_url(self): return reverse(self.MARK_DONE_URL_NAME, args=(self.referral.patient.id, self.referral.id, self.id)) def <|fim_middle|>(self): return reverse( 'admin:referral_followuprequest_change', args=(self.id,) ) def __str__(self): formatted_date = self.due_date.strftime("%D") return 'Followup with %s on %s about %s' % (self.patient, formatted_date, self.referral) class PatientContact(Note): followup_request = models.ForeignKey(FollowupRequest) referral = models.ForeignKey(Referral) contact_method = models.ForeignKey( ContactMethod, null=False, blank=False, help_text="What was the method of contact?") contact_status = models.ForeignKey( ContactResult, blank=False, null=False, help_text="Did you make contact with the patient about this referral?") PTSHOW_YES = "Y" PTSHOW_NO = "N" PTSHOW_OPTS = [(PTSHOW_YES, "Yes"), (PTSHOW_NO, "No")] has_appointment = models.CharField( choices=PTSHOW_OPTS, blank=True, max_length=1, verbose_name="Appointment scheduled?", help_text="Did the patient make an appointment?") no_apt_reason = models.ForeignKey( NoAptReason, blank=True, null=True, verbose_name="No appointment reason", help_text="If the patient didn't make an appointment, why not?") appointment_location = models.ManyToManyField( ReferralLocation, blank=True, help_text="Where did the patient make an appointment?") pt_showed = models.CharField( max_length=1, choices=PTSHOW_OPTS, blank=True, null=True, verbose_name="Appointment attended?", help_text="Did the patient show up to the appointment?") no_show_reason = models.ForeignKey( NoShowReason, blank=True, null=True, help_text="If the patient didn't go to the appointment, why not?") def short_text(self): """Return a short text description of this followup and what happened. Used on the patient chart view as the text in the list of followups. """ text = "" locations = " ,".join(map(str, self.appointment_location.all())) if self.pt_showed == self.PTSHOW_YES: text = "Patient went to appointment at " + locations + "." else: if self.has_appointment == self.PTSHOW_YES: text = ("Patient made appointment at " + locations + "but has not yet gone.") else: if self.contact_status.patient_reached: text = ("Successfully contacted patient but the " "patient has not made an appointment yet.") else: text = "Did not successfully contact patient" return text <|fim▁end|>
admin_url
<|file_name|>models.py<|end_file_name|><|fim▁begin|>"""Data models for referral system.""" from __future__ import unicode_literals from builtins import map from django.db import models from django.core.urlresolvers import reverse from pttrack.models import (ReferralType, ReferralLocation, Note, ContactMethod, CompletableMixin,) from followup.models import ContactResult, NoAptReason, NoShowReason class Referral(Note): """A record of a particular patient's referral to a particular center.""" STATUS_SUCCESSFUL = 'S' STATUS_PENDING = 'P' STATUS_UNSUCCESSFUL = 'U' # Status if there are no referrals of a specific type # Used in aggregate_referral_status NO_REFERRALS_CURRENTLY = "No referrals currently" REFERRAL_STATUSES = ( (STATUS_SUCCESSFUL, 'Successful'), (STATUS_PENDING, 'Pending'), (STATUS_UNSUCCESSFUL, 'Unsuccessful'), ) location = models.ManyToManyField(ReferralLocation) comments = models.TextField(blank=True) status = models.CharField( max_length=50, choices=REFERRAL_STATUSES, default=STATUS_PENDING) kind = models.ForeignKey( ReferralType, help_text="The kind of care the patient should recieve at the " "referral location.") def __str__(self): """Provides string to display on front end for referral. For FQHC referrals, returns referral kind and date. For non-FQHC referrals, returns referral location and date. """ formatted_date = self.written_datetime.strftime("%D") if self.kind.is_fqhc: return "%s referral on %s" % (self.kind, formatted_date) else: location_names = [loc.name for loc in self.location.all()] locations = " ,".join(location_names) return "Referral to %s on %s" % (locations, formatted_date) @staticmethod def aggregate_referral_status(referrals): referral_status_output = "" if referrals: all_successful = all(referral.status == Referral.STATUS_SUCCESSFUL for referral in referrals) if all_successful: referral_status_output = (dict(Referral.REFERRAL_STATUSES) [Referral.STATUS_SUCCESSFUL]) else: # Determine referral status based on the last FQHC referral referral_status_output = (dict(Referral.REFERRAL_STATUSES) [referrals.last().status]) else: referral_status_output = Referral.NO_REFERRALS_CURRENTLY return referral_status_output class FollowupRequest(Note, CompletableMixin): referral = models.ForeignKey(Referral) contact_instructions = models.TextField() MARK_DONE_URL_NAME = 'new-patient-contact' ADMIN_URL_NAME = '' def class_name(self): return self.__class__.__name__ def short_name(self): return "Referral" def summary(self): return self.contact_instructions def mark_done_url(self): return reverse(self.MARK_DONE_URL_NAME, args=(self.referral.patient.id, self.referral.id, self.id)) def admin_url(self): return reverse( 'admin:referral_followuprequest_change', args=(self.id,) ) def <|fim_middle|>(self): formatted_date = self.due_date.strftime("%D") return 'Followup with %s on %s about %s' % (self.patient, formatted_date, self.referral) class PatientContact(Note): followup_request = models.ForeignKey(FollowupRequest) referral = models.ForeignKey(Referral) contact_method = models.ForeignKey( ContactMethod, null=False, blank=False, help_text="What was the method of contact?") contact_status = models.ForeignKey( ContactResult, blank=False, null=False, help_text="Did you make contact with the patient about this referral?") PTSHOW_YES = "Y" PTSHOW_NO = "N" PTSHOW_OPTS = [(PTSHOW_YES, "Yes"), (PTSHOW_NO, "No")] has_appointment = models.CharField( choices=PTSHOW_OPTS, blank=True, max_length=1, verbose_name="Appointment scheduled?", help_text="Did the patient make an appointment?") no_apt_reason = models.ForeignKey( NoAptReason, blank=True, null=True, verbose_name="No appointment reason", help_text="If the patient didn't make an appointment, why not?") appointment_location = models.ManyToManyField( ReferralLocation, blank=True, help_text="Where did the patient make an appointment?") pt_showed = models.CharField( max_length=1, choices=PTSHOW_OPTS, blank=True, null=True, verbose_name="Appointment attended?", help_text="Did the patient show up to the appointment?") no_show_reason = models.ForeignKey( NoShowReason, blank=True, null=True, help_text="If the patient didn't go to the appointment, why not?") def short_text(self): """Return a short text description of this followup and what happened. Used on the patient chart view as the text in the list of followups. """ text = "" locations = " ,".join(map(str, self.appointment_location.all())) if self.pt_showed == self.PTSHOW_YES: text = "Patient went to appointment at " + locations + "." else: if self.has_appointment == self.PTSHOW_YES: text = ("Patient made appointment at " + locations + "but has not yet gone.") else: if self.contact_status.patient_reached: text = ("Successfully contacted patient but the " "patient has not made an appointment yet.") else: text = "Did not successfully contact patient" return text <|fim▁end|>
__str__
<|file_name|>models.py<|end_file_name|><|fim▁begin|>"""Data models for referral system.""" from __future__ import unicode_literals from builtins import map from django.db import models from django.core.urlresolvers import reverse from pttrack.models import (ReferralType, ReferralLocation, Note, ContactMethod, CompletableMixin,) from followup.models import ContactResult, NoAptReason, NoShowReason class Referral(Note): """A record of a particular patient's referral to a particular center.""" STATUS_SUCCESSFUL = 'S' STATUS_PENDING = 'P' STATUS_UNSUCCESSFUL = 'U' # Status if there are no referrals of a specific type # Used in aggregate_referral_status NO_REFERRALS_CURRENTLY = "No referrals currently" REFERRAL_STATUSES = ( (STATUS_SUCCESSFUL, 'Successful'), (STATUS_PENDING, 'Pending'), (STATUS_UNSUCCESSFUL, 'Unsuccessful'), ) location = models.ManyToManyField(ReferralLocation) comments = models.TextField(blank=True) status = models.CharField( max_length=50, choices=REFERRAL_STATUSES, default=STATUS_PENDING) kind = models.ForeignKey( ReferralType, help_text="The kind of care the patient should recieve at the " "referral location.") def __str__(self): """Provides string to display on front end for referral. For FQHC referrals, returns referral kind and date. For non-FQHC referrals, returns referral location and date. """ formatted_date = self.written_datetime.strftime("%D") if self.kind.is_fqhc: return "%s referral on %s" % (self.kind, formatted_date) else: location_names = [loc.name for loc in self.location.all()] locations = " ,".join(location_names) return "Referral to %s on %s" % (locations, formatted_date) @staticmethod def aggregate_referral_status(referrals): referral_status_output = "" if referrals: all_successful = all(referral.status == Referral.STATUS_SUCCESSFUL for referral in referrals) if all_successful: referral_status_output = (dict(Referral.REFERRAL_STATUSES) [Referral.STATUS_SUCCESSFUL]) else: # Determine referral status based on the last FQHC referral referral_status_output = (dict(Referral.REFERRAL_STATUSES) [referrals.last().status]) else: referral_status_output = Referral.NO_REFERRALS_CURRENTLY return referral_status_output class FollowupRequest(Note, CompletableMixin): referral = models.ForeignKey(Referral) contact_instructions = models.TextField() MARK_DONE_URL_NAME = 'new-patient-contact' ADMIN_URL_NAME = '' def class_name(self): return self.__class__.__name__ def short_name(self): return "Referral" def summary(self): return self.contact_instructions def mark_done_url(self): return reverse(self.MARK_DONE_URL_NAME, args=(self.referral.patient.id, self.referral.id, self.id)) def admin_url(self): return reverse( 'admin:referral_followuprequest_change', args=(self.id,) ) def __str__(self): formatted_date = self.due_date.strftime("%D") return 'Followup with %s on %s about %s' % (self.patient, formatted_date, self.referral) class PatientContact(Note): followup_request = models.ForeignKey(FollowupRequest) referral = models.ForeignKey(Referral) contact_method = models.ForeignKey( ContactMethod, null=False, blank=False, help_text="What was the method of contact?") contact_status = models.ForeignKey( ContactResult, blank=False, null=False, help_text="Did you make contact with the patient about this referral?") PTSHOW_YES = "Y" PTSHOW_NO = "N" PTSHOW_OPTS = [(PTSHOW_YES, "Yes"), (PTSHOW_NO, "No")] has_appointment = models.CharField( choices=PTSHOW_OPTS, blank=True, max_length=1, verbose_name="Appointment scheduled?", help_text="Did the patient make an appointment?") no_apt_reason = models.ForeignKey( NoAptReason, blank=True, null=True, verbose_name="No appointment reason", help_text="If the patient didn't make an appointment, why not?") appointment_location = models.ManyToManyField( ReferralLocation, blank=True, help_text="Where did the patient make an appointment?") pt_showed = models.CharField( max_length=1, choices=PTSHOW_OPTS, blank=True, null=True, verbose_name="Appointment attended?", help_text="Did the patient show up to the appointment?") no_show_reason = models.ForeignKey( NoShowReason, blank=True, null=True, help_text="If the patient didn't go to the appointment, why not?") def <|fim_middle|>(self): """Return a short text description of this followup and what happened. Used on the patient chart view as the text in the list of followups. """ text = "" locations = " ,".join(map(str, self.appointment_location.all())) if self.pt_showed == self.PTSHOW_YES: text = "Patient went to appointment at " + locations + "." else: if self.has_appointment == self.PTSHOW_YES: text = ("Patient made appointment at " + locations + "but has not yet gone.") else: if self.contact_status.patient_reached: text = ("Successfully contacted patient but the " "patient has not made an appointment yet.") else: text = "Did not successfully contact patient" return text <|fim▁end|>
short_text
<|file_name|>res_company.py<|end_file_name|><|fim▁begin|># -*- encoding: utf-8 -*- ############################################################################## # # res_partner # Copyright (c) 2013 Codeback Software S.L. (http://codeback.es) # @author: Miguel García <[email protected]> # @author: Javier Fuentes <[email protected]> #<|fim▁hole|># This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Affero General Public License for more details. # # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. # ############################################################################## from osv import fields, osv from datetime import datetime, timedelta from openerp.tools.translate import _ class res_company(osv.osv): """añadimos los nuevos campos""" _name = "res.company" _inherit = "res.company" _columns = { 'web_discount': fields.float('Descuento web (%)'), }<|fim▁end|>
<|file_name|>res_company.py<|end_file_name|><|fim▁begin|># -*- encoding: utf-8 -*- ############################################################################## # # res_partner # Copyright (c) 2013 Codeback Software S.L. (http://codeback.es) # @author: Miguel García <[email protected]> # @author: Javier Fuentes <[email protected]> # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Affero General Public License for more details. # # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. # ############################################################################## from osv import fields, osv from datetime import datetime, timedelta from openerp.tools.translate import _ class res_company(osv.osv): "<|fim_middle|> <|fim▁end|>
""añadimos los nuevos campos""" _name = "res.company" _inherit = "res.company" _columns = { 'web_discount': fields.float('Descuento web (%)'), }
<|file_name|>compiler.py<|end_file_name|><|fim▁begin|>import unittest, re from rexp.compiler import PatternCompiler <|fim▁hole|> def test_compile_1(self): compiler = PatternCompiler(pattern_set=dict( TEST=r'\w+' )) try: c1 = compiler.compile('$1{TEST}') except Exception as exc: self.assertTrue(1) c1 = compiler.compile('$1{TEST}', ['test']) self.assertEqual(c1, r'(?:(?P<test>(\w+)))') def test_compile_2(self): compiler = PatternCompiler(pattern_set=dict( TEST=r'\w+' )) try: c1 = compiler.compile('$1{TEST}') except: self.assertTrue(1) c1 = compiler.compile('$1{TEST}', ['test']) self.assertEqual(c1, r'(?:(?P<test>(\w+)))')<|fim▁end|>
class CompilerTestMethods(unittest.TestCase):
<|file_name|>compiler.py<|end_file_name|><|fim▁begin|>import unittest, re from rexp.compiler import PatternCompiler class CompilerTestMethods(unittest.TestCase): <|fim_middle|> <|fim▁end|>
def test_compile_1(self): compiler = PatternCompiler(pattern_set=dict( TEST=r'\w+' )) try: c1 = compiler.compile('$1{TEST}') except Exception as exc: self.assertTrue(1) c1 = compiler.compile('$1{TEST}', ['test']) self.assertEqual(c1, r'(?:(?P<test>(\w+)))') def test_compile_2(self): compiler = PatternCompiler(pattern_set=dict( TEST=r'\w+' )) try: c1 = compiler.compile('$1{TEST}') except: self.assertTrue(1) c1 = compiler.compile('$1{TEST}', ['test']) self.assertEqual(c1, r'(?:(?P<test>(\w+)))')
<|file_name|>compiler.py<|end_file_name|><|fim▁begin|>import unittest, re from rexp.compiler import PatternCompiler class CompilerTestMethods(unittest.TestCase): def test_compile_1(self): <|fim_middle|> def test_compile_2(self): compiler = PatternCompiler(pattern_set=dict( TEST=r'\w+' )) try: c1 = compiler.compile('$1{TEST}') except: self.assertTrue(1) c1 = compiler.compile('$1{TEST}', ['test']) self.assertEqual(c1, r'(?:(?P<test>(\w+)))') <|fim▁end|>
compiler = PatternCompiler(pattern_set=dict( TEST=r'\w+' )) try: c1 = compiler.compile('$1{TEST}') except Exception as exc: self.assertTrue(1) c1 = compiler.compile('$1{TEST}', ['test']) self.assertEqual(c1, r'(?:(?P<test>(\w+)))')
<|file_name|>compiler.py<|end_file_name|><|fim▁begin|>import unittest, re from rexp.compiler import PatternCompiler class CompilerTestMethods(unittest.TestCase): def test_compile_1(self): compiler = PatternCompiler(pattern_set=dict( TEST=r'\w+' )) try: c1 = compiler.compile('$1{TEST}') except Exception as exc: self.assertTrue(1) c1 = compiler.compile('$1{TEST}', ['test']) self.assertEqual(c1, r'(?:(?P<test>(\w+)))') def test_compile_2(self): <|fim_middle|> <|fim▁end|>
compiler = PatternCompiler(pattern_set=dict( TEST=r'\w+' )) try: c1 = compiler.compile('$1{TEST}') except: self.assertTrue(1) c1 = compiler.compile('$1{TEST}', ['test']) self.assertEqual(c1, r'(?:(?P<test>(\w+)))')
<|file_name|>compiler.py<|end_file_name|><|fim▁begin|>import unittest, re from rexp.compiler import PatternCompiler class CompilerTestMethods(unittest.TestCase): def <|fim_middle|>(self): compiler = PatternCompiler(pattern_set=dict( TEST=r'\w+' )) try: c1 = compiler.compile('$1{TEST}') except Exception as exc: self.assertTrue(1) c1 = compiler.compile('$1{TEST}', ['test']) self.assertEqual(c1, r'(?:(?P<test>(\w+)))') def test_compile_2(self): compiler = PatternCompiler(pattern_set=dict( TEST=r'\w+' )) try: c1 = compiler.compile('$1{TEST}') except: self.assertTrue(1) c1 = compiler.compile('$1{TEST}', ['test']) self.assertEqual(c1, r'(?:(?P<test>(\w+)))') <|fim▁end|>
test_compile_1
<|file_name|>compiler.py<|end_file_name|><|fim▁begin|>import unittest, re from rexp.compiler import PatternCompiler class CompilerTestMethods(unittest.TestCase): def test_compile_1(self): compiler = PatternCompiler(pattern_set=dict( TEST=r'\w+' )) try: c1 = compiler.compile('$1{TEST}') except Exception as exc: self.assertTrue(1) c1 = compiler.compile('$1{TEST}', ['test']) self.assertEqual(c1, r'(?:(?P<test>(\w+)))') def <|fim_middle|>(self): compiler = PatternCompiler(pattern_set=dict( TEST=r'\w+' )) try: c1 = compiler.compile('$1{TEST}') except: self.assertTrue(1) c1 = compiler.compile('$1{TEST}', ['test']) self.assertEqual(c1, r'(?:(?P<test>(\w+)))') <|fim▁end|>
test_compile_2
<|file_name|>cluster.py<|end_file_name|><|fim▁begin|>from changes.api.serializer import Crumbler, register from changes.models.node import Cluster @register(Cluster) class ClusterCrumbler(Crumbler): def crumble(self, instance, attrs): return { 'id': instance.id.hex, 'name': instance.label, 'dateCreated': instance.date_created,<|fim▁hole|> }<|fim▁end|>
<|file_name|>cluster.py<|end_file_name|><|fim▁begin|>from changes.api.serializer import Crumbler, register from changes.models.node import Cluster @register(Cluster) class ClusterCrumbler(Crumbler): <|fim_middle|> <|fim▁end|>
def crumble(self, instance, attrs): return { 'id': instance.id.hex, 'name': instance.label, 'dateCreated': instance.date_created, }
<|file_name|>cluster.py<|end_file_name|><|fim▁begin|>from changes.api.serializer import Crumbler, register from changes.models.node import Cluster @register(Cluster) class ClusterCrumbler(Crumbler): def crumble(self, instance, attrs): <|fim_middle|> <|fim▁end|>
return { 'id': instance.id.hex, 'name': instance.label, 'dateCreated': instance.date_created, }
<|file_name|>cluster.py<|end_file_name|><|fim▁begin|>from changes.api.serializer import Crumbler, register from changes.models.node import Cluster @register(Cluster) class ClusterCrumbler(Crumbler): def <|fim_middle|>(self, instance, attrs): return { 'id': instance.id.hex, 'name': instance.label, 'dateCreated': instance.date_created, } <|fim▁end|>
crumble
<|file_name|>Half_Year_End_Analysis.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*- """ Created on Thu Jan 03 10:16:39 2013 @author: Grahesh """ import pandas from qstkutil import DataAccess as da import numpy as np import math import copy import qstkutil.qsdateutil as du import datetime as dt import qstkutil.DataAccess as da import qstkutil.tsutil as tsu import qstkstudy.EventProfiler as ep """ Accepts a list of symbols along with start and end date Returns the Event Matrix which is a pandas Datamatrix Event matrix has the following structure : <|fim▁hole|> |IBM |GOOG|XOM |MSFT| GS | JP | (d1)|nan |nan | 1 |nan |nan | 1 | (d2)|nan | 1 |nan |nan |nan |nan | (d3)| 1 |nan | 1 |nan | 1 |nan | (d4)|nan | 1 |nan | 1 |nan |nan | ................................... ................................... Also, d1 = start date nan = no information about any event. 1 = status bit(positively confirms the event occurence) """ # Get the data from the data store storename = "NSEData" # get data from our daily prices source # Available field names: open, close, high, low, close, actual_close, volume closefield = "close" volumefield = "volume" window = 10 def getHalfYearEndDates(timestamps): newTS=[] tempYear=timestamps[0].year flag=1 for x in range(0, len(timestamps)-1): if(timestamps[x].year==tempYear): if(timestamps[x].month==4 and flag==1): newTS.append(timestamps[x-1]) flag=0 if(timestamps[x].month==10): newTS.append(timestamps[x-1]) tempYear=timestamps[x].year+1 flag=1 return newTS def findEvents(symbols, startday,endday, marketSymbol,verbose=False): # Reading the Data for the list of Symbols. timeofday=dt.timedelta(hours=16) timestamps = du.getNSEdays(startday,endday,timeofday) endOfHalfYear=getHalfYearEndDates(timestamps) dataobj = da.DataAccess('NSEData') if verbose: print __name__ + " reading data" # Reading the Data close = dataobj.get_data(timestamps, symbols, closefield) # Completing the Data - Removing the NaN values from the Matrix close = (close.fillna(method='ffill')).fillna(method='backfill') # Calculating Daily Returns for the Market tsu.returnize0(close.values) # Calculating the Returns of the Stock Relative to the Market # So if a Stock went up 5% and the Market rised 3%. The the return relative to market is 2% mktneutDM = close - close[marketSymbol] np_eventmat = copy.deepcopy(mktneutDM) for sym in symbols: for time in timestamps: np_eventmat[sym][time]=np.NAN if verbose: print __name__ + " finding events" # Generating the Event Matrix # Event described is : Analyzing half year events for given stocks. for symbol in symbols: for i in endOfHalfYear: np_eventmat[symbol][i] = 1.0 #overwriting by the bit, marking the event return np_eventmat ################################################# ################ MAIN CODE ###################### ################################################# symbols = np.loadtxt('NSE500port.csv',dtype='S13',comments='#', skiprows=1) # You might get a message about some files being missing, don't worry about it. #symbols =['SPY','BFRE','ATCS','RSERF','GDNEF','LAST','ATTUF','JBFCF','CYVA','SPF','XPO','EHECF','TEMO','AOLS','CSNT','REMI','GLRP','AIFLY','BEE','DJRT','CHSTF','AICAF'] #symbols=['NSE','3MINDIA.NS','AARTIIND.NS','ABAN.NS','ABB.NS','ABGSHIP.NS','ABIRLANUV.NS','ACC.NS','ADANIENT.NS','ADANIPORT.NS','ADANIPOWE.NS','ADVANTA.NS','ALLCARGO.NS','AIAENG.NS','AIL.NS','AZKOINDIA.NS'] startday = dt.datetime(2011,1,1) endday = dt.datetime(2012,1,1) eventMatrix = findEvents(symbols,startday,endday,marketSymbol='NSE500',verbose=True) eventMatrix.to_csv('eventmatrix.csv', sep=',') eventProfiler = ep.EventProfiler(eventMatrix,startday,endday,lookback_days=20,lookforward_days=20,verbose=True) eventProfiler.study(filename="HalfYearEventStudy.jpg",plotErrorBars=True,plotMarketNeutral=True,plotEvents=False,marketSymbol='NSE500')<|fim▁end|>
<|file_name|>Half_Year_End_Analysis.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*- """ Created on Thu Jan 03 10:16:39 2013 @author: Grahesh """ import pandas from qstkutil import DataAccess as da import numpy as np import math import copy import qstkutil.qsdateutil as du import datetime as dt import qstkutil.DataAccess as da import qstkutil.tsutil as tsu import qstkstudy.EventProfiler as ep """ Accepts a list of symbols along with start and end date Returns the Event Matrix which is a pandas Datamatrix Event matrix has the following structure : |IBM |GOOG|XOM |MSFT| GS | JP | (d1)|nan |nan | 1 |nan |nan | 1 | (d2)|nan | 1 |nan |nan |nan |nan | (d3)| 1 |nan | 1 |nan | 1 |nan | (d4)|nan | 1 |nan | 1 |nan |nan | ................................... ................................... Also, d1 = start date nan = no information about any event. 1 = status bit(positively confirms the event occurence) """ # Get the data from the data store storename = "NSEData" # get data from our daily prices source # Available field names: open, close, high, low, close, actual_close, volume closefield = "close" volumefield = "volume" window = 10 def getHalfYearEndDates(timestamps): <|fim_middle|> def findEvents(symbols, startday,endday, marketSymbol,verbose=False): # Reading the Data for the list of Symbols. timeofday=dt.timedelta(hours=16) timestamps = du.getNSEdays(startday,endday,timeofday) endOfHalfYear=getHalfYearEndDates(timestamps) dataobj = da.DataAccess('NSEData') if verbose: print __name__ + " reading data" # Reading the Data close = dataobj.get_data(timestamps, symbols, closefield) # Completing the Data - Removing the NaN values from the Matrix close = (close.fillna(method='ffill')).fillna(method='backfill') # Calculating Daily Returns for the Market tsu.returnize0(close.values) # Calculating the Returns of the Stock Relative to the Market # So if a Stock went up 5% and the Market rised 3%. The the return relative to market is 2% mktneutDM = close - close[marketSymbol] np_eventmat = copy.deepcopy(mktneutDM) for sym in symbols: for time in timestamps: np_eventmat[sym][time]=np.NAN if verbose: print __name__ + " finding events" # Generating the Event Matrix # Event described is : Analyzing half year events for given stocks. for symbol in symbols: for i in endOfHalfYear: np_eventmat[symbol][i] = 1.0 #overwriting by the bit, marking the event return np_eventmat ################################################# ################ MAIN CODE ###################### ################################################# symbols = np.loadtxt('NSE500port.csv',dtype='S13',comments='#', skiprows=1) # You might get a message about some files being missing, don't worry about it. #symbols =['SPY','BFRE','ATCS','RSERF','GDNEF','LAST','ATTUF','JBFCF','CYVA','SPF','XPO','EHECF','TEMO','AOLS','CSNT','REMI','GLRP','AIFLY','BEE','DJRT','CHSTF','AICAF'] #symbols=['NSE','3MINDIA.NS','AARTIIND.NS','ABAN.NS','ABB.NS','ABGSHIP.NS','ABIRLANUV.NS','ACC.NS','ADANIENT.NS','ADANIPORT.NS','ADANIPOWE.NS','ADVANTA.NS','ALLCARGO.NS','AIAENG.NS','AIL.NS','AZKOINDIA.NS'] startday = dt.datetime(2011,1,1) endday = dt.datetime(2012,1,1) eventMatrix = findEvents(symbols,startday,endday,marketSymbol='NSE500',verbose=True) eventMatrix.to_csv('eventmatrix.csv', sep=',') eventProfiler = ep.EventProfiler(eventMatrix,startday,endday,lookback_days=20,lookforward_days=20,verbose=True) eventProfiler.study(filename="HalfYearEventStudy.jpg",plotErrorBars=True,plotMarketNeutral=True,plotEvents=False,marketSymbol='NSE500') <|fim▁end|>
newTS=[] tempYear=timestamps[0].year flag=1 for x in range(0, len(timestamps)-1): if(timestamps[x].year==tempYear): if(timestamps[x].month==4 and flag==1): newTS.append(timestamps[x-1]) flag=0 if(timestamps[x].month==10): newTS.append(timestamps[x-1]) tempYear=timestamps[x].year+1 flag=1 return newTS
<|file_name|>Half_Year_End_Analysis.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*- """ Created on Thu Jan 03 10:16:39 2013 @author: Grahesh """ import pandas from qstkutil import DataAccess as da import numpy as np import math import copy import qstkutil.qsdateutil as du import datetime as dt import qstkutil.DataAccess as da import qstkutil.tsutil as tsu import qstkstudy.EventProfiler as ep """ Accepts a list of symbols along with start and end date Returns the Event Matrix which is a pandas Datamatrix Event matrix has the following structure : |IBM |GOOG|XOM |MSFT| GS | JP | (d1)|nan |nan | 1 |nan |nan | 1 | (d2)|nan | 1 |nan |nan |nan |nan | (d3)| 1 |nan | 1 |nan | 1 |nan | (d4)|nan | 1 |nan | 1 |nan |nan | ................................... ................................... Also, d1 = start date nan = no information about any event. 1 = status bit(positively confirms the event occurence) """ # Get the data from the data store storename = "NSEData" # get data from our daily prices source # Available field names: open, close, high, low, close, actual_close, volume closefield = "close" volumefield = "volume" window = 10 def getHalfYearEndDates(timestamps): newTS=[] tempYear=timestamps[0].year flag=1 for x in range(0, len(timestamps)-1): if(timestamps[x].year==tempYear): if(timestamps[x].month==4 and flag==1): newTS.append(timestamps[x-1]) flag=0 if(timestamps[x].month==10): newTS.append(timestamps[x-1]) tempYear=timestamps[x].year+1 flag=1 return newTS def findEvents(symbols, startday,endday, marketSymbol,verbose=False): # Reading the Data for the list of Symbols. <|fim_middle|> ################################################# ################ MAIN CODE ###################### ################################################# symbols = np.loadtxt('NSE500port.csv',dtype='S13',comments='#', skiprows=1) # You might get a message about some files being missing, don't worry about it. #symbols =['SPY','BFRE','ATCS','RSERF','GDNEF','LAST','ATTUF','JBFCF','CYVA','SPF','XPO','EHECF','TEMO','AOLS','CSNT','REMI','GLRP','AIFLY','BEE','DJRT','CHSTF','AICAF'] #symbols=['NSE','3MINDIA.NS','AARTIIND.NS','ABAN.NS','ABB.NS','ABGSHIP.NS','ABIRLANUV.NS','ACC.NS','ADANIENT.NS','ADANIPORT.NS','ADANIPOWE.NS','ADVANTA.NS','ALLCARGO.NS','AIAENG.NS','AIL.NS','AZKOINDIA.NS'] startday = dt.datetime(2011,1,1) endday = dt.datetime(2012,1,1) eventMatrix = findEvents(symbols,startday,endday,marketSymbol='NSE500',verbose=True) eventMatrix.to_csv('eventmatrix.csv', sep=',') eventProfiler = ep.EventProfiler(eventMatrix,startday,endday,lookback_days=20,lookforward_days=20,verbose=True) eventProfiler.study(filename="HalfYearEventStudy.jpg",plotErrorBars=True,plotMarketNeutral=True,plotEvents=False,marketSymbol='NSE500') <|fim▁end|>
timeofday=dt.timedelta(hours=16) timestamps = du.getNSEdays(startday,endday,timeofday) endOfHalfYear=getHalfYearEndDates(timestamps) dataobj = da.DataAccess('NSEData') if verbose: print __name__ + " reading data" # Reading the Data close = dataobj.get_data(timestamps, symbols, closefield) # Completing the Data - Removing the NaN values from the Matrix close = (close.fillna(method='ffill')).fillna(method='backfill') # Calculating Daily Returns for the Market tsu.returnize0(close.values) # Calculating the Returns of the Stock Relative to the Market # So if a Stock went up 5% and the Market rised 3%. The the return relative to market is 2% mktneutDM = close - close[marketSymbol] np_eventmat = copy.deepcopy(mktneutDM) for sym in symbols: for time in timestamps: np_eventmat[sym][time]=np.NAN if verbose: print __name__ + " finding events" # Generating the Event Matrix # Event described is : Analyzing half year events for given stocks. for symbol in symbols: for i in endOfHalfYear: np_eventmat[symbol][i] = 1.0 #overwriting by the bit, marking the event return np_eventmat
<|file_name|>Half_Year_End_Analysis.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*- """ Created on Thu Jan 03 10:16:39 2013 @author: Grahesh """ import pandas from qstkutil import DataAccess as da import numpy as np import math import copy import qstkutil.qsdateutil as du import datetime as dt import qstkutil.DataAccess as da import qstkutil.tsutil as tsu import qstkstudy.EventProfiler as ep """ Accepts a list of symbols along with start and end date Returns the Event Matrix which is a pandas Datamatrix Event matrix has the following structure : |IBM |GOOG|XOM |MSFT| GS | JP | (d1)|nan |nan | 1 |nan |nan | 1 | (d2)|nan | 1 |nan |nan |nan |nan | (d3)| 1 |nan | 1 |nan | 1 |nan | (d4)|nan | 1 |nan | 1 |nan |nan | ................................... ................................... Also, d1 = start date nan = no information about any event. 1 = status bit(positively confirms the event occurence) """ # Get the data from the data store storename = "NSEData" # get data from our daily prices source # Available field names: open, close, high, low, close, actual_close, volume closefield = "close" volumefield = "volume" window = 10 def <|fim_middle|>(timestamps): newTS=[] tempYear=timestamps[0].year flag=1 for x in range(0, len(timestamps)-1): if(timestamps[x].year==tempYear): if(timestamps[x].month==4 and flag==1): newTS.append(timestamps[x-1]) flag=0 if(timestamps[x].month==10): newTS.append(timestamps[x-1]) tempYear=timestamps[x].year+1 flag=1 return newTS def findEvents(symbols, startday,endday, marketSymbol,verbose=False): # Reading the Data for the list of Symbols. timeofday=dt.timedelta(hours=16) timestamps = du.getNSEdays(startday,endday,timeofday) endOfHalfYear=getHalfYearEndDates(timestamps) dataobj = da.DataAccess('NSEData') if verbose: print __name__ + " reading data" # Reading the Data close = dataobj.get_data(timestamps, symbols, closefield) # Completing the Data - Removing the NaN values from the Matrix close = (close.fillna(method='ffill')).fillna(method='backfill') # Calculating Daily Returns for the Market tsu.returnize0(close.values) # Calculating the Returns of the Stock Relative to the Market # So if a Stock went up 5% and the Market rised 3%. The the return relative to market is 2% mktneutDM = close - close[marketSymbol] np_eventmat = copy.deepcopy(mktneutDM) for sym in symbols: for time in timestamps: np_eventmat[sym][time]=np.NAN if verbose: print __name__ + " finding events" # Generating the Event Matrix # Event described is : Analyzing half year events for given stocks. for symbol in symbols: for i in endOfHalfYear: np_eventmat[symbol][i] = 1.0 #overwriting by the bit, marking the event return np_eventmat ################################################# ################ MAIN CODE ###################### ################################################# symbols = np.loadtxt('NSE500port.csv',dtype='S13',comments='#', skiprows=1) # You might get a message about some files being missing, don't worry about it. #symbols =['SPY','BFRE','ATCS','RSERF','GDNEF','LAST','ATTUF','JBFCF','CYVA','SPF','XPO','EHECF','TEMO','AOLS','CSNT','REMI','GLRP','AIFLY','BEE','DJRT','CHSTF','AICAF'] #symbols=['NSE','3MINDIA.NS','AARTIIND.NS','ABAN.NS','ABB.NS','ABGSHIP.NS','ABIRLANUV.NS','ACC.NS','ADANIENT.NS','ADANIPORT.NS','ADANIPOWE.NS','ADVANTA.NS','ALLCARGO.NS','AIAENG.NS','AIL.NS','AZKOINDIA.NS'] startday = dt.datetime(2011,1,1) endday = dt.datetime(2012,1,1) eventMatrix = findEvents(symbols,startday,endday,marketSymbol='NSE500',verbose=True) eventMatrix.to_csv('eventmatrix.csv', sep=',') eventProfiler = ep.EventProfiler(eventMatrix,startday,endday,lookback_days=20,lookforward_days=20,verbose=True) eventProfiler.study(filename="HalfYearEventStudy.jpg",plotErrorBars=True,plotMarketNeutral=True,plotEvents=False,marketSymbol='NSE500') <|fim▁end|>
getHalfYearEndDates
<|file_name|>Half_Year_End_Analysis.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*- """ Created on Thu Jan 03 10:16:39 2013 @author: Grahesh """ import pandas from qstkutil import DataAccess as da import numpy as np import math import copy import qstkutil.qsdateutil as du import datetime as dt import qstkutil.DataAccess as da import qstkutil.tsutil as tsu import qstkstudy.EventProfiler as ep """ Accepts a list of symbols along with start and end date Returns the Event Matrix which is a pandas Datamatrix Event matrix has the following structure : |IBM |GOOG|XOM |MSFT| GS | JP | (d1)|nan |nan | 1 |nan |nan | 1 | (d2)|nan | 1 |nan |nan |nan |nan | (d3)| 1 |nan | 1 |nan | 1 |nan | (d4)|nan | 1 |nan | 1 |nan |nan | ................................... ................................... Also, d1 = start date nan = no information about any event. 1 = status bit(positively confirms the event occurence) """ # Get the data from the data store storename = "NSEData" # get data from our daily prices source # Available field names: open, close, high, low, close, actual_close, volume closefield = "close" volumefield = "volume" window = 10 def getHalfYearEndDates(timestamps): newTS=[] tempYear=timestamps[0].year flag=1 for x in range(0, len(timestamps)-1): if(timestamps[x].year==tempYear): if(timestamps[x].month==4 and flag==1): newTS.append(timestamps[x-1]) flag=0 if(timestamps[x].month==10): newTS.append(timestamps[x-1]) tempYear=timestamps[x].year+1 flag=1 return newTS def <|fim_middle|>(symbols, startday,endday, marketSymbol,verbose=False): # Reading the Data for the list of Symbols. timeofday=dt.timedelta(hours=16) timestamps = du.getNSEdays(startday,endday,timeofday) endOfHalfYear=getHalfYearEndDates(timestamps) dataobj = da.DataAccess('NSEData') if verbose: print __name__ + " reading data" # Reading the Data close = dataobj.get_data(timestamps, symbols, closefield) # Completing the Data - Removing the NaN values from the Matrix close = (close.fillna(method='ffill')).fillna(method='backfill') # Calculating Daily Returns for the Market tsu.returnize0(close.values) # Calculating the Returns of the Stock Relative to the Market # So if a Stock went up 5% and the Market rised 3%. The the return relative to market is 2% mktneutDM = close - close[marketSymbol] np_eventmat = copy.deepcopy(mktneutDM) for sym in symbols: for time in timestamps: np_eventmat[sym][time]=np.NAN if verbose: print __name__ + " finding events" # Generating the Event Matrix # Event described is : Analyzing half year events for given stocks. for symbol in symbols: for i in endOfHalfYear: np_eventmat[symbol][i] = 1.0 #overwriting by the bit, marking the event return np_eventmat ################################################# ################ MAIN CODE ###################### ################################################# symbols = np.loadtxt('NSE500port.csv',dtype='S13',comments='#', skiprows=1) # You might get a message about some files being missing, don't worry about it. #symbols =['SPY','BFRE','ATCS','RSERF','GDNEF','LAST','ATTUF','JBFCF','CYVA','SPF','XPO','EHECF','TEMO','AOLS','CSNT','REMI','GLRP','AIFLY','BEE','DJRT','CHSTF','AICAF'] #symbols=['NSE','3MINDIA.NS','AARTIIND.NS','ABAN.NS','ABB.NS','ABGSHIP.NS','ABIRLANUV.NS','ACC.NS','ADANIENT.NS','ADANIPORT.NS','ADANIPOWE.NS','ADVANTA.NS','ALLCARGO.NS','AIAENG.NS','AIL.NS','AZKOINDIA.NS'] startday = dt.datetime(2011,1,1) endday = dt.datetime(2012,1,1) eventMatrix = findEvents(symbols,startday,endday,marketSymbol='NSE500',verbose=True) eventMatrix.to_csv('eventmatrix.csv', sep=',') eventProfiler = ep.EventProfiler(eventMatrix,startday,endday,lookback_days=20,lookforward_days=20,verbose=True) eventProfiler.study(filename="HalfYearEventStudy.jpg",plotErrorBars=True,plotMarketNeutral=True,plotEvents=False,marketSymbol='NSE500') <|fim▁end|>
findEvents
<|file_name|>Half_Year_End_Analysis.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*- """ Created on Thu Jan 03 10:16:39 2013 @author: Grahesh """ import pandas from qstkutil import DataAccess as da import numpy as np import math import copy import qstkutil.qsdateutil as du import datetime as dt import qstkutil.DataAccess as da import qstkutil.tsutil as tsu import qstkstudy.EventProfiler as ep """ Accepts a list of symbols along with start and end date Returns the Event Matrix which is a pandas Datamatrix Event matrix has the following structure : |IBM |GOOG|XOM |MSFT| GS | JP | (d1)|nan |nan | 1 |nan |nan | 1 | (d2)|nan | 1 |nan |nan |nan |nan | (d3)| 1 |nan | 1 |nan | 1 |nan | (d4)|nan | 1 |nan | 1 |nan |nan | ................................... ................................... Also, d1 = start date nan = no information about any event. 1 = status bit(positively confirms the event occurence) """ # Get the data from the data store storename = "NSEData" # get data from our daily prices source # Available field names: open, close, high, low, close, actual_close, volume closefield = "close" volumefield = "volume" window = 10 def getHalfYearEndDates(timestamps): newTS=[] tempYear=timestamps[0].year flag=1 for x in range(0, len(timestamps)-1): if(timestamps[x].year==tempYear): <|fim_middle|> return newTS def findEvents(symbols, startday,endday, marketSymbol,verbose=False): # Reading the Data for the list of Symbols. timeofday=dt.timedelta(hours=16) timestamps = du.getNSEdays(startday,endday,timeofday) endOfHalfYear=getHalfYearEndDates(timestamps) dataobj = da.DataAccess('NSEData') if verbose: print __name__ + " reading data" # Reading the Data close = dataobj.get_data(timestamps, symbols, closefield) # Completing the Data - Removing the NaN values from the Matrix close = (close.fillna(method='ffill')).fillna(method='backfill') # Calculating Daily Returns for the Market tsu.returnize0(close.values) # Calculating the Returns of the Stock Relative to the Market # So if a Stock went up 5% and the Market rised 3%. The the return relative to market is 2% mktneutDM = close - close[marketSymbol] np_eventmat = copy.deepcopy(mktneutDM) for sym in symbols: for time in timestamps: np_eventmat[sym][time]=np.NAN if verbose: print __name__ + " finding events" # Generating the Event Matrix # Event described is : Analyzing half year events for given stocks. for symbol in symbols: for i in endOfHalfYear: np_eventmat[symbol][i] = 1.0 #overwriting by the bit, marking the event return np_eventmat ################################################# ################ MAIN CODE ###################### ################################################# symbols = np.loadtxt('NSE500port.csv',dtype='S13',comments='#', skiprows=1) # You might get a message about some files being missing, don't worry about it. #symbols =['SPY','BFRE','ATCS','RSERF','GDNEF','LAST','ATTUF','JBFCF','CYVA','SPF','XPO','EHECF','TEMO','AOLS','CSNT','REMI','GLRP','AIFLY','BEE','DJRT','CHSTF','AICAF'] #symbols=['NSE','3MINDIA.NS','AARTIIND.NS','ABAN.NS','ABB.NS','ABGSHIP.NS','ABIRLANUV.NS','ACC.NS','ADANIENT.NS','ADANIPORT.NS','ADANIPOWE.NS','ADVANTA.NS','ALLCARGO.NS','AIAENG.NS','AIL.NS','AZKOINDIA.NS'] startday = dt.datetime(2011,1,1) endday = dt.datetime(2012,1,1) eventMatrix = findEvents(symbols,startday,endday,marketSymbol='NSE500',verbose=True) eventMatrix.to_csv('eventmatrix.csv', sep=',') eventProfiler = ep.EventProfiler(eventMatrix,startday,endday,lookback_days=20,lookforward_days=20,verbose=True) eventProfiler.study(filename="HalfYearEventStudy.jpg",plotErrorBars=True,plotMarketNeutral=True,plotEvents=False,marketSymbol='NSE500') <|fim▁end|>
if(timestamps[x].month==4 and flag==1): newTS.append(timestamps[x-1]) flag=0 if(timestamps[x].month==10): newTS.append(timestamps[x-1]) tempYear=timestamps[x].year+1 flag=1
<|file_name|>Half_Year_End_Analysis.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*- """ Created on Thu Jan 03 10:16:39 2013 @author: Grahesh """ import pandas from qstkutil import DataAccess as da import numpy as np import math import copy import qstkutil.qsdateutil as du import datetime as dt import qstkutil.DataAccess as da import qstkutil.tsutil as tsu import qstkstudy.EventProfiler as ep """ Accepts a list of symbols along with start and end date Returns the Event Matrix which is a pandas Datamatrix Event matrix has the following structure : |IBM |GOOG|XOM |MSFT| GS | JP | (d1)|nan |nan | 1 |nan |nan | 1 | (d2)|nan | 1 |nan |nan |nan |nan | (d3)| 1 |nan | 1 |nan | 1 |nan | (d4)|nan | 1 |nan | 1 |nan |nan | ................................... ................................... Also, d1 = start date nan = no information about any event. 1 = status bit(positively confirms the event occurence) """ # Get the data from the data store storename = "NSEData" # get data from our daily prices source # Available field names: open, close, high, low, close, actual_close, volume closefield = "close" volumefield = "volume" window = 10 def getHalfYearEndDates(timestamps): newTS=[] tempYear=timestamps[0].year flag=1 for x in range(0, len(timestamps)-1): if(timestamps[x].year==tempYear): if(timestamps[x].month==4 and flag==1): <|fim_middle|> if(timestamps[x].month==10): newTS.append(timestamps[x-1]) tempYear=timestamps[x].year+1 flag=1 return newTS def findEvents(symbols, startday,endday, marketSymbol,verbose=False): # Reading the Data for the list of Symbols. timeofday=dt.timedelta(hours=16) timestamps = du.getNSEdays(startday,endday,timeofday) endOfHalfYear=getHalfYearEndDates(timestamps) dataobj = da.DataAccess('NSEData') if verbose: print __name__ + " reading data" # Reading the Data close = dataobj.get_data(timestamps, symbols, closefield) # Completing the Data - Removing the NaN values from the Matrix close = (close.fillna(method='ffill')).fillna(method='backfill') # Calculating Daily Returns for the Market tsu.returnize0(close.values) # Calculating the Returns of the Stock Relative to the Market # So if a Stock went up 5% and the Market rised 3%. The the return relative to market is 2% mktneutDM = close - close[marketSymbol] np_eventmat = copy.deepcopy(mktneutDM) for sym in symbols: for time in timestamps: np_eventmat[sym][time]=np.NAN if verbose: print __name__ + " finding events" # Generating the Event Matrix # Event described is : Analyzing half year events for given stocks. for symbol in symbols: for i in endOfHalfYear: np_eventmat[symbol][i] = 1.0 #overwriting by the bit, marking the event return np_eventmat ################################################# ################ MAIN CODE ###################### ################################################# symbols = np.loadtxt('NSE500port.csv',dtype='S13',comments='#', skiprows=1) # You might get a message about some files being missing, don't worry about it. #symbols =['SPY','BFRE','ATCS','RSERF','GDNEF','LAST','ATTUF','JBFCF','CYVA','SPF','XPO','EHECF','TEMO','AOLS','CSNT','REMI','GLRP','AIFLY','BEE','DJRT','CHSTF','AICAF'] #symbols=['NSE','3MINDIA.NS','AARTIIND.NS','ABAN.NS','ABB.NS','ABGSHIP.NS','ABIRLANUV.NS','ACC.NS','ADANIENT.NS','ADANIPORT.NS','ADANIPOWE.NS','ADVANTA.NS','ALLCARGO.NS','AIAENG.NS','AIL.NS','AZKOINDIA.NS'] startday = dt.datetime(2011,1,1) endday = dt.datetime(2012,1,1) eventMatrix = findEvents(symbols,startday,endday,marketSymbol='NSE500',verbose=True) eventMatrix.to_csv('eventmatrix.csv', sep=',') eventProfiler = ep.EventProfiler(eventMatrix,startday,endday,lookback_days=20,lookforward_days=20,verbose=True) eventProfiler.study(filename="HalfYearEventStudy.jpg",plotErrorBars=True,plotMarketNeutral=True,plotEvents=False,marketSymbol='NSE500') <|fim▁end|>
newTS.append(timestamps[x-1]) flag=0
<|file_name|>Half_Year_End_Analysis.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*- """ Created on Thu Jan 03 10:16:39 2013 @author: Grahesh """ import pandas from qstkutil import DataAccess as da import numpy as np import math import copy import qstkutil.qsdateutil as du import datetime as dt import qstkutil.DataAccess as da import qstkutil.tsutil as tsu import qstkstudy.EventProfiler as ep """ Accepts a list of symbols along with start and end date Returns the Event Matrix which is a pandas Datamatrix Event matrix has the following structure : |IBM |GOOG|XOM |MSFT| GS | JP | (d1)|nan |nan | 1 |nan |nan | 1 | (d2)|nan | 1 |nan |nan |nan |nan | (d3)| 1 |nan | 1 |nan | 1 |nan | (d4)|nan | 1 |nan | 1 |nan |nan | ................................... ................................... Also, d1 = start date nan = no information about any event. 1 = status bit(positively confirms the event occurence) """ # Get the data from the data store storename = "NSEData" # get data from our daily prices source # Available field names: open, close, high, low, close, actual_close, volume closefield = "close" volumefield = "volume" window = 10 def getHalfYearEndDates(timestamps): newTS=[] tempYear=timestamps[0].year flag=1 for x in range(0, len(timestamps)-1): if(timestamps[x].year==tempYear): if(timestamps[x].month==4 and flag==1): newTS.append(timestamps[x-1]) flag=0 if(timestamps[x].month==10): <|fim_middle|> return newTS def findEvents(symbols, startday,endday, marketSymbol,verbose=False): # Reading the Data for the list of Symbols. timeofday=dt.timedelta(hours=16) timestamps = du.getNSEdays(startday,endday,timeofday) endOfHalfYear=getHalfYearEndDates(timestamps) dataobj = da.DataAccess('NSEData') if verbose: print __name__ + " reading data" # Reading the Data close = dataobj.get_data(timestamps, symbols, closefield) # Completing the Data - Removing the NaN values from the Matrix close = (close.fillna(method='ffill')).fillna(method='backfill') # Calculating Daily Returns for the Market tsu.returnize0(close.values) # Calculating the Returns of the Stock Relative to the Market # So if a Stock went up 5% and the Market rised 3%. The the return relative to market is 2% mktneutDM = close - close[marketSymbol] np_eventmat = copy.deepcopy(mktneutDM) for sym in symbols: for time in timestamps: np_eventmat[sym][time]=np.NAN if verbose: print __name__ + " finding events" # Generating the Event Matrix # Event described is : Analyzing half year events for given stocks. for symbol in symbols: for i in endOfHalfYear: np_eventmat[symbol][i] = 1.0 #overwriting by the bit, marking the event return np_eventmat ################################################# ################ MAIN CODE ###################### ################################################# symbols = np.loadtxt('NSE500port.csv',dtype='S13',comments='#', skiprows=1) # You might get a message about some files being missing, don't worry about it. #symbols =['SPY','BFRE','ATCS','RSERF','GDNEF','LAST','ATTUF','JBFCF','CYVA','SPF','XPO','EHECF','TEMO','AOLS','CSNT','REMI','GLRP','AIFLY','BEE','DJRT','CHSTF','AICAF'] #symbols=['NSE','3MINDIA.NS','AARTIIND.NS','ABAN.NS','ABB.NS','ABGSHIP.NS','ABIRLANUV.NS','ACC.NS','ADANIENT.NS','ADANIPORT.NS','ADANIPOWE.NS','ADVANTA.NS','ALLCARGO.NS','AIAENG.NS','AIL.NS','AZKOINDIA.NS'] startday = dt.datetime(2011,1,1) endday = dt.datetime(2012,1,1) eventMatrix = findEvents(symbols,startday,endday,marketSymbol='NSE500',verbose=True) eventMatrix.to_csv('eventmatrix.csv', sep=',') eventProfiler = ep.EventProfiler(eventMatrix,startday,endday,lookback_days=20,lookforward_days=20,verbose=True) eventProfiler.study(filename="HalfYearEventStudy.jpg",plotErrorBars=True,plotMarketNeutral=True,plotEvents=False,marketSymbol='NSE500') <|fim▁end|>
newTS.append(timestamps[x-1]) tempYear=timestamps[x].year+1 flag=1
<|file_name|>Half_Year_End_Analysis.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*- """ Created on Thu Jan 03 10:16:39 2013 @author: Grahesh """ import pandas from qstkutil import DataAccess as da import numpy as np import math import copy import qstkutil.qsdateutil as du import datetime as dt import qstkutil.DataAccess as da import qstkutil.tsutil as tsu import qstkstudy.EventProfiler as ep """ Accepts a list of symbols along with start and end date Returns the Event Matrix which is a pandas Datamatrix Event matrix has the following structure : |IBM |GOOG|XOM |MSFT| GS | JP | (d1)|nan |nan | 1 |nan |nan | 1 | (d2)|nan | 1 |nan |nan |nan |nan | (d3)| 1 |nan | 1 |nan | 1 |nan | (d4)|nan | 1 |nan | 1 |nan |nan | ................................... ................................... Also, d1 = start date nan = no information about any event. 1 = status bit(positively confirms the event occurence) """ # Get the data from the data store storename = "NSEData" # get data from our daily prices source # Available field names: open, close, high, low, close, actual_close, volume closefield = "close" volumefield = "volume" window = 10 def getHalfYearEndDates(timestamps): newTS=[] tempYear=timestamps[0].year flag=1 for x in range(0, len(timestamps)-1): if(timestamps[x].year==tempYear): if(timestamps[x].month==4 and flag==1): newTS.append(timestamps[x-1]) flag=0 if(timestamps[x].month==10): newTS.append(timestamps[x-1]) tempYear=timestamps[x].year+1 flag=1 return newTS def findEvents(symbols, startday,endday, marketSymbol,verbose=False): # Reading the Data for the list of Symbols. timeofday=dt.timedelta(hours=16) timestamps = du.getNSEdays(startday,endday,timeofday) endOfHalfYear=getHalfYearEndDates(timestamps) dataobj = da.DataAccess('NSEData') if verbose: <|fim_middle|> # Reading the Data close = dataobj.get_data(timestamps, symbols, closefield) # Completing the Data - Removing the NaN values from the Matrix close = (close.fillna(method='ffill')).fillna(method='backfill') # Calculating Daily Returns for the Market tsu.returnize0(close.values) # Calculating the Returns of the Stock Relative to the Market # So if a Stock went up 5% and the Market rised 3%. The the return relative to market is 2% mktneutDM = close - close[marketSymbol] np_eventmat = copy.deepcopy(mktneutDM) for sym in symbols: for time in timestamps: np_eventmat[sym][time]=np.NAN if verbose: print __name__ + " finding events" # Generating the Event Matrix # Event described is : Analyzing half year events for given stocks. for symbol in symbols: for i in endOfHalfYear: np_eventmat[symbol][i] = 1.0 #overwriting by the bit, marking the event return np_eventmat ################################################# ################ MAIN CODE ###################### ################################################# symbols = np.loadtxt('NSE500port.csv',dtype='S13',comments='#', skiprows=1) # You might get a message about some files being missing, don't worry about it. #symbols =['SPY','BFRE','ATCS','RSERF','GDNEF','LAST','ATTUF','JBFCF','CYVA','SPF','XPO','EHECF','TEMO','AOLS','CSNT','REMI','GLRP','AIFLY','BEE','DJRT','CHSTF','AICAF'] #symbols=['NSE','3MINDIA.NS','AARTIIND.NS','ABAN.NS','ABB.NS','ABGSHIP.NS','ABIRLANUV.NS','ACC.NS','ADANIENT.NS','ADANIPORT.NS','ADANIPOWE.NS','ADVANTA.NS','ALLCARGO.NS','AIAENG.NS','AIL.NS','AZKOINDIA.NS'] startday = dt.datetime(2011,1,1) endday = dt.datetime(2012,1,1) eventMatrix = findEvents(symbols,startday,endday,marketSymbol='NSE500',verbose=True) eventMatrix.to_csv('eventmatrix.csv', sep=',') eventProfiler = ep.EventProfiler(eventMatrix,startday,endday,lookback_days=20,lookforward_days=20,verbose=True) eventProfiler.study(filename="HalfYearEventStudy.jpg",plotErrorBars=True,plotMarketNeutral=True,plotEvents=False,marketSymbol='NSE500') <|fim▁end|>
print __name__ + " reading data"
<|file_name|>Half_Year_End_Analysis.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*- """ Created on Thu Jan 03 10:16:39 2013 @author: Grahesh """ import pandas from qstkutil import DataAccess as da import numpy as np import math import copy import qstkutil.qsdateutil as du import datetime as dt import qstkutil.DataAccess as da import qstkutil.tsutil as tsu import qstkstudy.EventProfiler as ep """ Accepts a list of symbols along with start and end date Returns the Event Matrix which is a pandas Datamatrix Event matrix has the following structure : |IBM |GOOG|XOM |MSFT| GS | JP | (d1)|nan |nan | 1 |nan |nan | 1 | (d2)|nan | 1 |nan |nan |nan |nan | (d3)| 1 |nan | 1 |nan | 1 |nan | (d4)|nan | 1 |nan | 1 |nan |nan | ................................... ................................... Also, d1 = start date nan = no information about any event. 1 = status bit(positively confirms the event occurence) """ # Get the data from the data store storename = "NSEData" # get data from our daily prices source # Available field names: open, close, high, low, close, actual_close, volume closefield = "close" volumefield = "volume" window = 10 def getHalfYearEndDates(timestamps): newTS=[] tempYear=timestamps[0].year flag=1 for x in range(0, len(timestamps)-1): if(timestamps[x].year==tempYear): if(timestamps[x].month==4 and flag==1): newTS.append(timestamps[x-1]) flag=0 if(timestamps[x].month==10): newTS.append(timestamps[x-1]) tempYear=timestamps[x].year+1 flag=1 return newTS def findEvents(symbols, startday,endday, marketSymbol,verbose=False): # Reading the Data for the list of Symbols. timeofday=dt.timedelta(hours=16) timestamps = du.getNSEdays(startday,endday,timeofday) endOfHalfYear=getHalfYearEndDates(timestamps) dataobj = da.DataAccess('NSEData') if verbose: print __name__ + " reading data" # Reading the Data close = dataobj.get_data(timestamps, symbols, closefield) # Completing the Data - Removing the NaN values from the Matrix close = (close.fillna(method='ffill')).fillna(method='backfill') # Calculating Daily Returns for the Market tsu.returnize0(close.values) # Calculating the Returns of the Stock Relative to the Market # So if a Stock went up 5% and the Market rised 3%. The the return relative to market is 2% mktneutDM = close - close[marketSymbol] np_eventmat = copy.deepcopy(mktneutDM) for sym in symbols: for time in timestamps: np_eventmat[sym][time]=np.NAN if verbose: <|fim_middle|> # Generating the Event Matrix # Event described is : Analyzing half year events for given stocks. for symbol in symbols: for i in endOfHalfYear: np_eventmat[symbol][i] = 1.0 #overwriting by the bit, marking the event return np_eventmat ################################################# ################ MAIN CODE ###################### ################################################# symbols = np.loadtxt('NSE500port.csv',dtype='S13',comments='#', skiprows=1) # You might get a message about some files being missing, don't worry about it. #symbols =['SPY','BFRE','ATCS','RSERF','GDNEF','LAST','ATTUF','JBFCF','CYVA','SPF','XPO','EHECF','TEMO','AOLS','CSNT','REMI','GLRP','AIFLY','BEE','DJRT','CHSTF','AICAF'] #symbols=['NSE','3MINDIA.NS','AARTIIND.NS','ABAN.NS','ABB.NS','ABGSHIP.NS','ABIRLANUV.NS','ACC.NS','ADANIENT.NS','ADANIPORT.NS','ADANIPOWE.NS','ADVANTA.NS','ALLCARGO.NS','AIAENG.NS','AIL.NS','AZKOINDIA.NS'] startday = dt.datetime(2011,1,1) endday = dt.datetime(2012,1,1) eventMatrix = findEvents(symbols,startday,endday,marketSymbol='NSE500',verbose=True) eventMatrix.to_csv('eventmatrix.csv', sep=',') eventProfiler = ep.EventProfiler(eventMatrix,startday,endday,lookback_days=20,lookforward_days=20,verbose=True) eventProfiler.study(filename="HalfYearEventStudy.jpg",plotErrorBars=True,plotMarketNeutral=True,plotEvents=False,marketSymbol='NSE500') <|fim▁end|>
print __name__ + " finding events"
<|file_name|>check_for_currupt_references.py<|end_file_name|><|fim▁begin|>from engine.api import API from engine.utils.printing_utils import progressBar from setup.utils.datastore_utils import repair_corrupt_reference, link_references_to_paper def remove_duplicates_from_cited_by(): print("\nRemove Duplicates") api = API() papers = api.get_all_paper() for i, paper in enumerate(papers): progressBar(i, len(papers)) paper.cited_by = list(dict.fromkeys(paper.cited_by)) api.client.update_paper(paper) def check_references(): print("\nCheck References") api = API() papers = api.get_all_paper() for i, paper in enumerate(papers): progressBar(i, len(papers)) other_papers = [p for p in papers if p.id != paper.id] for reference in paper.references: if not reference.get_paper_id(): continue ref_paper = api.get_paper(reference.get_paper_id()) if ref_paper.cited_by.count(paper.id) == 0: print() reference.paper_id = [] api.client.update_paper(paper) repair_corrupt_reference(reference, paper, other_papers, api) def check_cited_by():<|fim▁hole|> api = API() papers = api.get_all_paper() for i, paper in enumerate(papers): progressBar(i, len(papers)) for cited_paper_id in paper.cited_by: if not api.contains_paper(cited_paper_id): paper.cited_by.remove(cited_paper_id) api.client.update_paper(paper) continue cited_paper = api.get_paper(cited_paper_id) cited_paper_refs = [ref.get_paper_id() for ref in cited_paper.references if ref.get_paper_id()] if cited_paper_refs.count(paper.id) == 0: print() paper.cited_by.remove(cited_paper_id) api.client.update_paper(paper) link_references_to_paper(cited_paper, paper, api) def perform_checks(): check_cited_by() remove_duplicates_from_cited_by() check_references() if __name__ == "__main__": perform_checks() exit(0)<|fim▁end|>
print("\nCheck Cited by")
<|file_name|>check_for_currupt_references.py<|end_file_name|><|fim▁begin|>from engine.api import API from engine.utils.printing_utils import progressBar from setup.utils.datastore_utils import repair_corrupt_reference, link_references_to_paper def remove_duplicates_from_cited_by(): <|fim_middle|> def check_references(): print("\nCheck References") api = API() papers = api.get_all_paper() for i, paper in enumerate(papers): progressBar(i, len(papers)) other_papers = [p for p in papers if p.id != paper.id] for reference in paper.references: if not reference.get_paper_id(): continue ref_paper = api.get_paper(reference.get_paper_id()) if ref_paper.cited_by.count(paper.id) == 0: print() reference.paper_id = [] api.client.update_paper(paper) repair_corrupt_reference(reference, paper, other_papers, api) def check_cited_by(): print("\nCheck Cited by") api = API() papers = api.get_all_paper() for i, paper in enumerate(papers): progressBar(i, len(papers)) for cited_paper_id in paper.cited_by: if not api.contains_paper(cited_paper_id): paper.cited_by.remove(cited_paper_id) api.client.update_paper(paper) continue cited_paper = api.get_paper(cited_paper_id) cited_paper_refs = [ref.get_paper_id() for ref in cited_paper.references if ref.get_paper_id()] if cited_paper_refs.count(paper.id) == 0: print() paper.cited_by.remove(cited_paper_id) api.client.update_paper(paper) link_references_to_paper(cited_paper, paper, api) def perform_checks(): check_cited_by() remove_duplicates_from_cited_by() check_references() if __name__ == "__main__": perform_checks() exit(0) <|fim▁end|>
print("\nRemove Duplicates") api = API() papers = api.get_all_paper() for i, paper in enumerate(papers): progressBar(i, len(papers)) paper.cited_by = list(dict.fromkeys(paper.cited_by)) api.client.update_paper(paper)
<|file_name|>check_for_currupt_references.py<|end_file_name|><|fim▁begin|>from engine.api import API from engine.utils.printing_utils import progressBar from setup.utils.datastore_utils import repair_corrupt_reference, link_references_to_paper def remove_duplicates_from_cited_by(): print("\nRemove Duplicates") api = API() papers = api.get_all_paper() for i, paper in enumerate(papers): progressBar(i, len(papers)) paper.cited_by = list(dict.fromkeys(paper.cited_by)) api.client.update_paper(paper) def check_references(): <|fim_middle|> def check_cited_by(): print("\nCheck Cited by") api = API() papers = api.get_all_paper() for i, paper in enumerate(papers): progressBar(i, len(papers)) for cited_paper_id in paper.cited_by: if not api.contains_paper(cited_paper_id): paper.cited_by.remove(cited_paper_id) api.client.update_paper(paper) continue cited_paper = api.get_paper(cited_paper_id) cited_paper_refs = [ref.get_paper_id() for ref in cited_paper.references if ref.get_paper_id()] if cited_paper_refs.count(paper.id) == 0: print() paper.cited_by.remove(cited_paper_id) api.client.update_paper(paper) link_references_to_paper(cited_paper, paper, api) def perform_checks(): check_cited_by() remove_duplicates_from_cited_by() check_references() if __name__ == "__main__": perform_checks() exit(0) <|fim▁end|>
print("\nCheck References") api = API() papers = api.get_all_paper() for i, paper in enumerate(papers): progressBar(i, len(papers)) other_papers = [p for p in papers if p.id != paper.id] for reference in paper.references: if not reference.get_paper_id(): continue ref_paper = api.get_paper(reference.get_paper_id()) if ref_paper.cited_by.count(paper.id) == 0: print() reference.paper_id = [] api.client.update_paper(paper) repair_corrupt_reference(reference, paper, other_papers, api)
<|file_name|>check_for_currupt_references.py<|end_file_name|><|fim▁begin|>from engine.api import API from engine.utils.printing_utils import progressBar from setup.utils.datastore_utils import repair_corrupt_reference, link_references_to_paper def remove_duplicates_from_cited_by(): print("\nRemove Duplicates") api = API() papers = api.get_all_paper() for i, paper in enumerate(papers): progressBar(i, len(papers)) paper.cited_by = list(dict.fromkeys(paper.cited_by)) api.client.update_paper(paper) def check_references(): print("\nCheck References") api = API() papers = api.get_all_paper() for i, paper in enumerate(papers): progressBar(i, len(papers)) other_papers = [p for p in papers if p.id != paper.id] for reference in paper.references: if not reference.get_paper_id(): continue ref_paper = api.get_paper(reference.get_paper_id()) if ref_paper.cited_by.count(paper.id) == 0: print() reference.paper_id = [] api.client.update_paper(paper) repair_corrupt_reference(reference, paper, other_papers, api) def check_cited_by(): <|fim_middle|> def perform_checks(): check_cited_by() remove_duplicates_from_cited_by() check_references() if __name__ == "__main__": perform_checks() exit(0) <|fim▁end|>
print("\nCheck Cited by") api = API() papers = api.get_all_paper() for i, paper in enumerate(papers): progressBar(i, len(papers)) for cited_paper_id in paper.cited_by: if not api.contains_paper(cited_paper_id): paper.cited_by.remove(cited_paper_id) api.client.update_paper(paper) continue cited_paper = api.get_paper(cited_paper_id) cited_paper_refs = [ref.get_paper_id() for ref in cited_paper.references if ref.get_paper_id()] if cited_paper_refs.count(paper.id) == 0: print() paper.cited_by.remove(cited_paper_id) api.client.update_paper(paper) link_references_to_paper(cited_paper, paper, api)
<|file_name|>check_for_currupt_references.py<|end_file_name|><|fim▁begin|>from engine.api import API from engine.utils.printing_utils import progressBar from setup.utils.datastore_utils import repair_corrupt_reference, link_references_to_paper def remove_duplicates_from_cited_by(): print("\nRemove Duplicates") api = API() papers = api.get_all_paper() for i, paper in enumerate(papers): progressBar(i, len(papers)) paper.cited_by = list(dict.fromkeys(paper.cited_by)) api.client.update_paper(paper) def check_references(): print("\nCheck References") api = API() papers = api.get_all_paper() for i, paper in enumerate(papers): progressBar(i, len(papers)) other_papers = [p for p in papers if p.id != paper.id] for reference in paper.references: if not reference.get_paper_id(): continue ref_paper = api.get_paper(reference.get_paper_id()) if ref_paper.cited_by.count(paper.id) == 0: print() reference.paper_id = [] api.client.update_paper(paper) repair_corrupt_reference(reference, paper, other_papers, api) def check_cited_by(): print("\nCheck Cited by") api = API() papers = api.get_all_paper() for i, paper in enumerate(papers): progressBar(i, len(papers)) for cited_paper_id in paper.cited_by: if not api.contains_paper(cited_paper_id): paper.cited_by.remove(cited_paper_id) api.client.update_paper(paper) continue cited_paper = api.get_paper(cited_paper_id) cited_paper_refs = [ref.get_paper_id() for ref in cited_paper.references if ref.get_paper_id()] if cited_paper_refs.count(paper.id) == 0: print() paper.cited_by.remove(cited_paper_id) api.client.update_paper(paper) link_references_to_paper(cited_paper, paper, api) def perform_checks(): <|fim_middle|> if __name__ == "__main__": perform_checks() exit(0) <|fim▁end|>
check_cited_by() remove_duplicates_from_cited_by() check_references()
<|file_name|>check_for_currupt_references.py<|end_file_name|><|fim▁begin|>from engine.api import API from engine.utils.printing_utils import progressBar from setup.utils.datastore_utils import repair_corrupt_reference, link_references_to_paper def remove_duplicates_from_cited_by(): print("\nRemove Duplicates") api = API() papers = api.get_all_paper() for i, paper in enumerate(papers): progressBar(i, len(papers)) paper.cited_by = list(dict.fromkeys(paper.cited_by)) api.client.update_paper(paper) def check_references(): print("\nCheck References") api = API() papers = api.get_all_paper() for i, paper in enumerate(papers): progressBar(i, len(papers)) other_papers = [p for p in papers if p.id != paper.id] for reference in paper.references: if not reference.get_paper_id(): <|fim_middle|> ref_paper = api.get_paper(reference.get_paper_id()) if ref_paper.cited_by.count(paper.id) == 0: print() reference.paper_id = [] api.client.update_paper(paper) repair_corrupt_reference(reference, paper, other_papers, api) def check_cited_by(): print("\nCheck Cited by") api = API() papers = api.get_all_paper() for i, paper in enumerate(papers): progressBar(i, len(papers)) for cited_paper_id in paper.cited_by: if not api.contains_paper(cited_paper_id): paper.cited_by.remove(cited_paper_id) api.client.update_paper(paper) continue cited_paper = api.get_paper(cited_paper_id) cited_paper_refs = [ref.get_paper_id() for ref in cited_paper.references if ref.get_paper_id()] if cited_paper_refs.count(paper.id) == 0: print() paper.cited_by.remove(cited_paper_id) api.client.update_paper(paper) link_references_to_paper(cited_paper, paper, api) def perform_checks(): check_cited_by() remove_duplicates_from_cited_by() check_references() if __name__ == "__main__": perform_checks() exit(0) <|fim▁end|>
continue
<|file_name|>check_for_currupt_references.py<|end_file_name|><|fim▁begin|>from engine.api import API from engine.utils.printing_utils import progressBar from setup.utils.datastore_utils import repair_corrupt_reference, link_references_to_paper def remove_duplicates_from_cited_by(): print("\nRemove Duplicates") api = API() papers = api.get_all_paper() for i, paper in enumerate(papers): progressBar(i, len(papers)) paper.cited_by = list(dict.fromkeys(paper.cited_by)) api.client.update_paper(paper) def check_references(): print("\nCheck References") api = API() papers = api.get_all_paper() for i, paper in enumerate(papers): progressBar(i, len(papers)) other_papers = [p for p in papers if p.id != paper.id] for reference in paper.references: if not reference.get_paper_id(): continue ref_paper = api.get_paper(reference.get_paper_id()) if ref_paper.cited_by.count(paper.id) == 0: <|fim_middle|> def check_cited_by(): print("\nCheck Cited by") api = API() papers = api.get_all_paper() for i, paper in enumerate(papers): progressBar(i, len(papers)) for cited_paper_id in paper.cited_by: if not api.contains_paper(cited_paper_id): paper.cited_by.remove(cited_paper_id) api.client.update_paper(paper) continue cited_paper = api.get_paper(cited_paper_id) cited_paper_refs = [ref.get_paper_id() for ref in cited_paper.references if ref.get_paper_id()] if cited_paper_refs.count(paper.id) == 0: print() paper.cited_by.remove(cited_paper_id) api.client.update_paper(paper) link_references_to_paper(cited_paper, paper, api) def perform_checks(): check_cited_by() remove_duplicates_from_cited_by() check_references() if __name__ == "__main__": perform_checks() exit(0) <|fim▁end|>
print() reference.paper_id = [] api.client.update_paper(paper) repair_corrupt_reference(reference, paper, other_papers, api)
<|file_name|>check_for_currupt_references.py<|end_file_name|><|fim▁begin|>from engine.api import API from engine.utils.printing_utils import progressBar from setup.utils.datastore_utils import repair_corrupt_reference, link_references_to_paper def remove_duplicates_from_cited_by(): print("\nRemove Duplicates") api = API() papers = api.get_all_paper() for i, paper in enumerate(papers): progressBar(i, len(papers)) paper.cited_by = list(dict.fromkeys(paper.cited_by)) api.client.update_paper(paper) def check_references(): print("\nCheck References") api = API() papers = api.get_all_paper() for i, paper in enumerate(papers): progressBar(i, len(papers)) other_papers = [p for p in papers if p.id != paper.id] for reference in paper.references: if not reference.get_paper_id(): continue ref_paper = api.get_paper(reference.get_paper_id()) if ref_paper.cited_by.count(paper.id) == 0: print() reference.paper_id = [] api.client.update_paper(paper) repair_corrupt_reference(reference, paper, other_papers, api) def check_cited_by(): print("\nCheck Cited by") api = API() papers = api.get_all_paper() for i, paper in enumerate(papers): progressBar(i, len(papers)) for cited_paper_id in paper.cited_by: if not api.contains_paper(cited_paper_id): <|fim_middle|> cited_paper = api.get_paper(cited_paper_id) cited_paper_refs = [ref.get_paper_id() for ref in cited_paper.references if ref.get_paper_id()] if cited_paper_refs.count(paper.id) == 0: print() paper.cited_by.remove(cited_paper_id) api.client.update_paper(paper) link_references_to_paper(cited_paper, paper, api) def perform_checks(): check_cited_by() remove_duplicates_from_cited_by() check_references() if __name__ == "__main__": perform_checks() exit(0) <|fim▁end|>
paper.cited_by.remove(cited_paper_id) api.client.update_paper(paper) continue
<|file_name|>check_for_currupt_references.py<|end_file_name|><|fim▁begin|>from engine.api import API from engine.utils.printing_utils import progressBar from setup.utils.datastore_utils import repair_corrupt_reference, link_references_to_paper def remove_duplicates_from_cited_by(): print("\nRemove Duplicates") api = API() papers = api.get_all_paper() for i, paper in enumerate(papers): progressBar(i, len(papers)) paper.cited_by = list(dict.fromkeys(paper.cited_by)) api.client.update_paper(paper) def check_references(): print("\nCheck References") api = API() papers = api.get_all_paper() for i, paper in enumerate(papers): progressBar(i, len(papers)) other_papers = [p for p in papers if p.id != paper.id] for reference in paper.references: if not reference.get_paper_id(): continue ref_paper = api.get_paper(reference.get_paper_id()) if ref_paper.cited_by.count(paper.id) == 0: print() reference.paper_id = [] api.client.update_paper(paper) repair_corrupt_reference(reference, paper, other_papers, api) def check_cited_by(): print("\nCheck Cited by") api = API() papers = api.get_all_paper() for i, paper in enumerate(papers): progressBar(i, len(papers)) for cited_paper_id in paper.cited_by: if not api.contains_paper(cited_paper_id): paper.cited_by.remove(cited_paper_id) api.client.update_paper(paper) continue cited_paper = api.get_paper(cited_paper_id) cited_paper_refs = [ref.get_paper_id() for ref in cited_paper.references if ref.get_paper_id()] if cited_paper_refs.count(paper.id) == 0: <|fim_middle|> def perform_checks(): check_cited_by() remove_duplicates_from_cited_by() check_references() if __name__ == "__main__": perform_checks() exit(0) <|fim▁end|>
print() paper.cited_by.remove(cited_paper_id) api.client.update_paper(paper) link_references_to_paper(cited_paper, paper, api)
<|file_name|>check_for_currupt_references.py<|end_file_name|><|fim▁begin|>from engine.api import API from engine.utils.printing_utils import progressBar from setup.utils.datastore_utils import repair_corrupt_reference, link_references_to_paper def remove_duplicates_from_cited_by(): print("\nRemove Duplicates") api = API() papers = api.get_all_paper() for i, paper in enumerate(papers): progressBar(i, len(papers)) paper.cited_by = list(dict.fromkeys(paper.cited_by)) api.client.update_paper(paper) def check_references(): print("\nCheck References") api = API() papers = api.get_all_paper() for i, paper in enumerate(papers): progressBar(i, len(papers)) other_papers = [p for p in papers if p.id != paper.id] for reference in paper.references: if not reference.get_paper_id(): continue ref_paper = api.get_paper(reference.get_paper_id()) if ref_paper.cited_by.count(paper.id) == 0: print() reference.paper_id = [] api.client.update_paper(paper) repair_corrupt_reference(reference, paper, other_papers, api) def check_cited_by(): print("\nCheck Cited by") api = API() papers = api.get_all_paper() for i, paper in enumerate(papers): progressBar(i, len(papers)) for cited_paper_id in paper.cited_by: if not api.contains_paper(cited_paper_id): paper.cited_by.remove(cited_paper_id) api.client.update_paper(paper) continue cited_paper = api.get_paper(cited_paper_id) cited_paper_refs = [ref.get_paper_id() for ref in cited_paper.references if ref.get_paper_id()] if cited_paper_refs.count(paper.id) == 0: print() paper.cited_by.remove(cited_paper_id) api.client.update_paper(paper) link_references_to_paper(cited_paper, paper, api) def perform_checks(): check_cited_by() remove_duplicates_from_cited_by() check_references() if __name__ == "__main__": <|fim_middle|> <|fim▁end|>
perform_checks() exit(0)
<|file_name|>check_for_currupt_references.py<|end_file_name|><|fim▁begin|>from engine.api import API from engine.utils.printing_utils import progressBar from setup.utils.datastore_utils import repair_corrupt_reference, link_references_to_paper def <|fim_middle|>(): print("\nRemove Duplicates") api = API() papers = api.get_all_paper() for i, paper in enumerate(papers): progressBar(i, len(papers)) paper.cited_by = list(dict.fromkeys(paper.cited_by)) api.client.update_paper(paper) def check_references(): print("\nCheck References") api = API() papers = api.get_all_paper() for i, paper in enumerate(papers): progressBar(i, len(papers)) other_papers = [p for p in papers if p.id != paper.id] for reference in paper.references: if not reference.get_paper_id(): continue ref_paper = api.get_paper(reference.get_paper_id()) if ref_paper.cited_by.count(paper.id) == 0: print() reference.paper_id = [] api.client.update_paper(paper) repair_corrupt_reference(reference, paper, other_papers, api) def check_cited_by(): print("\nCheck Cited by") api = API() papers = api.get_all_paper() for i, paper in enumerate(papers): progressBar(i, len(papers)) for cited_paper_id in paper.cited_by: if not api.contains_paper(cited_paper_id): paper.cited_by.remove(cited_paper_id) api.client.update_paper(paper) continue cited_paper = api.get_paper(cited_paper_id) cited_paper_refs = [ref.get_paper_id() for ref in cited_paper.references if ref.get_paper_id()] if cited_paper_refs.count(paper.id) == 0: print() paper.cited_by.remove(cited_paper_id) api.client.update_paper(paper) link_references_to_paper(cited_paper, paper, api) def perform_checks(): check_cited_by() remove_duplicates_from_cited_by() check_references() if __name__ == "__main__": perform_checks() exit(0) <|fim▁end|>
remove_duplicates_from_cited_by
<|file_name|>check_for_currupt_references.py<|end_file_name|><|fim▁begin|>from engine.api import API from engine.utils.printing_utils import progressBar from setup.utils.datastore_utils import repair_corrupt_reference, link_references_to_paper def remove_duplicates_from_cited_by(): print("\nRemove Duplicates") api = API() papers = api.get_all_paper() for i, paper in enumerate(papers): progressBar(i, len(papers)) paper.cited_by = list(dict.fromkeys(paper.cited_by)) api.client.update_paper(paper) def <|fim_middle|>(): print("\nCheck References") api = API() papers = api.get_all_paper() for i, paper in enumerate(papers): progressBar(i, len(papers)) other_papers = [p for p in papers if p.id != paper.id] for reference in paper.references: if not reference.get_paper_id(): continue ref_paper = api.get_paper(reference.get_paper_id()) if ref_paper.cited_by.count(paper.id) == 0: print() reference.paper_id = [] api.client.update_paper(paper) repair_corrupt_reference(reference, paper, other_papers, api) def check_cited_by(): print("\nCheck Cited by") api = API() papers = api.get_all_paper() for i, paper in enumerate(papers): progressBar(i, len(papers)) for cited_paper_id in paper.cited_by: if not api.contains_paper(cited_paper_id): paper.cited_by.remove(cited_paper_id) api.client.update_paper(paper) continue cited_paper = api.get_paper(cited_paper_id) cited_paper_refs = [ref.get_paper_id() for ref in cited_paper.references if ref.get_paper_id()] if cited_paper_refs.count(paper.id) == 0: print() paper.cited_by.remove(cited_paper_id) api.client.update_paper(paper) link_references_to_paper(cited_paper, paper, api) def perform_checks(): check_cited_by() remove_duplicates_from_cited_by() check_references() if __name__ == "__main__": perform_checks() exit(0) <|fim▁end|>
check_references
<|file_name|>check_for_currupt_references.py<|end_file_name|><|fim▁begin|>from engine.api import API from engine.utils.printing_utils import progressBar from setup.utils.datastore_utils import repair_corrupt_reference, link_references_to_paper def remove_duplicates_from_cited_by(): print("\nRemove Duplicates") api = API() papers = api.get_all_paper() for i, paper in enumerate(papers): progressBar(i, len(papers)) paper.cited_by = list(dict.fromkeys(paper.cited_by)) api.client.update_paper(paper) def check_references(): print("\nCheck References") api = API() papers = api.get_all_paper() for i, paper in enumerate(papers): progressBar(i, len(papers)) other_papers = [p for p in papers if p.id != paper.id] for reference in paper.references: if not reference.get_paper_id(): continue ref_paper = api.get_paper(reference.get_paper_id()) if ref_paper.cited_by.count(paper.id) == 0: print() reference.paper_id = [] api.client.update_paper(paper) repair_corrupt_reference(reference, paper, other_papers, api) def <|fim_middle|>(): print("\nCheck Cited by") api = API() papers = api.get_all_paper() for i, paper in enumerate(papers): progressBar(i, len(papers)) for cited_paper_id in paper.cited_by: if not api.contains_paper(cited_paper_id): paper.cited_by.remove(cited_paper_id) api.client.update_paper(paper) continue cited_paper = api.get_paper(cited_paper_id) cited_paper_refs = [ref.get_paper_id() for ref in cited_paper.references if ref.get_paper_id()] if cited_paper_refs.count(paper.id) == 0: print() paper.cited_by.remove(cited_paper_id) api.client.update_paper(paper) link_references_to_paper(cited_paper, paper, api) def perform_checks(): check_cited_by() remove_duplicates_from_cited_by() check_references() if __name__ == "__main__": perform_checks() exit(0) <|fim▁end|>
check_cited_by
<|file_name|>check_for_currupt_references.py<|end_file_name|><|fim▁begin|>from engine.api import API from engine.utils.printing_utils import progressBar from setup.utils.datastore_utils import repair_corrupt_reference, link_references_to_paper def remove_duplicates_from_cited_by(): print("\nRemove Duplicates") api = API() papers = api.get_all_paper() for i, paper in enumerate(papers): progressBar(i, len(papers)) paper.cited_by = list(dict.fromkeys(paper.cited_by)) api.client.update_paper(paper) def check_references(): print("\nCheck References") api = API() papers = api.get_all_paper() for i, paper in enumerate(papers): progressBar(i, len(papers)) other_papers = [p for p in papers if p.id != paper.id] for reference in paper.references: if not reference.get_paper_id(): continue ref_paper = api.get_paper(reference.get_paper_id()) if ref_paper.cited_by.count(paper.id) == 0: print() reference.paper_id = [] api.client.update_paper(paper) repair_corrupt_reference(reference, paper, other_papers, api) def check_cited_by(): print("\nCheck Cited by") api = API() papers = api.get_all_paper() for i, paper in enumerate(papers): progressBar(i, len(papers)) for cited_paper_id in paper.cited_by: if not api.contains_paper(cited_paper_id): paper.cited_by.remove(cited_paper_id) api.client.update_paper(paper) continue cited_paper = api.get_paper(cited_paper_id) cited_paper_refs = [ref.get_paper_id() for ref in cited_paper.references if ref.get_paper_id()] if cited_paper_refs.count(paper.id) == 0: print() paper.cited_by.remove(cited_paper_id) api.client.update_paper(paper) link_references_to_paper(cited_paper, paper, api) def <|fim_middle|>(): check_cited_by() remove_duplicates_from_cited_by() check_references() if __name__ == "__main__": perform_checks() exit(0) <|fim▁end|>
perform_checks
<|file_name|>__init__.py<|end_file_name|><|fim▁begin|>#!/usr/bin/env python3 # -*- coding: utf-8 -*- # compute/__init__.py """ See |compute.subsystem|, |compute.network|, |compute.distance|, and |compute.parallel| for documentation. Attributes: all_complexes: Alias for :func:`pyphi.compute.network.all_complexes`. ces: Alias for :func:`pyphi.compute.subsystem.ces`. ces_distance: Alias for :func:`pyphi.compute.distance.ces_distance`. complexes: Alias for :func:`pyphi.compute.network.complexes`. concept_distance: Alias for :func:`pyphi.compute.distance.concept_distance`. conceptual_info: Alias for :func:`pyphi.compute.subsystem.conceptual_info`. condensed: Alias for :func:`pyphi.compute.network.condensed`. evaluate_cut: Alias for :func:`pyphi.compute.subsystem.evaluate_cut`.<|fim▁hole|> :func:`pyphi.compute.network.possible_complexes`. sia: Alias for :func:`pyphi.compute.subsystem.sia`. subsystems: Alias for :func:`pyphi.compute.network.subsystems`. """ # pylint: disable=unused-import from .distance import ces_distance, concept_distance from .network import ( all_complexes, complexes, condensed, major_complex, possible_complexes, subsystems, ) from .subsystem import ( ConceptStyleSystem, SystemIrreducibilityAnalysisConceptStyle, ces, concept_cuts, conceptual_info, evaluate_cut, phi, sia, sia_concept_style, )<|fim▁end|>
major_complex: Alias for :func:`pyphi.compute.network.major_complex`. phi: Alias for :func:`pyphi.compute.subsystem.phi`. possible_complexes: Alias for
<|file_name|>images_client.py<|end_file_name|><|fim▁begin|># Copyright 2012 OpenStack Foundation # All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. import json from six.moves.urllib import parse as urllib from tempest_lib import exceptions as lib_exc from tempest.api_schema.response.compute.v2_1 import images as schema from tempest.common import service_client from tempest.common import waiters class ImagesClientJSON(service_client.ServiceClient): def create_image(self, server_id, name, meta=None): """Creates an image of the original server.""" post_body = { 'createImage': { 'name': name,<|fim▁hole|> } if meta is not None: post_body['createImage']['metadata'] = meta post_body = json.dumps(post_body) resp, body = self.post('servers/%s/action' % str(server_id), post_body) self.validate_response(schema.create_image, resp, body) return service_client.ResponseBody(resp, body) def list_images(self, params=None): """Returns a list of all images filtered by any parameters.""" url = 'images' if params: url += '?%s' % urllib.urlencode(params) resp, body = self.get(url) body = json.loads(body) self.validate_response(schema.list_images, resp, body) return service_client.ResponseBodyList(resp, body['images']) def list_images_with_detail(self, params=None): """Returns a detailed list of images filtered by any parameters.""" url = 'images/detail' if params: url += '?%s' % urllib.urlencode(params) resp, body = self.get(url) body = json.loads(body) self.validate_response(schema.list_images_details, resp, body) return service_client.ResponseBodyList(resp, body['images']) def show_image(self, image_id): """Returns the details of a single image.""" resp, body = self.get("images/%s" % str(image_id)) self.expected_success(200, resp.status) body = json.loads(body) self.validate_response(schema.get_image, resp, body) return service_client.ResponseBody(resp, body['image']) def delete_image(self, image_id): """Deletes the provided image.""" resp, body = self.delete("images/%s" % str(image_id)) self.validate_response(schema.delete, resp, body) return service_client.ResponseBody(resp, body) def wait_for_image_status(self, image_id, status): """Waits for an image to reach a given status.""" waiters.wait_for_image_status(self, image_id, status) def list_image_metadata(self, image_id): """Lists all metadata items for an image.""" resp, body = self.get("images/%s/metadata" % str(image_id)) body = json.loads(body) self.validate_response(schema.image_metadata, resp, body) return service_client.ResponseBody(resp, body['metadata']) def set_image_metadata(self, image_id, meta): """Sets the metadata for an image.""" post_body = json.dumps({'metadata': meta}) resp, body = self.put('images/%s/metadata' % str(image_id), post_body) body = json.loads(body) self.validate_response(schema.image_metadata, resp, body) return service_client.ResponseBody(resp, body['metadata']) def update_image_metadata(self, image_id, meta): """Updates the metadata for an image.""" post_body = json.dumps({'metadata': meta}) resp, body = self.post('images/%s/metadata' % str(image_id), post_body) body = json.loads(body) self.validate_response(schema.image_metadata, resp, body) return service_client.ResponseBody(resp, body['metadata']) def get_image_metadata_item(self, image_id, key): """Returns the value for a specific image metadata key.""" resp, body = self.get("images/%s/metadata/%s" % (str(image_id), key)) body = json.loads(body) self.validate_response(schema.image_meta_item, resp, body) return service_client.ResponseBody(resp, body['meta']) def set_image_metadata_item(self, image_id, key, meta): """Sets the value for a specific image metadata key.""" post_body = json.dumps({'meta': meta}) resp, body = self.put('images/%s/metadata/%s' % (str(image_id), key), post_body) body = json.loads(body) self.validate_response(schema.image_meta_item, resp, body) return service_client.ResponseBody(resp, body['meta']) def delete_image_metadata_item(self, image_id, key): """Deletes a single image metadata key/value pair.""" resp, body = self.delete("images/%s/metadata/%s" % (str(image_id), key)) self.validate_response(schema.delete, resp, body) return service_client.ResponseBody(resp, body) def is_resource_deleted(self, id): try: self.show_image(id) except lib_exc.NotFound: return True return False @property def resource_type(self): """Returns the primary type of resource this client works with.""" return 'image'<|fim▁end|>
}
<|file_name|>images_client.py<|end_file_name|><|fim▁begin|># Copyright 2012 OpenStack Foundation # All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. import json from six.moves.urllib import parse as urllib from tempest_lib import exceptions as lib_exc from tempest.api_schema.response.compute.v2_1 import images as schema from tempest.common import service_client from tempest.common import waiters class ImagesClientJSON(service_client.ServiceClient): <|fim_middle|> <|fim▁end|>
def create_image(self, server_id, name, meta=None): """Creates an image of the original server.""" post_body = { 'createImage': { 'name': name, } } if meta is not None: post_body['createImage']['metadata'] = meta post_body = json.dumps(post_body) resp, body = self.post('servers/%s/action' % str(server_id), post_body) self.validate_response(schema.create_image, resp, body) return service_client.ResponseBody(resp, body) def list_images(self, params=None): """Returns a list of all images filtered by any parameters.""" url = 'images' if params: url += '?%s' % urllib.urlencode(params) resp, body = self.get(url) body = json.loads(body) self.validate_response(schema.list_images, resp, body) return service_client.ResponseBodyList(resp, body['images']) def list_images_with_detail(self, params=None): """Returns a detailed list of images filtered by any parameters.""" url = 'images/detail' if params: url += '?%s' % urllib.urlencode(params) resp, body = self.get(url) body = json.loads(body) self.validate_response(schema.list_images_details, resp, body) return service_client.ResponseBodyList(resp, body['images']) def show_image(self, image_id): """Returns the details of a single image.""" resp, body = self.get("images/%s" % str(image_id)) self.expected_success(200, resp.status) body = json.loads(body) self.validate_response(schema.get_image, resp, body) return service_client.ResponseBody(resp, body['image']) def delete_image(self, image_id): """Deletes the provided image.""" resp, body = self.delete("images/%s" % str(image_id)) self.validate_response(schema.delete, resp, body) return service_client.ResponseBody(resp, body) def wait_for_image_status(self, image_id, status): """Waits for an image to reach a given status.""" waiters.wait_for_image_status(self, image_id, status) def list_image_metadata(self, image_id): """Lists all metadata items for an image.""" resp, body = self.get("images/%s/metadata" % str(image_id)) body = json.loads(body) self.validate_response(schema.image_metadata, resp, body) return service_client.ResponseBody(resp, body['metadata']) def set_image_metadata(self, image_id, meta): """Sets the metadata for an image.""" post_body = json.dumps({'metadata': meta}) resp, body = self.put('images/%s/metadata' % str(image_id), post_body) body = json.loads(body) self.validate_response(schema.image_metadata, resp, body) return service_client.ResponseBody(resp, body['metadata']) def update_image_metadata(self, image_id, meta): """Updates the metadata for an image.""" post_body = json.dumps({'metadata': meta}) resp, body = self.post('images/%s/metadata' % str(image_id), post_body) body = json.loads(body) self.validate_response(schema.image_metadata, resp, body) return service_client.ResponseBody(resp, body['metadata']) def get_image_metadata_item(self, image_id, key): """Returns the value for a specific image metadata key.""" resp, body = self.get("images/%s/metadata/%s" % (str(image_id), key)) body = json.loads(body) self.validate_response(schema.image_meta_item, resp, body) return service_client.ResponseBody(resp, body['meta']) def set_image_metadata_item(self, image_id, key, meta): """Sets the value for a specific image metadata key.""" post_body = json.dumps({'meta': meta}) resp, body = self.put('images/%s/metadata/%s' % (str(image_id), key), post_body) body = json.loads(body) self.validate_response(schema.image_meta_item, resp, body) return service_client.ResponseBody(resp, body['meta']) def delete_image_metadata_item(self, image_id, key): """Deletes a single image metadata key/value pair.""" resp, body = self.delete("images/%s/metadata/%s" % (str(image_id), key)) self.validate_response(schema.delete, resp, body) return service_client.ResponseBody(resp, body) def is_resource_deleted(self, id): try: self.show_image(id) except lib_exc.NotFound: return True return False @property def resource_type(self): """Returns the primary type of resource this client works with.""" return 'image'
<|file_name|>images_client.py<|end_file_name|><|fim▁begin|># Copyright 2012 OpenStack Foundation # All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. import json from six.moves.urllib import parse as urllib from tempest_lib import exceptions as lib_exc from tempest.api_schema.response.compute.v2_1 import images as schema from tempest.common import service_client from tempest.common import waiters class ImagesClientJSON(service_client.ServiceClient): def create_image(self, server_id, name, meta=None): <|fim_middle|> def list_images(self, params=None): """Returns a list of all images filtered by any parameters.""" url = 'images' if params: url += '?%s' % urllib.urlencode(params) resp, body = self.get(url) body = json.loads(body) self.validate_response(schema.list_images, resp, body) return service_client.ResponseBodyList(resp, body['images']) def list_images_with_detail(self, params=None): """Returns a detailed list of images filtered by any parameters.""" url = 'images/detail' if params: url += '?%s' % urllib.urlencode(params) resp, body = self.get(url) body = json.loads(body) self.validate_response(schema.list_images_details, resp, body) return service_client.ResponseBodyList(resp, body['images']) def show_image(self, image_id): """Returns the details of a single image.""" resp, body = self.get("images/%s" % str(image_id)) self.expected_success(200, resp.status) body = json.loads(body) self.validate_response(schema.get_image, resp, body) return service_client.ResponseBody(resp, body['image']) def delete_image(self, image_id): """Deletes the provided image.""" resp, body = self.delete("images/%s" % str(image_id)) self.validate_response(schema.delete, resp, body) return service_client.ResponseBody(resp, body) def wait_for_image_status(self, image_id, status): """Waits for an image to reach a given status.""" waiters.wait_for_image_status(self, image_id, status) def list_image_metadata(self, image_id): """Lists all metadata items for an image.""" resp, body = self.get("images/%s/metadata" % str(image_id)) body = json.loads(body) self.validate_response(schema.image_metadata, resp, body) return service_client.ResponseBody(resp, body['metadata']) def set_image_metadata(self, image_id, meta): """Sets the metadata for an image.""" post_body = json.dumps({'metadata': meta}) resp, body = self.put('images/%s/metadata' % str(image_id), post_body) body = json.loads(body) self.validate_response(schema.image_metadata, resp, body) return service_client.ResponseBody(resp, body['metadata']) def update_image_metadata(self, image_id, meta): """Updates the metadata for an image.""" post_body = json.dumps({'metadata': meta}) resp, body = self.post('images/%s/metadata' % str(image_id), post_body) body = json.loads(body) self.validate_response(schema.image_metadata, resp, body) return service_client.ResponseBody(resp, body['metadata']) def get_image_metadata_item(self, image_id, key): """Returns the value for a specific image metadata key.""" resp, body = self.get("images/%s/metadata/%s" % (str(image_id), key)) body = json.loads(body) self.validate_response(schema.image_meta_item, resp, body) return service_client.ResponseBody(resp, body['meta']) def set_image_metadata_item(self, image_id, key, meta): """Sets the value for a specific image metadata key.""" post_body = json.dumps({'meta': meta}) resp, body = self.put('images/%s/metadata/%s' % (str(image_id), key), post_body) body = json.loads(body) self.validate_response(schema.image_meta_item, resp, body) return service_client.ResponseBody(resp, body['meta']) def delete_image_metadata_item(self, image_id, key): """Deletes a single image metadata key/value pair.""" resp, body = self.delete("images/%s/metadata/%s" % (str(image_id), key)) self.validate_response(schema.delete, resp, body) return service_client.ResponseBody(resp, body) def is_resource_deleted(self, id): try: self.show_image(id) except lib_exc.NotFound: return True return False @property def resource_type(self): """Returns the primary type of resource this client works with.""" return 'image' <|fim▁end|>
"""Creates an image of the original server.""" post_body = { 'createImage': { 'name': name, } } if meta is not None: post_body['createImage']['metadata'] = meta post_body = json.dumps(post_body) resp, body = self.post('servers/%s/action' % str(server_id), post_body) self.validate_response(schema.create_image, resp, body) return service_client.ResponseBody(resp, body)
<|file_name|>images_client.py<|end_file_name|><|fim▁begin|># Copyright 2012 OpenStack Foundation # All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. import json from six.moves.urllib import parse as urllib from tempest_lib import exceptions as lib_exc from tempest.api_schema.response.compute.v2_1 import images as schema from tempest.common import service_client from tempest.common import waiters class ImagesClientJSON(service_client.ServiceClient): def create_image(self, server_id, name, meta=None): """Creates an image of the original server.""" post_body = { 'createImage': { 'name': name, } } if meta is not None: post_body['createImage']['metadata'] = meta post_body = json.dumps(post_body) resp, body = self.post('servers/%s/action' % str(server_id), post_body) self.validate_response(schema.create_image, resp, body) return service_client.ResponseBody(resp, body) def list_images(self, params=None): <|fim_middle|> def list_images_with_detail(self, params=None): """Returns a detailed list of images filtered by any parameters.""" url = 'images/detail' if params: url += '?%s' % urllib.urlencode(params) resp, body = self.get(url) body = json.loads(body) self.validate_response(schema.list_images_details, resp, body) return service_client.ResponseBodyList(resp, body['images']) def show_image(self, image_id): """Returns the details of a single image.""" resp, body = self.get("images/%s" % str(image_id)) self.expected_success(200, resp.status) body = json.loads(body) self.validate_response(schema.get_image, resp, body) return service_client.ResponseBody(resp, body['image']) def delete_image(self, image_id): """Deletes the provided image.""" resp, body = self.delete("images/%s" % str(image_id)) self.validate_response(schema.delete, resp, body) return service_client.ResponseBody(resp, body) def wait_for_image_status(self, image_id, status): """Waits for an image to reach a given status.""" waiters.wait_for_image_status(self, image_id, status) def list_image_metadata(self, image_id): """Lists all metadata items for an image.""" resp, body = self.get("images/%s/metadata" % str(image_id)) body = json.loads(body) self.validate_response(schema.image_metadata, resp, body) return service_client.ResponseBody(resp, body['metadata']) def set_image_metadata(self, image_id, meta): """Sets the metadata for an image.""" post_body = json.dumps({'metadata': meta}) resp, body = self.put('images/%s/metadata' % str(image_id), post_body) body = json.loads(body) self.validate_response(schema.image_metadata, resp, body) return service_client.ResponseBody(resp, body['metadata']) def update_image_metadata(self, image_id, meta): """Updates the metadata for an image.""" post_body = json.dumps({'metadata': meta}) resp, body = self.post('images/%s/metadata' % str(image_id), post_body) body = json.loads(body) self.validate_response(schema.image_metadata, resp, body) return service_client.ResponseBody(resp, body['metadata']) def get_image_metadata_item(self, image_id, key): """Returns the value for a specific image metadata key.""" resp, body = self.get("images/%s/metadata/%s" % (str(image_id), key)) body = json.loads(body) self.validate_response(schema.image_meta_item, resp, body) return service_client.ResponseBody(resp, body['meta']) def set_image_metadata_item(self, image_id, key, meta): """Sets the value for a specific image metadata key.""" post_body = json.dumps({'meta': meta}) resp, body = self.put('images/%s/metadata/%s' % (str(image_id), key), post_body) body = json.loads(body) self.validate_response(schema.image_meta_item, resp, body) return service_client.ResponseBody(resp, body['meta']) def delete_image_metadata_item(self, image_id, key): """Deletes a single image metadata key/value pair.""" resp, body = self.delete("images/%s/metadata/%s" % (str(image_id), key)) self.validate_response(schema.delete, resp, body) return service_client.ResponseBody(resp, body) def is_resource_deleted(self, id): try: self.show_image(id) except lib_exc.NotFound: return True return False @property def resource_type(self): """Returns the primary type of resource this client works with.""" return 'image' <|fim▁end|>
"""Returns a list of all images filtered by any parameters.""" url = 'images' if params: url += '?%s' % urllib.urlencode(params) resp, body = self.get(url) body = json.loads(body) self.validate_response(schema.list_images, resp, body) return service_client.ResponseBodyList(resp, body['images'])
<|file_name|>images_client.py<|end_file_name|><|fim▁begin|># Copyright 2012 OpenStack Foundation # All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. import json from six.moves.urllib import parse as urllib from tempest_lib import exceptions as lib_exc from tempest.api_schema.response.compute.v2_1 import images as schema from tempest.common import service_client from tempest.common import waiters class ImagesClientJSON(service_client.ServiceClient): def create_image(self, server_id, name, meta=None): """Creates an image of the original server.""" post_body = { 'createImage': { 'name': name, } } if meta is not None: post_body['createImage']['metadata'] = meta post_body = json.dumps(post_body) resp, body = self.post('servers/%s/action' % str(server_id), post_body) self.validate_response(schema.create_image, resp, body) return service_client.ResponseBody(resp, body) def list_images(self, params=None): """Returns a list of all images filtered by any parameters.""" url = 'images' if params: url += '?%s' % urllib.urlencode(params) resp, body = self.get(url) body = json.loads(body) self.validate_response(schema.list_images, resp, body) return service_client.ResponseBodyList(resp, body['images']) def list_images_with_detail(self, params=None): <|fim_middle|> def show_image(self, image_id): """Returns the details of a single image.""" resp, body = self.get("images/%s" % str(image_id)) self.expected_success(200, resp.status) body = json.loads(body) self.validate_response(schema.get_image, resp, body) return service_client.ResponseBody(resp, body['image']) def delete_image(self, image_id): """Deletes the provided image.""" resp, body = self.delete("images/%s" % str(image_id)) self.validate_response(schema.delete, resp, body) return service_client.ResponseBody(resp, body) def wait_for_image_status(self, image_id, status): """Waits for an image to reach a given status.""" waiters.wait_for_image_status(self, image_id, status) def list_image_metadata(self, image_id): """Lists all metadata items for an image.""" resp, body = self.get("images/%s/metadata" % str(image_id)) body = json.loads(body) self.validate_response(schema.image_metadata, resp, body) return service_client.ResponseBody(resp, body['metadata']) def set_image_metadata(self, image_id, meta): """Sets the metadata for an image.""" post_body = json.dumps({'metadata': meta}) resp, body = self.put('images/%s/metadata' % str(image_id), post_body) body = json.loads(body) self.validate_response(schema.image_metadata, resp, body) return service_client.ResponseBody(resp, body['metadata']) def update_image_metadata(self, image_id, meta): """Updates the metadata for an image.""" post_body = json.dumps({'metadata': meta}) resp, body = self.post('images/%s/metadata' % str(image_id), post_body) body = json.loads(body) self.validate_response(schema.image_metadata, resp, body) return service_client.ResponseBody(resp, body['metadata']) def get_image_metadata_item(self, image_id, key): """Returns the value for a specific image metadata key.""" resp, body = self.get("images/%s/metadata/%s" % (str(image_id), key)) body = json.loads(body) self.validate_response(schema.image_meta_item, resp, body) return service_client.ResponseBody(resp, body['meta']) def set_image_metadata_item(self, image_id, key, meta): """Sets the value for a specific image metadata key.""" post_body = json.dumps({'meta': meta}) resp, body = self.put('images/%s/metadata/%s' % (str(image_id), key), post_body) body = json.loads(body) self.validate_response(schema.image_meta_item, resp, body) return service_client.ResponseBody(resp, body['meta']) def delete_image_metadata_item(self, image_id, key): """Deletes a single image metadata key/value pair.""" resp, body = self.delete("images/%s/metadata/%s" % (str(image_id), key)) self.validate_response(schema.delete, resp, body) return service_client.ResponseBody(resp, body) def is_resource_deleted(self, id): try: self.show_image(id) except lib_exc.NotFound: return True return False @property def resource_type(self): """Returns the primary type of resource this client works with.""" return 'image' <|fim▁end|>
"""Returns a detailed list of images filtered by any parameters.""" url = 'images/detail' if params: url += '?%s' % urllib.urlencode(params) resp, body = self.get(url) body = json.loads(body) self.validate_response(schema.list_images_details, resp, body) return service_client.ResponseBodyList(resp, body['images'])
<|file_name|>images_client.py<|end_file_name|><|fim▁begin|># Copyright 2012 OpenStack Foundation # All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. import json from six.moves.urllib import parse as urllib from tempest_lib import exceptions as lib_exc from tempest.api_schema.response.compute.v2_1 import images as schema from tempest.common import service_client from tempest.common import waiters class ImagesClientJSON(service_client.ServiceClient): def create_image(self, server_id, name, meta=None): """Creates an image of the original server.""" post_body = { 'createImage': { 'name': name, } } if meta is not None: post_body['createImage']['metadata'] = meta post_body = json.dumps(post_body) resp, body = self.post('servers/%s/action' % str(server_id), post_body) self.validate_response(schema.create_image, resp, body) return service_client.ResponseBody(resp, body) def list_images(self, params=None): """Returns a list of all images filtered by any parameters.""" url = 'images' if params: url += '?%s' % urllib.urlencode(params) resp, body = self.get(url) body = json.loads(body) self.validate_response(schema.list_images, resp, body) return service_client.ResponseBodyList(resp, body['images']) def list_images_with_detail(self, params=None): """Returns a detailed list of images filtered by any parameters.""" url = 'images/detail' if params: url += '?%s' % urllib.urlencode(params) resp, body = self.get(url) body = json.loads(body) self.validate_response(schema.list_images_details, resp, body) return service_client.ResponseBodyList(resp, body['images']) def show_image(self, image_id): <|fim_middle|> def delete_image(self, image_id): """Deletes the provided image.""" resp, body = self.delete("images/%s" % str(image_id)) self.validate_response(schema.delete, resp, body) return service_client.ResponseBody(resp, body) def wait_for_image_status(self, image_id, status): """Waits for an image to reach a given status.""" waiters.wait_for_image_status(self, image_id, status) def list_image_metadata(self, image_id): """Lists all metadata items for an image.""" resp, body = self.get("images/%s/metadata" % str(image_id)) body = json.loads(body) self.validate_response(schema.image_metadata, resp, body) return service_client.ResponseBody(resp, body['metadata']) def set_image_metadata(self, image_id, meta): """Sets the metadata for an image.""" post_body = json.dumps({'metadata': meta}) resp, body = self.put('images/%s/metadata' % str(image_id), post_body) body = json.loads(body) self.validate_response(schema.image_metadata, resp, body) return service_client.ResponseBody(resp, body['metadata']) def update_image_metadata(self, image_id, meta): """Updates the metadata for an image.""" post_body = json.dumps({'metadata': meta}) resp, body = self.post('images/%s/metadata' % str(image_id), post_body) body = json.loads(body) self.validate_response(schema.image_metadata, resp, body) return service_client.ResponseBody(resp, body['metadata']) def get_image_metadata_item(self, image_id, key): """Returns the value for a specific image metadata key.""" resp, body = self.get("images/%s/metadata/%s" % (str(image_id), key)) body = json.loads(body) self.validate_response(schema.image_meta_item, resp, body) return service_client.ResponseBody(resp, body['meta']) def set_image_metadata_item(self, image_id, key, meta): """Sets the value for a specific image metadata key.""" post_body = json.dumps({'meta': meta}) resp, body = self.put('images/%s/metadata/%s' % (str(image_id), key), post_body) body = json.loads(body) self.validate_response(schema.image_meta_item, resp, body) return service_client.ResponseBody(resp, body['meta']) def delete_image_metadata_item(self, image_id, key): """Deletes a single image metadata key/value pair.""" resp, body = self.delete("images/%s/metadata/%s" % (str(image_id), key)) self.validate_response(schema.delete, resp, body) return service_client.ResponseBody(resp, body) def is_resource_deleted(self, id): try: self.show_image(id) except lib_exc.NotFound: return True return False @property def resource_type(self): """Returns the primary type of resource this client works with.""" return 'image' <|fim▁end|>
"""Returns the details of a single image.""" resp, body = self.get("images/%s" % str(image_id)) self.expected_success(200, resp.status) body = json.loads(body) self.validate_response(schema.get_image, resp, body) return service_client.ResponseBody(resp, body['image'])
<|file_name|>images_client.py<|end_file_name|><|fim▁begin|># Copyright 2012 OpenStack Foundation # All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. import json from six.moves.urllib import parse as urllib from tempest_lib import exceptions as lib_exc from tempest.api_schema.response.compute.v2_1 import images as schema from tempest.common import service_client from tempest.common import waiters class ImagesClientJSON(service_client.ServiceClient): def create_image(self, server_id, name, meta=None): """Creates an image of the original server.""" post_body = { 'createImage': { 'name': name, } } if meta is not None: post_body['createImage']['metadata'] = meta post_body = json.dumps(post_body) resp, body = self.post('servers/%s/action' % str(server_id), post_body) self.validate_response(schema.create_image, resp, body) return service_client.ResponseBody(resp, body) def list_images(self, params=None): """Returns a list of all images filtered by any parameters.""" url = 'images' if params: url += '?%s' % urllib.urlencode(params) resp, body = self.get(url) body = json.loads(body) self.validate_response(schema.list_images, resp, body) return service_client.ResponseBodyList(resp, body['images']) def list_images_with_detail(self, params=None): """Returns a detailed list of images filtered by any parameters.""" url = 'images/detail' if params: url += '?%s' % urllib.urlencode(params) resp, body = self.get(url) body = json.loads(body) self.validate_response(schema.list_images_details, resp, body) return service_client.ResponseBodyList(resp, body['images']) def show_image(self, image_id): """Returns the details of a single image.""" resp, body = self.get("images/%s" % str(image_id)) self.expected_success(200, resp.status) body = json.loads(body) self.validate_response(schema.get_image, resp, body) return service_client.ResponseBody(resp, body['image']) def delete_image(self, image_id): <|fim_middle|> def wait_for_image_status(self, image_id, status): """Waits for an image to reach a given status.""" waiters.wait_for_image_status(self, image_id, status) def list_image_metadata(self, image_id): """Lists all metadata items for an image.""" resp, body = self.get("images/%s/metadata" % str(image_id)) body = json.loads(body) self.validate_response(schema.image_metadata, resp, body) return service_client.ResponseBody(resp, body['metadata']) def set_image_metadata(self, image_id, meta): """Sets the metadata for an image.""" post_body = json.dumps({'metadata': meta}) resp, body = self.put('images/%s/metadata' % str(image_id), post_body) body = json.loads(body) self.validate_response(schema.image_metadata, resp, body) return service_client.ResponseBody(resp, body['metadata']) def update_image_metadata(self, image_id, meta): """Updates the metadata for an image.""" post_body = json.dumps({'metadata': meta}) resp, body = self.post('images/%s/metadata' % str(image_id), post_body) body = json.loads(body) self.validate_response(schema.image_metadata, resp, body) return service_client.ResponseBody(resp, body['metadata']) def get_image_metadata_item(self, image_id, key): """Returns the value for a specific image metadata key.""" resp, body = self.get("images/%s/metadata/%s" % (str(image_id), key)) body = json.loads(body) self.validate_response(schema.image_meta_item, resp, body) return service_client.ResponseBody(resp, body['meta']) def set_image_metadata_item(self, image_id, key, meta): """Sets the value for a specific image metadata key.""" post_body = json.dumps({'meta': meta}) resp, body = self.put('images/%s/metadata/%s' % (str(image_id), key), post_body) body = json.loads(body) self.validate_response(schema.image_meta_item, resp, body) return service_client.ResponseBody(resp, body['meta']) def delete_image_metadata_item(self, image_id, key): """Deletes a single image metadata key/value pair.""" resp, body = self.delete("images/%s/metadata/%s" % (str(image_id), key)) self.validate_response(schema.delete, resp, body) return service_client.ResponseBody(resp, body) def is_resource_deleted(self, id): try: self.show_image(id) except lib_exc.NotFound: return True return False @property def resource_type(self): """Returns the primary type of resource this client works with.""" return 'image' <|fim▁end|>
"""Deletes the provided image.""" resp, body = self.delete("images/%s" % str(image_id)) self.validate_response(schema.delete, resp, body) return service_client.ResponseBody(resp, body)
<|file_name|>images_client.py<|end_file_name|><|fim▁begin|># Copyright 2012 OpenStack Foundation # All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. import json from six.moves.urllib import parse as urllib from tempest_lib import exceptions as lib_exc from tempest.api_schema.response.compute.v2_1 import images as schema from tempest.common import service_client from tempest.common import waiters class ImagesClientJSON(service_client.ServiceClient): def create_image(self, server_id, name, meta=None): """Creates an image of the original server.""" post_body = { 'createImage': { 'name': name, } } if meta is not None: post_body['createImage']['metadata'] = meta post_body = json.dumps(post_body) resp, body = self.post('servers/%s/action' % str(server_id), post_body) self.validate_response(schema.create_image, resp, body) return service_client.ResponseBody(resp, body) def list_images(self, params=None): """Returns a list of all images filtered by any parameters.""" url = 'images' if params: url += '?%s' % urllib.urlencode(params) resp, body = self.get(url) body = json.loads(body) self.validate_response(schema.list_images, resp, body) return service_client.ResponseBodyList(resp, body['images']) def list_images_with_detail(self, params=None): """Returns a detailed list of images filtered by any parameters.""" url = 'images/detail' if params: url += '?%s' % urllib.urlencode(params) resp, body = self.get(url) body = json.loads(body) self.validate_response(schema.list_images_details, resp, body) return service_client.ResponseBodyList(resp, body['images']) def show_image(self, image_id): """Returns the details of a single image.""" resp, body = self.get("images/%s" % str(image_id)) self.expected_success(200, resp.status) body = json.loads(body) self.validate_response(schema.get_image, resp, body) return service_client.ResponseBody(resp, body['image']) def delete_image(self, image_id): """Deletes the provided image.""" resp, body = self.delete("images/%s" % str(image_id)) self.validate_response(schema.delete, resp, body) return service_client.ResponseBody(resp, body) def wait_for_image_status(self, image_id, status): <|fim_middle|> def list_image_metadata(self, image_id): """Lists all metadata items for an image.""" resp, body = self.get("images/%s/metadata" % str(image_id)) body = json.loads(body) self.validate_response(schema.image_metadata, resp, body) return service_client.ResponseBody(resp, body['metadata']) def set_image_metadata(self, image_id, meta): """Sets the metadata for an image.""" post_body = json.dumps({'metadata': meta}) resp, body = self.put('images/%s/metadata' % str(image_id), post_body) body = json.loads(body) self.validate_response(schema.image_metadata, resp, body) return service_client.ResponseBody(resp, body['metadata']) def update_image_metadata(self, image_id, meta): """Updates the metadata for an image.""" post_body = json.dumps({'metadata': meta}) resp, body = self.post('images/%s/metadata' % str(image_id), post_body) body = json.loads(body) self.validate_response(schema.image_metadata, resp, body) return service_client.ResponseBody(resp, body['metadata']) def get_image_metadata_item(self, image_id, key): """Returns the value for a specific image metadata key.""" resp, body = self.get("images/%s/metadata/%s" % (str(image_id), key)) body = json.loads(body) self.validate_response(schema.image_meta_item, resp, body) return service_client.ResponseBody(resp, body['meta']) def set_image_metadata_item(self, image_id, key, meta): """Sets the value for a specific image metadata key.""" post_body = json.dumps({'meta': meta}) resp, body = self.put('images/%s/metadata/%s' % (str(image_id), key), post_body) body = json.loads(body) self.validate_response(schema.image_meta_item, resp, body) return service_client.ResponseBody(resp, body['meta']) def delete_image_metadata_item(self, image_id, key): """Deletes a single image metadata key/value pair.""" resp, body = self.delete("images/%s/metadata/%s" % (str(image_id), key)) self.validate_response(schema.delete, resp, body) return service_client.ResponseBody(resp, body) def is_resource_deleted(self, id): try: self.show_image(id) except lib_exc.NotFound: return True return False @property def resource_type(self): """Returns the primary type of resource this client works with.""" return 'image' <|fim▁end|>
"""Waits for an image to reach a given status.""" waiters.wait_for_image_status(self, image_id, status)
<|file_name|>images_client.py<|end_file_name|><|fim▁begin|># Copyright 2012 OpenStack Foundation # All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. import json from six.moves.urllib import parse as urllib from tempest_lib import exceptions as lib_exc from tempest.api_schema.response.compute.v2_1 import images as schema from tempest.common import service_client from tempest.common import waiters class ImagesClientJSON(service_client.ServiceClient): def create_image(self, server_id, name, meta=None): """Creates an image of the original server.""" post_body = { 'createImage': { 'name': name, } } if meta is not None: post_body['createImage']['metadata'] = meta post_body = json.dumps(post_body) resp, body = self.post('servers/%s/action' % str(server_id), post_body) self.validate_response(schema.create_image, resp, body) return service_client.ResponseBody(resp, body) def list_images(self, params=None): """Returns a list of all images filtered by any parameters.""" url = 'images' if params: url += '?%s' % urllib.urlencode(params) resp, body = self.get(url) body = json.loads(body) self.validate_response(schema.list_images, resp, body) return service_client.ResponseBodyList(resp, body['images']) def list_images_with_detail(self, params=None): """Returns a detailed list of images filtered by any parameters.""" url = 'images/detail' if params: url += '?%s' % urllib.urlencode(params) resp, body = self.get(url) body = json.loads(body) self.validate_response(schema.list_images_details, resp, body) return service_client.ResponseBodyList(resp, body['images']) def show_image(self, image_id): """Returns the details of a single image.""" resp, body = self.get("images/%s" % str(image_id)) self.expected_success(200, resp.status) body = json.loads(body) self.validate_response(schema.get_image, resp, body) return service_client.ResponseBody(resp, body['image']) def delete_image(self, image_id): """Deletes the provided image.""" resp, body = self.delete("images/%s" % str(image_id)) self.validate_response(schema.delete, resp, body) return service_client.ResponseBody(resp, body) def wait_for_image_status(self, image_id, status): """Waits for an image to reach a given status.""" waiters.wait_for_image_status(self, image_id, status) def list_image_metadata(self, image_id): <|fim_middle|> def set_image_metadata(self, image_id, meta): """Sets the metadata for an image.""" post_body = json.dumps({'metadata': meta}) resp, body = self.put('images/%s/metadata' % str(image_id), post_body) body = json.loads(body) self.validate_response(schema.image_metadata, resp, body) return service_client.ResponseBody(resp, body['metadata']) def update_image_metadata(self, image_id, meta): """Updates the metadata for an image.""" post_body = json.dumps({'metadata': meta}) resp, body = self.post('images/%s/metadata' % str(image_id), post_body) body = json.loads(body) self.validate_response(schema.image_metadata, resp, body) return service_client.ResponseBody(resp, body['metadata']) def get_image_metadata_item(self, image_id, key): """Returns the value for a specific image metadata key.""" resp, body = self.get("images/%s/metadata/%s" % (str(image_id), key)) body = json.loads(body) self.validate_response(schema.image_meta_item, resp, body) return service_client.ResponseBody(resp, body['meta']) def set_image_metadata_item(self, image_id, key, meta): """Sets the value for a specific image metadata key.""" post_body = json.dumps({'meta': meta}) resp, body = self.put('images/%s/metadata/%s' % (str(image_id), key), post_body) body = json.loads(body) self.validate_response(schema.image_meta_item, resp, body) return service_client.ResponseBody(resp, body['meta']) def delete_image_metadata_item(self, image_id, key): """Deletes a single image metadata key/value pair.""" resp, body = self.delete("images/%s/metadata/%s" % (str(image_id), key)) self.validate_response(schema.delete, resp, body) return service_client.ResponseBody(resp, body) def is_resource_deleted(self, id): try: self.show_image(id) except lib_exc.NotFound: return True return False @property def resource_type(self): """Returns the primary type of resource this client works with.""" return 'image' <|fim▁end|>
"""Lists all metadata items for an image.""" resp, body = self.get("images/%s/metadata" % str(image_id)) body = json.loads(body) self.validate_response(schema.image_metadata, resp, body) return service_client.ResponseBody(resp, body['metadata'])
<|file_name|>images_client.py<|end_file_name|><|fim▁begin|># Copyright 2012 OpenStack Foundation # All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. import json from six.moves.urllib import parse as urllib from tempest_lib import exceptions as lib_exc from tempest.api_schema.response.compute.v2_1 import images as schema from tempest.common import service_client from tempest.common import waiters class ImagesClientJSON(service_client.ServiceClient): def create_image(self, server_id, name, meta=None): """Creates an image of the original server.""" post_body = { 'createImage': { 'name': name, } } if meta is not None: post_body['createImage']['metadata'] = meta post_body = json.dumps(post_body) resp, body = self.post('servers/%s/action' % str(server_id), post_body) self.validate_response(schema.create_image, resp, body) return service_client.ResponseBody(resp, body) def list_images(self, params=None): """Returns a list of all images filtered by any parameters.""" url = 'images' if params: url += '?%s' % urllib.urlencode(params) resp, body = self.get(url) body = json.loads(body) self.validate_response(schema.list_images, resp, body) return service_client.ResponseBodyList(resp, body['images']) def list_images_with_detail(self, params=None): """Returns a detailed list of images filtered by any parameters.""" url = 'images/detail' if params: url += '?%s' % urllib.urlencode(params) resp, body = self.get(url) body = json.loads(body) self.validate_response(schema.list_images_details, resp, body) return service_client.ResponseBodyList(resp, body['images']) def show_image(self, image_id): """Returns the details of a single image.""" resp, body = self.get("images/%s" % str(image_id)) self.expected_success(200, resp.status) body = json.loads(body) self.validate_response(schema.get_image, resp, body) return service_client.ResponseBody(resp, body['image']) def delete_image(self, image_id): """Deletes the provided image.""" resp, body = self.delete("images/%s" % str(image_id)) self.validate_response(schema.delete, resp, body) return service_client.ResponseBody(resp, body) def wait_for_image_status(self, image_id, status): """Waits for an image to reach a given status.""" waiters.wait_for_image_status(self, image_id, status) def list_image_metadata(self, image_id): """Lists all metadata items for an image.""" resp, body = self.get("images/%s/metadata" % str(image_id)) body = json.loads(body) self.validate_response(schema.image_metadata, resp, body) return service_client.ResponseBody(resp, body['metadata']) def set_image_metadata(self, image_id, meta): <|fim_middle|> def update_image_metadata(self, image_id, meta): """Updates the metadata for an image.""" post_body = json.dumps({'metadata': meta}) resp, body = self.post('images/%s/metadata' % str(image_id), post_body) body = json.loads(body) self.validate_response(schema.image_metadata, resp, body) return service_client.ResponseBody(resp, body['metadata']) def get_image_metadata_item(self, image_id, key): """Returns the value for a specific image metadata key.""" resp, body = self.get("images/%s/metadata/%s" % (str(image_id), key)) body = json.loads(body) self.validate_response(schema.image_meta_item, resp, body) return service_client.ResponseBody(resp, body['meta']) def set_image_metadata_item(self, image_id, key, meta): """Sets the value for a specific image metadata key.""" post_body = json.dumps({'meta': meta}) resp, body = self.put('images/%s/metadata/%s' % (str(image_id), key), post_body) body = json.loads(body) self.validate_response(schema.image_meta_item, resp, body) return service_client.ResponseBody(resp, body['meta']) def delete_image_metadata_item(self, image_id, key): """Deletes a single image metadata key/value pair.""" resp, body = self.delete("images/%s/metadata/%s" % (str(image_id), key)) self.validate_response(schema.delete, resp, body) return service_client.ResponseBody(resp, body) def is_resource_deleted(self, id): try: self.show_image(id) except lib_exc.NotFound: return True return False @property def resource_type(self): """Returns the primary type of resource this client works with.""" return 'image' <|fim▁end|>
"""Sets the metadata for an image.""" post_body = json.dumps({'metadata': meta}) resp, body = self.put('images/%s/metadata' % str(image_id), post_body) body = json.loads(body) self.validate_response(schema.image_metadata, resp, body) return service_client.ResponseBody(resp, body['metadata'])
<|file_name|>images_client.py<|end_file_name|><|fim▁begin|># Copyright 2012 OpenStack Foundation # All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. import json from six.moves.urllib import parse as urllib from tempest_lib import exceptions as lib_exc from tempest.api_schema.response.compute.v2_1 import images as schema from tempest.common import service_client from tempest.common import waiters class ImagesClientJSON(service_client.ServiceClient): def create_image(self, server_id, name, meta=None): """Creates an image of the original server.""" post_body = { 'createImage': { 'name': name, } } if meta is not None: post_body['createImage']['metadata'] = meta post_body = json.dumps(post_body) resp, body = self.post('servers/%s/action' % str(server_id), post_body) self.validate_response(schema.create_image, resp, body) return service_client.ResponseBody(resp, body) def list_images(self, params=None): """Returns a list of all images filtered by any parameters.""" url = 'images' if params: url += '?%s' % urllib.urlencode(params) resp, body = self.get(url) body = json.loads(body) self.validate_response(schema.list_images, resp, body) return service_client.ResponseBodyList(resp, body['images']) def list_images_with_detail(self, params=None): """Returns a detailed list of images filtered by any parameters.""" url = 'images/detail' if params: url += '?%s' % urllib.urlencode(params) resp, body = self.get(url) body = json.loads(body) self.validate_response(schema.list_images_details, resp, body) return service_client.ResponseBodyList(resp, body['images']) def show_image(self, image_id): """Returns the details of a single image.""" resp, body = self.get("images/%s" % str(image_id)) self.expected_success(200, resp.status) body = json.loads(body) self.validate_response(schema.get_image, resp, body) return service_client.ResponseBody(resp, body['image']) def delete_image(self, image_id): """Deletes the provided image.""" resp, body = self.delete("images/%s" % str(image_id)) self.validate_response(schema.delete, resp, body) return service_client.ResponseBody(resp, body) def wait_for_image_status(self, image_id, status): """Waits for an image to reach a given status.""" waiters.wait_for_image_status(self, image_id, status) def list_image_metadata(self, image_id): """Lists all metadata items for an image.""" resp, body = self.get("images/%s/metadata" % str(image_id)) body = json.loads(body) self.validate_response(schema.image_metadata, resp, body) return service_client.ResponseBody(resp, body['metadata']) def set_image_metadata(self, image_id, meta): """Sets the metadata for an image.""" post_body = json.dumps({'metadata': meta}) resp, body = self.put('images/%s/metadata' % str(image_id), post_body) body = json.loads(body) self.validate_response(schema.image_metadata, resp, body) return service_client.ResponseBody(resp, body['metadata']) def update_image_metadata(self, image_id, meta): <|fim_middle|> def get_image_metadata_item(self, image_id, key): """Returns the value for a specific image metadata key.""" resp, body = self.get("images/%s/metadata/%s" % (str(image_id), key)) body = json.loads(body) self.validate_response(schema.image_meta_item, resp, body) return service_client.ResponseBody(resp, body['meta']) def set_image_metadata_item(self, image_id, key, meta): """Sets the value for a specific image metadata key.""" post_body = json.dumps({'meta': meta}) resp, body = self.put('images/%s/metadata/%s' % (str(image_id), key), post_body) body = json.loads(body) self.validate_response(schema.image_meta_item, resp, body) return service_client.ResponseBody(resp, body['meta']) def delete_image_metadata_item(self, image_id, key): """Deletes a single image metadata key/value pair.""" resp, body = self.delete("images/%s/metadata/%s" % (str(image_id), key)) self.validate_response(schema.delete, resp, body) return service_client.ResponseBody(resp, body) def is_resource_deleted(self, id): try: self.show_image(id) except lib_exc.NotFound: return True return False @property def resource_type(self): """Returns the primary type of resource this client works with.""" return 'image' <|fim▁end|>
"""Updates the metadata for an image.""" post_body = json.dumps({'metadata': meta}) resp, body = self.post('images/%s/metadata' % str(image_id), post_body) body = json.loads(body) self.validate_response(schema.image_metadata, resp, body) return service_client.ResponseBody(resp, body['metadata'])
<|file_name|>images_client.py<|end_file_name|><|fim▁begin|># Copyright 2012 OpenStack Foundation # All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. import json from six.moves.urllib import parse as urllib from tempest_lib import exceptions as lib_exc from tempest.api_schema.response.compute.v2_1 import images as schema from tempest.common import service_client from tempest.common import waiters class ImagesClientJSON(service_client.ServiceClient): def create_image(self, server_id, name, meta=None): """Creates an image of the original server.""" post_body = { 'createImage': { 'name': name, } } if meta is not None: post_body['createImage']['metadata'] = meta post_body = json.dumps(post_body) resp, body = self.post('servers/%s/action' % str(server_id), post_body) self.validate_response(schema.create_image, resp, body) return service_client.ResponseBody(resp, body) def list_images(self, params=None): """Returns a list of all images filtered by any parameters.""" url = 'images' if params: url += '?%s' % urllib.urlencode(params) resp, body = self.get(url) body = json.loads(body) self.validate_response(schema.list_images, resp, body) return service_client.ResponseBodyList(resp, body['images']) def list_images_with_detail(self, params=None): """Returns a detailed list of images filtered by any parameters.""" url = 'images/detail' if params: url += '?%s' % urllib.urlencode(params) resp, body = self.get(url) body = json.loads(body) self.validate_response(schema.list_images_details, resp, body) return service_client.ResponseBodyList(resp, body['images']) def show_image(self, image_id): """Returns the details of a single image.""" resp, body = self.get("images/%s" % str(image_id)) self.expected_success(200, resp.status) body = json.loads(body) self.validate_response(schema.get_image, resp, body) return service_client.ResponseBody(resp, body['image']) def delete_image(self, image_id): """Deletes the provided image.""" resp, body = self.delete("images/%s" % str(image_id)) self.validate_response(schema.delete, resp, body) return service_client.ResponseBody(resp, body) def wait_for_image_status(self, image_id, status): """Waits for an image to reach a given status.""" waiters.wait_for_image_status(self, image_id, status) def list_image_metadata(self, image_id): """Lists all metadata items for an image.""" resp, body = self.get("images/%s/metadata" % str(image_id)) body = json.loads(body) self.validate_response(schema.image_metadata, resp, body) return service_client.ResponseBody(resp, body['metadata']) def set_image_metadata(self, image_id, meta): """Sets the metadata for an image.""" post_body = json.dumps({'metadata': meta}) resp, body = self.put('images/%s/metadata' % str(image_id), post_body) body = json.loads(body) self.validate_response(schema.image_metadata, resp, body) return service_client.ResponseBody(resp, body['metadata']) def update_image_metadata(self, image_id, meta): """Updates the metadata for an image.""" post_body = json.dumps({'metadata': meta}) resp, body = self.post('images/%s/metadata' % str(image_id), post_body) body = json.loads(body) self.validate_response(schema.image_metadata, resp, body) return service_client.ResponseBody(resp, body['metadata']) def get_image_metadata_item(self, image_id, key): <|fim_middle|> def set_image_metadata_item(self, image_id, key, meta): """Sets the value for a specific image metadata key.""" post_body = json.dumps({'meta': meta}) resp, body = self.put('images/%s/metadata/%s' % (str(image_id), key), post_body) body = json.loads(body) self.validate_response(schema.image_meta_item, resp, body) return service_client.ResponseBody(resp, body['meta']) def delete_image_metadata_item(self, image_id, key): """Deletes a single image metadata key/value pair.""" resp, body = self.delete("images/%s/metadata/%s" % (str(image_id), key)) self.validate_response(schema.delete, resp, body) return service_client.ResponseBody(resp, body) def is_resource_deleted(self, id): try: self.show_image(id) except lib_exc.NotFound: return True return False @property def resource_type(self): """Returns the primary type of resource this client works with.""" return 'image' <|fim▁end|>
"""Returns the value for a specific image metadata key.""" resp, body = self.get("images/%s/metadata/%s" % (str(image_id), key)) body = json.loads(body) self.validate_response(schema.image_meta_item, resp, body) return service_client.ResponseBody(resp, body['meta'])
<|file_name|>images_client.py<|end_file_name|><|fim▁begin|># Copyright 2012 OpenStack Foundation # All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. import json from six.moves.urllib import parse as urllib from tempest_lib import exceptions as lib_exc from tempest.api_schema.response.compute.v2_1 import images as schema from tempest.common import service_client from tempest.common import waiters class ImagesClientJSON(service_client.ServiceClient): def create_image(self, server_id, name, meta=None): """Creates an image of the original server.""" post_body = { 'createImage': { 'name': name, } } if meta is not None: post_body['createImage']['metadata'] = meta post_body = json.dumps(post_body) resp, body = self.post('servers/%s/action' % str(server_id), post_body) self.validate_response(schema.create_image, resp, body) return service_client.ResponseBody(resp, body) def list_images(self, params=None): """Returns a list of all images filtered by any parameters.""" url = 'images' if params: url += '?%s' % urllib.urlencode(params) resp, body = self.get(url) body = json.loads(body) self.validate_response(schema.list_images, resp, body) return service_client.ResponseBodyList(resp, body['images']) def list_images_with_detail(self, params=None): """Returns a detailed list of images filtered by any parameters.""" url = 'images/detail' if params: url += '?%s' % urllib.urlencode(params) resp, body = self.get(url) body = json.loads(body) self.validate_response(schema.list_images_details, resp, body) return service_client.ResponseBodyList(resp, body['images']) def show_image(self, image_id): """Returns the details of a single image.""" resp, body = self.get("images/%s" % str(image_id)) self.expected_success(200, resp.status) body = json.loads(body) self.validate_response(schema.get_image, resp, body) return service_client.ResponseBody(resp, body['image']) def delete_image(self, image_id): """Deletes the provided image.""" resp, body = self.delete("images/%s" % str(image_id)) self.validate_response(schema.delete, resp, body) return service_client.ResponseBody(resp, body) def wait_for_image_status(self, image_id, status): """Waits for an image to reach a given status.""" waiters.wait_for_image_status(self, image_id, status) def list_image_metadata(self, image_id): """Lists all metadata items for an image.""" resp, body = self.get("images/%s/metadata" % str(image_id)) body = json.loads(body) self.validate_response(schema.image_metadata, resp, body) return service_client.ResponseBody(resp, body['metadata']) def set_image_metadata(self, image_id, meta): """Sets the metadata for an image.""" post_body = json.dumps({'metadata': meta}) resp, body = self.put('images/%s/metadata' % str(image_id), post_body) body = json.loads(body) self.validate_response(schema.image_metadata, resp, body) return service_client.ResponseBody(resp, body['metadata']) def update_image_metadata(self, image_id, meta): """Updates the metadata for an image.""" post_body = json.dumps({'metadata': meta}) resp, body = self.post('images/%s/metadata' % str(image_id), post_body) body = json.loads(body) self.validate_response(schema.image_metadata, resp, body) return service_client.ResponseBody(resp, body['metadata']) def get_image_metadata_item(self, image_id, key): """Returns the value for a specific image metadata key.""" resp, body = self.get("images/%s/metadata/%s" % (str(image_id), key)) body = json.loads(body) self.validate_response(schema.image_meta_item, resp, body) return service_client.ResponseBody(resp, body['meta']) def set_image_metadata_item(self, image_id, key, meta): <|fim_middle|> def delete_image_metadata_item(self, image_id, key): """Deletes a single image metadata key/value pair.""" resp, body = self.delete("images/%s/metadata/%s" % (str(image_id), key)) self.validate_response(schema.delete, resp, body) return service_client.ResponseBody(resp, body) def is_resource_deleted(self, id): try: self.show_image(id) except lib_exc.NotFound: return True return False @property def resource_type(self): """Returns the primary type of resource this client works with.""" return 'image' <|fim▁end|>
"""Sets the value for a specific image metadata key.""" post_body = json.dumps({'meta': meta}) resp, body = self.put('images/%s/metadata/%s' % (str(image_id), key), post_body) body = json.loads(body) self.validate_response(schema.image_meta_item, resp, body) return service_client.ResponseBody(resp, body['meta'])
<|file_name|>images_client.py<|end_file_name|><|fim▁begin|># Copyright 2012 OpenStack Foundation # All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. import json from six.moves.urllib import parse as urllib from tempest_lib import exceptions as lib_exc from tempest.api_schema.response.compute.v2_1 import images as schema from tempest.common import service_client from tempest.common import waiters class ImagesClientJSON(service_client.ServiceClient): def create_image(self, server_id, name, meta=None): """Creates an image of the original server.""" post_body = { 'createImage': { 'name': name, } } if meta is not None: post_body['createImage']['metadata'] = meta post_body = json.dumps(post_body) resp, body = self.post('servers/%s/action' % str(server_id), post_body) self.validate_response(schema.create_image, resp, body) return service_client.ResponseBody(resp, body) def list_images(self, params=None): """Returns a list of all images filtered by any parameters.""" url = 'images' if params: url += '?%s' % urllib.urlencode(params) resp, body = self.get(url) body = json.loads(body) self.validate_response(schema.list_images, resp, body) return service_client.ResponseBodyList(resp, body['images']) def list_images_with_detail(self, params=None): """Returns a detailed list of images filtered by any parameters.""" url = 'images/detail' if params: url += '?%s' % urllib.urlencode(params) resp, body = self.get(url) body = json.loads(body) self.validate_response(schema.list_images_details, resp, body) return service_client.ResponseBodyList(resp, body['images']) def show_image(self, image_id): """Returns the details of a single image.""" resp, body = self.get("images/%s" % str(image_id)) self.expected_success(200, resp.status) body = json.loads(body) self.validate_response(schema.get_image, resp, body) return service_client.ResponseBody(resp, body['image']) def delete_image(self, image_id): """Deletes the provided image.""" resp, body = self.delete("images/%s" % str(image_id)) self.validate_response(schema.delete, resp, body) return service_client.ResponseBody(resp, body) def wait_for_image_status(self, image_id, status): """Waits for an image to reach a given status.""" waiters.wait_for_image_status(self, image_id, status) def list_image_metadata(self, image_id): """Lists all metadata items for an image.""" resp, body = self.get("images/%s/metadata" % str(image_id)) body = json.loads(body) self.validate_response(schema.image_metadata, resp, body) return service_client.ResponseBody(resp, body['metadata']) def set_image_metadata(self, image_id, meta): """Sets the metadata for an image.""" post_body = json.dumps({'metadata': meta}) resp, body = self.put('images/%s/metadata' % str(image_id), post_body) body = json.loads(body) self.validate_response(schema.image_metadata, resp, body) return service_client.ResponseBody(resp, body['metadata']) def update_image_metadata(self, image_id, meta): """Updates the metadata for an image.""" post_body = json.dumps({'metadata': meta}) resp, body = self.post('images/%s/metadata' % str(image_id), post_body) body = json.loads(body) self.validate_response(schema.image_metadata, resp, body) return service_client.ResponseBody(resp, body['metadata']) def get_image_metadata_item(self, image_id, key): """Returns the value for a specific image metadata key.""" resp, body = self.get("images/%s/metadata/%s" % (str(image_id), key)) body = json.loads(body) self.validate_response(schema.image_meta_item, resp, body) return service_client.ResponseBody(resp, body['meta']) def set_image_metadata_item(self, image_id, key, meta): """Sets the value for a specific image metadata key.""" post_body = json.dumps({'meta': meta}) resp, body = self.put('images/%s/metadata/%s' % (str(image_id), key), post_body) body = json.loads(body) self.validate_response(schema.image_meta_item, resp, body) return service_client.ResponseBody(resp, body['meta']) def delete_image_metadata_item(self, image_id, key): <|fim_middle|> def is_resource_deleted(self, id): try: self.show_image(id) except lib_exc.NotFound: return True return False @property def resource_type(self): """Returns the primary type of resource this client works with.""" return 'image' <|fim▁end|>
"""Deletes a single image metadata key/value pair.""" resp, body = self.delete("images/%s/metadata/%s" % (str(image_id), key)) self.validate_response(schema.delete, resp, body) return service_client.ResponseBody(resp, body)
<|file_name|>images_client.py<|end_file_name|><|fim▁begin|># Copyright 2012 OpenStack Foundation # All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. import json from six.moves.urllib import parse as urllib from tempest_lib import exceptions as lib_exc from tempest.api_schema.response.compute.v2_1 import images as schema from tempest.common import service_client from tempest.common import waiters class ImagesClientJSON(service_client.ServiceClient): def create_image(self, server_id, name, meta=None): """Creates an image of the original server.""" post_body = { 'createImage': { 'name': name, } } if meta is not None: post_body['createImage']['metadata'] = meta post_body = json.dumps(post_body) resp, body = self.post('servers/%s/action' % str(server_id), post_body) self.validate_response(schema.create_image, resp, body) return service_client.ResponseBody(resp, body) def list_images(self, params=None): """Returns a list of all images filtered by any parameters.""" url = 'images' if params: url += '?%s' % urllib.urlencode(params) resp, body = self.get(url) body = json.loads(body) self.validate_response(schema.list_images, resp, body) return service_client.ResponseBodyList(resp, body['images']) def list_images_with_detail(self, params=None): """Returns a detailed list of images filtered by any parameters.""" url = 'images/detail' if params: url += '?%s' % urllib.urlencode(params) resp, body = self.get(url) body = json.loads(body) self.validate_response(schema.list_images_details, resp, body) return service_client.ResponseBodyList(resp, body['images']) def show_image(self, image_id): """Returns the details of a single image.""" resp, body = self.get("images/%s" % str(image_id)) self.expected_success(200, resp.status) body = json.loads(body) self.validate_response(schema.get_image, resp, body) return service_client.ResponseBody(resp, body['image']) def delete_image(self, image_id): """Deletes the provided image.""" resp, body = self.delete("images/%s" % str(image_id)) self.validate_response(schema.delete, resp, body) return service_client.ResponseBody(resp, body) def wait_for_image_status(self, image_id, status): """Waits for an image to reach a given status.""" waiters.wait_for_image_status(self, image_id, status) def list_image_metadata(self, image_id): """Lists all metadata items for an image.""" resp, body = self.get("images/%s/metadata" % str(image_id)) body = json.loads(body) self.validate_response(schema.image_metadata, resp, body) return service_client.ResponseBody(resp, body['metadata']) def set_image_metadata(self, image_id, meta): """Sets the metadata for an image.""" post_body = json.dumps({'metadata': meta}) resp, body = self.put('images/%s/metadata' % str(image_id), post_body) body = json.loads(body) self.validate_response(schema.image_metadata, resp, body) return service_client.ResponseBody(resp, body['metadata']) def update_image_metadata(self, image_id, meta): """Updates the metadata for an image.""" post_body = json.dumps({'metadata': meta}) resp, body = self.post('images/%s/metadata' % str(image_id), post_body) body = json.loads(body) self.validate_response(schema.image_metadata, resp, body) return service_client.ResponseBody(resp, body['metadata']) def get_image_metadata_item(self, image_id, key): """Returns the value for a specific image metadata key.""" resp, body = self.get("images/%s/metadata/%s" % (str(image_id), key)) body = json.loads(body) self.validate_response(schema.image_meta_item, resp, body) return service_client.ResponseBody(resp, body['meta']) def set_image_metadata_item(self, image_id, key, meta): """Sets the value for a specific image metadata key.""" post_body = json.dumps({'meta': meta}) resp, body = self.put('images/%s/metadata/%s' % (str(image_id), key), post_body) body = json.loads(body) self.validate_response(schema.image_meta_item, resp, body) return service_client.ResponseBody(resp, body['meta']) def delete_image_metadata_item(self, image_id, key): """Deletes a single image metadata key/value pair.""" resp, body = self.delete("images/%s/metadata/%s" % (str(image_id), key)) self.validate_response(schema.delete, resp, body) return service_client.ResponseBody(resp, body) def is_resource_deleted(self, id): <|fim_middle|> @property def resource_type(self): """Returns the primary type of resource this client works with.""" return 'image' <|fim▁end|>
try: self.show_image(id) except lib_exc.NotFound: return True return False
<|file_name|>images_client.py<|end_file_name|><|fim▁begin|># Copyright 2012 OpenStack Foundation # All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. import json from six.moves.urllib import parse as urllib from tempest_lib import exceptions as lib_exc from tempest.api_schema.response.compute.v2_1 import images as schema from tempest.common import service_client from tempest.common import waiters class ImagesClientJSON(service_client.ServiceClient): def create_image(self, server_id, name, meta=None): """Creates an image of the original server.""" post_body = { 'createImage': { 'name': name, } } if meta is not None: post_body['createImage']['metadata'] = meta post_body = json.dumps(post_body) resp, body = self.post('servers/%s/action' % str(server_id), post_body) self.validate_response(schema.create_image, resp, body) return service_client.ResponseBody(resp, body) def list_images(self, params=None): """Returns a list of all images filtered by any parameters.""" url = 'images' if params: url += '?%s' % urllib.urlencode(params) resp, body = self.get(url) body = json.loads(body) self.validate_response(schema.list_images, resp, body) return service_client.ResponseBodyList(resp, body['images']) def list_images_with_detail(self, params=None): """Returns a detailed list of images filtered by any parameters.""" url = 'images/detail' if params: url += '?%s' % urllib.urlencode(params) resp, body = self.get(url) body = json.loads(body) self.validate_response(schema.list_images_details, resp, body) return service_client.ResponseBodyList(resp, body['images']) def show_image(self, image_id): """Returns the details of a single image.""" resp, body = self.get("images/%s" % str(image_id)) self.expected_success(200, resp.status) body = json.loads(body) self.validate_response(schema.get_image, resp, body) return service_client.ResponseBody(resp, body['image']) def delete_image(self, image_id): """Deletes the provided image.""" resp, body = self.delete("images/%s" % str(image_id)) self.validate_response(schema.delete, resp, body) return service_client.ResponseBody(resp, body) def wait_for_image_status(self, image_id, status): """Waits for an image to reach a given status.""" waiters.wait_for_image_status(self, image_id, status) def list_image_metadata(self, image_id): """Lists all metadata items for an image.""" resp, body = self.get("images/%s/metadata" % str(image_id)) body = json.loads(body) self.validate_response(schema.image_metadata, resp, body) return service_client.ResponseBody(resp, body['metadata']) def set_image_metadata(self, image_id, meta): """Sets the metadata for an image.""" post_body = json.dumps({'metadata': meta}) resp, body = self.put('images/%s/metadata' % str(image_id), post_body) body = json.loads(body) self.validate_response(schema.image_metadata, resp, body) return service_client.ResponseBody(resp, body['metadata']) def update_image_metadata(self, image_id, meta): """Updates the metadata for an image.""" post_body = json.dumps({'metadata': meta}) resp, body = self.post('images/%s/metadata' % str(image_id), post_body) body = json.loads(body) self.validate_response(schema.image_metadata, resp, body) return service_client.ResponseBody(resp, body['metadata']) def get_image_metadata_item(self, image_id, key): """Returns the value for a specific image metadata key.""" resp, body = self.get("images/%s/metadata/%s" % (str(image_id), key)) body = json.loads(body) self.validate_response(schema.image_meta_item, resp, body) return service_client.ResponseBody(resp, body['meta']) def set_image_metadata_item(self, image_id, key, meta): """Sets the value for a specific image metadata key.""" post_body = json.dumps({'meta': meta}) resp, body = self.put('images/%s/metadata/%s' % (str(image_id), key), post_body) body = json.loads(body) self.validate_response(schema.image_meta_item, resp, body) return service_client.ResponseBody(resp, body['meta']) def delete_image_metadata_item(self, image_id, key): """Deletes a single image metadata key/value pair.""" resp, body = self.delete("images/%s/metadata/%s" % (str(image_id), key)) self.validate_response(schema.delete, resp, body) return service_client.ResponseBody(resp, body) def is_resource_deleted(self, id): try: self.show_image(id) except lib_exc.NotFound: return True return False @property def resource_type(self): <|fim_middle|> <|fim▁end|>
"""Returns the primary type of resource this client works with.""" return 'image'
<|file_name|>images_client.py<|end_file_name|><|fim▁begin|># Copyright 2012 OpenStack Foundation # All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. import json from six.moves.urllib import parse as urllib from tempest_lib import exceptions as lib_exc from tempest.api_schema.response.compute.v2_1 import images as schema from tempest.common import service_client from tempest.common import waiters class ImagesClientJSON(service_client.ServiceClient): def create_image(self, server_id, name, meta=None): """Creates an image of the original server.""" post_body = { 'createImage': { 'name': name, } } if meta is not None: <|fim_middle|> post_body = json.dumps(post_body) resp, body = self.post('servers/%s/action' % str(server_id), post_body) self.validate_response(schema.create_image, resp, body) return service_client.ResponseBody(resp, body) def list_images(self, params=None): """Returns a list of all images filtered by any parameters.""" url = 'images' if params: url += '?%s' % urllib.urlencode(params) resp, body = self.get(url) body = json.loads(body) self.validate_response(schema.list_images, resp, body) return service_client.ResponseBodyList(resp, body['images']) def list_images_with_detail(self, params=None): """Returns a detailed list of images filtered by any parameters.""" url = 'images/detail' if params: url += '?%s' % urllib.urlencode(params) resp, body = self.get(url) body = json.loads(body) self.validate_response(schema.list_images_details, resp, body) return service_client.ResponseBodyList(resp, body['images']) def show_image(self, image_id): """Returns the details of a single image.""" resp, body = self.get("images/%s" % str(image_id)) self.expected_success(200, resp.status) body = json.loads(body) self.validate_response(schema.get_image, resp, body) return service_client.ResponseBody(resp, body['image']) def delete_image(self, image_id): """Deletes the provided image.""" resp, body = self.delete("images/%s" % str(image_id)) self.validate_response(schema.delete, resp, body) return service_client.ResponseBody(resp, body) def wait_for_image_status(self, image_id, status): """Waits for an image to reach a given status.""" waiters.wait_for_image_status(self, image_id, status) def list_image_metadata(self, image_id): """Lists all metadata items for an image.""" resp, body = self.get("images/%s/metadata" % str(image_id)) body = json.loads(body) self.validate_response(schema.image_metadata, resp, body) return service_client.ResponseBody(resp, body['metadata']) def set_image_metadata(self, image_id, meta): """Sets the metadata for an image.""" post_body = json.dumps({'metadata': meta}) resp, body = self.put('images/%s/metadata' % str(image_id), post_body) body = json.loads(body) self.validate_response(schema.image_metadata, resp, body) return service_client.ResponseBody(resp, body['metadata']) def update_image_metadata(self, image_id, meta): """Updates the metadata for an image.""" post_body = json.dumps({'metadata': meta}) resp, body = self.post('images/%s/metadata' % str(image_id), post_body) body = json.loads(body) self.validate_response(schema.image_metadata, resp, body) return service_client.ResponseBody(resp, body['metadata']) def get_image_metadata_item(self, image_id, key): """Returns the value for a specific image metadata key.""" resp, body = self.get("images/%s/metadata/%s" % (str(image_id), key)) body = json.loads(body) self.validate_response(schema.image_meta_item, resp, body) return service_client.ResponseBody(resp, body['meta']) def set_image_metadata_item(self, image_id, key, meta): """Sets the value for a specific image metadata key.""" post_body = json.dumps({'meta': meta}) resp, body = self.put('images/%s/metadata/%s' % (str(image_id), key), post_body) body = json.loads(body) self.validate_response(schema.image_meta_item, resp, body) return service_client.ResponseBody(resp, body['meta']) def delete_image_metadata_item(self, image_id, key): """Deletes a single image metadata key/value pair.""" resp, body = self.delete("images/%s/metadata/%s" % (str(image_id), key)) self.validate_response(schema.delete, resp, body) return service_client.ResponseBody(resp, body) def is_resource_deleted(self, id): try: self.show_image(id) except lib_exc.NotFound: return True return False @property def resource_type(self): """Returns the primary type of resource this client works with.""" return 'image' <|fim▁end|>
post_body['createImage']['metadata'] = meta
<|file_name|>images_client.py<|end_file_name|><|fim▁begin|># Copyright 2012 OpenStack Foundation # All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. import json from six.moves.urllib import parse as urllib from tempest_lib import exceptions as lib_exc from tempest.api_schema.response.compute.v2_1 import images as schema from tempest.common import service_client from tempest.common import waiters class ImagesClientJSON(service_client.ServiceClient): def create_image(self, server_id, name, meta=None): """Creates an image of the original server.""" post_body = { 'createImage': { 'name': name, } } if meta is not None: post_body['createImage']['metadata'] = meta post_body = json.dumps(post_body) resp, body = self.post('servers/%s/action' % str(server_id), post_body) self.validate_response(schema.create_image, resp, body) return service_client.ResponseBody(resp, body) def list_images(self, params=None): """Returns a list of all images filtered by any parameters.""" url = 'images' if params: <|fim_middle|> resp, body = self.get(url) body = json.loads(body) self.validate_response(schema.list_images, resp, body) return service_client.ResponseBodyList(resp, body['images']) def list_images_with_detail(self, params=None): """Returns a detailed list of images filtered by any parameters.""" url = 'images/detail' if params: url += '?%s' % urllib.urlencode(params) resp, body = self.get(url) body = json.loads(body) self.validate_response(schema.list_images_details, resp, body) return service_client.ResponseBodyList(resp, body['images']) def show_image(self, image_id): """Returns the details of a single image.""" resp, body = self.get("images/%s" % str(image_id)) self.expected_success(200, resp.status) body = json.loads(body) self.validate_response(schema.get_image, resp, body) return service_client.ResponseBody(resp, body['image']) def delete_image(self, image_id): """Deletes the provided image.""" resp, body = self.delete("images/%s" % str(image_id)) self.validate_response(schema.delete, resp, body) return service_client.ResponseBody(resp, body) def wait_for_image_status(self, image_id, status): """Waits for an image to reach a given status.""" waiters.wait_for_image_status(self, image_id, status) def list_image_metadata(self, image_id): """Lists all metadata items for an image.""" resp, body = self.get("images/%s/metadata" % str(image_id)) body = json.loads(body) self.validate_response(schema.image_metadata, resp, body) return service_client.ResponseBody(resp, body['metadata']) def set_image_metadata(self, image_id, meta): """Sets the metadata for an image.""" post_body = json.dumps({'metadata': meta}) resp, body = self.put('images/%s/metadata' % str(image_id), post_body) body = json.loads(body) self.validate_response(schema.image_metadata, resp, body) return service_client.ResponseBody(resp, body['metadata']) def update_image_metadata(self, image_id, meta): """Updates the metadata for an image.""" post_body = json.dumps({'metadata': meta}) resp, body = self.post('images/%s/metadata' % str(image_id), post_body) body = json.loads(body) self.validate_response(schema.image_metadata, resp, body) return service_client.ResponseBody(resp, body['metadata']) def get_image_metadata_item(self, image_id, key): """Returns the value for a specific image metadata key.""" resp, body = self.get("images/%s/metadata/%s" % (str(image_id), key)) body = json.loads(body) self.validate_response(schema.image_meta_item, resp, body) return service_client.ResponseBody(resp, body['meta']) def set_image_metadata_item(self, image_id, key, meta): """Sets the value for a specific image metadata key.""" post_body = json.dumps({'meta': meta}) resp, body = self.put('images/%s/metadata/%s' % (str(image_id), key), post_body) body = json.loads(body) self.validate_response(schema.image_meta_item, resp, body) return service_client.ResponseBody(resp, body['meta']) def delete_image_metadata_item(self, image_id, key): """Deletes a single image metadata key/value pair.""" resp, body = self.delete("images/%s/metadata/%s" % (str(image_id), key)) self.validate_response(schema.delete, resp, body) return service_client.ResponseBody(resp, body) def is_resource_deleted(self, id): try: self.show_image(id) except lib_exc.NotFound: return True return False @property def resource_type(self): """Returns the primary type of resource this client works with.""" return 'image' <|fim▁end|>
url += '?%s' % urllib.urlencode(params)
<|file_name|>images_client.py<|end_file_name|><|fim▁begin|># Copyright 2012 OpenStack Foundation # All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. import json from six.moves.urllib import parse as urllib from tempest_lib import exceptions as lib_exc from tempest.api_schema.response.compute.v2_1 import images as schema from tempest.common import service_client from tempest.common import waiters class ImagesClientJSON(service_client.ServiceClient): def create_image(self, server_id, name, meta=None): """Creates an image of the original server.""" post_body = { 'createImage': { 'name': name, } } if meta is not None: post_body['createImage']['metadata'] = meta post_body = json.dumps(post_body) resp, body = self.post('servers/%s/action' % str(server_id), post_body) self.validate_response(schema.create_image, resp, body) return service_client.ResponseBody(resp, body) def list_images(self, params=None): """Returns a list of all images filtered by any parameters.""" url = 'images' if params: url += '?%s' % urllib.urlencode(params) resp, body = self.get(url) body = json.loads(body) self.validate_response(schema.list_images, resp, body) return service_client.ResponseBodyList(resp, body['images']) def list_images_with_detail(self, params=None): """Returns a detailed list of images filtered by any parameters.""" url = 'images/detail' if params: <|fim_middle|> resp, body = self.get(url) body = json.loads(body) self.validate_response(schema.list_images_details, resp, body) return service_client.ResponseBodyList(resp, body['images']) def show_image(self, image_id): """Returns the details of a single image.""" resp, body = self.get("images/%s" % str(image_id)) self.expected_success(200, resp.status) body = json.loads(body) self.validate_response(schema.get_image, resp, body) return service_client.ResponseBody(resp, body['image']) def delete_image(self, image_id): """Deletes the provided image.""" resp, body = self.delete("images/%s" % str(image_id)) self.validate_response(schema.delete, resp, body) return service_client.ResponseBody(resp, body) def wait_for_image_status(self, image_id, status): """Waits for an image to reach a given status.""" waiters.wait_for_image_status(self, image_id, status) def list_image_metadata(self, image_id): """Lists all metadata items for an image.""" resp, body = self.get("images/%s/metadata" % str(image_id)) body = json.loads(body) self.validate_response(schema.image_metadata, resp, body) return service_client.ResponseBody(resp, body['metadata']) def set_image_metadata(self, image_id, meta): """Sets the metadata for an image.""" post_body = json.dumps({'metadata': meta}) resp, body = self.put('images/%s/metadata' % str(image_id), post_body) body = json.loads(body) self.validate_response(schema.image_metadata, resp, body) return service_client.ResponseBody(resp, body['metadata']) def update_image_metadata(self, image_id, meta): """Updates the metadata for an image.""" post_body = json.dumps({'metadata': meta}) resp, body = self.post('images/%s/metadata' % str(image_id), post_body) body = json.loads(body) self.validate_response(schema.image_metadata, resp, body) return service_client.ResponseBody(resp, body['metadata']) def get_image_metadata_item(self, image_id, key): """Returns the value for a specific image metadata key.""" resp, body = self.get("images/%s/metadata/%s" % (str(image_id), key)) body = json.loads(body) self.validate_response(schema.image_meta_item, resp, body) return service_client.ResponseBody(resp, body['meta']) def set_image_metadata_item(self, image_id, key, meta): """Sets the value for a specific image metadata key.""" post_body = json.dumps({'meta': meta}) resp, body = self.put('images/%s/metadata/%s' % (str(image_id), key), post_body) body = json.loads(body) self.validate_response(schema.image_meta_item, resp, body) return service_client.ResponseBody(resp, body['meta']) def delete_image_metadata_item(self, image_id, key): """Deletes a single image metadata key/value pair.""" resp, body = self.delete("images/%s/metadata/%s" % (str(image_id), key)) self.validate_response(schema.delete, resp, body) return service_client.ResponseBody(resp, body) def is_resource_deleted(self, id): try: self.show_image(id) except lib_exc.NotFound: return True return False @property def resource_type(self): """Returns the primary type of resource this client works with.""" return 'image' <|fim▁end|>
url += '?%s' % urllib.urlencode(params)
<|file_name|>images_client.py<|end_file_name|><|fim▁begin|># Copyright 2012 OpenStack Foundation # All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. import json from six.moves.urllib import parse as urllib from tempest_lib import exceptions as lib_exc from tempest.api_schema.response.compute.v2_1 import images as schema from tempest.common import service_client from tempest.common import waiters class ImagesClientJSON(service_client.ServiceClient): def <|fim_middle|>(self, server_id, name, meta=None): """Creates an image of the original server.""" post_body = { 'createImage': { 'name': name, } } if meta is not None: post_body['createImage']['metadata'] = meta post_body = json.dumps(post_body) resp, body = self.post('servers/%s/action' % str(server_id), post_body) self.validate_response(schema.create_image, resp, body) return service_client.ResponseBody(resp, body) def list_images(self, params=None): """Returns a list of all images filtered by any parameters.""" url = 'images' if params: url += '?%s' % urllib.urlencode(params) resp, body = self.get(url) body = json.loads(body) self.validate_response(schema.list_images, resp, body) return service_client.ResponseBodyList(resp, body['images']) def list_images_with_detail(self, params=None): """Returns a detailed list of images filtered by any parameters.""" url = 'images/detail' if params: url += '?%s' % urllib.urlencode(params) resp, body = self.get(url) body = json.loads(body) self.validate_response(schema.list_images_details, resp, body) return service_client.ResponseBodyList(resp, body['images']) def show_image(self, image_id): """Returns the details of a single image.""" resp, body = self.get("images/%s" % str(image_id)) self.expected_success(200, resp.status) body = json.loads(body) self.validate_response(schema.get_image, resp, body) return service_client.ResponseBody(resp, body['image']) def delete_image(self, image_id): """Deletes the provided image.""" resp, body = self.delete("images/%s" % str(image_id)) self.validate_response(schema.delete, resp, body) return service_client.ResponseBody(resp, body) def wait_for_image_status(self, image_id, status): """Waits for an image to reach a given status.""" waiters.wait_for_image_status(self, image_id, status) def list_image_metadata(self, image_id): """Lists all metadata items for an image.""" resp, body = self.get("images/%s/metadata" % str(image_id)) body = json.loads(body) self.validate_response(schema.image_metadata, resp, body) return service_client.ResponseBody(resp, body['metadata']) def set_image_metadata(self, image_id, meta): """Sets the metadata for an image.""" post_body = json.dumps({'metadata': meta}) resp, body = self.put('images/%s/metadata' % str(image_id), post_body) body = json.loads(body) self.validate_response(schema.image_metadata, resp, body) return service_client.ResponseBody(resp, body['metadata']) def update_image_metadata(self, image_id, meta): """Updates the metadata for an image.""" post_body = json.dumps({'metadata': meta}) resp, body = self.post('images/%s/metadata' % str(image_id), post_body) body = json.loads(body) self.validate_response(schema.image_metadata, resp, body) return service_client.ResponseBody(resp, body['metadata']) def get_image_metadata_item(self, image_id, key): """Returns the value for a specific image metadata key.""" resp, body = self.get("images/%s/metadata/%s" % (str(image_id), key)) body = json.loads(body) self.validate_response(schema.image_meta_item, resp, body) return service_client.ResponseBody(resp, body['meta']) def set_image_metadata_item(self, image_id, key, meta): """Sets the value for a specific image metadata key.""" post_body = json.dumps({'meta': meta}) resp, body = self.put('images/%s/metadata/%s' % (str(image_id), key), post_body) body = json.loads(body) self.validate_response(schema.image_meta_item, resp, body) return service_client.ResponseBody(resp, body['meta']) def delete_image_metadata_item(self, image_id, key): """Deletes a single image metadata key/value pair.""" resp, body = self.delete("images/%s/metadata/%s" % (str(image_id), key)) self.validate_response(schema.delete, resp, body) return service_client.ResponseBody(resp, body) def is_resource_deleted(self, id): try: self.show_image(id) except lib_exc.NotFound: return True return False @property def resource_type(self): """Returns the primary type of resource this client works with.""" return 'image' <|fim▁end|>
create_image
<|file_name|>images_client.py<|end_file_name|><|fim▁begin|># Copyright 2012 OpenStack Foundation # All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. import json from six.moves.urllib import parse as urllib from tempest_lib import exceptions as lib_exc from tempest.api_schema.response.compute.v2_1 import images as schema from tempest.common import service_client from tempest.common import waiters class ImagesClientJSON(service_client.ServiceClient): def create_image(self, server_id, name, meta=None): """Creates an image of the original server.""" post_body = { 'createImage': { 'name': name, } } if meta is not None: post_body['createImage']['metadata'] = meta post_body = json.dumps(post_body) resp, body = self.post('servers/%s/action' % str(server_id), post_body) self.validate_response(schema.create_image, resp, body) return service_client.ResponseBody(resp, body) def <|fim_middle|>(self, params=None): """Returns a list of all images filtered by any parameters.""" url = 'images' if params: url += '?%s' % urllib.urlencode(params) resp, body = self.get(url) body = json.loads(body) self.validate_response(schema.list_images, resp, body) return service_client.ResponseBodyList(resp, body['images']) def list_images_with_detail(self, params=None): """Returns a detailed list of images filtered by any parameters.""" url = 'images/detail' if params: url += '?%s' % urllib.urlencode(params) resp, body = self.get(url) body = json.loads(body) self.validate_response(schema.list_images_details, resp, body) return service_client.ResponseBodyList(resp, body['images']) def show_image(self, image_id): """Returns the details of a single image.""" resp, body = self.get("images/%s" % str(image_id)) self.expected_success(200, resp.status) body = json.loads(body) self.validate_response(schema.get_image, resp, body) return service_client.ResponseBody(resp, body['image']) def delete_image(self, image_id): """Deletes the provided image.""" resp, body = self.delete("images/%s" % str(image_id)) self.validate_response(schema.delete, resp, body) return service_client.ResponseBody(resp, body) def wait_for_image_status(self, image_id, status): """Waits for an image to reach a given status.""" waiters.wait_for_image_status(self, image_id, status) def list_image_metadata(self, image_id): """Lists all metadata items for an image.""" resp, body = self.get("images/%s/metadata" % str(image_id)) body = json.loads(body) self.validate_response(schema.image_metadata, resp, body) return service_client.ResponseBody(resp, body['metadata']) def set_image_metadata(self, image_id, meta): """Sets the metadata for an image.""" post_body = json.dumps({'metadata': meta}) resp, body = self.put('images/%s/metadata' % str(image_id), post_body) body = json.loads(body) self.validate_response(schema.image_metadata, resp, body) return service_client.ResponseBody(resp, body['metadata']) def update_image_metadata(self, image_id, meta): """Updates the metadata for an image.""" post_body = json.dumps({'metadata': meta}) resp, body = self.post('images/%s/metadata' % str(image_id), post_body) body = json.loads(body) self.validate_response(schema.image_metadata, resp, body) return service_client.ResponseBody(resp, body['metadata']) def get_image_metadata_item(self, image_id, key): """Returns the value for a specific image metadata key.""" resp, body = self.get("images/%s/metadata/%s" % (str(image_id), key)) body = json.loads(body) self.validate_response(schema.image_meta_item, resp, body) return service_client.ResponseBody(resp, body['meta']) def set_image_metadata_item(self, image_id, key, meta): """Sets the value for a specific image metadata key.""" post_body = json.dumps({'meta': meta}) resp, body = self.put('images/%s/metadata/%s' % (str(image_id), key), post_body) body = json.loads(body) self.validate_response(schema.image_meta_item, resp, body) return service_client.ResponseBody(resp, body['meta']) def delete_image_metadata_item(self, image_id, key): """Deletes a single image metadata key/value pair.""" resp, body = self.delete("images/%s/metadata/%s" % (str(image_id), key)) self.validate_response(schema.delete, resp, body) return service_client.ResponseBody(resp, body) def is_resource_deleted(self, id): try: self.show_image(id) except lib_exc.NotFound: return True return False @property def resource_type(self): """Returns the primary type of resource this client works with.""" return 'image' <|fim▁end|>
list_images
<|file_name|>images_client.py<|end_file_name|><|fim▁begin|># Copyright 2012 OpenStack Foundation # All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. import json from six.moves.urllib import parse as urllib from tempest_lib import exceptions as lib_exc from tempest.api_schema.response.compute.v2_1 import images as schema from tempest.common import service_client from tempest.common import waiters class ImagesClientJSON(service_client.ServiceClient): def create_image(self, server_id, name, meta=None): """Creates an image of the original server.""" post_body = { 'createImage': { 'name': name, } } if meta is not None: post_body['createImage']['metadata'] = meta post_body = json.dumps(post_body) resp, body = self.post('servers/%s/action' % str(server_id), post_body) self.validate_response(schema.create_image, resp, body) return service_client.ResponseBody(resp, body) def list_images(self, params=None): """Returns a list of all images filtered by any parameters.""" url = 'images' if params: url += '?%s' % urllib.urlencode(params) resp, body = self.get(url) body = json.loads(body) self.validate_response(schema.list_images, resp, body) return service_client.ResponseBodyList(resp, body['images']) def <|fim_middle|>(self, params=None): """Returns a detailed list of images filtered by any parameters.""" url = 'images/detail' if params: url += '?%s' % urllib.urlencode(params) resp, body = self.get(url) body = json.loads(body) self.validate_response(schema.list_images_details, resp, body) return service_client.ResponseBodyList(resp, body['images']) def show_image(self, image_id): """Returns the details of a single image.""" resp, body = self.get("images/%s" % str(image_id)) self.expected_success(200, resp.status) body = json.loads(body) self.validate_response(schema.get_image, resp, body) return service_client.ResponseBody(resp, body['image']) def delete_image(self, image_id): """Deletes the provided image.""" resp, body = self.delete("images/%s" % str(image_id)) self.validate_response(schema.delete, resp, body) return service_client.ResponseBody(resp, body) def wait_for_image_status(self, image_id, status): """Waits for an image to reach a given status.""" waiters.wait_for_image_status(self, image_id, status) def list_image_metadata(self, image_id): """Lists all metadata items for an image.""" resp, body = self.get("images/%s/metadata" % str(image_id)) body = json.loads(body) self.validate_response(schema.image_metadata, resp, body) return service_client.ResponseBody(resp, body['metadata']) def set_image_metadata(self, image_id, meta): """Sets the metadata for an image.""" post_body = json.dumps({'metadata': meta}) resp, body = self.put('images/%s/metadata' % str(image_id), post_body) body = json.loads(body) self.validate_response(schema.image_metadata, resp, body) return service_client.ResponseBody(resp, body['metadata']) def update_image_metadata(self, image_id, meta): """Updates the metadata for an image.""" post_body = json.dumps({'metadata': meta}) resp, body = self.post('images/%s/metadata' % str(image_id), post_body) body = json.loads(body) self.validate_response(schema.image_metadata, resp, body) return service_client.ResponseBody(resp, body['metadata']) def get_image_metadata_item(self, image_id, key): """Returns the value for a specific image metadata key.""" resp, body = self.get("images/%s/metadata/%s" % (str(image_id), key)) body = json.loads(body) self.validate_response(schema.image_meta_item, resp, body) return service_client.ResponseBody(resp, body['meta']) def set_image_metadata_item(self, image_id, key, meta): """Sets the value for a specific image metadata key.""" post_body = json.dumps({'meta': meta}) resp, body = self.put('images/%s/metadata/%s' % (str(image_id), key), post_body) body = json.loads(body) self.validate_response(schema.image_meta_item, resp, body) return service_client.ResponseBody(resp, body['meta']) def delete_image_metadata_item(self, image_id, key): """Deletes a single image metadata key/value pair.""" resp, body = self.delete("images/%s/metadata/%s" % (str(image_id), key)) self.validate_response(schema.delete, resp, body) return service_client.ResponseBody(resp, body) def is_resource_deleted(self, id): try: self.show_image(id) except lib_exc.NotFound: return True return False @property def resource_type(self): """Returns the primary type of resource this client works with.""" return 'image' <|fim▁end|>
list_images_with_detail
<|file_name|>images_client.py<|end_file_name|><|fim▁begin|># Copyright 2012 OpenStack Foundation # All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. import json from six.moves.urllib import parse as urllib from tempest_lib import exceptions as lib_exc from tempest.api_schema.response.compute.v2_1 import images as schema from tempest.common import service_client from tempest.common import waiters class ImagesClientJSON(service_client.ServiceClient): def create_image(self, server_id, name, meta=None): """Creates an image of the original server.""" post_body = { 'createImage': { 'name': name, } } if meta is not None: post_body['createImage']['metadata'] = meta post_body = json.dumps(post_body) resp, body = self.post('servers/%s/action' % str(server_id), post_body) self.validate_response(schema.create_image, resp, body) return service_client.ResponseBody(resp, body) def list_images(self, params=None): """Returns a list of all images filtered by any parameters.""" url = 'images' if params: url += '?%s' % urllib.urlencode(params) resp, body = self.get(url) body = json.loads(body) self.validate_response(schema.list_images, resp, body) return service_client.ResponseBodyList(resp, body['images']) def list_images_with_detail(self, params=None): """Returns a detailed list of images filtered by any parameters.""" url = 'images/detail' if params: url += '?%s' % urllib.urlencode(params) resp, body = self.get(url) body = json.loads(body) self.validate_response(schema.list_images_details, resp, body) return service_client.ResponseBodyList(resp, body['images']) def <|fim_middle|>(self, image_id): """Returns the details of a single image.""" resp, body = self.get("images/%s" % str(image_id)) self.expected_success(200, resp.status) body = json.loads(body) self.validate_response(schema.get_image, resp, body) return service_client.ResponseBody(resp, body['image']) def delete_image(self, image_id): """Deletes the provided image.""" resp, body = self.delete("images/%s" % str(image_id)) self.validate_response(schema.delete, resp, body) return service_client.ResponseBody(resp, body) def wait_for_image_status(self, image_id, status): """Waits for an image to reach a given status.""" waiters.wait_for_image_status(self, image_id, status) def list_image_metadata(self, image_id): """Lists all metadata items for an image.""" resp, body = self.get("images/%s/metadata" % str(image_id)) body = json.loads(body) self.validate_response(schema.image_metadata, resp, body) return service_client.ResponseBody(resp, body['metadata']) def set_image_metadata(self, image_id, meta): """Sets the metadata for an image.""" post_body = json.dumps({'metadata': meta}) resp, body = self.put('images/%s/metadata' % str(image_id), post_body) body = json.loads(body) self.validate_response(schema.image_metadata, resp, body) return service_client.ResponseBody(resp, body['metadata']) def update_image_metadata(self, image_id, meta): """Updates the metadata for an image.""" post_body = json.dumps({'metadata': meta}) resp, body = self.post('images/%s/metadata' % str(image_id), post_body) body = json.loads(body) self.validate_response(schema.image_metadata, resp, body) return service_client.ResponseBody(resp, body['metadata']) def get_image_metadata_item(self, image_id, key): """Returns the value for a specific image metadata key.""" resp, body = self.get("images/%s/metadata/%s" % (str(image_id), key)) body = json.loads(body) self.validate_response(schema.image_meta_item, resp, body) return service_client.ResponseBody(resp, body['meta']) def set_image_metadata_item(self, image_id, key, meta): """Sets the value for a specific image metadata key.""" post_body = json.dumps({'meta': meta}) resp, body = self.put('images/%s/metadata/%s' % (str(image_id), key), post_body) body = json.loads(body) self.validate_response(schema.image_meta_item, resp, body) return service_client.ResponseBody(resp, body['meta']) def delete_image_metadata_item(self, image_id, key): """Deletes a single image metadata key/value pair.""" resp, body = self.delete("images/%s/metadata/%s" % (str(image_id), key)) self.validate_response(schema.delete, resp, body) return service_client.ResponseBody(resp, body) def is_resource_deleted(self, id): try: self.show_image(id) except lib_exc.NotFound: return True return False @property def resource_type(self): """Returns the primary type of resource this client works with.""" return 'image' <|fim▁end|>
show_image
<|file_name|>images_client.py<|end_file_name|><|fim▁begin|># Copyright 2012 OpenStack Foundation # All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. import json from six.moves.urllib import parse as urllib from tempest_lib import exceptions as lib_exc from tempest.api_schema.response.compute.v2_1 import images as schema from tempest.common import service_client from tempest.common import waiters class ImagesClientJSON(service_client.ServiceClient): def create_image(self, server_id, name, meta=None): """Creates an image of the original server.""" post_body = { 'createImage': { 'name': name, } } if meta is not None: post_body['createImage']['metadata'] = meta post_body = json.dumps(post_body) resp, body = self.post('servers/%s/action' % str(server_id), post_body) self.validate_response(schema.create_image, resp, body) return service_client.ResponseBody(resp, body) def list_images(self, params=None): """Returns a list of all images filtered by any parameters.""" url = 'images' if params: url += '?%s' % urllib.urlencode(params) resp, body = self.get(url) body = json.loads(body) self.validate_response(schema.list_images, resp, body) return service_client.ResponseBodyList(resp, body['images']) def list_images_with_detail(self, params=None): """Returns a detailed list of images filtered by any parameters.""" url = 'images/detail' if params: url += '?%s' % urllib.urlencode(params) resp, body = self.get(url) body = json.loads(body) self.validate_response(schema.list_images_details, resp, body) return service_client.ResponseBodyList(resp, body['images']) def show_image(self, image_id): """Returns the details of a single image.""" resp, body = self.get("images/%s" % str(image_id)) self.expected_success(200, resp.status) body = json.loads(body) self.validate_response(schema.get_image, resp, body) return service_client.ResponseBody(resp, body['image']) def <|fim_middle|>(self, image_id): """Deletes the provided image.""" resp, body = self.delete("images/%s" % str(image_id)) self.validate_response(schema.delete, resp, body) return service_client.ResponseBody(resp, body) def wait_for_image_status(self, image_id, status): """Waits for an image to reach a given status.""" waiters.wait_for_image_status(self, image_id, status) def list_image_metadata(self, image_id): """Lists all metadata items for an image.""" resp, body = self.get("images/%s/metadata" % str(image_id)) body = json.loads(body) self.validate_response(schema.image_metadata, resp, body) return service_client.ResponseBody(resp, body['metadata']) def set_image_metadata(self, image_id, meta): """Sets the metadata for an image.""" post_body = json.dumps({'metadata': meta}) resp, body = self.put('images/%s/metadata' % str(image_id), post_body) body = json.loads(body) self.validate_response(schema.image_metadata, resp, body) return service_client.ResponseBody(resp, body['metadata']) def update_image_metadata(self, image_id, meta): """Updates the metadata for an image.""" post_body = json.dumps({'metadata': meta}) resp, body = self.post('images/%s/metadata' % str(image_id), post_body) body = json.loads(body) self.validate_response(schema.image_metadata, resp, body) return service_client.ResponseBody(resp, body['metadata']) def get_image_metadata_item(self, image_id, key): """Returns the value for a specific image metadata key.""" resp, body = self.get("images/%s/metadata/%s" % (str(image_id), key)) body = json.loads(body) self.validate_response(schema.image_meta_item, resp, body) return service_client.ResponseBody(resp, body['meta']) def set_image_metadata_item(self, image_id, key, meta): """Sets the value for a specific image metadata key.""" post_body = json.dumps({'meta': meta}) resp, body = self.put('images/%s/metadata/%s' % (str(image_id), key), post_body) body = json.loads(body) self.validate_response(schema.image_meta_item, resp, body) return service_client.ResponseBody(resp, body['meta']) def delete_image_metadata_item(self, image_id, key): """Deletes a single image metadata key/value pair.""" resp, body = self.delete("images/%s/metadata/%s" % (str(image_id), key)) self.validate_response(schema.delete, resp, body) return service_client.ResponseBody(resp, body) def is_resource_deleted(self, id): try: self.show_image(id) except lib_exc.NotFound: return True return False @property def resource_type(self): """Returns the primary type of resource this client works with.""" return 'image' <|fim▁end|>
delete_image
<|file_name|>images_client.py<|end_file_name|><|fim▁begin|># Copyright 2012 OpenStack Foundation # All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. import json from six.moves.urllib import parse as urllib from tempest_lib import exceptions as lib_exc from tempest.api_schema.response.compute.v2_1 import images as schema from tempest.common import service_client from tempest.common import waiters class ImagesClientJSON(service_client.ServiceClient): def create_image(self, server_id, name, meta=None): """Creates an image of the original server.""" post_body = { 'createImage': { 'name': name, } } if meta is not None: post_body['createImage']['metadata'] = meta post_body = json.dumps(post_body) resp, body = self.post('servers/%s/action' % str(server_id), post_body) self.validate_response(schema.create_image, resp, body) return service_client.ResponseBody(resp, body) def list_images(self, params=None): """Returns a list of all images filtered by any parameters.""" url = 'images' if params: url += '?%s' % urllib.urlencode(params) resp, body = self.get(url) body = json.loads(body) self.validate_response(schema.list_images, resp, body) return service_client.ResponseBodyList(resp, body['images']) def list_images_with_detail(self, params=None): """Returns a detailed list of images filtered by any parameters.""" url = 'images/detail' if params: url += '?%s' % urllib.urlencode(params) resp, body = self.get(url) body = json.loads(body) self.validate_response(schema.list_images_details, resp, body) return service_client.ResponseBodyList(resp, body['images']) def show_image(self, image_id): """Returns the details of a single image.""" resp, body = self.get("images/%s" % str(image_id)) self.expected_success(200, resp.status) body = json.loads(body) self.validate_response(schema.get_image, resp, body) return service_client.ResponseBody(resp, body['image']) def delete_image(self, image_id): """Deletes the provided image.""" resp, body = self.delete("images/%s" % str(image_id)) self.validate_response(schema.delete, resp, body) return service_client.ResponseBody(resp, body) def <|fim_middle|>(self, image_id, status): """Waits for an image to reach a given status.""" waiters.wait_for_image_status(self, image_id, status) def list_image_metadata(self, image_id): """Lists all metadata items for an image.""" resp, body = self.get("images/%s/metadata" % str(image_id)) body = json.loads(body) self.validate_response(schema.image_metadata, resp, body) return service_client.ResponseBody(resp, body['metadata']) def set_image_metadata(self, image_id, meta): """Sets the metadata for an image.""" post_body = json.dumps({'metadata': meta}) resp, body = self.put('images/%s/metadata' % str(image_id), post_body) body = json.loads(body) self.validate_response(schema.image_metadata, resp, body) return service_client.ResponseBody(resp, body['metadata']) def update_image_metadata(self, image_id, meta): """Updates the metadata for an image.""" post_body = json.dumps({'metadata': meta}) resp, body = self.post('images/%s/metadata' % str(image_id), post_body) body = json.loads(body) self.validate_response(schema.image_metadata, resp, body) return service_client.ResponseBody(resp, body['metadata']) def get_image_metadata_item(self, image_id, key): """Returns the value for a specific image metadata key.""" resp, body = self.get("images/%s/metadata/%s" % (str(image_id), key)) body = json.loads(body) self.validate_response(schema.image_meta_item, resp, body) return service_client.ResponseBody(resp, body['meta']) def set_image_metadata_item(self, image_id, key, meta): """Sets the value for a specific image metadata key.""" post_body = json.dumps({'meta': meta}) resp, body = self.put('images/%s/metadata/%s' % (str(image_id), key), post_body) body = json.loads(body) self.validate_response(schema.image_meta_item, resp, body) return service_client.ResponseBody(resp, body['meta']) def delete_image_metadata_item(self, image_id, key): """Deletes a single image metadata key/value pair.""" resp, body = self.delete("images/%s/metadata/%s" % (str(image_id), key)) self.validate_response(schema.delete, resp, body) return service_client.ResponseBody(resp, body) def is_resource_deleted(self, id): try: self.show_image(id) except lib_exc.NotFound: return True return False @property def resource_type(self): """Returns the primary type of resource this client works with.""" return 'image' <|fim▁end|>
wait_for_image_status
<|file_name|>images_client.py<|end_file_name|><|fim▁begin|># Copyright 2012 OpenStack Foundation # All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. import json from six.moves.urllib import parse as urllib from tempest_lib import exceptions as lib_exc from tempest.api_schema.response.compute.v2_1 import images as schema from tempest.common import service_client from tempest.common import waiters class ImagesClientJSON(service_client.ServiceClient): def create_image(self, server_id, name, meta=None): """Creates an image of the original server.""" post_body = { 'createImage': { 'name': name, } } if meta is not None: post_body['createImage']['metadata'] = meta post_body = json.dumps(post_body) resp, body = self.post('servers/%s/action' % str(server_id), post_body) self.validate_response(schema.create_image, resp, body) return service_client.ResponseBody(resp, body) def list_images(self, params=None): """Returns a list of all images filtered by any parameters.""" url = 'images' if params: url += '?%s' % urllib.urlencode(params) resp, body = self.get(url) body = json.loads(body) self.validate_response(schema.list_images, resp, body) return service_client.ResponseBodyList(resp, body['images']) def list_images_with_detail(self, params=None): """Returns a detailed list of images filtered by any parameters.""" url = 'images/detail' if params: url += '?%s' % urllib.urlencode(params) resp, body = self.get(url) body = json.loads(body) self.validate_response(schema.list_images_details, resp, body) return service_client.ResponseBodyList(resp, body['images']) def show_image(self, image_id): """Returns the details of a single image.""" resp, body = self.get("images/%s" % str(image_id)) self.expected_success(200, resp.status) body = json.loads(body) self.validate_response(schema.get_image, resp, body) return service_client.ResponseBody(resp, body['image']) def delete_image(self, image_id): """Deletes the provided image.""" resp, body = self.delete("images/%s" % str(image_id)) self.validate_response(schema.delete, resp, body) return service_client.ResponseBody(resp, body) def wait_for_image_status(self, image_id, status): """Waits for an image to reach a given status.""" waiters.wait_for_image_status(self, image_id, status) def <|fim_middle|>(self, image_id): """Lists all metadata items for an image.""" resp, body = self.get("images/%s/metadata" % str(image_id)) body = json.loads(body) self.validate_response(schema.image_metadata, resp, body) return service_client.ResponseBody(resp, body['metadata']) def set_image_metadata(self, image_id, meta): """Sets the metadata for an image.""" post_body = json.dumps({'metadata': meta}) resp, body = self.put('images/%s/metadata' % str(image_id), post_body) body = json.loads(body) self.validate_response(schema.image_metadata, resp, body) return service_client.ResponseBody(resp, body['metadata']) def update_image_metadata(self, image_id, meta): """Updates the metadata for an image.""" post_body = json.dumps({'metadata': meta}) resp, body = self.post('images/%s/metadata' % str(image_id), post_body) body = json.loads(body) self.validate_response(schema.image_metadata, resp, body) return service_client.ResponseBody(resp, body['metadata']) def get_image_metadata_item(self, image_id, key): """Returns the value for a specific image metadata key.""" resp, body = self.get("images/%s/metadata/%s" % (str(image_id), key)) body = json.loads(body) self.validate_response(schema.image_meta_item, resp, body) return service_client.ResponseBody(resp, body['meta']) def set_image_metadata_item(self, image_id, key, meta): """Sets the value for a specific image metadata key.""" post_body = json.dumps({'meta': meta}) resp, body = self.put('images/%s/metadata/%s' % (str(image_id), key), post_body) body = json.loads(body) self.validate_response(schema.image_meta_item, resp, body) return service_client.ResponseBody(resp, body['meta']) def delete_image_metadata_item(self, image_id, key): """Deletes a single image metadata key/value pair.""" resp, body = self.delete("images/%s/metadata/%s" % (str(image_id), key)) self.validate_response(schema.delete, resp, body) return service_client.ResponseBody(resp, body) def is_resource_deleted(self, id): try: self.show_image(id) except lib_exc.NotFound: return True return False @property def resource_type(self): """Returns the primary type of resource this client works with.""" return 'image' <|fim▁end|>
list_image_metadata
<|file_name|>images_client.py<|end_file_name|><|fim▁begin|># Copyright 2012 OpenStack Foundation # All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. import json from six.moves.urllib import parse as urllib from tempest_lib import exceptions as lib_exc from tempest.api_schema.response.compute.v2_1 import images as schema from tempest.common import service_client from tempest.common import waiters class ImagesClientJSON(service_client.ServiceClient): def create_image(self, server_id, name, meta=None): """Creates an image of the original server.""" post_body = { 'createImage': { 'name': name, } } if meta is not None: post_body['createImage']['metadata'] = meta post_body = json.dumps(post_body) resp, body = self.post('servers/%s/action' % str(server_id), post_body) self.validate_response(schema.create_image, resp, body) return service_client.ResponseBody(resp, body) def list_images(self, params=None): """Returns a list of all images filtered by any parameters.""" url = 'images' if params: url += '?%s' % urllib.urlencode(params) resp, body = self.get(url) body = json.loads(body) self.validate_response(schema.list_images, resp, body) return service_client.ResponseBodyList(resp, body['images']) def list_images_with_detail(self, params=None): """Returns a detailed list of images filtered by any parameters.""" url = 'images/detail' if params: url += '?%s' % urllib.urlencode(params) resp, body = self.get(url) body = json.loads(body) self.validate_response(schema.list_images_details, resp, body) return service_client.ResponseBodyList(resp, body['images']) def show_image(self, image_id): """Returns the details of a single image.""" resp, body = self.get("images/%s" % str(image_id)) self.expected_success(200, resp.status) body = json.loads(body) self.validate_response(schema.get_image, resp, body) return service_client.ResponseBody(resp, body['image']) def delete_image(self, image_id): """Deletes the provided image.""" resp, body = self.delete("images/%s" % str(image_id)) self.validate_response(schema.delete, resp, body) return service_client.ResponseBody(resp, body) def wait_for_image_status(self, image_id, status): """Waits for an image to reach a given status.""" waiters.wait_for_image_status(self, image_id, status) def list_image_metadata(self, image_id): """Lists all metadata items for an image.""" resp, body = self.get("images/%s/metadata" % str(image_id)) body = json.loads(body) self.validate_response(schema.image_metadata, resp, body) return service_client.ResponseBody(resp, body['metadata']) def <|fim_middle|>(self, image_id, meta): """Sets the metadata for an image.""" post_body = json.dumps({'metadata': meta}) resp, body = self.put('images/%s/metadata' % str(image_id), post_body) body = json.loads(body) self.validate_response(schema.image_metadata, resp, body) return service_client.ResponseBody(resp, body['metadata']) def update_image_metadata(self, image_id, meta): """Updates the metadata for an image.""" post_body = json.dumps({'metadata': meta}) resp, body = self.post('images/%s/metadata' % str(image_id), post_body) body = json.loads(body) self.validate_response(schema.image_metadata, resp, body) return service_client.ResponseBody(resp, body['metadata']) def get_image_metadata_item(self, image_id, key): """Returns the value for a specific image metadata key.""" resp, body = self.get("images/%s/metadata/%s" % (str(image_id), key)) body = json.loads(body) self.validate_response(schema.image_meta_item, resp, body) return service_client.ResponseBody(resp, body['meta']) def set_image_metadata_item(self, image_id, key, meta): """Sets the value for a specific image metadata key.""" post_body = json.dumps({'meta': meta}) resp, body = self.put('images/%s/metadata/%s' % (str(image_id), key), post_body) body = json.loads(body) self.validate_response(schema.image_meta_item, resp, body) return service_client.ResponseBody(resp, body['meta']) def delete_image_metadata_item(self, image_id, key): """Deletes a single image metadata key/value pair.""" resp, body = self.delete("images/%s/metadata/%s" % (str(image_id), key)) self.validate_response(schema.delete, resp, body) return service_client.ResponseBody(resp, body) def is_resource_deleted(self, id): try: self.show_image(id) except lib_exc.NotFound: return True return False @property def resource_type(self): """Returns the primary type of resource this client works with.""" return 'image' <|fim▁end|>
set_image_metadata
<|file_name|>images_client.py<|end_file_name|><|fim▁begin|># Copyright 2012 OpenStack Foundation # All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. import json from six.moves.urllib import parse as urllib from tempest_lib import exceptions as lib_exc from tempest.api_schema.response.compute.v2_1 import images as schema from tempest.common import service_client from tempest.common import waiters class ImagesClientJSON(service_client.ServiceClient): def create_image(self, server_id, name, meta=None): """Creates an image of the original server.""" post_body = { 'createImage': { 'name': name, } } if meta is not None: post_body['createImage']['metadata'] = meta post_body = json.dumps(post_body) resp, body = self.post('servers/%s/action' % str(server_id), post_body) self.validate_response(schema.create_image, resp, body) return service_client.ResponseBody(resp, body) def list_images(self, params=None): """Returns a list of all images filtered by any parameters.""" url = 'images' if params: url += '?%s' % urllib.urlencode(params) resp, body = self.get(url) body = json.loads(body) self.validate_response(schema.list_images, resp, body) return service_client.ResponseBodyList(resp, body['images']) def list_images_with_detail(self, params=None): """Returns a detailed list of images filtered by any parameters.""" url = 'images/detail' if params: url += '?%s' % urllib.urlencode(params) resp, body = self.get(url) body = json.loads(body) self.validate_response(schema.list_images_details, resp, body) return service_client.ResponseBodyList(resp, body['images']) def show_image(self, image_id): """Returns the details of a single image.""" resp, body = self.get("images/%s" % str(image_id)) self.expected_success(200, resp.status) body = json.loads(body) self.validate_response(schema.get_image, resp, body) return service_client.ResponseBody(resp, body['image']) def delete_image(self, image_id): """Deletes the provided image.""" resp, body = self.delete("images/%s" % str(image_id)) self.validate_response(schema.delete, resp, body) return service_client.ResponseBody(resp, body) def wait_for_image_status(self, image_id, status): """Waits for an image to reach a given status.""" waiters.wait_for_image_status(self, image_id, status) def list_image_metadata(self, image_id): """Lists all metadata items for an image.""" resp, body = self.get("images/%s/metadata" % str(image_id)) body = json.loads(body) self.validate_response(schema.image_metadata, resp, body) return service_client.ResponseBody(resp, body['metadata']) def set_image_metadata(self, image_id, meta): """Sets the metadata for an image.""" post_body = json.dumps({'metadata': meta}) resp, body = self.put('images/%s/metadata' % str(image_id), post_body) body = json.loads(body) self.validate_response(schema.image_metadata, resp, body) return service_client.ResponseBody(resp, body['metadata']) def <|fim_middle|>(self, image_id, meta): """Updates the metadata for an image.""" post_body = json.dumps({'metadata': meta}) resp, body = self.post('images/%s/metadata' % str(image_id), post_body) body = json.loads(body) self.validate_response(schema.image_metadata, resp, body) return service_client.ResponseBody(resp, body['metadata']) def get_image_metadata_item(self, image_id, key): """Returns the value for a specific image metadata key.""" resp, body = self.get("images/%s/metadata/%s" % (str(image_id), key)) body = json.loads(body) self.validate_response(schema.image_meta_item, resp, body) return service_client.ResponseBody(resp, body['meta']) def set_image_metadata_item(self, image_id, key, meta): """Sets the value for a specific image metadata key.""" post_body = json.dumps({'meta': meta}) resp, body = self.put('images/%s/metadata/%s' % (str(image_id), key), post_body) body = json.loads(body) self.validate_response(schema.image_meta_item, resp, body) return service_client.ResponseBody(resp, body['meta']) def delete_image_metadata_item(self, image_id, key): """Deletes a single image metadata key/value pair.""" resp, body = self.delete("images/%s/metadata/%s" % (str(image_id), key)) self.validate_response(schema.delete, resp, body) return service_client.ResponseBody(resp, body) def is_resource_deleted(self, id): try: self.show_image(id) except lib_exc.NotFound: return True return False @property def resource_type(self): """Returns the primary type of resource this client works with.""" return 'image' <|fim▁end|>
update_image_metadata
<|file_name|>images_client.py<|end_file_name|><|fim▁begin|># Copyright 2012 OpenStack Foundation # All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. import json from six.moves.urllib import parse as urllib from tempest_lib import exceptions as lib_exc from tempest.api_schema.response.compute.v2_1 import images as schema from tempest.common import service_client from tempest.common import waiters class ImagesClientJSON(service_client.ServiceClient): def create_image(self, server_id, name, meta=None): """Creates an image of the original server.""" post_body = { 'createImage': { 'name': name, } } if meta is not None: post_body['createImage']['metadata'] = meta post_body = json.dumps(post_body) resp, body = self.post('servers/%s/action' % str(server_id), post_body) self.validate_response(schema.create_image, resp, body) return service_client.ResponseBody(resp, body) def list_images(self, params=None): """Returns a list of all images filtered by any parameters.""" url = 'images' if params: url += '?%s' % urllib.urlencode(params) resp, body = self.get(url) body = json.loads(body) self.validate_response(schema.list_images, resp, body) return service_client.ResponseBodyList(resp, body['images']) def list_images_with_detail(self, params=None): """Returns a detailed list of images filtered by any parameters.""" url = 'images/detail' if params: url += '?%s' % urllib.urlencode(params) resp, body = self.get(url) body = json.loads(body) self.validate_response(schema.list_images_details, resp, body) return service_client.ResponseBodyList(resp, body['images']) def show_image(self, image_id): """Returns the details of a single image.""" resp, body = self.get("images/%s" % str(image_id)) self.expected_success(200, resp.status) body = json.loads(body) self.validate_response(schema.get_image, resp, body) return service_client.ResponseBody(resp, body['image']) def delete_image(self, image_id): """Deletes the provided image.""" resp, body = self.delete("images/%s" % str(image_id)) self.validate_response(schema.delete, resp, body) return service_client.ResponseBody(resp, body) def wait_for_image_status(self, image_id, status): """Waits for an image to reach a given status.""" waiters.wait_for_image_status(self, image_id, status) def list_image_metadata(self, image_id): """Lists all metadata items for an image.""" resp, body = self.get("images/%s/metadata" % str(image_id)) body = json.loads(body) self.validate_response(schema.image_metadata, resp, body) return service_client.ResponseBody(resp, body['metadata']) def set_image_metadata(self, image_id, meta): """Sets the metadata for an image.""" post_body = json.dumps({'metadata': meta}) resp, body = self.put('images/%s/metadata' % str(image_id), post_body) body = json.loads(body) self.validate_response(schema.image_metadata, resp, body) return service_client.ResponseBody(resp, body['metadata']) def update_image_metadata(self, image_id, meta): """Updates the metadata for an image.""" post_body = json.dumps({'metadata': meta}) resp, body = self.post('images/%s/metadata' % str(image_id), post_body) body = json.loads(body) self.validate_response(schema.image_metadata, resp, body) return service_client.ResponseBody(resp, body['metadata']) def <|fim_middle|>(self, image_id, key): """Returns the value for a specific image metadata key.""" resp, body = self.get("images/%s/metadata/%s" % (str(image_id), key)) body = json.loads(body) self.validate_response(schema.image_meta_item, resp, body) return service_client.ResponseBody(resp, body['meta']) def set_image_metadata_item(self, image_id, key, meta): """Sets the value for a specific image metadata key.""" post_body = json.dumps({'meta': meta}) resp, body = self.put('images/%s/metadata/%s' % (str(image_id), key), post_body) body = json.loads(body) self.validate_response(schema.image_meta_item, resp, body) return service_client.ResponseBody(resp, body['meta']) def delete_image_metadata_item(self, image_id, key): """Deletes a single image metadata key/value pair.""" resp, body = self.delete("images/%s/metadata/%s" % (str(image_id), key)) self.validate_response(schema.delete, resp, body) return service_client.ResponseBody(resp, body) def is_resource_deleted(self, id): try: self.show_image(id) except lib_exc.NotFound: return True return False @property def resource_type(self): """Returns the primary type of resource this client works with.""" return 'image' <|fim▁end|>
get_image_metadata_item
<|file_name|>images_client.py<|end_file_name|><|fim▁begin|># Copyright 2012 OpenStack Foundation # All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. import json from six.moves.urllib import parse as urllib from tempest_lib import exceptions as lib_exc from tempest.api_schema.response.compute.v2_1 import images as schema from tempest.common import service_client from tempest.common import waiters class ImagesClientJSON(service_client.ServiceClient): def create_image(self, server_id, name, meta=None): """Creates an image of the original server.""" post_body = { 'createImage': { 'name': name, } } if meta is not None: post_body['createImage']['metadata'] = meta post_body = json.dumps(post_body) resp, body = self.post('servers/%s/action' % str(server_id), post_body) self.validate_response(schema.create_image, resp, body) return service_client.ResponseBody(resp, body) def list_images(self, params=None): """Returns a list of all images filtered by any parameters.""" url = 'images' if params: url += '?%s' % urllib.urlencode(params) resp, body = self.get(url) body = json.loads(body) self.validate_response(schema.list_images, resp, body) return service_client.ResponseBodyList(resp, body['images']) def list_images_with_detail(self, params=None): """Returns a detailed list of images filtered by any parameters.""" url = 'images/detail' if params: url += '?%s' % urllib.urlencode(params) resp, body = self.get(url) body = json.loads(body) self.validate_response(schema.list_images_details, resp, body) return service_client.ResponseBodyList(resp, body['images']) def show_image(self, image_id): """Returns the details of a single image.""" resp, body = self.get("images/%s" % str(image_id)) self.expected_success(200, resp.status) body = json.loads(body) self.validate_response(schema.get_image, resp, body) return service_client.ResponseBody(resp, body['image']) def delete_image(self, image_id): """Deletes the provided image.""" resp, body = self.delete("images/%s" % str(image_id)) self.validate_response(schema.delete, resp, body) return service_client.ResponseBody(resp, body) def wait_for_image_status(self, image_id, status): """Waits for an image to reach a given status.""" waiters.wait_for_image_status(self, image_id, status) def list_image_metadata(self, image_id): """Lists all metadata items for an image.""" resp, body = self.get("images/%s/metadata" % str(image_id)) body = json.loads(body) self.validate_response(schema.image_metadata, resp, body) return service_client.ResponseBody(resp, body['metadata']) def set_image_metadata(self, image_id, meta): """Sets the metadata for an image.""" post_body = json.dumps({'metadata': meta}) resp, body = self.put('images/%s/metadata' % str(image_id), post_body) body = json.loads(body) self.validate_response(schema.image_metadata, resp, body) return service_client.ResponseBody(resp, body['metadata']) def update_image_metadata(self, image_id, meta): """Updates the metadata for an image.""" post_body = json.dumps({'metadata': meta}) resp, body = self.post('images/%s/metadata' % str(image_id), post_body) body = json.loads(body) self.validate_response(schema.image_metadata, resp, body) return service_client.ResponseBody(resp, body['metadata']) def get_image_metadata_item(self, image_id, key): """Returns the value for a specific image metadata key.""" resp, body = self.get("images/%s/metadata/%s" % (str(image_id), key)) body = json.loads(body) self.validate_response(schema.image_meta_item, resp, body) return service_client.ResponseBody(resp, body['meta']) def <|fim_middle|>(self, image_id, key, meta): """Sets the value for a specific image metadata key.""" post_body = json.dumps({'meta': meta}) resp, body = self.put('images/%s/metadata/%s' % (str(image_id), key), post_body) body = json.loads(body) self.validate_response(schema.image_meta_item, resp, body) return service_client.ResponseBody(resp, body['meta']) def delete_image_metadata_item(self, image_id, key): """Deletes a single image metadata key/value pair.""" resp, body = self.delete("images/%s/metadata/%s" % (str(image_id), key)) self.validate_response(schema.delete, resp, body) return service_client.ResponseBody(resp, body) def is_resource_deleted(self, id): try: self.show_image(id) except lib_exc.NotFound: return True return False @property def resource_type(self): """Returns the primary type of resource this client works with.""" return 'image' <|fim▁end|>
set_image_metadata_item
<|file_name|>images_client.py<|end_file_name|><|fim▁begin|># Copyright 2012 OpenStack Foundation # All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. import json from six.moves.urllib import parse as urllib from tempest_lib import exceptions as lib_exc from tempest.api_schema.response.compute.v2_1 import images as schema from tempest.common import service_client from tempest.common import waiters class ImagesClientJSON(service_client.ServiceClient): def create_image(self, server_id, name, meta=None): """Creates an image of the original server.""" post_body = { 'createImage': { 'name': name, } } if meta is not None: post_body['createImage']['metadata'] = meta post_body = json.dumps(post_body) resp, body = self.post('servers/%s/action' % str(server_id), post_body) self.validate_response(schema.create_image, resp, body) return service_client.ResponseBody(resp, body) def list_images(self, params=None): """Returns a list of all images filtered by any parameters.""" url = 'images' if params: url += '?%s' % urllib.urlencode(params) resp, body = self.get(url) body = json.loads(body) self.validate_response(schema.list_images, resp, body) return service_client.ResponseBodyList(resp, body['images']) def list_images_with_detail(self, params=None): """Returns a detailed list of images filtered by any parameters.""" url = 'images/detail' if params: url += '?%s' % urllib.urlencode(params) resp, body = self.get(url) body = json.loads(body) self.validate_response(schema.list_images_details, resp, body) return service_client.ResponseBodyList(resp, body['images']) def show_image(self, image_id): """Returns the details of a single image.""" resp, body = self.get("images/%s" % str(image_id)) self.expected_success(200, resp.status) body = json.loads(body) self.validate_response(schema.get_image, resp, body) return service_client.ResponseBody(resp, body['image']) def delete_image(self, image_id): """Deletes the provided image.""" resp, body = self.delete("images/%s" % str(image_id)) self.validate_response(schema.delete, resp, body) return service_client.ResponseBody(resp, body) def wait_for_image_status(self, image_id, status): """Waits for an image to reach a given status.""" waiters.wait_for_image_status(self, image_id, status) def list_image_metadata(self, image_id): """Lists all metadata items for an image.""" resp, body = self.get("images/%s/metadata" % str(image_id)) body = json.loads(body) self.validate_response(schema.image_metadata, resp, body) return service_client.ResponseBody(resp, body['metadata']) def set_image_metadata(self, image_id, meta): """Sets the metadata for an image.""" post_body = json.dumps({'metadata': meta}) resp, body = self.put('images/%s/metadata' % str(image_id), post_body) body = json.loads(body) self.validate_response(schema.image_metadata, resp, body) return service_client.ResponseBody(resp, body['metadata']) def update_image_metadata(self, image_id, meta): """Updates the metadata for an image.""" post_body = json.dumps({'metadata': meta}) resp, body = self.post('images/%s/metadata' % str(image_id), post_body) body = json.loads(body) self.validate_response(schema.image_metadata, resp, body) return service_client.ResponseBody(resp, body['metadata']) def get_image_metadata_item(self, image_id, key): """Returns the value for a specific image metadata key.""" resp, body = self.get("images/%s/metadata/%s" % (str(image_id), key)) body = json.loads(body) self.validate_response(schema.image_meta_item, resp, body) return service_client.ResponseBody(resp, body['meta']) def set_image_metadata_item(self, image_id, key, meta): """Sets the value for a specific image metadata key.""" post_body = json.dumps({'meta': meta}) resp, body = self.put('images/%s/metadata/%s' % (str(image_id), key), post_body) body = json.loads(body) self.validate_response(schema.image_meta_item, resp, body) return service_client.ResponseBody(resp, body['meta']) def <|fim_middle|>(self, image_id, key): """Deletes a single image metadata key/value pair.""" resp, body = self.delete("images/%s/metadata/%s" % (str(image_id), key)) self.validate_response(schema.delete, resp, body) return service_client.ResponseBody(resp, body) def is_resource_deleted(self, id): try: self.show_image(id) except lib_exc.NotFound: return True return False @property def resource_type(self): """Returns the primary type of resource this client works with.""" return 'image' <|fim▁end|>
delete_image_metadata_item
<|file_name|>images_client.py<|end_file_name|><|fim▁begin|># Copyright 2012 OpenStack Foundation # All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. import json from six.moves.urllib import parse as urllib from tempest_lib import exceptions as lib_exc from tempest.api_schema.response.compute.v2_1 import images as schema from tempest.common import service_client from tempest.common import waiters class ImagesClientJSON(service_client.ServiceClient): def create_image(self, server_id, name, meta=None): """Creates an image of the original server.""" post_body = { 'createImage': { 'name': name, } } if meta is not None: post_body['createImage']['metadata'] = meta post_body = json.dumps(post_body) resp, body = self.post('servers/%s/action' % str(server_id), post_body) self.validate_response(schema.create_image, resp, body) return service_client.ResponseBody(resp, body) def list_images(self, params=None): """Returns a list of all images filtered by any parameters.""" url = 'images' if params: url += '?%s' % urllib.urlencode(params) resp, body = self.get(url) body = json.loads(body) self.validate_response(schema.list_images, resp, body) return service_client.ResponseBodyList(resp, body['images']) def list_images_with_detail(self, params=None): """Returns a detailed list of images filtered by any parameters.""" url = 'images/detail' if params: url += '?%s' % urllib.urlencode(params) resp, body = self.get(url) body = json.loads(body) self.validate_response(schema.list_images_details, resp, body) return service_client.ResponseBodyList(resp, body['images']) def show_image(self, image_id): """Returns the details of a single image.""" resp, body = self.get("images/%s" % str(image_id)) self.expected_success(200, resp.status) body = json.loads(body) self.validate_response(schema.get_image, resp, body) return service_client.ResponseBody(resp, body['image']) def delete_image(self, image_id): """Deletes the provided image.""" resp, body = self.delete("images/%s" % str(image_id)) self.validate_response(schema.delete, resp, body) return service_client.ResponseBody(resp, body) def wait_for_image_status(self, image_id, status): """Waits for an image to reach a given status.""" waiters.wait_for_image_status(self, image_id, status) def list_image_metadata(self, image_id): """Lists all metadata items for an image.""" resp, body = self.get("images/%s/metadata" % str(image_id)) body = json.loads(body) self.validate_response(schema.image_metadata, resp, body) return service_client.ResponseBody(resp, body['metadata']) def set_image_metadata(self, image_id, meta): """Sets the metadata for an image.""" post_body = json.dumps({'metadata': meta}) resp, body = self.put('images/%s/metadata' % str(image_id), post_body) body = json.loads(body) self.validate_response(schema.image_metadata, resp, body) return service_client.ResponseBody(resp, body['metadata']) def update_image_metadata(self, image_id, meta): """Updates the metadata for an image.""" post_body = json.dumps({'metadata': meta}) resp, body = self.post('images/%s/metadata' % str(image_id), post_body) body = json.loads(body) self.validate_response(schema.image_metadata, resp, body) return service_client.ResponseBody(resp, body['metadata']) def get_image_metadata_item(self, image_id, key): """Returns the value for a specific image metadata key.""" resp, body = self.get("images/%s/metadata/%s" % (str(image_id), key)) body = json.loads(body) self.validate_response(schema.image_meta_item, resp, body) return service_client.ResponseBody(resp, body['meta']) def set_image_metadata_item(self, image_id, key, meta): """Sets the value for a specific image metadata key.""" post_body = json.dumps({'meta': meta}) resp, body = self.put('images/%s/metadata/%s' % (str(image_id), key), post_body) body = json.loads(body) self.validate_response(schema.image_meta_item, resp, body) return service_client.ResponseBody(resp, body['meta']) def delete_image_metadata_item(self, image_id, key): """Deletes a single image metadata key/value pair.""" resp, body = self.delete("images/%s/metadata/%s" % (str(image_id), key)) self.validate_response(schema.delete, resp, body) return service_client.ResponseBody(resp, body) def <|fim_middle|>(self, id): try: self.show_image(id) except lib_exc.NotFound: return True return False @property def resource_type(self): """Returns the primary type of resource this client works with.""" return 'image' <|fim▁end|>
is_resource_deleted
<|file_name|>images_client.py<|end_file_name|><|fim▁begin|># Copyright 2012 OpenStack Foundation # All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. import json from six.moves.urllib import parse as urllib from tempest_lib import exceptions as lib_exc from tempest.api_schema.response.compute.v2_1 import images as schema from tempest.common import service_client from tempest.common import waiters class ImagesClientJSON(service_client.ServiceClient): def create_image(self, server_id, name, meta=None): """Creates an image of the original server.""" post_body = { 'createImage': { 'name': name, } } if meta is not None: post_body['createImage']['metadata'] = meta post_body = json.dumps(post_body) resp, body = self.post('servers/%s/action' % str(server_id), post_body) self.validate_response(schema.create_image, resp, body) return service_client.ResponseBody(resp, body) def list_images(self, params=None): """Returns a list of all images filtered by any parameters.""" url = 'images' if params: url += '?%s' % urllib.urlencode(params) resp, body = self.get(url) body = json.loads(body) self.validate_response(schema.list_images, resp, body) return service_client.ResponseBodyList(resp, body['images']) def list_images_with_detail(self, params=None): """Returns a detailed list of images filtered by any parameters.""" url = 'images/detail' if params: url += '?%s' % urllib.urlencode(params) resp, body = self.get(url) body = json.loads(body) self.validate_response(schema.list_images_details, resp, body) return service_client.ResponseBodyList(resp, body['images']) def show_image(self, image_id): """Returns the details of a single image.""" resp, body = self.get("images/%s" % str(image_id)) self.expected_success(200, resp.status) body = json.loads(body) self.validate_response(schema.get_image, resp, body) return service_client.ResponseBody(resp, body['image']) def delete_image(self, image_id): """Deletes the provided image.""" resp, body = self.delete("images/%s" % str(image_id)) self.validate_response(schema.delete, resp, body) return service_client.ResponseBody(resp, body) def wait_for_image_status(self, image_id, status): """Waits for an image to reach a given status.""" waiters.wait_for_image_status(self, image_id, status) def list_image_metadata(self, image_id): """Lists all metadata items for an image.""" resp, body = self.get("images/%s/metadata" % str(image_id)) body = json.loads(body) self.validate_response(schema.image_metadata, resp, body) return service_client.ResponseBody(resp, body['metadata']) def set_image_metadata(self, image_id, meta): """Sets the metadata for an image.""" post_body = json.dumps({'metadata': meta}) resp, body = self.put('images/%s/metadata' % str(image_id), post_body) body = json.loads(body) self.validate_response(schema.image_metadata, resp, body) return service_client.ResponseBody(resp, body['metadata']) def update_image_metadata(self, image_id, meta): """Updates the metadata for an image.""" post_body = json.dumps({'metadata': meta}) resp, body = self.post('images/%s/metadata' % str(image_id), post_body) body = json.loads(body) self.validate_response(schema.image_metadata, resp, body) return service_client.ResponseBody(resp, body['metadata']) def get_image_metadata_item(self, image_id, key): """Returns the value for a specific image metadata key.""" resp, body = self.get("images/%s/metadata/%s" % (str(image_id), key)) body = json.loads(body) self.validate_response(schema.image_meta_item, resp, body) return service_client.ResponseBody(resp, body['meta']) def set_image_metadata_item(self, image_id, key, meta): """Sets the value for a specific image metadata key.""" post_body = json.dumps({'meta': meta}) resp, body = self.put('images/%s/metadata/%s' % (str(image_id), key), post_body) body = json.loads(body) self.validate_response(schema.image_meta_item, resp, body) return service_client.ResponseBody(resp, body['meta']) def delete_image_metadata_item(self, image_id, key): """Deletes a single image metadata key/value pair.""" resp, body = self.delete("images/%s/metadata/%s" % (str(image_id), key)) self.validate_response(schema.delete, resp, body) return service_client.ResponseBody(resp, body) def is_resource_deleted(self, id): try: self.show_image(id) except lib_exc.NotFound: return True return False @property def <|fim_middle|>(self): """Returns the primary type of resource this client works with.""" return 'image' <|fim▁end|>
resource_type
<|file_name|>__init__.py<|end_file_name|><|fim▁begin|># -*- encoding: utf-8 -*- ############################################################################## # # OpenERP, Open Source Management Solution # # Copyright (c) 2013-2015 Noviat nv/sa (www.noviat.com). # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as # published by the Free Software Foundation, either version 3 of the # License, or (at your option) any later version. #<|fim▁hole|># MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Affero General Public License for more details. # # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. # ############################################################################## from . import account from . import res_partner from . import ir_actions<|fim▁end|>
# This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of