Beispiel #1
0
 def delete_consult_file(self, pk):
     if not self.file_util:
         self.file_util = FileUtil(self._user, 'consult', self.language)
     if self.file_util.get_file(pk):
         if self.file_util.delete_file():
             return True
     self.add_error_list(self.file_util.get_errors())
     return False
Beispiel #2
0
 def new_consult_file(self, pk, info, files):
     if not self.file_util:
         self.file_util = FileUtil(self._user, 'consult', self.language)
     if self.consult_util.get_consult(pk):
         info['consult'] = self.consult_util.get_consult().pk
         if self.file_util.new_file(info, files):
             if self.consult_util.client_notify(
                     tab='file', consult=self.file_util.get_file().consult):
                 return True
         self.add_error_list(self.file_util.get_errors())
         self._form_errors = self.file_util.get_form_errors()
         self.add_error_list(self.consult_util.get_errors())
         return False
     else:
         self.add_error_list(self.consult_util.get_errors())
         return False
Beispiel #3
0
 def get_project_files(self):
     if not self.file_util:
         self.file_util = FileUtil(self._user, 'project', self.language)
     project = self.project_util.get_project()
     self.add_error_list(self.project_util.get_errors())
     return self.file_util.get_object_files(project) if project else []
Beispiel #4
0
 def get_consult_files(self):
     if not self.file_util:
         self.file_util = FileUtil(self._user, 'consult', self.language)
     consult = self.consult_util.get_consult()
     self.add_error_list(self.consult_util.get_errors())
     return self.file_util.get_object_files(consult) if consult else []
