VC: Fix error on clone page for legacy-ID events
[cds-indico.git] / indico / MaKaC / badgeDesignConf.py
blob8eaef648ce8bab4677c9ee688e4025cab0ae22a9
1 # This file is part of Indico.
2 # Copyright (C) 2002 - 2015 European Organization for Nuclear Research (CERN).
4 # Indico is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License as
6 # published by the Free Software Foundation; either version 3 of the
7 # License, or (at your option) any later version.
9 # Indico is distributed in the hope that it will be useful, but
10 # WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 # General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with Indico; if not, see <http://www.gnu.org/licenses/>.
17 from MaKaC.registration import Registrant
18 from conference import Conference
19 from badge import BadgeTemplateItem
20 from MaKaC.webinterface.common.countries import CountryHolder
21 from MaKaC.i18n import _
22 from indico.util.date_time import format_date
23 from indico.util.string import safe_upper
26 class RegistrantBadge:
28 @classmethod
29 def getArgumentType(cls):
30 return Registrant
32 class RegistrantCountry(RegistrantBadge):
34 @classmethod
35 def getValue(cls, reg):
36 return CountryHolder().getCountryById(reg.getCountry())
39 class RegistrantFullName2(RegistrantBadge):
40 """
41 FullName without Title.
42 """
43 @classmethod
44 def getValue(cls, reg):
45 return reg.getFullName(title=False)
47 class RegistrantFullName3(RegistrantBadge):
48 """
49 FullName with Title and with the FirstName first.
50 """
51 @classmethod
52 def getValue(cls, reg):
53 return reg.getFullName(firstNameFirst=True)
55 class RegistrantFullName4(RegistrantBadge):
56 """
57 FullName without Title and with the FirstName first.
58 """
59 @classmethod
60 def getValue(cls, reg):
61 return reg.getFullName(title=False, firstNameFirst=True)
63 class RegistrantFullName5(RegistrantBadge):
64 """
65 FullName with Title, the FirstName first and uppercase in surname.
66 """
68 @classmethod
69 def getValue(cls, reg):
70 res = "%s %s" % (reg.getFirstName(), safe_upper(reg.getFamilyName()))
71 res = res.strip()
72 if reg.getTitle() != "":
73 res = "%s %s" % (reg.getTitle(), res)
74 return res
77 class RegistrantFullName6(RegistrantBadge):
78 """
79 FullName without Title, the FirstName first and uppercase inthe surname.
80 """
82 @classmethod
83 def getValue(cls, reg):
84 res = "%s %s" % (reg.getFirstName(), safe_upper(reg.getFamilyName()))
85 res = res.strip()
86 return res
88 class ConferenceDates:
90 @classmethod
91 def getArgumentType(cls):
92 return Conference
94 @classmethod
95 def getValue(cls, conf):
96 adjusted_sDate = conf.getAdjustedStartDate()
97 adjusted_eDate = conf.getAdjustedEndDate()
98 confDateInterval = _("%s to %s") % (format_date(adjusted_sDate, format='long'), format_date(adjusted_eDate, format='long'))
99 if adjusted_sDate.strftime("%d%B%Y") == \
100 adjusted_eDate.strftime("%d%B%Y"):
101 confDateInterval = format_date(adjusted_sDate, format='long')
102 elif adjusted_sDate.strftime("%B%Y") == adjusted_eDate.strftime("%B%Y"):
103 confDateInterval = "%s-%s %s" % (adjusted_sDate.day, adjusted_eDate.day, format_date(adjusted_sDate, format='MMMM yyyy'))
104 return confDateInterval
107 class BadgeDesignConfiguration:
108 """ This class has 2 objects:
109 -items_actions maps the name of an item to the action that should be taken
110 at the time it is drawed.
111 -groups organizes the item names into groups. These groups are used for the
112 <select> box in the WConfModifBadgeDesign.tpl file.
115 """ Dictionary that maps the name of an item to the action that should be taken
116 at the time it is drawed.
117 An action can be:
118 -A method: depending on the class owning the method, a Conference object,
119 a Registrant object, or a BadgeTemplateItem object should be passed to the method.
120 The method must return a string.
121 For example: 'Full Name' : Registrant.getFullName means that, if a badgeTemplate
122 has a 'Full Name' item, each time a badge will be drawed, the Full Name of the
123 registrant will be drawed as returned by the method getFullName of the class Registrant.
124 -A class: when there is no method already available for what we need, we have
125 to write a custom class (see classes above).
126 These classes must have 2 methods:
127 *it must have a getArgumentType() method, which returns either Conference, Registrant or BadgeTemplateItem.
128 Depending on what is returned, we will pass a different object to the getValue() method.
129 *it must have a getValue(object) method, to which a Conference instance, a Registrant instance or a
130 BadgeTemplateItem instance must be passed, depending on the result of the getArgumentType() method.
133 def __init__(self):
135 self.items_actions = { "Title": (_("Title"), Registrant.getTitle),
136 "Full Name": (_("Full Name"), Registrant.getFullName),
137 "Full Name (w/o title)": (_("Full Name (w/o title)"), RegistrantFullName2),
138 "Full Name B": (_("Full Name B"), RegistrantFullName3),
139 "Full Name B (w/o title)": (_("Full Name B (w/o title)"), RegistrantFullName4),
140 "Full Name C": (_("Full Name C"), RegistrantFullName5),
141 "Full Name C (w/o title)": (_("Full Name C (w/o title)"), RegistrantFullName6),
142 "First Name": (_("First Name"), Registrant.getFirstName),
143 "Surname": (_("Surname"), Registrant.getSurName),
144 "Position": (_("Position"), Registrant.getPosition),
145 "Institution": (_("Institution"), Registrant.getInstitution),
146 "Country": (_("Country"), RegistrantCountry),
147 "City": (_("City"), Registrant.getCity),
148 "Address": (_("Address"), Registrant.getAddress),
149 "Phone": (_("Phone"), Registrant.getPhone),
150 "Fax": (_("Fax"), Registrant.getFax),
151 "Email": (_("Email"), Registrant.getEmail),
152 "Personal homepage": (_("Personal homepage"), Registrant.getPersonalHomepage),
153 "Amount": (_("Amount"), Registrant.getTotal),
154 "Conference Name": (_("Conference Name"), Conference.getTitle),
155 "Conference Dates": (_("Conference Dates"), ConferenceDates),
156 "Fixed Text": (_("Fixed Text"), BadgeTemplateItem.getFixedText)
159 """ Dictionary that maps group names to the item names that fall into that group.
160 The groups are only used for the <select> box in the WConfModifBadgeDesign.tpl file.
162 self.groups = [( _("Registrant Data"), [ "Title", "Full Name", "Full Name (w/o title)", "Full Name B", "Full Name B (w/o title)", "Full Name C", "Full Name C (w/o title)", "First Name", "Surname", "Position",
163 "Institution", "Country", "City", "Address", "Phone", "Fax", "Email", "Personal homepage", "Amount"]),
164 ( _("Conference Data"), [ "Conference Name", "Conference Dates"]),
165 ( _("Fixed Elements"), [ "Fixed Text"])]