Filled in Graduation parsing in export_mysql
[sitecorepy.git] / sitecore / prof / __init__.py
1 #!/usr/bin/env python
2 # Copyright (C) 2010 W. Trevor King <wking@drexel.edu>
3 #
4 # This file is part of SiteCorePy.
5 #
6 # SiteCorePy is free software; you can redistribute it and/or modify it
7 # under the terms of the GNU General Public License as published by the
8 # Free Software Foundation, either version 2 of the License, or (at your
9 # option) any later version.
10 #
11 # SiteCorePy is distributed in the hope that it will be useful, but
12 # WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 # General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License
17 # along with SiteCorePy.  If not, see <http://www.gnu.org/licenses/>.
18
19 """
20 Sitecore Faculty Profile        Corresponding Information
21
22 Faculty Information
23 -------------------
24 Degrees*        Degrees Earned (i.e. Dr., PhD)
25 College*        University Graduated From
26 Program Area Within Department (i.e. Anthropology)
27 Office* Office Location
28 Office Hours    (If applicable)
29 Specialization* Research Areas/Specialization
30 Publications    Publications Listing (If applicable)
31 Professional Society    (If applicable)
32 Academic Distinctions   (If applicable)
33 Research Interests      (Please use "Specialization" Field)
34 Personal Site   Website Address (If applicable)
35
36 Personal Profile
37 ----------------
38 Title*  Professional Title (i.e. Director of Publication Management)
39 First Name*     First Name / Middle Name
40 Last Name*      Last Name
41 Bio     Brief Bio/Profile/Blurb
42 Short Bio       Presentations (If applicable)
43 Headshot*       Photograph - Size should be width: 125px height: 150px 
44 Email*  Email
45 Phone*  Phone # - Please use this format: (111) 111-1111
46 Fax     Lab Name, Lab Phone (If applicable, please use "Lab Name, Lab Phone" format)
47 CV      Resume
48
49 * field required.
50
51 If a basic text field (a field with no "editor") has more than one
52 item in it then separate the items with a comma. For example: If a
53 faculty member has more than one title, then list their titles like
54 this: Professor of Communication, Director of Publication Management,
55 Yearbook Advisor, etc.
56 """
57
58 class AttributeHolder (object):
59     fields = []
60
61     def __init__(self, *args, **kwargs):
62         for field in self.fields:
63             setattr(self, field, None)
64         for field,arg in zip(self.fields, args):
65             setattr(self, field, arg)
66         for field,value in kwargs.items():
67             assert field in self.fields, '%s not in %s' % (field, self.fields)
68             setattr(self, field, value)
69
70     def __str__(self):
71         return self.__unicode__()
72
73     def __repr__(self):
74         return '<%s>' % self.__unicode__().replace('\n',';')
75
76     def __unicode__(self):
77         lines = ['%s:' % self.__class__.__name__]
78         for field in self.fields:
79             value = getattr(self, field)
80             if value == None:
81                 continue
82             if isinstance(value, (tuple, list)):
83                 for v in value:
84                     lines.extend(self._format_value(field, v))
85             else:
86                 lines.extend(self._format_value(field, value))
87         return u'\n'.join(lines)
88
89     def _format_value(self, field, value):
90         value_lines = unicode(value).splitlines()
91         if isinstance(value, AttributeHolder):
92             prefix = '  '
93         else:
94             prefix = '  %s: ' % field
95         return ['%s%s' % (prefix, L) for L in value_lines]
96
97 class Name (AttributeHolder):
98     fields = ['first_middle', 'last']
99
100 class Graduation (AttributeHolder):
101     fields = ['college', 'field', 'title', 'year']
102
103 class Contact (AttributeHolder):
104     fields = ['office', 'email', 'website', 'phone', 'lab', 'lab_phone']
105
106 class Bio (AttributeHolder):
107     fields = ['specialization', 'publications', 'profile', 'cv']
108
109 class Professor (AttributeHolder):
110     fields = ['name', 'title', 'graduations', 'contact', 'bio']
111
112 #  LocalWords:  SiteCorePy