Beispiel #5
0
class ClientObject(BaseUtil):
    def __init__(self, user):
        super(ClientObject, self).__init__()
        self._util_name = 'Client Object'
        self._user = user
        self._form_errors = {}
        self.user_util = UserUtil(self._user, 'client')
        self._profile = self.load_profile()
        self._client = self._profile.client if self._profile else None
        self.language = self.select_language()
        self.message_util = MessageUtil(self._user)
        self.consult_util = ConsultUtil(self._user, self.language)
        self.hosting_util = HostingUtil(self._user, self.language)
        self.project_util = ProjectUtil(self._user, self.language)
        self.bill_util = None
        self.chat_util = None
        self.event_util = None
        self.file_util = None
        self.ra_util = None
        self.timeline_util = None

    def select_language(self):
        if self._profile:
            return self._profile.language
        elif self._client:
            return self._client.language
        return 'en'

    def get_form_errors(self):
        return self._form_errors

    #
    #
    #   PUBLIC FUNCTIONS
    #
    #

    def new_message(self, info):
        info['contact_name'] = info.get('contact_name',
                                        self._user.get_full_name())
        info['contact_email'] = info.get('contact_email', self._user.email)
        info['message_type'] = info.get('message_type', 'contact')
        if self.message_util.new_message(info):
            return True
        else:
            self.add_error_list(self.message_util.get_errors())
            self._form_errors = self.message_util.get_form_errors()
            return False

    def get_counts(self):
        return {
            'project':
            self.project_util.get_client_projects(self._client, count=True)
            if self._client else 0,
            'hosting':
            self.hosting_util.get_client_hosting(self._client, count=True)
            if self._client else 0,
            'consult':
            self.consult_util.get_client_consults(self._client, count=True)
            if self._client else 0,
        }

    #
    #
    #   USER FUNCTIONS
    #
    #

    def get_user(self):
        return self.user_util.get_user()

    def get_user_profile(self):
        if self._profile:
            return self._profile
        profile = self.user_util.get_user_profile()
        self.add_error_list(self.user_util.get_errors())
        return profile

    def load_profile(self):
        profile = self.user_util.get_user_profile()
        self.add_error_list(self.user_util.get_errors())
        return profile

    def get_user_client(self):
        if self._client:
            return self._client
        else:
            self._profile = self.user_util.get_user_profile()
            self.add_error_list(self.user_util.get_errors())
            self._client = self._profile.client if self._profile else None
            return self._client

    def get_client_balance(self):
        if not self.bill_util:
            self.bill_util = BillingUtil(self._user, 'project', self.language)
        balance = self.bill_util.get_client_balance(self._client)
        self.add_error_list(self.bill_util.get_errors())
        return balance

        #
        #
        #

    def edit_profile(self, info):

        if self.user_util.edit_user(
                info['user']) and self.user_util.edit_profile(info['profile']):
            return True
        self.add_error_list(self.user_util.get_errors())
        self._form_errors = self.user_util.get_form_errors()
        return False

    def change_password(self, info):
        if self.user_util.change_password(info):
            return True
        self.add_error_list(self.user_util.get_errors())
        return False

    def upload_profile_picture(self, info, files):
        if self.user_util.upload_client_photo(info, files):
            return True
        self.add_error_list(self.user_util.get_errors())
        self._form_errors = self.user_util.get_form_errors()
        return False

    #
    #
    #
    #
    #

    def get_project(self, pk=None):
        project = self.project_util.get_project(pk)
        self.add_error_list(self.project_util.get_errors())
        return project

    def get_notified_projects(self):
        return self.project_util.get_staff_notified_projects()

    def get_client_projects(self):
        if self._client:
            return self.project_util.get_client_projects(self._client)
        return []

    def get_project_required_actions(self):
        if not self.ra_util:
            self.ra_util = RequiredActionUtil(self._user, 'project',
                                              self.language)
        project = self.project_util.get_project()
        self.add_error_list(self.project_util.get_errors())
        temp = self.ra_util.get_object_required_actions(
            project) if project else []
        return {
            'all': temp,
            'count': len([x for x in temp if x.completed is False])
        }

    def get_project_timeline(self):
        if not self.timeline_util:
            self.timeline_util = TimelineUtil(self._user, self.language)
        project = self.project_util.get_project()
        sections = self.timeline_util.get_timeline_sections(
            project) if project else []
        timeline = []
        for x in sections:
            timeline.append({
                'section':
                x,
                'items':
                self.timeline_util.get_timeline_section_items(x)
            })
        return timeline

    def get_project_hosting(self):
        project = self.project_util.get_project()
        self.add_error_list(self.project_util.get_errors())
        return self.hosting_util.get_project_hosting(
            project) if project else []

    def get_project_bills(self):
        if not self.bill_util:
            self.bill_util = BillingUtil(self._user, 'project', self.language)
        project = self.project_util.get_project()
        self.add_error_list(self.project_util.get_errors())
        return self.bill_util.get_object_bills(project) if project else []

    def get_project_files(self):
        if not self.file_util:
            self.file_util = FileUtil(self._user, 'project', self.language)
        project = self.project_util.get_project()
        self.add_error_list(self.project_util.get_errors())
        return self.file_util.get_object_files(project) if project else []

    def get_project_chat(self):
        if not self.chat_util:
            self.chat_util = ChatUtil('project', self.language)
        project = self.project_util.get_project()
        chat = self.chat_util.get_object_chat(project)
        return {'chat': chat, 'messages': self.chat_util.get_chat_messages()}

        #
        #
        #

    def mark_project_required_action_as_completed(self, pk):
        if not self.ra_util:
            self.ra_util = RequiredActionUtil(self._user, 'project',
                                              self.language)
        if self.ra_util.get_required_action(pk):
            if self.ra_util.mark_as_completed():
                if self.project_util.client_notify(
                        tab='action',
                        project=self.ra_util.get_required_action().project):
                    return True
        self.add_error_list(self.ra_util.get_errors())
        self.add_error_list(self.project_util.get_errors())
        return False

    def report_project_bill(self, pk):
        if not self.bill_util:
            self.bill_util = BillingUtil(self._user, 'project', self.language)
        if self.bill_util.get_bill(pk):
            if self.bill_util.report():
                if self.project_util.client_notify(
                        tab='bill', project=self.bill_util.get_bill().project):
                    return True
        self.add_error_list(self.bill_util.get_errors())
        self.add_error_list(self.project_util.get_errors())
        return False

    def new_project_file(self, pk, info, files):
        if not self.file_util:
            self.file_util = FileUtil(self._user, 'project', self.language)
        if self.project_util.get_project(pk):
            info['project'] = self.project_util.get_project().pk
            if self.file_util.new_file(info, files):
                if self.project_util.client_notify(
                        tab='file', project=self.file_util.get_file().project):
                    return True
            self.add_error_list(self.file_util.get_errors())
            self.add_error_list(self.project_util.get_errors())
            self._form_errors = self.file_util.get_form_errors()
            return False
        else:
            self.add_error_list(self.project_util.get_errors())
            return False

    def delete_project_file(self, pk):
        if not self.file_util:
            self.file_util = FileUtil(self._user, 'project', self.language)
        if self.file_util.get_file(pk):
            if self.file_util.delete_file():
                return True
        self.add_error_list(self.file_util.get_errors())
        return False

    def new_project_chat_message(self, pk, info):
        if not self.chat_util:
            self.chat_util = ChatUtil('project', self.language)
        if self.project_util.get_project(pk):
            if self.chat_util.get_object_chat(self.project_util.get_project()):
                info['user'] = self._user.pk
                if self.chat_util.new_chat_message(info):
                    if self.project_util.client_notify(
                            tab='chat',
                            project=self.chat_util.get_chat().project):
                        return True
                self._form_errors = self.chat_util.get_form_errors()
            self.add_error_list(self.chat_util.get_errors())
            self.add_error_list(self.project_util.get_errors())
            return False
        else:
            self.add_error_list(self.project_util.get_errors())
            return False

    #
    #
    #
    #
    #

    def get_consult(self, pk=None):
        consult = self.consult_util.get_consult(pk)
        self.add_error_list(self.consult_util.get_errors())
        return consult

    def get_notified_consults(self):
        return self.consult_util.get_staff_notified_consults()

    def get_client_consults(self):
        if self._client:
            return self.consult_util.get_client_consults(self._client)
        return []

    def get_consult_required_actions(self):
        if not self.ra_util:
            self.ra_util = RequiredActionUtil(self._user, 'consult',
                                              self.language)
        consult = self.consult_util.get_consult()
        self.add_error_list(self.consult_util.get_errors())
        temp = self.ra_util.get_object_required_actions(
            consult) if consult else []
        return {
            'all': temp,
            'count': len([x for x in temp if x.completed is False])
        }

    def get_consult_events(self):
        if not self.event_util:
            self.event_util = EventUtil(self._user, 'consult', self.language)
        consult = self.consult_util.get_consult()
        self.add_error_list(self.consult_util.get_errors())
        return self.event_util.get_object_events(consult) if consult else []

    def get_consult_bills(self):
        if not self.bill_util:
            self.bill_util = BillingUtil(self._user, 'consult', self.language)
        consult = self.consult_util.get_consult()
        self.add_error_list(self.consult_util.get_errors())
        return self.bill_util.get_object_bills(consult) if consult else []

    def get_consult_files(self):
        if not self.file_util:
            self.file_util = FileUtil(self._user, 'consult', self.language)
        consult = self.consult_util.get_consult()
        self.add_error_list(self.consult_util.get_errors())
        return self.file_util.get_object_files(consult) if consult else []

    def get_consult_chat(self):
        if not self.chat_util:
            self.chat_util = ChatUtil('consult', self.language)
        consult = self.consult_util.get_consult()
        chat = self.chat_util.get_object_chat(consult)
        return {'chat': chat, 'messages': self.chat_util.get_chat_messages()}

        #
        #
        #

    def mark_consult_required_action_as_completed(self, pk):
        if not self.ra_util:
            self.ra_util = RequiredActionUtil(self._user, 'consult',
                                              self.language)
        if self.ra_util.get_required_action(pk):
            if self.ra_util.mark_as_completed():
                if self.consult_util.client_notify(
                        tab='action',
                        consult=self.ra_util.get_required_action().consult):
                    return True
        self.add_error_list(self.ra_util.get_errors())
        self.add_error_list(self.consult_util.get_errors())
        return False

    def report_consult_bill(self, pk):
        if not self.bill_util:
            self.bill_util = BillingUtil(self._user, 'consult', self.language)
        if self.bill_util.get_bill(pk):
            if self.bill_util.report():
                if self.consult_util.client_notify(
                        tab='bill', consult=self.bill_util.get_bill().consult):
                    return True
        self.add_error_list(self.bill_util.get_errors())
        self.add_error_list(self.consult_util.get_errors())
        return False

    def new_consult_file(self, pk, info, files):
        if not self.file_util:
            self.file_util = FileUtil(self._user, 'consult', self.language)
        if self.consult_util.get_consult(pk):
            info['consult'] = self.consult_util.get_consult().pk
            if self.file_util.new_file(info, files):
                if self.consult_util.client_notify(
                        tab='file', consult=self.file_util.get_file().consult):
                    return True
            self.add_error_list(self.file_util.get_errors())
            self._form_errors = self.file_util.get_form_errors()
            self.add_error_list(self.consult_util.get_errors())
            return False
        else:
            self.add_error_list(self.consult_util.get_errors())
            return False

    def delete_consult_file(self, pk):
        if not self.file_util:
            self.file_util = FileUtil(self._user, 'consult', self.language)
        if self.file_util.get_file(pk):
            if self.file_util.delete_file():
                return True
        self.add_error_list(self.file_util.get_errors())
        return False

    def new_consult_chat_message(self, pk, info):
        if not self.chat_util:
            self.chat_util = ChatUtil('consult', self.language)
        if self.consult_util.get_consult(pk):
            if self.chat_util.get_object_chat(self.consult_util.get_consult()):
                info['user'] = self._user.pk
                if self.chat_util.new_chat_message(info):
                    if self.consult_util.client_notify(
                            tab='chat',
                            consult=self.chat_util.get_chat().consult):
                        return True
                self._form_errors = self.chat_util.get_form_errors()
            self.add_error_list(self.chat_util.get_errors())
            self.add_error_list(self.consult_util.get_errors())
            return False
        else:
            self.add_error_list(self.consult_util.get_errors())
            return False

    #
    #
    #
    #
    #

    def get_hosting(self, pk=None):
        hosting = self.hosting_util.get_hosting(pk)
        self.add_error_list(self.hosting_util.get_errors())
        return hosting

    def get_notified_hosting(self):
        return self.hosting_util.get_staff_notified_hosting()

    def get_client_hosting(self):
        if self._client:
            return self.hosting_util.get_client_hosting(self._client)
        return []

    def get_hosting_events(self):
        if not self.event_util:
            self.event_util = EventUtil(self._user, 'hosting', self.language)
        hosting = self.hosting_util.get_hosting()
        self.add_error_list(self.hosting_util.get_errors())
        return self.event_util.get_object_events(hosting) if hosting else []

    def get_hosting_bills(self):
        if not self.bill_util:
            self.bill_util = BillingUtil(self._user, 'hosting', self.language)
        hosting = self.hosting_util.get_hosting()
        self.add_error_list(self.hosting_util.get_errors())
        return self.bill_util.get_object_bills(hosting) if hosting else []

    def get_hosting_chat(self):
        if not self.chat_util:
            self.chat_util = ChatUtil('hosting', self.language)
        hosting = self.hosting_util.get_hosting()
        chat = self.chat_util.get_object_chat(hosting)
        return {'chat': chat, 'messages': self.chat_util.get_chat_messages()}

        #
        #
        #

    def request_hosting_access_key(self, pk):
        if self.hosting_util.get_hosting(pk):
            if self.hosting_util.request_access_key():
                return True
        self.add_error_list(self.hosting_util.get_errors())
        return False

    def start_hosting(self, pk):
        if self.hosting_util.get_hosting(pk):
            if self.hosting_util.client_start_hosting():
                return True
        self.add_error_list(self.hosting_util.get_errors())
        return False

    def stop_hosting(self, pk):
        if self.hosting_util.get_hosting(pk):
            if self.hosting_util.client_stop_hosting():
                return True
        self.add_error_list(self.hosting_util.get_errors())
        return False

    def terminate_hosting(self, pk):
        if self.hosting_util.get_hosting(pk):
            if self.hosting_util.client_terminate_hosting():
                return True
        self.add_error_list(self.hosting_util.get_errors())
        return False

    def report_hosting_bill(self, pk):
        if not self.bill_util:
            self.bill_util = BillingUtil(self._user, 'hosting', self.language)
        if self.bill_util.get_bill(pk):
            if self.bill_util.report():
                if self.hosting_util.client_notify(
                        tab='bill', hosting=self.bill_util.get_bill().hosting):
                    return True
        self.add_error_list(self.bill_util.get_errors())
        self.add_error_list(self.hosting_util.get_errors())
        return False

    def new_hosting_chat_message(self, pk, info):
        if not self.chat_util:
            self.chat_util = ChatUtil('hosting', self.language)
        if self.hosting_util.get_hosting(pk):
            if self.chat_util.get_object_chat(self.hosting_util.get_hosting()):
                info['user'] = self._user.pk
                if self.chat_util.new_chat_message(info):
                    if self.hosting_util.client_notify(
                            tab='chat',
                            hosting=self.chat_util.get_chat().hosting):
                        return True
                self._form_errors = self.chat_util.get_form_errors()
            self.add_error_list(self.chat_util.get_errors())
            self.add_error_list(self.hosting_util.get_errors())
            return False
        else:
            self.add_error_list(self.hosting_util.get_errors())
            return False