class DomainManager(ObjectsManager): manager_name = u"domains" manager_verbose_name = u"مدیریت حوزه ها" filter_form = DomainForm actions = [ AddAction(DomainActionForm), EditAction(DomainActionForm, action_verbose_name=u"بررسی و ویرایش"), DeleteAction() ] def get_all_data(self): return Domain.objects.filter() def get_columns(self): columns = [ ManagerColumn('name', u"نام حوزه", '10'), ManagerColumn('confirmed', u"تایید شده", '10'), ManagerColumn('requester', u"درخواست دهنده", '10', True, True), ] return columns def can_view(self): if PermissionController.is_admin(self.http_request.user): return True return False def get_requester(self, data): if not data.confirmed: clusters = data.clusters.all() if clusters: link = u"/clusters/actions/?t=action&n=edit_cluster&i=%s" % clusters[ 0].id return u"""<a onClick="MyWindow=window.open('%s','خوشه/فرد',width=800,height=600); return false;"href='#' class="jqgrid-a">%s</a>""" % ( link, unicode(clusters[0])) return None
class MessageManager(ObjectsManager): manager_name = u"news_manager" manager_verbose_name = u"اخبار" filter_form = NewsFilterForm actions = [ AddAction(NewsForm, save_def=save_news), EditAction(NewsForm), ShowAction(NewsShowForm, height='350'), DeleteAction(), ] def get_all_data(self): return News.objects.filter() def get_columns(self): columns = [ ManagerColumn('title', u"عنوان", 7), ManagerColumn('body', u"متن", 20, True), ManagerColumn('created_on', u"تاریخ ایجاد", 3), ManagerColumn('publish_date', u"تاریخ انتشار", 3), ] return columns def get_body(self, obj): body = obj.body.replace('\r\n', ' ').replace('\n\r', ' ').replace( '\r', ' ').replace('\n', ' ') if len(body) > 45: body = body[:45] + ' ...' return body
class MemberProjectManager(ObjectsManager): manager_name = u"projects" manager_verbose_name = u"طرح های من" filter_form = MemberProjectFilterForm actions = [EditProjectAction(),ProjectReportUploadAction(), DeleteAction(action_verbose_name=u"انصراف از طرح"), ProjectDetailAction(for_admin=False)] def can_view(self): if PermissionController.is_member(self.http_request.user): return True def get_all_data(self): return Project.objects.filter( Q(single_member=self.http_request.user.member) | Q(cluster__members__user=self.http_request.user)) def get_columns(self): columns = [ ManagerColumn('title', u"عنوان", '10'), ManagerColumn('keywords', u"کلید واژه ها", '10'), ManagerColumn('domain', u"حوزه طرح", '10'), ManagerColumn('state', u"مرحله", '10'), ManagerColumn('project_status', u"مرحله داوری", '10'), ManagerColumn('attended_members', u"انجام دهنده ها", '20', True), ] return columns def get_attended_members(self, data): return u"، ".join([unicode(x) for x in data.attended_members.all()]) def get_filter_form_content(self): return """
class ContactManager(ObjectsManager): manager_name = u"contact_manager" manager_verbose_name = u"تماس ها" filter_form = ContactFilterForm actions = [ DeleteAction(), ShowAction(ContactShowForm, height='350'), ] def get_all_data(self): return ContactUs.objects.filter() def get_columns(self): columns = [ ManagerColumn('title', u"عنوان", 7), ManagerColumn('body', u"متن", 20, True), ManagerColumn('email', u"پست الکترونیک", 7), ManagerColumn('created_on', u"تاریخ ایجاد", 3), ] return columns def get_body(self, obj): body = obj.body.replace('\r\n', ' ').replace('\n\r', ' ').replace( '\r', ' ').replace('\n', ' ') if len(body) > 45: body = body[:45] + ' ...' return body
class ClusterManager(ObjectsManager): manager_name = u"clusters" manager_verbose_name = u"مدیریت خوشه ها" filter_form = ClusterForm actions = [ ShowAction(ClusterActionForm, height='300'), EditClusterAction(), ClusterConfirmAction(), DeleteAction() ] filter_handlers = ( ('name', 'str'), ('domains', 'm2m'), ('institute', 'str'), ('head', 'm2o'), ('degree', 'this'), ('members', '', 'members__in'), ('confirmed', 'null_bool', 'head__is_confirmed'), ) def get_all_data(self): return Cluster.objects.filter() def get_columns(self): columns = [ ManagerColumn('name', u"نام خوشه", '10'), ManagerColumn('domains', u"حوزه فعالیت", '10', True), ManagerColumn('institute', u"دانشگاه / موسسه", '10'), ManagerColumn('head', u"سر خوشه", '10'), ManagerColumn('users', u"اعضا", '11', True, True), ManagerColumn('created_on', u"تاریخ ثبت", '10'), ManagerColumn('confirm', u"تاییدشده", '10', True), ManagerColumn('degree', u"درجه", '10'), ] return columns def get_domains(self, data): return u', '.join([unicode(d) for d in data.domains.filter()]) def get_users(self, data): res = u"""<ol>""" for item in data.get_members_and_links(): if item[1]: res += u"""<li><a onClick="MyWindow=window.open('%s','جزئیات عضو',width=800,height=600); return false;"href='#' class="jqgrid-a">%s</a></li>""" % ( item[1], item[0]) else: res += u"""<li>%s (عدم ثبت نام)</li>""" % (item[0]) res += u"""</ol>""" return res def get_confirm(self, data): return data.head.is_confirmed def can_view(self): if PermissionController.is_admin(self.http_request.user): return True return False
def __init__(self, http_request): super(MessageManager, self).__init__(http_request=http_request) if PermissionController.is_admin(http_request.user): self.actions = [ SendMessage(), DeleteAction(), ShowMessage(), SendEmail(), ]
class FeedbackManager(ObjectsManager): manager_name = u"feedback_manager" manager_verbose_name = u"مشاهده نظرات و پیشنهادات" filter_form = FeedbackFilterForm actions = [ DeleteAction(), ShowAction(FeedbackShowForm, height='350'), ] def get_all_data(self): return Feedback.objects.filter() def get_columns(self): columns = [ ManagerColumn('title', u"عنوان", 7), ManagerColumn('body', u"متن", 20, True), ManagerColumn('creator', u"ایجادکننده", 3), ManagerColumn('created_on', u"تاریخ ایجاد", 3), ManagerColumn('feeder', u"پیشنهاددهنده", 3, True, True), ManagerColumn('cluster_feeder', u"خوشه پیشنهاددهنده", 5, True, True), ] return columns def get_body(self, obj): body = obj.body.replace('\r\n', ' ').replace('\n\r', ' ').replace( '\r', ' ').replace('\n', ' ') if len(body) > 45: body = body[:45] + ' ...' return body def get_feeder(self, data): from cluster.account.account.models import Member try: link = u"/members/actions/?t=action&n=edit_member&i=%s" % data.creator.member.id return u"""<a onClick="MyWindow=window.open('%s','خوشه/فرد',width=800,height=600); return false;"href='#' class="jqgrid-a">%s</a>""" % ( link, unicode(data.creator.member)) except Member.DoesNotExist: return None def get_cluster_feeder(self, data): from cluster.account.account.models import Member, Cluster try: if data.creator.member.cluster: link = u"/clusters/actions/?t=action&n=edit_cluster&i=%s" % data.creator.member.cluster.id return u"""<a onClick="MyWindow=window.open('%s','خوشه/فرد',width=800,height=600); return false;"href='#' class="jqgrid-a">%s</a>""" % ( link, unicode(data.creator.member.cluster)) except (Member.DoesNotExist, Cluster.DoesNotExist): return None
class ProjectsManagement(ObjectsManager): manager_name = u"projects_management" manager_verbose_name = u"مدیریت طرح ها" filter_form = ProjectsManagementFilterForm actions = [AdminProjectCheckAction(), ProjectDetailAction(), DeleteAction()] filter_handlers = ( ('title', 'str'), ('keywords', 'str'), ('domain', 'm2m'), ('project_status', 'int'), ('cluster', 'm2m'), ('single_member', 'm2m'), ('milestone_from', 'pdate', 'milestones__milestone_date__gte'), ('milestone_until', 'pdate', 'milestones__milestone_date__lte'), ) def can_view(self): if PermissionController.is_admin(self.http_request.user): return True return False def get_all_data(self): return Project.objects.filter() def get_columns(self): columns = [ ManagerColumn('title', u"عنوان", '10'), ManagerColumn('cluster', u"خوشه/عضو", '10', True, True), ManagerColumn('keywords', u"کلید واژه ها", '10'), ManagerColumn('domain', u"حوزه طرح", '10'), ManagerColumn('state', u"مرحله", '10'), ManagerColumn('project_status', u"مرحله داوری", '10'), ManagerColumn('attended_members', u"انجام دهنده ها", '20', True), ] return columns def get_cluster(self, data): if data.cluster: link = u"/clusters/actions/?t=action&n=edit_cluster&i=%s" % data.cluster.id return u"""<a onClick="MyWindow=window.open('%s','خوشه/فرد',width=800,height=600); return false;"href='#' class="jqgrid-a">%s</a>""" % ( link, unicode(data.cluster)) if data.single_member and not data.cluster: link = u"/members/actions/?t=action&n=edit_member&i=%s" % data.single_member.id return u"""<a onClick="MyWindow=window.open('%s','خوشه/فرد',width=800,height=600); return false;"href='#' class="jqgrid-a">%s</a>""" % ( link, unicode(data.single_member)) def get_attended_members(self, data): return u"، ".join([unicode(x) for x in data.attended_members.all()])
class NoClusterMemberManager(MemberManager): manager_name = u"no_cluster_members" manager_verbose_name = u"مدیریت افراد بدون خوشه" filter_form = NoClusterMemberActionForm actions = [ ShowAction(MemberActionForm), DeleteAction(), ConfirmAction('is_confirmed', on_change_event=member_confirm_change) ] def get_all_data(self): return Member.objects.filter(cluster__isnull=True) def get_full_name(self, data): link = u"/members/actions/?t=action&n=edit_member&i=%s" % data.id return u"""<a onClick="MyWindow=window.open('%s','خوشه/فرد',width=800,height=600); return false;"href='#' class="jqgrid-a">%s</a>""" % ( link, unicode(data.user)) def get_columns(self): columns = [ ManagerColumn('full_name', u"نام و نام خانوادگی", '200', True, True), ManagerColumn('cluster', u"خوشه", '150', True, True), ManagerColumn('gender', u"جنسیت", '40'), ManagerColumn('national_code', u"کد ملی", '80'), ManagerColumn('birth_date', u"تاریخ تولد", '80'), ManagerColumn('residence_city', u"شهر محل اقامت", '80'), ManagerColumn('mobile', u"تلفن همراه", '70', True, True), ManagerColumn('military_status', u"وضعیت نظام وظیفه", '80'), ManagerColumn('foundation_of_elites', u"عضویت در بنیاد ملی نخبگان", '80'), ManagerColumn('created_on', u"تاریخ ثبت نام", '80'), ManagerColumn('is_confirmed', u"تایید شده", '60'), ManagerColumn('last_uni', u"آخرین محل تحصیل", '80', True), ManagerColumn('last_end_year', u"سال فارغ التحصیلی", '80', True), ManagerColumn('last_field', u"رشته تحصیلی", '80', True), ManagerColumn('last_orientation', u"گرایش", '80', True), ] return columns filter_handlers = ( ('first_name', 'str', 'user__first_name'), ('last_name', 'str', 'user__last_name'), ('national_code', 'this'), ('military_status', 'this'), ('foundation_of_elites', 'null_bool'), )
class UserManager(ObjectsManager): manager_name = u"users" manager_verbose_name = u"مدیریت کاربران" filter_form = UserForm actions = [DeleteAction(), ChangeUserName(), AddAction(UserForm)] def get_all_data(self): return User.objects.filter() def get_columns(self): columns = [ ManagerColumn('first_name', u"نام", '10'), ManagerColumn('last_name', u"نام خانوادگی", '10'), ManagerColumn('username', u"نام کاربری", '10'), ] return columns def can_view(self): if PermissionController.is_admin(self.http_request.user): return True return False
class LinkManager(ObjectsManager): manager_name = u"links_manager" manager_verbose_name = u"لینک ها" filter_form = LinkFilterForm actions = [ AddAction(LinkForm), EditAction(LinkForm), ShowAction(LinkShowForm, height='350'), DeleteAction(), ] def get_all_data(self): return Link.objects.filter() def get_columns(self): columns = [ ManagerColumn('title', u"عنوان", 12), ManagerColumn('url', u"لینک", 12), ManagerColumn('order', u"ترتیب نمایش", 3), ManagerColumn('created_on', u"تاریخ ایجاد", 4), ] return columns
class SupervisorManager(ObjectsManager): manager_name = u"supervisors_management" manager_verbose_name = u"ناظران" filter_form = SupervisorFilterForm actions = [ AddAction(SupervisorForm), EditAction(SupervisorForm), ShowAction(SupervisorForm), DeleteAction() ] def get_all_data(self): return Supervisor.objects.filter() def get_columns(self): columns = [ ManagerColumn('full_name', u"نام و نام خانوادگی", '30', True), ManagerColumn('email', u"پست الکترونیک", '10', True), ManagerColumn('username', u"نام کاربری", '10', True), ManagerColumn('mobile', u"تلفن همراه", '10'), ] return columns def get_full_name(self, data): return unicode(data) def get_email(self, data): return unicode(data.user.email) def get_username(self, data): return unicode(data.user.username) def can_view(self): if PermissionController.is_admin(self.http_request.user): return True return False
class ArbiterManager(ObjectsManager): manager_name = u"arbiters_management" manager_verbose_name = u"داوران" filter_form = ArbiterFilterForm actions = [AddAction(ArbiterForm, save_def=arbiter_save), EditAction(AdminEditArbiter), ShowAction(AdminEditArbiter), DeleteAction(), ConfirmAction('is_confirmed'), ArbiterInvitationAction()] def get_all_data(self): return Arbiter.objects.filter(invited=False) def get_columns(self): columns = [ ManagerColumn('full_name', u"نام و نام خانوادگی", '30', True), ManagerColumn('gender', u"جنسیت", '10'), ManagerColumn('national_code', u"کد ملی", '10'), ManagerColumn('birth_date', u"تاریخ تولد", '10'), ManagerColumn('workplace', u"نام محل کار", '10'), # ManagerColumn('field', u"رشته", '10'), ManagerColumn('domains', u"حوزه های مورد علاقه", '30', True), ManagerColumn('created_on', u"تاریخ ثبت نام", '10'), ManagerColumn('is_confirmed', u"تایید شده", '10'), ] return columns def get_full_name(self, data): return unicode(data) def get_domains(self, data): return u', '.join([unicode(d) for d in data.interested_domain.filter()]) def can_view(self): if PermissionController.is_admin(self.http_request.user): return True return False
class MessageManager(ObjectsManager): manager_name = u"messages" manager_verbose_name = u"جعبه پیام ها" filter_form = MessageFilterForm actions = [ SendMessage(), DeleteAction(), ShowMessage(), ] filter_handlers = ( ('title', 'str'), ('body', 'str'), ('sender', 'this'), ) def __init__(self, http_request): super(MessageManager, self).__init__(http_request=http_request) if PermissionController.is_admin(http_request.user): self.actions = [ SendMessage(), DeleteAction(), ShowMessage(), SendEmail(), ] def get_all_data(self): return Message.objects.filter( Q(receivers=self.http_request.user) | Q(sender=self.http_request.user)) def get_columns(self): columns = [ ManagerColumn('sender', u"فرستنده", 5), ManagerColumn('title', u"عنوان", 7), ManagerColumn('body', u"متن", 15, True), ManagerColumn('receiver', u"گیرنده", 5, True), # ManagerColumn('state', u"خوانده شده", 3, True), ] return columns def get_body(self, obj): body = obj.body.replace('\r\n', ' ').replace('\n\r', ' ').replace( '\r', ' ').replace('\n', ' ') if len(body) > 45: body = body[:45] + ' ...' return body def get_receiver(self, obj): res = [] six = obj.receivers.all()[0:6] for item in six[0:5]: res.append(unicode(item)) output = u','.join(res) if len(six) == 6: output += " ..." return output def get_state(self, obj): state = obj if state == Message.READ: return u"بله" # result = u'<img src="/static/manager/images/read.png" />' else: return u"خیر" # result = u'<img src="/static/manager/images/unread.png" />' def other_filter_func(self, all_data, form): if form: form_data = form.data status = form_data.get('status') if status == u'2': all_data = all_data.filter( sender=self.http_request.user).distinct() elif status == u'3': pass else: all_data = all_data.filter( receivers=self.http_request.user).distinct() return all_data