def create_model_formfields(self): super().create_model_formfields() obj = self.model_object user = PyFormsMiddleware.user() person = user.person_user.first() self._costcenter = ControlAutoComplete( 'Cost center', queryset=CostCenter.objects.active().by_person(person), changed_event=self.load_finance_projects, default=obj.expensecode.project.costcenter.pk if obj and obj.expensecode else None) self._financeprj = ControlAutoComplete( 'Finance project', queryset=Project.objects.all(), enabled=False, changed_event=self.load_expense_codes, default=obj.expensecode.project.pk if obj and obj.expensecode else None) if obj and obj.expensecode: self.load_expense_codes() if person is None: self.warning('Sorry you require a person associated to your user.') return
def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self._start = ControlDate('Start') self._end = ControlDate('End') self._groups = ControlAutoComplete('Groups', multiple=True, queryset=Group.objects.all()) self._costcenters = ControlAutoComplete( 'Cost centers', multiple=True, queryset=CostCenter.objects.all()) self._projects = ControlAutoComplete('Projects', multiple=True, queryset=Project.objects.all()) self._applybtn = ControlButton('Apply', default=self.populate_report) self._updategraphs_btn = ControlButton('Update graphs', default=self.populate_graphs) self._projs_pie = ControlPieChart('Projects') self._grps_pie = ControlPieChart('Groups') self._fellow_pie = ControlPieChart('Fellowship type') self._amount_chart = ControlBarsChart('Amount per date') self._list = ControlQueryList( 'List', rows_per_page=15, headers=[ 'Person', 'Contract:Start', 'Contract:Until', 'Contract:Salary', 'Contract:Ref', 'Contract:Position', 'Contract:Fellowship type', 'Contract:Fellowship ref', 'Paid:Amount', 'Paid:Start', 'Paid:Until', 'Paid:Req. num.', 'Paid:Req. created', 'C.C. Group', 'C.C.', 'Proj.', 'Grant' ], list_display=[ 'contract__person', 'contract__start', 'contract__end', 'contract__salary', 'contract__ref', 'contract__position', 'contract__fellowship_type', 'contract__fellowship_ref', 'total', 'start', 'end', 'order__requisition_number', 'order__requisition_date', 'project__costcenter__group', 'project__costcenter__code', 'project__code', 'project__grant' ]) self.formset = [ no_columns('_start', '_end', '_groups', '_costcenters', '_projects', '_applybtn'), segment('_list'), (segment('h2:Amount per projects', '_projs_pie', css='overflow'), segment('h2:Amount per groups', '_grps_pie', css='overflow')), (segment('h2:Amount per fellowship', '_fellow_pie', css='overflow'), ' '), segment('_amount_chart', css='overflow'), ]
def __init__(self, *args, **kwargs): self._custom_form_app_id = None self.select_form = ControlAutoComplete( 'Form', changed_event=self.__update_custom_form_evt) self.customized_form = ControlEmptyWidget(name='customized_form', parent=self) super().__init__(*args, **kwargs)
def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self._search = ControlText('Search by name', on_enter_event=self.populate_list) self._groups = ControlAutoComplete("Filter by groups", queryset=Group.objects.all(), multiple=True, changed_event=self.populate_list) self._list = ControlQueryList('People', list_display=self.LIST_DISPLAY, headers=self.LIST_HEADERS, columns_size=self.LIST_COLS_SIZES) self.formset = ['_search', '_groups', '_list'] self.populate_list()
def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self._user = ControlAutoComplete( 'User', queryset=User.objects.all(), changed_event=self.__populate_lists, queryset_filter=self.__members_queryset_filter) self._contracts = ControlQueryList( 'Contracts', default=Contract.objects.filter(pk=None), list_display=[ 'person', 'ref', 'position', 'start', 'end', 'is_active' ]) self._proposals = ControlQueryList( 'Proposals', default=ContractProposal.objects.filter(pk=None), list_display=[ 'personname', 'position', 'start', 'end_date', 'supervisor', 'status_icon' ]) self._people = ControlQueryList('People', default=Person.objects.filter(pk=None), list_display=[ 'thumbnail_80x80', 'full_name', 'person_email', 'person_active' ]) self._orders = ControlQueryList('Orders', default=Order.objects.filter(pk=None), list_display=[ 'order_desc', 'order_req', 'finance', 'order_amount', 'order_reqnum', 'order_reqdate', 'order_ponum', 'expense_codes' ]) self.formset = [ '_user', { 'a:Contracts': ['_contracts'], 'b:Proposals': ['_proposals'], 'c:People': ['_people'], 'd:Orders': ['_orders'], } ]
def __init__(self, *args, **kwargs): self._img = ControlImg('Image', label_visible=False) super().__init__(*args, **kwargs) self.start.changed_event = self.__update_end_date self.months_duration.changed_event = self.__update_end_date self.days_duration.changed_event = self.__update_end_date # Handle situation where Add Form is opened as inline if not hasattr(self, 'person'): person = Person.objects.get(pk=self.parent_pk) self.person = ControlAutoComplete( label='Person', queryset=Person.objects.all(), default=person.pk, readonly=True, ) self.__update_image_evt() self.person.changed_event = self.__update_image_evt
def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self._startyear = ControlInteger('Start year') self._endyear = ControlInteger('End year') self._keypubs = ControlCheckBox('Pub. types', default=False) self._pubtypes = ControlAutoComplete('Publications types', multiple=True, queryset=PubType.objects.all()) self._applybtn = ControlButton('Apply', default=self.populate_graph) self._linegraph = ControlLineChart('Publications per year') #self._journalschart = ControlPieChart('Publications per journal') self._journalslist = ControlList( 'Publications per journal', horizontal_headers=['Journals', 'N pubs', '%']) self.formset = [ no_columns('_startyear', '_endyear', '_pubtypes', '_keypubs', '_applybtn'), segment('_linegraph'), '_journalslist' ]
def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) authors = kwargs.get('authors') title = kwargs.get('title') journal_name = kwargs.get('journal_name') doi = kwargs.get('doi') pubdate = kwargs.get('pubdate') pubyear = kwargs.get('pubyear') self.pub_hash = str( (authors, title, journal_name, doi, pubdate, pubyear)) text = f""" <table> <tr> <th style='text-align: right' >Title</th> <td style='padding:5px;padding-left:10px;' colspan='3' >{title}</th> <tr/> <tr> <th style='text-align: right' >Authors</th> <td style='padding:5px;padding-left:10px;' colspan='3' >{authors}</th> <tr/> <tr> <th style='text-align: right' >Journal</th> <td style='padding:5px;padding-left:10px;' >{journal_name}</th> <th style='text-align: right' >Pub date</th> <td style='padding:5px;padding-left:10px;' >{pubdate}</th> <tr/> <tr> <th style='text-align: right' >Year</th> <td style='padding:5px;padding-left:10px;' >{pubyear}</th> <th style='text-align: right' >Doi</th> <td style='padding:5px;padding-left:10px;' >{doi}</th> <tr/> </table> """ self._person = ControlAutoComplete( 'Author', queryset=Person.objects.all().order_by('full_name'), visible=False) self._authoralias = ControlText('Author alias', visible=False) self._addalias = ControlButton('Add alias', default=self.__add_author_alias_evt, visible=False) alias = AuthorAlias.objects.all() self._authors = ControlList( 'Unknown authors', default=[[a] for a in authors.split(';') if not alias.filter(name=a).exists()], horizontal_headers=['Authors alias'], item_selection_changed_event=self.__authors_selection_changed_evt) self._ignorebtn = ControlButton('Ignore this publication', css='red', default=self.__ignore_this_pub_evt, label_visible=False) self._info = ControlLabel(text) self._details = ControlEmptyWidget(parent=self, name='_details', default=PubsList(**kwargs)) self.formset = [ '_ignorebtn', '_info', ('_person', '_authoralias', '_addalias'), '_authors', segment('_details', css='secondary') ] if len(self._authors.value) == 0: self._authors.hide()
class UpdatePublication(BaseWidget): TITLE = 'Search publication' LAYOUT_POSITION = conf.ORQUESTRA_NEW_BIGWINDOW def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) authors = kwargs.get('authors') title = kwargs.get('title') journal_name = kwargs.get('journal_name') doi = kwargs.get('doi') pubdate = kwargs.get('pubdate') pubyear = kwargs.get('pubyear') self.pub_hash = str( (authors, title, journal_name, doi, pubdate, pubyear)) text = f""" <table> <tr> <th style='text-align: right' >Title</th> <td style='padding:5px;padding-left:10px;' colspan='3' >{title}</th> <tr/> <tr> <th style='text-align: right' >Authors</th> <td style='padding:5px;padding-left:10px;' colspan='3' >{authors}</th> <tr/> <tr> <th style='text-align: right' >Journal</th> <td style='padding:5px;padding-left:10px;' >{journal_name}</th> <th style='text-align: right' >Pub date</th> <td style='padding:5px;padding-left:10px;' >{pubdate}</th> <tr/> <tr> <th style='text-align: right' >Year</th> <td style='padding:5px;padding-left:10px;' >{pubyear}</th> <th style='text-align: right' >Doi</th> <td style='padding:5px;padding-left:10px;' >{doi}</th> <tr/> </table> """ self._person = ControlAutoComplete( 'Author', queryset=Person.objects.all().order_by('full_name'), visible=False) self._authoralias = ControlText('Author alias', visible=False) self._addalias = ControlButton('Add alias', default=self.__add_author_alias_evt, visible=False) alias = AuthorAlias.objects.all() self._authors = ControlList( 'Unknown authors', default=[[a] for a in authors.split(';') if not alias.filter(name=a).exists()], horizontal_headers=['Authors alias'], item_selection_changed_event=self.__authors_selection_changed_evt) self._ignorebtn = ControlButton('Ignore this publication', css='red', default=self.__ignore_this_pub_evt, label_visible=False) self._info = ControlLabel(text) self._details = ControlEmptyWidget(parent=self, name='_details', default=PubsList(**kwargs)) self.formset = [ '_ignorebtn', '_info', ('_person', '_authoralias', '_addalias'), '_authors', segment('_details', css='secondary') ] if len(self._authors.value) == 0: self._authors.hide() def __authors_selection_changed_evt(self): if self._authors.selected_row_index >= 0: self._addalias.show() self._authoralias.show() self._person.show() self._authoralias.value = self._authors.value[ self._authors.selected_row_index][0] else: self._addalias.hide() self._authoralias.hide() self._person.hide() def __add_author_alias_evt(self): if self._authoralias.value and self._person.value: a = AuthorAlias(name=self._authoralias.value, person=Person.objects.get(pk=self._person.value)) a.save() data = self._authors.value newdata = [] for row in data: if row[0] == self._authoralias.value: continue newdata.append(row) self._authors.value = newdata self._addalias.hide() self._authoralias.hide() self._person.hide() def __ignore_this_pub_evt(self): filepath = os.path.join(settings.MEDIA_ROOT, conf.APP_IMPORT_PUBLICATIONS_BLACKLIST_FILE) with open(filepath, 'a') as out: out.write(str(self.pub_hash) + '\n') self.close() @classmethod def has_permissions(cls, user): if user.is_superuser: return True return user.groups.filter( permissions__codename__in=['app_access_imp_pub']).exists()